Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>16 bit PCM has a range - 32768 to 32767. So, multiply each of your PCM samples by (1.0f/32768.0f) into a new array of floats, and pass that to your resample. </p> <p>Going back to float after resampling, multiply by 32768.0, saturate (clip anything outside the range - 32768 to 32767), round (or dither as Björn mentioned) and then cast back to short. </p> <p>Test code that shows conversion forward and back using multiplies with no bit errors:</p> <pre><code>// PcmConvertTest.cpp : Defines the entry point for the console application. // #include &lt;assert.h&gt; #include &lt;string.h&gt; #include &lt;stdint.h&gt; #define SZ 65536 #define MAX(x,y) ((x)&gt;(y)) ? (x) : (y) #define MIN(x,y) ((x)&lt;(y)) ? (x) : (y) int main(int argc, char* argv[]) { int16_t *pIntBuf1 = new int16_t[SZ]; int16_t *pIntBuf2 = new int16_t[SZ]; float *pFloatBuf = new float[SZ]; // Create an initial short buffer for testing for( int i = 0; i &lt; SZ; i++) { pIntBuf1[i] = (int16_t)(-32768 + i); } // Convert the buffer to floats. (before resampling) const float div = (1.0f/32768.0f); for( int i = 0; i &lt; SZ; i++) { pFloatBuf[i] = div * (float)pIntBuf1[i]; } // Convert back to shorts const float mul = (32768.0f); for( int i = 0; i &lt; SZ; i++) { int32_t tmp = (int32_t)(mul * pFloatBuf[i]); tmp = MAX( tmp, -32768 ); // CLIP &lt; 32768 tmp = MIN( tmp, 32767 ); // CLIP &gt; 32767 pIntBuf2[i] = tmp; } // Check that the conversion went int16_t to float and back to int for every PCM value without any errors. assert( 0 == memcmp( pIntBuf1, pIntBuf2, sizeof(int16_t) * SZ) ); delete pIntBuf1; delete pIntBuf2; delete pFloatBuf; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload