Ciao a tutti,
sono un pò di giorni che ormai sbatto la testa per fare una cosa che inizialmente mi sembrava abbastanza semplice, e cioè estrarre la sezione raw-data da un file wav in formato double per poi elaborare il file così ottenuto successivamente. In pratica fare, in ambiente c/c++, quello che banalmente fa il comando wavread di matlab.
Premetto che sono un novellino con c/c++, tuttavia guardando in internet ho trovato un piccolo codice che sembrava fosse adatto per i miei scopi. Il problema è dovuto al fatto che i dati estratti (per quanto io mi sia sforzato di fare dei casting a double) sono sempre restituiti in singola precisione (float). Di seguito allego il codice in questione e una parte dell'output con la speranza che possiate aiutarmi... le ho provate davvero tutte!
Grazie in anticipo

------------------------------------BEGIN-----------------------------------------------
// parser.cpp : definisce il punto di ingresso dell'applicazione console.
//

#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <iostream>
#include <limits>
#include <cfloat>
#include <iostream>
#include <iomanip>


using namespace std;


#include "parser.h"

int _tmain(int argc, _TCHAR* argv[])
{
binaryToAscii();
return 0;
}

void binaryToAscii()
{
FILE *infile, *outfile;
char prefix[4];
char fileFormat[8];
unsigned char ch;
double byteValue;
unsigned int i;
char ckID[5];
unsigned long nChunkSize;
short int wFormatTag;
short int nChannels;
unsigned long nSamplesPerSecond;
unsigned long nAvgBytesPerSecond;
short int nBlockAlign;
short int nBitsPerSample;

/* Open source for binary read (will fail if file does not exist) */
infile = fopen( "C:\\temp\\parser files\\file1.wav", "rb" );
{
if (infile==NULL)
//printf( "The source file %s was not opened!\n");
exit(2);
}

/* Open output for write */
outfile = fopen("C:\\temp\\parser files\\file1.txt", "w" );
{
if (outfile==NULL)
//printf( "The output file %s was not opened\n");
exit(3);
}

// Read the header bytes.
fscanf( infile, "%4c", prefix );
fscanf( infile, "%4c", &nChunkSize );
fscanf( infile, "%8c", fileFormat );
fscanf( infile, "%4c", &nChunkSize );
fscanf( infile, "%2c", &wFormatTag );
fscanf( infile, "%2c", &nChannels );
fscanf( infile, "%4c", &nSamplesPerSecond );
fscanf( infile, "%4c", &nAvgBytesPerSecond );
fscanf( infile, "%2c", &nBlockAlign );
fscanf( infile, "%2c", &nBitsPerSample );
fscanf( infile, "%4s", &ckID );
fscanf( infile, "%4c", &nChunkSize );

// Testing on the file format variables would go here.

// Scan and convert the bytes.
for( i = 0; (i < nChunkSize);i++ ) {
fscanf( infile, "%c", &ch );
byteValue = ((double)ch-128)/128;
fprintf_s(outfile,"%1.16lf\n",byteValue);
}

/* All files are closed: */
fclose(infile);
fclose(outfile);
}

------------------------------------END-----------------------------------------------

OUTPUT RESTITUITO
-0.7031250000000000
-1.0000000000000000
-0.7812500000000000
-1.0000000000000000
-0.8906250000000000
-1.0000000000000000
0.9843750000000000
0.9921875000000000
0.8593750000000000
0.9921875000000000
0.8906250000000000
0.9921875000000000
0.9843750000000000
0.9921875000000000
-0.9531250000000000
-1.0000000000000000
-0.9843750000000000
-1.0000000000000000
-0.9531250000000000
-1.0000000000000000
-0.8906250000000000
-1.0000000000000000
-0.8906250000000000
-1.0000000000000000
-0.8750000000000000
-1.0000000000000000
-0.8281250000000000
-1.0000000000000000
-0.7968750000000000