Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ reading 16bit Wav file
    text
    copied!<p>I'm having trouble reading in a 16bit .wav file. I have read in the header information, however, the conversion does not seem to work.</p> <p>For example, in Matlab if I read in wave file I get the following type of data:</p> <pre><code> -0.0064, -0.0047, -0.0051, -0.0036, -0.0046, -0.0059, -0.0051 </code></pre> <p>However, in my C++ program the following is returned:</p> <pre><code>0.960938, -0.00390625, -0.949219, -0.00390625, -0.996094, -0.00390625 </code></pre> <p>I need the data to be represented the same way. Now, for <code>8 bit</code> .wav files I did the following:</p> <pre><code>uint8_t c; for(unsigned i=0; (i &lt; size); i++) { c = (unsigned)(unsigned char)(data[i]); double t = (c-128)/128.0; rawSignal.push_back(t); } </code></pre> <p>This worked, however, when I did this for 16bit:</p> <pre><code>uint16_t c; for(unsigned i=0; (i &lt; size); i++) { c = (signed)(signed char)(data[i]); double t = (c-256)/256.0; rawSignal.push_back(t); } </code></pre> <p>Does not work and shows the output (above). </p> <p>I'm following the standards found <a href="http://www.mathworks.co.uk/help/matlab/ref/wavread.html" rel="nofollow noreferrer">Here</a></p> <p>Where <code>data</code> is a <code>char</code> array and <code>rawSignal</code> is a <code>std::vector&lt;double&gt;</code> I'm probably just handing the conversion wrong but cannot seem to find out where. Anyone have any suggestions?</p> <p>Thanks</p> <p>EDIT:</p> <p>This is what is now displaying (In a graph):</p> <p><img src="https://i.stack.imgur.com/Ws26O.jpg" alt="enter image description here"></p> <p>This is what it should be displaying:</p> <p><img src="https://i.stack.imgur.com/ZY4Ms.jpg" alt="enter image description here"></p>
 

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