<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">The only thing you need to change, is
      to divide by INT16_MAX - not INT32_MAX, because in your software
      conversion context you use S16 as your target format. This should
      give you -1 to 1 range from a -32767 to +32767 amplitude.
      Therefore your variable "myFrame" should be int16_t instead.<br>
      <br>
      Also the memcpy part is wrong:<br>
      memcpy(&myFrame, &localBuffer[ch * i], dataSize *
      sizeof(uint8_t));<br>
      <br>
      Correct is:<br>
      memcpy(&myFrame, &localBuffer[i * ch * dataSize],
      dataSize); // * sizeof(uint8_t) is useless, its always and will
      ever be 1<br>
      <br>
      Also here are a few tips:<br>
      <br>
      1.) Do not use, global/static variables outside of a class for no
      reason. Just move the variables out from the global space into
      class members. If this needs to be static then use static members
      instead.<br>
      <br>
      2.) Short variables names re bad - use long names, it does not
      hurt to write "sampleIndex" instead of "i". This way others and
      propably can understand the code much better.<br>
      <br>
      3.) Fix bad naming of variables:<br>
      <br>
      myFrame -> conversionSampleS16<br>
      dataSize -> sourceSampleSize<br>
      localBuffer -> conversionBuffer<br>
      buffer -> targetFloatBuffer<br>
      <br>
      In addition it does not hurt to add the type to the variable names
      as well - especially when writing audio code.<br>
      <br>
      4.) You have no idea if the buffer passed to getPcmFloat() fits
      the samples you wanna write. It would be to pass a size_t
      bufferLength as well.<br>
      <br>
      Am 21.10.2018 um 11:37 schrieb Matthieu Regnauld:<br>
    </div>
    <blockquote type="cite"
cite="mid:CADjM6tDO-+W+OTvjx3_-Bxr8xpf0YWQw+P_DWtyjSusGYVct0Q@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">
            <div dir="ltr">
              <div dir="ltr">Thanks a lot for your help.
                <div><br>
                </div>
                <div>That said, I still haven't managed to solve my
                  problem, and I'm new to FFMpeg.</div>
                <div><br>
                </div>
                <div>My final goal is to be able to extract raw audio
                  frames from an OGG file on the fly (and, if possible,
                  from any other format), and convert them in an array
                  of float amplitudes (between -1 and 1).</div>
                <div><br>
                </div>
                <div>Here is a copy of the code that I'm trying to make
                  work: <a
href="https://gist.github.com/mregnauld/2538d98308ad57eb75cfcd36aab5099a"
                    moz-do-not-send="true">https://gist.github.com/mregnauld/2538d98308ad57eb75cfcd36aab5099a</a></div>
                <div><br>
                </div>
                <div>I initiate my player this way:</div>
                <div>
                  <div><font face="monospace, monospace"><span style="white-space:pre">   </span>FFMpegPlayer*
                      ffMpegPlayer = new FFMpegPlayer();</font></div>
                  <div><font face="monospace, monospace"><span style="white-space:pre">   </span>ffMpegPlayer->createFFmpeg("/path/to/my/file.ogg");</font></div>
                </div>
                <div><br>
                </div>
                <div>And later on, when I need audio samples, I do this
                  way, and I redirect the <font face="monospace,
                    monospace">buffer</font> directly to the audio
                  output (it for an Android app):</div>
                <div><font face="monospace, monospace"><span style="white-space:pre">     </span>float
                    *buffer;<br>
                  </font></div>
                <div>
                  <div>
                    <div><font face="monospace, monospace"><span style="white-space:pre"> </span>ffMpegPlayer->getPcmFloat(buffer);</font></div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <br>
        </div>
        <div>I still have white noice so far, but I can hear a little
          bit the music (actually I guess it more that I can hear it),
          which makes me think that I'm close to the solution.</div>
        <div><br>
        </div>
        <div>What should I change in my code to get the proper float
          amplitudes?</div>
        <div><br>
        </div>
        <div>Thanks for your help.</div>
        <div><br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Libav-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Libav-user@ffmpeg.org">Libav-user@ffmpeg.org</a>
<a class="moz-txt-link-freetext" href="http://ffmpeg.org/mailman/listinfo/libav-user">http://ffmpeg.org/mailman/listinfo/libav-user</a>
</pre>
    </blockquote>
    <p><br>
    </p>
  </body>
</html>