I'm writing an Android application that records audio using Obeo and writes the wave file using libsndfile.
I've verified that the audio stream data is proper by editing the Subchunk2Size which specifies the size of the data portion of the file. This produces a playable audio file, which tells me that the data is being written with the exception of this one variable.
So the question is: Why isn't libsndfile writing the subchunksize (data size) variable into the wave header?
I'm opening the file as RDWR because the audio needs to be appended (when the user pauses, or stops the audio, they can keep recording to the same file).
Here's the file opening code:
Note: the file pointer is global, I've included it there only to show what struct it is.
SF_INFO info;
info.channels = channel_count;
info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
info.samplerate = sample_rate;
// info.seekable = SF_TRUE;
SNDFILE * file = sf_open(url.c_str(), SFM_RDWR, &info);
Obeo returns data using callbacks. This is my callback which is called whenever the audio device fills the specified buffer.
DataCallbackResult Recorder::onAudioReady(
oboe::AudioStream * stream, void * audio_data, int32_t num_of_frames){
// __android_log_print(ANDROID_LOG_INFO,
// "AudioEngine", "Callback!.");
sf_seek(file, 0, SEEK_END);
sf_writef_short(file, reinterpret_cast<const short*>(audio_data), num_of_frames);
return DataCallbackResult::Continue;
}
Later in the class deconstruction, I'm calling:
sf_write_sync(file);
sf_close(file);
This is the hex of the binary data written by Libsndfile.
52494646 08000000 57415645 666D7420 10000000 03000200 44AC0000 20620500 08002000 66616374 04000000 00000000 (data) 64617461 (subchunksize) 00000000
Any information from users who have used libsndfile on linux or android is much appreciated!
Thank you.