NAO robot: porting ALSoundExtractor to qi framwork

后端 未结 4 807
臣服心动
臣服心动 2021-01-22 07:28

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

4条回答
  •  孤独总比滥情好
    2021-01-22 08:23

    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.

提交回复
热议问题