videolabs / libspatialaudio

Ambisonic encoding / decoding and binauralization library in C++
Other
192 stars 37 forks source link

AmbisonicProcessor: Rotating around {0, 0, 0} is not a null op in 3rd order #32

Open konradglas opened 3 years ago

konradglas commented 3 years ago

Hi! When I run the code below, I would expect the sound field not being altered at all. But in channel 12 I can see a boost of 3.5. Is this expected, because I am using the processor wrong?

#include "AmbisonicEncoder.h"
#include "AmbisonicProcessor.h"

#include <iostream>
#include <vector>

int main(int argc, char *argv[]) {

  CAmbisonicEncoder encoder;
  encoder.Configure(3, true, 0);
  encoder.SetPosition({0.0, M_PI * 0.5, 0.0});

  int sampleCount = 10;

  std::vector<float> dirac;
  dirac.resize(sampleCount, 0.f);
  dirac[0] = 1.f;

  CBFormat impulse;
  impulse.Configure(3, true, 10);
  // encode a signal from a mono impulse
  encoder.Process(dirac.data(), impulse.GetSampleCount(), &impulse);

  CAmbisonicProcessor processor;
  processor.Configure(3, true, sampleCount, 0);
  processor.SetOrientation({0, 0, 0});
  processor.Refresh();

  std::cout << "Channel 12 at "<< impulse.m_ppfChannels[12][0] << std::endl;
  // rotate by nothing
  processor.Process(&impulse, sampleCount);
  // result is different
  std::cout << "Channel 12 at " << impulse.m_ppfChannels[12][0] << std::endl;
}