onAudioReady callback method for Oboe is never called

0

I'm using Oboe library for a music android app developing in Qt.

In my sound processing class which dervives from AudioStreamCallback I use the builder to create both a recording and playback stream and this works fine and I received AAUDIO_OK as a result for opening boths streams. I've registered this class as the callback on both streams, but for some reason my onAudioReady callback method is never called for either stream. I've simplied my code below, but it's driving me mad, I must be doing something really basically wrong, but I can't figure it out.

#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()

So when I run the app within the android emulator, I get the following in the console:

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
asked on Stack Overflow Apr 17, 2020 by user3518443

3 Answers

2

Passing (this) is correct because your class implements oboe::AudioStreamCallback.

I notice that you are using the same callback method for both input and output. Normally we only use an output callback and then read() data from the input stream from the output callback.

answered on Stack Overflow May 21, 2020 by philburk
0

I've figured it out. It was the pointed to the callback that was wrong. I changed the

inBuilder->setCallback(mCallback)

to

inBuilder->setCallback(this)

and that caused the callback to trigger. I'll need to figure out why

AudioStreamCallback *mCallback

is not the right type to store the point to this!

answered on Stack Overflow Apr 17, 2020 by user3518443
0
managedStream->requestStart();

is required after openManagedStream.

For example:

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();
}
answered on Stack Overflow Nov 14, 2020 by Yuya Matsuo

User contributions licensed under CC BY-SA 3.0