Search code examples
androidc++audiooboe

Android oboe glitch/noise/distortion


I'm trying to use oboe in my audio/video communication app, and I'm trying the onAudioReady round-trip callback as in the oboe guide: https://github.com/google/oboe/blob/main/docs/FullGuide.md

Now I'm frustrating:

  1. If the read directly write into the *audioData, the sound quality is perfect, i.e.:
auto result = recordingStream->read(audioData, numFrames, 0);
  1. But if I add a buffer between them, there is significant noise/glitch which is very undesirable:
auto result = recordingStream->read(buffer, numFrames, 0);
std::copy(buffer, buffer + numFrames, static_cast<int16_t *>(audioData));

By inspecting log, this buffering action is done within 1ms, suppose won't hurt?

Both 1 and 2 also use PCM_I16 audio format, buffer is int16_t * with size of numFrames.

Hopefully someone can point out what's wrong to cause this? Sorry I'm lack of audio processing and c++ knowledge.


Solution

  • I've figured it out because the channel is stereo, samples per frames are 2, i.e.:

    auto result = recordingStream->read(buffer, numFrames, 0);
    std::copy(buffer, buffer + numFrames * 2, static_cast<int16_t *>(audioData));