NAO robot: porting ALSoundExtractor to qi framwork

后端 未结 4 815
臣服心动
臣服心动 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:15

    The following is what has eventually worked for me and concludes the topic.

    // **************** service.h ****************
    
    typedef signed short AL_SOUND_FORMAT;       // copy from alaudio/alsoundextractor.h
    
    class SoundProcessing
      {
    public:
        SoundProcessing(qi::SessionPtr session);
        void init(void);                // a replacement for a function automatically called in NAOqi 2.1.4
        virtual ~SoundProcessing(void); 
        void processRemote(const int& nbOfChannels, const int& nbrOfSamplesByChannel, const qi::AnyValue& timestamp, const qi::AnyValue& buffer);
    
    private:
        qi::SessionPtr _session;
        qi::AnyObject audio;
      };
    
    // **************** service.cpp ****************
    
    SoundProcessing::SoundProcessing(qi::SessionPtr session) : _session(session)
      {
       _session->waitForService("ALAudioDevice");
        audio = _session->service("ALAudioDevice");
      } // constructor
      
    QI_REGISTER_MT_OBJECT(SoundProcessing, init, processRemote);
    
    
    SoundProcessing::~SoundProcessing(void)
      { 
        audio.call("unsubscribe", "SoundProcessing");
      } // destructor
      
    
    void SoundProcessing::init(void)    
      {
        audio.call("setClientPreferences",
                                  "SoundProcessing",
                                 _FREQ48K,          // 48000 Hz requested
                                  0,    
                                  1     
                                );  
                                
        audio.call("subscribe", "SoundProcessing");
      } // SoundProcessing::init
    
    
    void SoundProcessing::processRemote(const int& nbOfChannels,const int& nbrOfSamplesByChannel, const qi::AnyValue& timestamp, const qi::AnyValue& qibuffer)
      { 
        std::pair charBuffer = qibuffer.unwrap().asRaw();
        AL_SOUND_FORMAT *buffer = (AL_SOUND_FORMAT *)charBuffer.first;
        
        (...)
      } // SoundProcessing::process
    
    
    // **************** main.cpp ****************
    
    int main(int argc, char* argv[])
      {
        qi::ApplicationSession app(argc, argv);
        app.start();
        qi::SessionPtr session = app.session();
        
        session->registerService("SoundProcessing", qi::AnyObject(boost::make_shared(session)));
    
        qi::AnyObject sp = session->service("SoundProcessing");
        sp.call("init");
        
        app.run();
        return 0;
      }
    

提交回复
热议问题