Closed dbajpeyi closed 2 years ago
The problem is the way you're doing your pointer offsetting. You should instead make them void pointers and offset them with ma_get_bytes_per_frame(format, channels)
. In the callback you have this:
double* buffArr = *(buffer) + start;
That's wrong. Instead you should do something like this:
void* buffArr = ma_offset_ptr(*buffer, start * ma_get_bytes_per_frame(pDecoder->outputFormat, pDecoder->outputChannels));
That's assuming start
is in PCM frames and not bytes, which it looks like it is if I'm reading it correctly.
Also, with your buffer allocation:
outputBuffer = malloc(buffLength * sizeof(*outputBuffer));
Change that this:
outputBuffer = malloc(buffLength * ma_get_bytes_per_frame(pDecoder->outputFormat, pDecoder->outputChannels));
The only reason this wasn't crashing is by coincidence. If you had passed in a file with, say, 4 channels, it would have crashed.
So to summarise, as a start I would replace all of your double*
pointers with void*
and offset with ma_offset_ptr()
and ma_get_bytes_per_frame()
. Once you've done that let me know if you have any other issues and we'll go from there.
Aha! Right I mixed up the idea of frames with bytes. Damn! Thank you for the hints, I will try this out and get back with results.
Alright! That worked out! Thank you so much for the help :)
Scenario
I am trying to:
ma_decoder_read_pcm_frames
,pOutput
to anoutputBuffer
and,outputBuffer
usingma_encoder_write_pcm_frames
Seems like the copy ends up copying 0.0000 into certain equal sections of 480 frames. On inspecting the output on Audacity, this is clear:
Here are the missing spots:
My approach is here in this gist.
Debug info
What I found interesting is that there's for some reason resampling going on, although in my code I use the decoder's settings from the input file.
Also apologies in advance - I am a fresher when it comes to C and audio in C :) Any help would be a big learning experience for me :)