kb_wav.c File Reference

This module provides functions to read, write and playback wav data from/to a wav file. More...

Include dependency graph for kb_wav.c:

Go to the source code of this file.

Defines

#define print_type(t)   printf("%c%c%c%c\n" , t[0], t[1], t[2], t[3])

Functions

int kb_wav_play (snd_t *snd, char *filename, unsigned soundbufsize)
void kb_wav_init (WAV *wav)
int kb_wav_open (WAV *wav, const char *file, int read)
void kb_wav_close (WAV *wav)
int kb_wav_read_data (WAV *wav, void *buf, unsigned int size)
int kb_wav_write_data (WAV *wav, void *buf, unsigned int len)
void kb_wav_set_format (WAV *wav, unsigned short format, unsigned short nb_channel, unsigned long sample_rate, unsigned short bit_per_sample)
int kb_wav_read_hdr (WAV *wav, COMMON_CHUNK_HEADER *hdr)
int kb_wav_write_hdr (WAV *wav, COMMON_CHUNK_HEADER *hdr)
void kb_wav_dump_format (WAV *wav)


Detailed Description

This module provides functions to read, write and playback wav data from/to a wav file.

wav files handling

Author:
CÚdric Gaudin (K-Team SA)

Pierre Bureau (K-Team SA)

Note:
Copyright (C) 2004 K-TEAM SA

Definition in file kb_wav.c.


Define Documentation

#define print_type (  )     printf("%c%c%c%c\n" , t[0], t[1], t[2], t[3])

Definition at line 26 of file kb_wav.c.


Function Documentation

void kb_wav_close ( WAV wav  ) 

This function closes a wav file.

Parameters:
wav the wav struct linked to the wav file

Definition at line 161 of file kb_wav.c.

References COMMON_CHUNK_HEADER::chunk, RIFF_CHUNK_HEADER::chunk_content, WAV::file, WAV::fmt, COMMON_CHUNK_HEADER::fmt, kb_wav_write_hdr(), WAV::length, COMMON_CHUNK_HEADER::length, WAV::modified, COMMON_CHUNK_HEADER::riff, and COMMON_CHUNK_HEADER::type.

Referenced by kb_wav_play(), koa_sound_task(), and main().

Here is the call graph for this function:

void kb_wav_dump_format ( WAV wav  ) 

This function dumps the wav file header to the standard output.

Parameters:
wav the wav struct

Definition at line 411 of file kb_wav.c.

References FMT_CHUNK_HEADER::bit_per_sample, FMT_CHUNK_HEADER::byte_per_sample, FMT_CHUNK_HEADER::byte_per_sec, WAV::fmt, FMT_CHUNK_HEADER::format, FMT_CHUNK_HEADER::nb_channel, and FMT_CHUNK_HEADER::sample_rate.

void kb_wav_init ( WAV wav  ) 

This function initializes the wav struct, it must be called before calling other wav functions.

Parameters:
wav the wav struct to initialize

Definition at line 91 of file kb_wav.c.

References WAV::file, WAV::length, and WAV::modified.

Referenced by kb_wav_play(), koa_sound_task(), and main().

int kb_wav_open ( WAV wav,
const char *  file,
int  read 
)

This function opens a wav file for reading or writing

Parameters:
wav the wav struct to use with the given file
file the file to read or write
read set to 1 for reading or to 0 for writing
Returns:
  • the data length on success
  • -1 if the file cannot be opened

Definition at line 107 of file kb_wav.c.

References COMMON_CHUNK_HEADER::chunk, RIFF_CHUNK_HEADER::chunk_content, WAV::file, COMMON_CHUNK_HEADER::fmt, WAV::fmt, kb_wav_read_hdr(), kb_wav_write_hdr(), COMMON_CHUNK_HEADER::length, WAV::length, WAV::modified, COMMON_CHUNK_HEADER::riff, and COMMON_CHUNK_HEADER::type.

Referenced by kb_wav_play(), koa_sound_task(), and main().

Here is the call graph for this function:

int kb_wav_play ( snd_t snd,
char *  filename,
unsigned  soundbufsize 
)

Play a wav file to the given sound interface. The sound interface must be initialized first using kb_sound_init and kb_sound_open. This function does not return until the full wav file is played.

Parameters:
snd the sound interface
filename the name of wav file to play
soundbufsize the size of the sound buffer
Returns:
an error code or 0 if successful

Todo:
change the format check to be used with different sound interfaces. So far only the KoreMedia interface is supported.

Definition at line 37 of file kb_wav.c.

References FMT_CHUNK_HEADER::bit_per_sample, buf, WAV::fmt, KB_ERROR, KB_ERROR_BADSOUND, KB_ERROR_FILEOPEN, kb_snd_play(), KB_WARN_SOUNDIO, KB_WARN_SOUNDSAMPLE, kb_warning(), kb_wav_close(), kb_wav_init(), kb_wav_open(), kb_wav_read_data(), and FMT_CHUNK_HEADER::nb_channel.

Here is the call graph for this function:

int kb_wav_read_data ( WAV wav,
void *  buf,
unsigned int  size 
)

This function reads a given number of data from a file opened with kb_wav_open. The resulting data are placed in buf and can be played using kb_snd_play.

Parameters:
wav the wav struct
buf the buffer to store the data
size the length of data to read
Returns:
the number of bytes read

Definition at line 197 of file kb_wav.c.

References FMT_CHUNK_HEADER::byte_per_sample, WAV::file, WAV::fmt, SWAP_LONG, and SWAP_WORD.

Referenced by kb_wav_play(), koa_sound_task(), and main().

int kb_wav_read_hdr ( WAV wav,
COMMON_CHUNK_HEADER hdr 
)

This function reads Wave File header.

Definition at line 306 of file kb_wav.c.

References WAV::file, SWAP_LONG, and SWAP_WORD.

Referenced by kb_wav_open().

void kb_wav_set_format ( WAV wav,
unsigned short  format,
unsigned short  nb_channel,
unsigned long  sample_rate,
unsigned short  bit_per_sample 
)

Set the format for the given wav struct. The format is usually read from the wav file header using kb_wav_open.

Definition at line 281 of file kb_wav.c.

References FMT_CHUNK_HEADER::bit_per_sample, FMT_CHUNK_HEADER::byte_per_sample, FMT_CHUNK_HEADER::byte_per_sec, WAV::fmt, FMT_CHUNK_HEADER::format, WAV::modified, FMT_CHUNK_HEADER::nb_channel, and FMT_CHUNK_HEADER::sample_rate.

int kb_wav_write_data ( WAV wav,
void *  buf,
unsigned int  len 
)

This function writes some data into the file.

Parameters:
wav the wav struct
buf the data to be writen
len the amount of bytes to write
Returns:
the number of bytes writen

Definition at line 238 of file kb_wav.c.

References FMT_CHUNK_HEADER::byte_per_sample, WAV::file, WAV::fmt, WAV::length, WAV::modified, SWAP_LONG, and SWAP_WORD.

int kb_wav_write_hdr ( WAV wav,
COMMON_CHUNK_HEADER hdr 
)


Generated on Wed Dec 15 11:49:28 2010 for KoreBot Library by  doxygen 1.5.5