title: How to read raw PCM data from file and convert to float?
body: <p>I read a binary file of raw PCM data but cannot convert it to floats correctly. I am reading a raw pcm file that audacity recognizes as 16 bit unsigned. I am using the following code:</p>
  
  <pre><code>fseek(stream, 0, SEEK_END);
  size = ftell(stream);
  fseek(stream, 0, SEEK_SET);
  uint8_t * buf = (uint8_t *)malloc(size);
  float * f = (float *)malloc(size * sizeof(float) / 2);
  
  //read buffer
  fread(buf, sizeof(uint8_t), size, stream);
  
  //convert to float:
  for(int j=0;j&lt;size;j+=2){
    int16_t temp1 = buf[j] | buf[j+1] &lt;&lt; 8;
    f[j/2]=(float)temp1/(float)32767.0;
    if( f[j/2] &gt; 1 ) 
      f[j/2] = 1;
    if( f[j/2] &lt; -1 ) 
      f[j/2] = -1;
  }
  </code></pre>
  
  <p>What am I doing wrong here?</p>