Recording audio signals

Hi,I’m new to QNX and I’m trying to record radio signals and transfer them to another program in a file.I’ve tried to use the waverec.c program in the audio developers guide but can’t get the data recorded in readable text format.I want an array of the digits representing the sound recorded so I can use this data in another program. Can you help?

OK, so you record a buffer of data (which represents the PCM data). What kind of text format to you want to write it out in? It is binary data. What format does your other program want it in?

I want to write it as a text file…My program takes data as digits…1,0.004,0.7,-0.3 ,for example.I looked at the waverec.c program and i’m thinking it’s the riff_hdr struct that causes me to get data that’s not completely readable…am I right? My program accepts the data as text…Thanks for the reply…

I assume this array of digits you want has some meaning. Basically wavrec shows you how to set up the hardware to give you buffers of raw PCM data. It writes the header to the output file (which describes the format of the data) and then n buffers of data in the format previously described.

The header describes how many voices(stero, mono), the bitrate, etc… All of this effects the interpretation of the data. The data buffer is going to represent n “samples” of data in the format specified. It is up to you to interpret what that means.

If you choose 8 bits, mono, then each byte in the mSampleBfr1 will represent a sample - if you want to print that as a number from 0-255, or as a bit pattern (01101101), it is up to you.

As far as your text format goes, what do the number represent? Are they integers, or floating point? What are the valid ranges? All of this is very important if you want to generate data for your program to read.


I’m basically recording an audio signal from a radio receiver…then transfering it into a text file which stores the data that i want to send to a filtering program that receives an array of numbers.How can I change the header to give me ASCII format text?
Thanks Rick

Without knowing the meaning, it is useless. Each byte has a value from 0-255. That is about all I can tell you with the info you have provided.

int i;

for(i = 0; i < sizeof(mSampleBuf1), i++ )
  printf( "%d ", mSampleBuf1[i] );

Hi, I now get some information from running the program…I’m using siigned numbers so I’m getting values from -128 to 127. I need the data in floating point format and say when I input a sine wave,I want to get numbers between -1 and 1.

One problem I’ve encountered is…When there’s no signal input,I still get values from the channel…The value is either 127 or -128.
What can I do to ensure that with no input I get 0 output. This is the command I use to read values form the buffer:

for(i=0;i<=440;i++) //Use this to get just 441 values from buffer { fprintf(file1,"%d \n",mSampleBfr1[i]); }
Is doing that ok?Is that how you’d normally read what is recorded in text format?

From the sporadic info you gave, it’s really hard to give you hints since everything is a blur (at least to me).

Ok so you got waverec.c. Did you modify it to get the output format you wanted or you are trying to use it as is and let the filter progam deal with the format.

In the sample of code you have for(i=0; i<=440; i++) most code will be written as for (i=0; i<441; i++) which is easier for the typical brain to understand. The code will not read from a file, but instead create a file (fprintf). So its definitely not how you read from a text file. Instead you could use fscanf( file, “%d”, &mSampleBfr1[i] ); Personnaly I preferer to use fgets and parse the string with strtol depending on format of data.

First I suggest you get waverec to record in 16 bit (8 bit is kinda lame for recording ;-). I’m actually surprise it was setup to record in 8 bit mono in the first place.

In order to get floating point format you will need to scale the value, sound hardware works with integer. That’s simple math.

I’m also surprise you get 127 or -128 when there is no sound, usually you should get values around 0 (not always 0 since depending on your hardware you can have noise). Is it possible you are misintepreting the value (could be in 16bits stereo)