wavfile - dynamically parse and fill different formats of wav headers, such as 44
bytes, 46
bytes, 98
bytes, etc.
This repository provides a set of apis for reading and writing wav header, and also provides three examples to show the application of these apis:
- wav2pcm: convert wav file to pcm file, remove wav header;
- pcm2wav: convert pcm file to wav file, fill
44
bytes's wav header; - wavinfo: dynamically parse wav header of input;
$ make clean all
$ ./wav2pcm xxx.wav xxx.pcm
$ ./pcm2wav xxx.pcm xxx.wav channels bits samplerate
$ ./wavinfo xxx.wav
FILE *wavfile_read_open(const char *filename, unsigned int *size);
open wav file to read.
filename
: wav file path to read;size
: return pcm data size of wav file;
Success
: wav file descriptor, skip this wav header;Failed
:NULL
;
int wavfile_read(FILE *fp, void *data, size_t size);
read pcm data from wav file.
fp
: wav file descriptor to read;data
: pcm data to read;size
: pcm data size to read;
Success
: number of bytes read;Failed
:0
or less than0
;
int wavfile_read_close(FILE *fp);
close wav file.
fp
: wav file descriptor;
Success
:0
;Failed
:-1
;
FILE *wavfile_write_open(const char *filename);
open wav file to write.
filename
: wav file path to write;
Success
: wav file descriptor, skip 44 bytes of header.;Failed
:NULL
;
int wavfile_write(FILE *fp, void *data, size_t size);
write pcm data to wav file.
fp
: wav file descriptor to write;data
: pcm data to write;size
: pcm data size to write;
Success
: number of bytes written;Failed
:0
or less than the size written;
int wavfile_write_close(FILE *fp, int channels, int bits, int samplerate);
close wav file.
fp
: wav file descriptor;channels
: channels of wav file;bits
: bits of wav file;samplerate
: samplerate of wav file;
Success
:0
;Failed
:-1
;
int wavfile_info(FILE *fp, wavfile_header_t *header);
get wav header info in struct wavfile_header_t
.
fp
: wav file descriptor;header
: structwavfile_header_t
for saving wav header info;
Success
:0
;Failed
:-1
;