PDA

View Full Version : How to read RAW audio file ?



fitzy
6th August 2010, 09:53
Hello,

I have some files written as raw audio data.

The audio data I am trying to read is encoded in 16 bits, has only 1 channel and with rate 22050 Hz.

Pb1: How can I retrieve the amplitude of the wave ?

Here is what I tried to do to solve Pb1 (don't know if it is good) :

QByteArray by = file->read(16);
but I get something like :

"}??????? ©²¾É"
I tried to convert that to an integer but it doesn't work (I always get 0, but there are datas in the file, I checked with Audacity):

qDebug() << by.toInt();
--
Pb2: How can I create a RAW audio file if I have the amplitude of the wave ?




Any idea ?


.

fitzy
6th August 2010, 10:34
Ok I have solved problem 1 :



QFile *file = new QFile("D:/IA/recordSound/debug/test.raw");
file->open(QIODevice::ReadOnly);

QDataStream in(file);
for(int i=0; i<100; i++){
// Read the data
char buf[16];
qint64 lineLength = in.readRawData(buf, sizeof(buf));

int test = qFromBigEndian(*(qint16 *)(buf));
qDebug() << test;

}

This code retrieves the amplitude of the wave (in the RAW file).

fitzy
6th August 2010, 13:37
I really have no idea !

I am trying to change my integers into something like this :

}??????? ©²¾É (cf first post)

but I don't know how !