Record audio generate by my app, not the mic #1258
-
I understand this is likely out of scope but here is my question: My app allows users to play an instrument along with mp3 audio files. The instrument is powered by Oboe but the mp3 files are played using a MediaPlayer. I want to record/capture the audio generated by my app, not the mic, and save it to an mp3 or other compressed format file. Possible solutions:
Can you please advise on this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Certainly possible, but yes, more difficult to implement than
You could look at using https://developer.android.com/guide/topics/media/playback-capture, however I'm not certain that it works for apps to record their own audio. Should be quite simple to test out though. |
Beta Was this translation helpful? Give feedback.
-
If you want capture the output of your app then this may work. Create an atomic FifoBuffer using the internal FIFO tool from Oboe. uint32_t capacity = sampleRate / 2; Launch a thread that will periodically, maybe every 50 msec, will wake up and Then in your callback, write() a copy of your audio data to the FIFO. It is important that the file is written in a separate thread, not the callback, because file I/O can block and cause glitches in the audio. |
Beta Was this translation helpful? Give feedback.
If you want capture the output of your app then this may work.
Create an atomic FifoBuffer using the internal FIFO tool from Oboe.
https://github.com/google/oboe/blob/master/src/fifo/FifoBuffer.h
Make it fairly large, like a half second worth of data.
uint32_t capacity = sampleRate / 2;
FifoBuffer *fifo = new FifoBuffer(stream->getBytesPerFrame(), capacity);
Launch a thread that will periodically, maybe every 50 msec, will wake up and
read() from the FIFO and write the data to a file.
The fifo->read() method will return the number of frames actually read.
Then in your callback, write() a copy of your audio data to the FIFO.
It is important that the file is written in a separate thread, no…