<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
<div>Hi Gary. From what Iīve found, the first problem is here:</div><div><br></div><div><div>bool FileRead :: getWavInfo( const char *fileName )</div><div>{</div><div>......</div><div><br></div><div><div>if ( format_tag == 1 ) {</div><div>&nbsp; &nbsp; if (temp == 8)</div><div>&nbsp; &nbsp; &nbsp; dataType_ = STK_SINT8;</div><div>&nbsp; &nbsp; else if (temp == 16)</div><div>&nbsp; &nbsp; &nbsp; dataType_ = STK_SINT16;</div><div>&nbsp; &nbsp; else if (temp == 32)</div><div>&nbsp; &nbsp; &nbsp; dataType_ = STK_SINT32;</div><div>&nbsp; }</div></div><div><br></div><div>......</div><div>}</div><div><br></div><div>That part of the code never checks for 24 bits files, so loading such files always returns an error.<i>&nbsp;</i>I changed it to:</div><div><br></div><div>.....</div><div><div>if ( format_tag == 1 ) {</div><div>&nbsp; &nbsp; if (temp == 8)</div><div>&nbsp; &nbsp; &nbsp; dataType_ = STK_SINT8;</div><div>&nbsp; &nbsp; else if (temp == 16)</div><div>&nbsp; &nbsp; &nbsp; dataType_ = STK_SINT16;</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>else if (temp == 24)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp;dataType_ = STK_SINT24;</div><div>&nbsp; &nbsp; else if (temp == 32)</div><div>&nbsp; &nbsp; &nbsp; dataType_ = STK_SINT32;</div><div>&nbsp; }</div></div><div>.....</div><div><br></div><div>Now FileRead loads 24bit files, but wonīt reproduce them correctly. The next problem I found is in the read(...) method. You are using bit shifting to get the 3 loaded bytes become the 3 lowest bytes of the buffer, but wouldnīt it also shift the sign bit? Anyway, code is easier to understand so hereīs my "fix":</div><div><br></div><div>....</div><div>else if ( dataType_ == STK_SINT24 ) {</div><div>&nbsp; &nbsp; // 24-bit values are harder to import efficiently since there is</div><div>&nbsp; &nbsp; // no native 24-bit type. &nbsp;The following routine works but is much</div><div>&nbsp; &nbsp; // less efficient that that used for the other data types.</div><div>&nbsp; &nbsp; SINT32 buf;</div><div>&nbsp; &nbsp; StkFloat gain = 1.0 / 2147483648.0; // 1/ 2^23 * 1/2^8 &nbsp; &nbsp; &nbsp;</div><div>&nbsp; &nbsp; if ( fseek(fd_, dataOffset_+(offset*3), SEEK_SET ) == -1 ) goto error;</div><div>&nbsp; &nbsp; for ( i=0; i&lt;nSamples; i++ ) {</div><div>&nbsp; &nbsp; &nbsp; if ( fread( &amp;buf, 3, 1, fd_ ) != 1 ) goto error;</div><div>&nbsp; &nbsp; &nbsp; if ( byteswap_ )</div><div>&nbsp; &nbsp; &nbsp; &nbsp; swap32( (unsigned char *) &amp;buf );</div><div>&nbsp; &nbsp; &nbsp; if (wavFile_)</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>buf &lt;&lt;= 8;</div><div>&nbsp; &nbsp; &nbsp; if ( doNormalize )</div><div>&nbsp; &nbsp; &nbsp; &nbsp; buffer[i] = buf * gain; // "gain" also &nbsp;includes 1/256. See next comment</div><div>&nbsp; &nbsp; &nbsp; else</div><div>&nbsp; &nbsp; &nbsp; &nbsp; buffer[i] = buf / 256; // shift to the right without affecting the sign bit?</div><div>&nbsp; &nbsp; }&nbsp;</div><div><i>....</i></div><div><i><br></i></div><div>Notice that Iīm shifting bits to the left when the file loaded is a Wav file, and only after byteswapping. Thatīs because with wav files the 3 loaded bytes always end up being the lowest 3 bytes of the buffer, but the sign bit should be placed in the highest byte. After that, If a normalization is needed, I multiply the buffer by the gain factor, which includes a (1/256), which AFAIK is analogous to a buf &gt;&gt;= 8, without the "sign" problem. If no noemalization is needed, I still apply the buf * 1/256, to get my data back into the lowest 3 bytes without the sign problem.</div><div><br></div><div>With all this fixes I finally can get to load and reproduce wav and AIFF files without problem in a Windows XP environment. Now, since Iīm quite new to audio file formats, and have only been using c++ for a few months, I could be horribly wrong about all this stuff! What do you think?</div><div><br></div><div>Best regards,</div><div><br></div><div>Carlos</div><div><br></div>&gt; <br>&gt; Hi Carlos,<br>&gt; <br>&gt; I recently noticed some discrepancies with 24-bit support in STK (and RtAudio).  While SINT24 was listed as "Upper 3 bytes of 32-bit signed integer", the code in FileRead was partly assuming it to be the lower 3 bytes.  After some consideration, I decided to change the definition of SINT24 to the "lower 3 bytes" for the next release, with the resulting addition of one line to the FileRead :: open() function code:<br>&gt; <br>&gt;      if ( fread( &amp;buf, 3, 1, fd_ ) != 1 ) goto error;<br>&gt; +      buf &gt;&gt;= 8;<br>&gt;       if ( byteswap_ ) ...<br>&gt; <br>&gt; Is this the problem you found?  Do you see any particular advantage to defining an SINT24 to be the upper vs. the lower 3 bytes?<br>&gt; <br>&gt; Regards,<br>&gt; <br>&gt; --gary<br>&gt; <br><br></div>                                               </div></body>
</html>