Note that there are some explanatory texts on larger screens.

plurals
  1. POReading Wav Files, wrong output
    primarykey
    data
    text
    <p>I have posted a simular problem before (Thought it would be better to start a fresh and hopefully, get more opinions on it). Basically, the problem is that I am trying to read the data from a .wav file, however, the output is different to that of what it is in MatLab. </p> <p>In C++ the output is:</p> <p>-128</p> <p>Whereas in Matlab:</p> <p>0</p> <p>The output is completely different, not just small differences, but the whole dataset is wrong and I don't seem to know why. I think it might have something to do with endianness but, I am not sure. Here is the header information about the .wav file:</p> <pre><code>**** WAV FILE ***** Chunk IDRIFFN? Chunk Size: 57934 Format: WAVEfmt Format: IDfmt FormatSize: 18 Format2: 1 Channel Num: 1 Sample Rate: 22050 Byte Rate: 22050 Align: 1 Bits Per Sample: 8 </code></pre> <p>And the code:</p> <pre><code>file.read(this-&gt;chunkId, 4); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;chunkSize), 4); file.read(this-&gt;format, 4); file.read(this-&gt;formatId, 4); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;formatSize), 4); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;format2), 2); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;numChannels), 2); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;sampleRate), 4); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;byteRate), 4); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;align), 2); file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;bitsPerSample), 4); char testing[4] = {0}; int testingSize = 0; while(file.read(testing, 4) &amp;&amp; (testing[0] != 'd' || testing[1] != 'a' || testing[2] != 't' || testing[3] != 'a')) { file.read(reinterpret_cast&lt;char*&gt;(&amp;testingSize), 4); file.seekg(testingSize, std::ios_base::cur); } this-&gt;dataId[0] = testing[0]; this-&gt;dataId[1] = testing[1]; this-&gt;dataId[2] = testing[2]; this-&gt;dataId[3] = testing[3]; file.read(reinterpret_cast&lt;char*&gt;(&amp;this-&gt;dataSize), 4); this-&gt;data = new char[this-&gt;dataSize]; file.read(data,this-&gt;dataSize); cout &lt;&lt; "**** WAV FILE *****" &lt;&lt; endl; cout &lt;&lt; "Chunk ID" &lt;&lt; this-&gt;chunkId &lt;&lt; endl; cout &lt;&lt; "Chunk Size" &lt;&lt; this-&gt;chunkSize &lt;&lt; endl; cout &lt;&lt; "Format: " &lt;&lt; this-&gt;format &lt;&lt; endl; cout &lt;&lt; "Format ID" &lt;&lt; this-&gt;formatId &lt;&lt; endl; cout &lt;&lt; "FormatSize" &lt;&lt; this-&gt;formatSize &lt;&lt; endl; cout &lt;&lt; "Format2 " &lt;&lt; this-&gt;format2 &lt;&lt; endl; cout &lt;&lt; "Channel Num" &lt;&lt; this-&gt;numChannels &lt;&lt; endl; cout &lt;&lt; "Sample Rate" &lt;&lt; this-&gt;sampleRate &lt;&lt; endl; cout &lt;&lt; "Byte Rate" &lt;&lt; this-&gt;byteRate &lt;&lt; endl; cout &lt;&lt; "Align" &lt;&lt; this-&gt;align &lt;&lt; endl; cout &lt;&lt; "Bits Per Sample" &lt;&lt; this-&gt;bitsPerSample &lt;&lt; endl; cout &lt;&lt; "Size" &lt;&lt; testingSize &lt;&lt; endl; for(unsigned i=0; (i &lt; 20); i++){ cout &lt;&lt; (float) data[i] &lt;&lt; endl; } return true; </code></pre> <p>Can anyone see where I am going wrong? I have tried to debug it, but, had no joy (I'm using g++ to compile). Any help would be greatly appreciated :) Sorry I keep asking this, it's really annoying me now!</p> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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