【问题标题】:onAudioReady callback method for Oboe is never called永远不会调用 Oboe 的 onAudioReady 回调方法
【发布时间】:2020-04-17 21:01:16
【问题描述】:

我正在将双簧管库用于在 Qt 中开发的音乐 android 应用程序。

在我从 AudioStreamCallback 派生的声音处理类中,我使用构建器创建录制和播放流,这工作正常,我收到 AAUDIO_OK 作为打开两个流的结果。我已将此类注册为两个流上的回调,但由于某种原因,我的 onAudioReady 回调方法从未为任何一个流调用。我在下面简化了我的代码,但它让我发疯,我一定是做错了什么,但我想不通。

#include <oboe/Oboe.h>
#include <QDebug>

class CSound : pulic QThread, public oboe::AudioStreamCallback
{
public:
   CSound() {    }

   void CSound::setupStreams() {
      mCallback = this;
      oboe::AudioStreamBuilder inBuilder, outBuilder;
      outBuilder->setCallback(mCallback)
           ->setDirection(oboe::Direction::Output)
           ->setChannelCount(oboe::ChannelCount::Stereo)
           ->setFormat(oboe::AudioFormat::Float)
           ->setSharingMode(oboe::SharingMode::Exclusive)
           ->setPerformanceMode(oboe::PerformanceMode::LowLatency);
       oboe::Result result = outBuilder.openManagedStream(mPlayStream);
       if (result != oboe::Result::OK) {
         return;
       }
       inBuilder->setCallback(mCallback)
            ->setDirection(oboe::Direction::Input)
            ->setBufferCapacityInFrames(256)
            ->setSampleRate(48000)
            ->setChannelCount(oboe::ChannelCount::Stereo)
            ->setFormat(oboe::AudioFormat::Float)
            ->setSharingMode(oboe::SharingMode::Exclusive)
            ->setPerformanceMode(oboe::PerformanceMode::LowLatency);
       result = inBuilder.openManagedStream(mRecordingStream);
       if (result != oboe::Result::OK) {
           qInfo() << "Error, stream closing";
           closeStream(mPlayStream);
           return;
       } 
   }

   virtual oboe::DataCallbackResult onAudioReady(oboe::AudioStream *oboeStream, void *audioData, int32_t numFrames) {
       qInfo() << "Never called";
   }

private:
   AudioStreamCallback *mCallback;
   oboe::ManagedStream mRecordingStream;
   oboe::ManagedStream mPlayStream;
};

CSound::Start()

所以当我在 android 模拟器中运行应用程序时,我会在控制台中看到以下内容:

D AAudio  : AAudioStreamBuilder_openStream() called ----------------------------------------
D AudioStreamBuilder: build() EXCLUSIVE sharing mode not supported. Use SHARED.
D         : PlayerBase::PlayerBase()
I AAudioStream: open() rate   = 0, channels    = 2, format   = 2, sharing = SH, dir = OUTPUT
I AAudioStream: open() device = 0, sessionId   = 0, perfMode = 12, callback: ON with frames = 0
I AAudioStream: open() usage  = 1, contentType = 2, inputPreset = 6
D AudioStreamTrack: open(), request notificationFrames = -8, frameCount = 0
I AudioTrack: AUDIO_OUTPUT_FLAG_FAST successful; frameCount 0 -> 5760
W AudioStreamTrack: open() sampleRate changed from 0 to 48000
W AudioStreamTrack: open() flags changed from 0x00000104 to 0x00000004
D AAudio  : AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for (0xd807c400) ----------------
D AAudio  : AAudioStreamBuilder_openStream() called ----------------------------------------
D AudioStreamBuilder: build() EXCLUSIVE sharing mode not supported. Use SHARED.
D         : PlayerBase::PlayerBase()
I AAudioStream: open() rate   = 48000, channels    = 2, format   = 2, sharing = SH, dir = INPUT
I AAudioStream: open() device = 0, sessionId   = 0, perfMode = 12, callback: ON with frames = 0
I AAudioStream: open() usage  = 1, contentType = 2, inputPreset = 6
D AudioStreamRecord: open() used a different device format but no FAST path, reopen
W AudioStreamRecord: open() flags changed from 0x00000005 to 0x00000000
W AudioStreamRecord: open() perfMode changed from 12 to 10
D AAudio  : AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for (0xd71d7200) ----------------

【问题讨论】:

    标签: android c++ qt oboe


    【解决方案1】:

    传递 (this) 是正确的,因为您的类实现了 oboe::AudioStreamCallback。

    我注意到您对输入和输出使用相同的回调方法。 通常我们只使用一个输出回调,然后从输出回调中读取输入流中的数据。

    【讨论】:

      【解决方案2】:

      我想通了。指向错误的是回调。我改了

      inBuilder->setCallback(mCallback)
      

      inBuilder->setCallback(this)
      

      这导致回调触发。我需要弄清楚为什么

      AudioStreamCallback *mCallback
      

      不是存储指向 this 的正确类型!

      【讨论】:

        【解决方案3】:
        managedStream->requestStart();
        

        openManagedStream之后是必需的。

        例如:

        Result result = builder.setDirection(Direction::Input)
                ->setPerformanceMode(PerformanceMode::PowerSaving)
                ->setSampleRate(sampleRate)
                ->setSharingMode(SharingMode::Exclusive)
                ->setFormat(AudioFormat::Float)
                ->setChannelCount(ChannelCount::Mono)
                ->setCallback(callback)
                ->openManagedStream(managedStream);
        
        if (result == Result::OK) {
            managedStream->requestStart();
        }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-08-09
          • 1970-01-01
          • 2014-06-22
          • 2012-02-18
          • 1970-01-01
          • 1970-01-01
          • 2017-01-19
          相关资源
          最近更新 更多