When porting from NAOqi to qi framework I achieved a partial success. I do however still have the following problem. I do not know how to implement sound processing with ALSound
To use this API, you must write a Qi Service that advertises this method:
void processRemote(
int nbOfChannels,
int nbrOfSamplesByChannel,
const qi::AnyValue& timestamp,
const qi::AnyValue& buffer)
{
std::pair charBuffer = value.unwrap().asRaw();
const signed short* data = (const signed short*)charBuffer.first;
// process the data like in the example.
}
Note that with the Qi framework:
AL::ALValue
is replaced by qi::AnyValue
.
Getting the binary data (aka "raw") is slightly different.AL_SOUND_FORMAT
is replaced by signed short*
.ALSoundExtractor
is not available, so we needed to do the conversion to const AL_SOUND_FORMAT*
by ourselves.Say your service is registered as "MySoundExtractor"
, you will have to tell ALAudioDevice
to start the sound extraction and send the data to your service as follows:
auto audio = session->service("ALAudioDevice").value();
int nNbrChannelFlag = 0; // ALL_Channels: 0, AL::LEFTCHANNEL: 1, AL::RIGHTCHANNEL: 2; AL::FRONTCHANNEL: 3 or AL::REARCHANNEL: 4.
int nDeinterleave = 0;
int nSampleRate = 48000;
audio->setClientPreferences("MySoundExtractor", nSampleRate, nNbrChannelFlag, nDeinterleave);
audio->subscribe("MySoundExtractor");
Note that I did not test this code, so let me know what may be wrong.