[Libav-user] I can't get audio decoding to work.

Bill Messenger apothemmusic at gmail.com
Fri Jun 17 23:06:06 CEST 2016


I'm trying to create a class that uses FFmpeg to decode any audio file and
store it into memory. Then it has a function that returns a float value of
any sample in that buffer. The code I wrote works perfectly for wav and
flac files, produces weird audio for mp3 and ogg files, and crashes on
certain mp3 files. I spent days trying to figure out why it isn't working,
but I can't come up with anything.

I think the reason why the audio is weird for mp3 and ogg files is that it
uses planar audio instead of interleaved audio, but I don't see what's
wrong with the code I wrote. I may be missing something though. For
example, to get a sample for 16 bit interleaved audio I use:

int16_t tmp = ((int16_t*)sampleBuffer)[numChannels*sample + channel];
rv = (float)tmp / 32767.0f;

and to get a sample for 16 bit planar audio I use:

int16_t tmp = ((int16_t*)sampleBuffer)[sample + numSamples*channel];
rv = (float)tmp / 32767.0f;

And I have no clue why it crashes on certain mp3 files. I paid close
attention to make sure there is enough memory allocated in the buffer.
What's even weirder is that the file I created "Chiptune 15 2.mp3" didn't
crash, but when I renamed it to "test.mp3", it crashed! These crashes
happen on line 139 of "AudioDecoder.cpp":

std::memcpy(sampleBuffer + totalBufferSize, frame->extended_data[0],
dataSize);

with an "Access violation reading location" error in vcruntime140d.dll. It
says it isn't with location 0x0000000000000000 or 0xFFFFFFFFFFFFFFFF
though, it's a different random location.

I attached a zip file with the c++ code and two mp3's. Oh yeah, I should
also mention that I'm using MSVC 2015 Community in Windows 10.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160617/c2d577c5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Files.zip
Type: application/zip
Size: 722911 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/libav-user/attachments/20160617/c2d577c5/attachment.zip>


More information about the Libav-user mailing list