Page 1 of 1

Accessing WAVE data values

PostPosted: January 24th, 2013, 7:52 am
by PalmiePaul
Hi there
I have an application that requires me to edit the individual PCM data values in a WAVE file. I have written the following code
wave := tWave.create;
wave.loadFromFile(openDialog.fileName);
wave.BeginRead;
setLength(buffer, 4);
byteTally := wave.stream.read(buffer, 4);
for i := 0 to byteTally-1 do
showMessage(intToStr(buffer[i]));

If I’ve understood correctly, this should output the first four data bytes from the WAVE file. Clearly, I haven’t understood correctly, because the showmessage causes an access violation error. Can you tell me why?

At a more global level, does your package have some way of getting the data values out of the file as integers? Even if I manage to fix the code above, I don’t really want to have to assemble bytes that represent two’s complement numbers into integers.

Thanks
Paul

Re: Accessing WAVE data values

PostPosted: January 24th, 2013, 4:55 pm
by Kambiz
The Read method of Stream class requires a const argument but you passed a pointer. Try this:
Code: Select all
byteTally := wave.stream.read(buffer[0], 4);

To read wave data as integer values, you just need to define you buffer as array of integers. In this case just remember to pass the appropriate value for the Count parameter of the Stream.Read method.