<div dir="ltr">Okay, we're finally getting somewhere! I found out that frame->data[0] only contains the data for the left channel. When I play the left channel, it sounds correct. I used frame->linesize[] (0-7) and found that only data[0] contains data. Where is the data for the right channel? I tried calling "avcodec_decode_audio4(codecCtx, frame, &gotFrame, &packet);" twice in the same packet, but that just gave me garbled audio.</div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jun 25, 2016 at 8:39 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">But I tried "std::memcpy(sampleBuffer + totalBufferSize, frame->data[0], dataSize-4);", and it still gave me the same result. I even tried subtracting 8, 16, 32, 64, and so on, and it still gave the same result. When I go up to dataSize/2, however, it doesn't give me that <span style="font-size:12.8px">UNADDRESSABLE ACCESS error. Does frame->data[0] only contain half of the data for planar audio?</span></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 24, 2016 at 6:58 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 used "<span style="color:rgb(0,0,0);white-space:pre-wrap">_heapchk" in every place I could think of in my function, and it always returns "</span><span style="color:rgb(0,0,0);font-family:Consolas,Courier,monospace;font-size:13px;line-height:17.55px">_HEAPOK" before the line that crashes. I can't see the value of _heapchk() after the crash though, Visual Studio won't let me continue after the crash. I also made a new project that just uses the FFmpeg libraries to make sure the problem wasn't with PortAudio or wxWidgets, but it's still crashing in that same place. When I ran it through Dr. Memory with an mp3 or ogg file, it output an UNADDRESSABLE ACCESS error. When I ran it with a wav or flac file, it didn't output that error.</span><div><span style="color:rgb(0,0,0);font-family:Consolas,Courier,monospace;font-size:13px;line-height:17.55px"><br></span></div><div><span style="color:rgb(0,0,0);font-family:Consolas,Courier,monospace;font-size:13px;line-height:17.55px">This is what Dr. Memory output with the mp3 file one: (Line </span><span style="font-size:13px;line-height:17.55px;color:rgb(0,0,0);font-family:Consolas,Courier,monospace">154 of audiodecoder.cpp is the "</span><font color="#000000" face="Consolas, Courier, monospace"><span style="line-height:17.55px">std::memcpy(sampleBuffer + totalBufferSize, frame->data[0], dataSize);" that was crashing before. I guess I should also mention that the crash happens in both 32 bit and 64 bit builds in both debug and release mode.)</span></font><div><br></div><div><div>Dr. Memory version 1.10.1 build 3 built on Apr 10 2016 18:05:55</div><div>Dr. Memory results for pid 2804: "FFmpegTest.exe"</div><div>Application cmdline: "C:\Users\BillM\Documents\My_Files\Code\FFmpegTest\x64\Release\FFmpegTest.exe"</div><div>Recorded 115 suppression(s) from default C:\Program Files (x86)\Dr. Memory\bin64\suppress-default.txt</div><div><br></div><div>Error #1: UNADDRESSABLE ACCESS beyond heap bounds: reading 0x000002a77c94fbb8-0x000002a77c94fbbc 4 byte(s)</div><div># 0 replace_memmove                           [d:\drmemory_package\drmemory\replace.c:763]</div><div># 1 AudioDecoder::decodeFile                  [c:\users\billm\documents\my_files\code\ffmpegtest\ffmpegtest\audiodecoder.cpp:154]</div><div># 2 VCRUNTIME140.dll!set_se_translator       +0x47a    (0x00007ff846f44acb <VCRUNTIME140.dll+0x4acb>)</div><div># 3 VCRUNTIME140.dll!set_se_translator       +0x21b    (0x00007ff846f4486c <VCRUNTIME140.dll+0x486c>)</div><div># 4 MSVCP140.dll!std::basic_ostream<>::flush  [f:\dd\vctools\crt\crtw32\stdhpp\ostream:581]</div><div># 5 KERNEL32.dll!BaseThreadInitThunk         +0x21     (0x00007ff850678102 <KERNEL32.dll+0x18102>)</div><div>Note: @0:00:01.844 in thread 11544</div><div>Note: refers to 1 byte(s) beyond last valid byte in prior malloc</div><div>Note: prev lower malloc:  0x000002a77c94f290-0x000002a77c94fbb7</div><div>Note: allocated here:</div><div>Note: # 0 replace_malloc               [d:\drmemory_package\common\alloc_replace.c:2576]</div><div>Note: # 1 avcodec-57.dll!?            +0x0      (0x00007ff81b56e61c <avcodec-57.dll+0x4fe61c>)</div><div>Note: # 2 avutil-55.dll!?             +0x0      (0x00007ff821617b6c <avutil-55.dll+0x27b6c>)</div><div>Note: # 3 avutil-55.dll!?             +0x0      (0x00007ff8215f627a <avutil-55.dll+0x627a>)</div><div>Note: # 4 avutil-55.dll!?             +0x0      (0x00007ff821617e92 <avutil-55.dll+0x27e92>)</div><div>Note: # 5 avutil-55.dll!?             +0x0      (0x00007ff8215f6c06 <avutil-55.dll+0x6c06>)</div><div>Note: # 6 avutil-55.dll!?             +0x0      (0x00007ff8215f69a8 <avutil-55.dll+0x69a8>)</div><div>Note: # 7 avcodec-57.dll!?            +0x0      (0x00007ff81b7af025 <avcodec-57.dll+0x73f025>)</div><div>Note: # 8 avcodec-57.dll!?            +0x0      (0x00007ff81c00dc4d <avcodec-57.dll+0xf9dc4d>)</div><div>Note: # 9 avcodec-57.dll!?            +0x0      (0x00007ff81b7af385 <avcodec-57.dll+0x73f385>)</div><div>Note: #10 avcodec-57.dll!?            +0x0      (0x00007ff81b7af66b <avcodec-57.dll+0x73f66b>)</div><div>Note: #11 avcodec-57.dll!?            +0x0      (0x00007ff81b574b9a <avcodec-57.dll+0x504b9a>)</div><div>Note: instruction: mov    (%rcx) -> %ecx</div><div><br></div><div>Error #2: LEAK 1175 direct bytes 0x000002a77c946100-0x000002a77c946597 + 0 indirect bytes</div><div># 0 replace_malloc                              [d:\drmemory_package\common\alloc_replace.c:2576]</div><div># 1 avutil-55.dll!?                            +0x0      (0x00007ff82161c761 <avutil-55.dll+0x2c761>)</div><div># 2 avutil-55.dll!?                            +0x0      (0x00007ff821617b6c <avutil-55.dll+0x27b6c>)</div><div># 3 avcodec-57.dll!?                           +0x0      (0x00007ff81b646873 <avcodec-57.dll+0x5d6873>)</div><div># 4 AudioDecoder::decodeFile                    [c:\users\billm\documents\my_files\code\ffmpegtest\ffmpegtest\audiodecoder.cpp:63]</div><div># 5 VCRUNTIME140.dll!set_se_translator         +0x47a    (0x00007ff846f44acb <VCRUNTIME140.dll+0x4acb>)</div><div># 6 VCRUNTIME140.dll!set_se_translator         +0x21b    (0x00007ff846f4486c <VCRUNTIME140.dll+0x486c>)</div><div># 7 MSVCP140.dll!std::basic_filebuf<>::_Unlock  [f:\dd\vctools\crt\crtw32\stdhpp\fstream:365]</div><div># 8 MSVCP140.dll!std::basic_ostream<>::flush    [f:\dd\vctools\crt\crtw32\stdhpp\ostream:581]</div><div># 9 KERNEL32.dll!BaseThreadInitThunk           +0x21     (0x00007ff850678102 <KERNEL32.dll+0x18102>)</div><div><br></div><div>===========================================================================</div><div>FINAL SUMMARY:</div><div><br></div><div>DUPLICATE ERROR COUNTS:</div><div><span style="white-space:pre-wrap">       </span>Error #   1:   1706</div><div><br></div><div>SUPPRESSIONS USED:</div><div><br></div><div>ERRORS FOUND:</div><div>      1 unique,  1706 total unaddressable access(es)</div><div>      0 unique,     0 total invalid heap argument(s)</div><div>      0 unique,     0 total GDI usage error(s)</div><div>      0 unique,     0 total handle leak(s)</div><div>      0 unique,     0 total warning(s)</div><div>      1 unique,     1 total,   1175 byte(s) of leak(s)</div><div>      0 unique,     0 total,      0 byte(s) of possible leak(s)</div><div>ERRORS IGNORED:</div><div>      1 potential leak(s) (suspected false positives)</div><div>         (details: C:\Users\BillM\AppData\Roaming\Dr. Memory\DrMemory-FFmpegTest.exe.2804.000\potential_errors.txt)</div><div>     14 unique,    14 total,   7286 byte(s) of still-reachable allocation(s)</div><div>         (re-run with "-show_reachable" for details)</div><div>Details: C:\Users\BillM\AppData\Roaming\Dr. Memory\DrMemory-FFmpegTest.exe.2804.000\results.txt</div></div><div><div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 22, 2016 at 3:58 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>I added some code to check if it was crashing because dataSize is negative. It's not. Also, I found out that dtSize in this instance is 4608, and no matter what I do, sizeof(frame->data[0]) is always 8. Also, I tried sizeof(frame->data) which returned 64.</div><div><br></div><div><div>int dtSize = av_samples_get_buffer_size(nullptr, codecCtx->channels, frame->nb_samples, codecCtx->sample_fmt, 1);</div><div><span style="white-space:pre-wrap">                      </span>wxGetApp().popUpErrorDialog("dtSize: " + std::to_string(dtSize));</div><div><span style="white-space:pre-wrap">                      </span>dataSize = dtSize;</div><span><div><br></div><div><span style="white-space:pre-wrap">                  </span>while(totalBufferSize + dataSize > estimatedBuffSize)</div><div><span style="white-space:pre-wrap">                 </span>{</div><div><span style="white-space:pre-wrap">                                </span>estimatedBuffSize *= 1.1;</div><div><span style="white-space:pre-wrap">                                </span>sampleBuffer = (uint8_t*)std::realloc(sampleBuffer, estimatedBuffSize);</div><div><span style="white-space:pre-wrap">                  </span>}</div><div><span style="white-space:pre-wrap">                        </span></div></span><div><span style="white-space:pre-wrap">                    </span>wxGetApp().popUpErrorDialog("sizeof(frame->data[0]): " + std::to_string(sizeof(frame->data[0])));</div><span><div><br></div><div><span style="white-space:pre-wrap">                   </span>std::memcpy(sampleBuffer + totalBufferSize, frame->data[0], dataSize);</div><div><br></div><div><span style="white-space:pre-wrap">                       </span>totalBufferSize += dataSize;</div><div><span style="white-space:pre-wrap">                     </span>totalSamples += frame->nb_samples;</div></span></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jun 20, 2016 at 5:47 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">This is the function I'm using to decode the audio file. My guess is that it's crashing because "dataSize" is larger than "frame->data[0]", but I'm pretty sure my calculation of dataSize is correct. Am I copying the frame data to "sampleBuffer" the wrong way?<div><br></div><div><div>bool AudioDecoder::decodeFile(std::string* filename)</div><div>{</div><div><span style="white-space:pre-wrap">  </span>reset(); // if a file has already been decoded, free it from memory and reset</div><div><br></div><div><span style="white-space:pre-wrap">   </span>AVFormatContext* formatCtx = avformat_alloc_context();</div><div><span style="white-space:pre-wrap">   </span>if(avformat_open_input(&formatCtx, filename->c_str(), nullptr, nullptr) < 0)</div><div><span style="white-space:pre-wrap">   </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("Couldn't open \"" + *filename + "\".");</div><div><span style="white-space:pre-wrap">           </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>if(avformat_find_stream_info(formatCtx, nullptr) < 0)</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("Couldn't find file info for \"" + *filename + "\".");</div><div><span style="white-space:pre-wrap">             </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>av_dump_format(formatCtx, 0, filename->c_str(), false);</div><div><br></div><div><span style="white-space:pre-wrap">      </span>int streamID = -1;</div><div><span style="white-space:pre-wrap">       </span>for(int i = 0; i < formatCtx->nb_streams; i++)</div><div><span style="white-space:pre-wrap">     </span>{</div><div><span style="white-space:pre-wrap">                </span>if(formatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)</div><div><span style="white-space:pre-wrap">              </span>{</div><div><span style="white-space:pre-wrap">                        </span>streamID = i;</div><div><span style="white-space:pre-wrap">                    </span>break;</div><div><span style="white-space:pre-wrap">           </span>}</div><div><span style="white-space:pre-wrap">        </span>}</div><div><span style="white-space:pre-wrap">        </span>if(streamID == -1)</div><div><span style="white-space:pre-wrap">       </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("\"" + *filename + "\" does not contain audio.");</div><div><span style="white-space:pre-wrap">              </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>AVCodecContext* codecCtx = formatCtx->streams[streamID]->codec;</div><div><span style="white-space:pre-wrap">    </span>AVCodec* codec = avcodec_find_decoder(codecCtx->codec_id);</div><div><span style="white-space:pre-wrap">    </span>if(!codec)</div><div><span style="white-space:pre-wrap">       </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("Couldn't find the codec for \"" + *filename + "\".");</div><div><span style="white-space:pre-wrap">             </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><span style="white-space:pre-wrap">        </span>if(avcodec_open2(codecCtx, codec, nullptr) < 0)</div><div><span style="white-space:pre-wrap">       </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("Couldn't open the codec for\"" + *filename + "\".");</div><div><span style="white-space:pre-wrap">              </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>sampleFormat = codecCtx->sample_fmt;</div><div><span style="white-space:pre-wrap">  </span>if(!(sampleFormat == AV_SAMPLE_FMT_U8 || sampleFormat == AV_SAMPLE_FMT_U8P ||</div><div><span style="white-space:pre-wrap">            </span>sampleFormat == AV_SAMPLE_FMT_S16 || sampleFormat == AV_SAMPLE_FMT_S16P ||</div><div><span style="white-space:pre-wrap">               </span>sampleFormat == AV_SAMPLE_FMT_S32 || sampleFormat == AV_SAMPLE_FMT_S32P ||</div><div><span style="white-space:pre-wrap">               </span>sampleFormat == AV_SAMPLE_FMT_FLT || sampleFormat == AV_SAMPLE_FMT_FLTP ||</div><div><span style="white-space:pre-wrap">               </span>sampleFormat == AV_SAMPLE_FMT_DBL || sampleFormat == AV_SAMPLE_FMT_DBLP))</div><div><span style="white-space:pre-wrap">        </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("\"" + *filename + "\" uses an unsupported format.");</div><div><span style="white-space:pre-wrap">          </span>avcodec_close(codecCtx);</div><div><span style="white-space:pre-wrap">         </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>planar = false;</div><div><span style="white-space:pre-wrap">  </span>if(sampleFormat == AV_SAMPLE_FMT_U8P || sampleFormat == AV_SAMPLE_FMT_S16P ||</div><div><span style="white-space:pre-wrap">    </span>   sampleFormat == AV_SAMPLE_FMT_S32P || sampleFormat == AV_SAMPLE_FMT_FLTP || sampleFormat == AV_SAMPLE_FMT_DBLP)</div><div><span style="white-space:pre-wrap">      </span>{</div><div><span style="white-space:pre-wrap">                </span>planar = true;</div><div><span style="white-space:pre-wrap">   </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>AVFrame* frame = av_frame_alloc();</div><div><span style="white-space:pre-wrap">       </span>if(!frame)</div><div><span style="white-space:pre-wrap">       </span>{</div><div><span style="white-space:pre-wrap">                </span>wxGetApp().popUpErrorDialog("Failed to allocate an audio frame.");</div><div><span style="white-space:pre-wrap">             </span>avcodec_close(codecCtx);</div><div><span style="white-space:pre-wrap">         </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">            </span>return false;</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>AVPacket packet;</div><div><span style="white-space:pre-wrap"> </span>av_init_packet(&packet);</div><div><br></div><div><span style="white-space:pre-wrap">    </span>duration = formatCtx->duration / (double)AV_TIME_BASE; // duration is defined in AudioDecoder.h as "double duration = 0;"</div><div><br></div><div><span style="white-space:pre-wrap">  </span>uint64_t estimatedBuffSize = std::ceil(duration * codecCtx->sample_rate * av_get_bytes_per_sample(codecCtx->sample_fmt) * codecCtx->channels);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>sampleBuffer = (uint8_t*)std::malloc(estimatedBuffSize); // sampleBuffer is defined in AudioDecoder.h as "uint8_t* sampleBuffer = nullptr;"</div><div><span style="white-space:pre-wrap">    </span>sampleBufferSet = true;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>int len;</div><div><span style="white-space:pre-wrap"> </span>int gotFrame = 0;</div><div><span style="white-space:pre-wrap">        </span>uint64_t dataSize;</div><div><span style="white-space:pre-wrap">       </span>uint64_t totalBufferSize = 0;</div><div><span style="white-space:pre-wrap">    </span>uint64_t totalSamples = 0;</div><div><span style="white-space:pre-wrap">       </span>while(av_read_frame(formatCtx, &packet) == 0)</div><div><span style="white-space:pre-wrap">        </span>{</div><div><span style="white-space:pre-wrap">                </span>len = avcodec_decode_audio4(codecCtx, frame, &gotFrame, &packet);</div><div><span style="white-space:pre-wrap">                </span>if(len < 0)</div><div><span style="white-space:pre-wrap">           </span>{</div><div><span style="white-space:pre-wrap">                        </span>wxGetApp().popUpErrorDialog("Error while decoding.");</div><div><span style="white-space:pre-wrap">                  </span>std::free(sampleBuffer);</div><div><span style="white-space:pre-wrap">                 </span>sampleBufferSet = false;</div><div><span style="white-space:pre-wrap">                 </span>av_packet_unref(&packet);</div><div><span style="white-space:pre-wrap">                    </span>av_frame_free(&frame);</div><div><span style="white-space:pre-wrap">                       </span>avcodec_close(codecCtx);</div><div><span style="white-space:pre-wrap">                 </span>avformat_close_input(&formatCtx);</div><div><span style="white-space:pre-wrap">                    </span>return false;</div><div><span style="white-space:pre-wrap">            </span>}</div><div><br></div><div><span style="white-space:pre-wrap">               </span>if(gotFrame)</div><div><span style="white-space:pre-wrap">             </span>{</div><div><span style="white-space:pre-wrap">                        </span>dataSize = av_samples_get_buffer_size(nullptr, codecCtx->channels, frame->nb_samples, codecCtx->sample_fmt, 1);</div><div><br></div><div><span style="white-space:pre-wrap">                        </span>while(totalBufferSize + dataSize > estimatedBuffSize)</div><div><span style="white-space:pre-wrap">                 </span>{</div><div><span style="white-space:pre-wrap">                                </span>estimatedBuffSize *= 1.1;</div><div><span style="white-space:pre-wrap">                                </span>sampleBuffer = (uint8_t*)std::realloc(sampleBuffer, estimatedBuffSize);</div><div><span style="white-space:pre-wrap">                  </span>}</div><div><br></div><div><span style="white-space:pre-wrap">                       </span>std::memcpy(sampleBuffer + totalBufferSize, frame->data[0], dataSize);</div><div><br></div><div><span style="white-space:pre-wrap">                       </span>totalBufferSize += dataSize;</div><div><span style="white-space:pre-wrap">                     </span>totalSamples += frame->nb_samples;</div><div><span style="white-space:pre-wrap">            </span>}</div><div><br></div><div><span style="white-space:pre-wrap">               </span>av_packet_unref(&packet);</div><div><span style="white-space:pre-wrap">    </span>}</div><div><br></div><div><span style="white-space:pre-wrap">       </span>sampleBuffer = (uint8_t*)std::realloc(sampleBuffer, totalBufferSize);</div><div><br></div><div><span style="white-space:pre-wrap">   </span>numChannels = codecCtx->channels;</div><div><span style="white-space:pre-wrap">     </span>sampleRate = codecCtx->sample_rate;</div><div><span style="white-space:pre-wrap">   </span>numSamples = totalSamples;</div><div><span style="white-space:pre-wrap">       </span>bufferSize = totalBufferSize;</div><div><br></div><div><span style="white-space:pre-wrap">   </span>av_packet_unref(&packet);</div><div><span style="white-space:pre-wrap">    </span>av_frame_free(&frame);</div><div><span style="white-space:pre-wrap">       </span>avcodec_close(codecCtx);</div><div><span style="white-space:pre-wrap"> </span>avformat_close_input(&formatCtx);</div><div><br></div><div><span style="white-space:pre-wrap">   </span>didInit = true;</div><div><br></div><div><span style="white-space:pre-wrap"> </span>return true;</div><div>}</div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jun 17, 2016 at 4:20 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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><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><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:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);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>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>