Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>1</strong> You're reading bytes instead of 16-bit samples in this else branch:</p> <pre><code>while (!feof(infile)) { if (is_8bit) { fread(inbuff8, 1, BUFSIZE, infile); } else { fread(inbuff16, 1, BUFSIZE, infile); // &lt;-- should be BUFSIZE*2 } </code></pre> <p><strong>2</strong> You don't saturate the values when scaling, e.g. original 16-bit sample = 32000 and factor = 1.5 will wrap around the integer value instead of clamping it to the maximum of 32767.</p> <p><strong>3</strong> You don't look at the RIFF and other headers at all. In WAV files, it is possible that the audio data is followed by some informational footers or preceded by additional headers. Or in other words: Your <code>header</code> struct is too static. You should also read the WAV format from the file instead of having a parameter saying it's 8 bit samples.</p> <p><strong>4</strong> This just won't happen:</p> <pre><code> outbuff16[i] = factor * inbuff16[i]; if ((int)outbuff16[i] &gt; MAX_16BIT_AMP) </code></pre> <p>8-bit/16-bit values will never be greater than 255/32768 except if your computer inserts some magic bits into the memory when integers overflows :P</p> <p>And audio samples are signed, so the ranges are -128;127 and -32768;32767. Overflow checking must occur in the multiplication expression. You're also making assumptions on the floating-point-to-integer rounding mode, which is configurable and should be considered. Something like <code>if(roundf(factor * inbuff16[i]) &gt; 32767 || roundf(factor * inbuff16[i]) &lt; -32768)</code>, maybe.</p> <p><strong>5</strong> You don't store the result of <code>fread</code>, so you will write too many samples to the output file.</p> <p><strong>6</strong> And as a last point, you're reinventing the wheel. As long as this is for learning, it's okay. Else you should use existing libraries.</p>
    singulars
    1. This table or related slice is empty.
    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. 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.
 

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