Hello,
gcc 4.4.2 c89
I have a wave file: 8000 Hz 16 bit
I am wondering if there anyway I can load the raw data of this wave file into a buffer.
Many thanks for any advice
Hello,
gcc 4.4.2 c89
I have a wave file: 8000 Hz 16 bit
I am wondering if there anyway I can load the raw data of this wave file into a buffer.
Many thanks for any advice
Yes, you're looking for reading a binary file in C. Something like this:
FILE* f;
char buf[MAX_FILE_SIZE];
int n;
f = fopen("filename.bin", "rb");
if (f)
{
n = fread(buf, sizeof(char), MAX_FILE_SIZE, f);
}
else
{
// error opening file
}
This reads a buffer of bytes. From it you can build your data. Reading multi-byte data directly is more tricky because you run into issues of representation and endianness.
Two key C functions are used:
fopen
that opens a file in binary mode (the "rb" flag)fread
that reads block data (useful for binary streams). Documented here.If you want to process the sound samples, you would be best to use a library that interprets the sound data for you. For example libsndfile.
The best way IMHO would be to use a linked list with elements holding a large(1024 or more) fixed size char arrays.