beautypg.com

Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 114

background image

KTD-S0057-I

Page 110 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


static void set_wav_header (wav_header *w)
{

strcpy (w->chunkId, "RIFF");

w->chunkSize = BUFSIZE + sizeof (wav_header) - 8;

strcpy (w->format, "WAVE");

strcpy (w->subChunkId, "fmt ");

w->subChunkSize = 16;

/* Length of sub-header - 8 */

w->audioFormat = FMT_PCM;

/* PCM, uncompressed */

w->numChannels = MONO;

w->sampleRate = RATE_44kHz;

w->byteRate = RATE_44kHz * (SAMPLEBITS / 8) * w->numChannels;

/* only valid for 8, 16 and 24 bits */

w->blockAlign = (SAMPLEBITS / 8) * w->numChannels;

/* only valid for 8, 16 and 24 bits */

w->bitsPerSample = SAMPLEBITS;

strcpy (w->subChunkId2, "data");

w->subChunkSize2 = BUFSIZE;

}

static int write_wav_file (wav_header w)
{
FILE

*wavfile;

wavfile = fopen (FILENAME, "w");

if (! wavfile)

return

EXIT_FAILURE;

if (fwrite (&w, sizeof (wav_header), 1, wavfile) != 1)

return

EXIT_FAILURE;

if (fwrite (&buf, sizeof (short), FRAMES, wavfile) != FRAMES)

return

EXIT_FAILURE;

fclose(wavfile);
return

EXIT_SUCCESS;

}

int main (void)
{
int

err;

unsigned int rrate;

wav_header

wavhdr;

snd_pcm_t

*capture_handle;

snd_pcm_hw_params_t

*hw_params;

if ((err = snd_pcm_open (&capture_handle, device, SND_PCM_STREAM_CAPTURE, 0)) < 0)

{

fprintf (stderr, "Cannot open audio device %s (%s)\n", device, snd_strerror (err));

return

EXIT_FAILURE;

}

if ((err = snd_pcm_hw_params_malloc (&hw_params)) < 0)

{

fprintf (stderr, "Cannot allocate hardware parameter structure (%s)\n", snd_strerror (err));

return

EXIT_FAILURE;

}

This manual is related to the following products: