<div dir="ltr">Update: I found out that it only crashes in debug mode. When I build it in release mode, it doesn't crash. It must be a bug in MSVC 2015 or something.</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 17, 2016 at 4:06 PM, Bill Messenger <span dir="ltr"><<a href="mailto:apothemmusic@gmail.com" target="_blank">apothemmusic@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">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.<div><br></div><div>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:</div><div><br></div><div><div>int16_t tmp = ((int16_t*)sampleBuffer)[numChannels*sample + channel];</div><div>rv = (float)tmp / 32767.0f;</div></div><div><br></div><div>and to get a sample for 16 bit planar audio I use:</div><div><br></div><div><div>int16_t tmp = ((int16_t*)sampleBuffer)[sample + numSamples*channel];</div><div>rv = (float)tmp / 32767.0f;</div></div><div><br></div><div>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":</div><div><br></div><div>std::memcpy(sampleBuffer + totalBufferSize, frame->extended_data[0], dataSize);<br></div><div><br></div><div>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.</div><div><br></div><div>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.</div></div>
</blockquote></div><br></div>