I'm trying to use the Oboe library to generate sound in my Android Studio project, but I'm having some issues.
I followed this documentation https://github.com/google/oboe/blob/main/docs/FullGuide.md and I wrote this code that supposed to play a sound but when I execute it I only hear a noise that lasts less than a second.
I have increased the size of the buffer and number of frames and still I get the same result.
The expected result should be the sound lasts for more than 1 second.
Exactly 80096/22000 = ~3.64
seconds.
#include "createStream.h"
int main() {
oboe::AudioStreamBuilder streamBuilder;
streamBuilder.setSampleRate(22000);
std::shared_ptr<oboe::AudioStream> mStream;
oboe::Result result = streamBuilder.openStream(mStream);
if (result != oboe::Result::OK) {
return 10;
}
result = mStream->requestStart();
int16_t buffer[80096];
int numFrames = sizeof(buffer) / sizeof(buffer[0]);
for (int i = 0; i < 80096; i++) {
int a = rand() % 65536;
buffer[i] = a;
}
mStream->write(buffer, numFrames, -1);
if (result != oboe::Result::OK) {
return 9;
}
mStream->requestStop();
mStream->close();
return 150;
}