S
siroregano
Hi Everyone-
I'm new to this group, and almost-as-new to asking programming
questions publicly, so please forgive me if I miss a convention or two!
I have a text file, around 40,000 lines long, where each line is a
string of 4 ASCII characters corresponding to a 12-bit hexadecimal
audio sample. The file reads something like this...
081F
081C
081A
0818
080E
etc...
I would like to write a simple C program in a Linux environment that
will read in this file, convert the strings to signed 2's-compliment
int samples, and output a simple WAV audio file. I've found several
resources on "The Canonical WAV format" via Google, and they describe
the format pretty well.
I already have a program reading in the file and fprintf'ing each line
out to stdout, as a stub. Now I need to build the WAV file.
Question #1: Am I reinventing the wheel? Does anyone know of another
piece of code out there that could do this out-of-the-box? I saw that
ogg123 seems to have a "raw" device option, but there doesn't seem to
be much documentation as to what it expects as a raw sample stream.
Question #2, for those familiar with WAV files: The WAV docs seem to
indicate that there can be only one DATA chunk in each WAV file. In a
DATA chunk, you get 4 bytes to give the size of your data... But what
if you have more data bytes than you can drop into an unsigned 4-byte
int?
Question #3, which is more C-language related: The WAV format uses
little-endian bit orders for all data, but the byte-order of several of
the multibyte (either 2-byte or 4-byte) variables is big-endian. So for
an int, the most-significant-byte would be stored in the first byte of
memory, the next-most-significant byte would follow it, and so on...
What is the byte order used by x86/gnu-linux? How can I flip around the
byte order of certain variables so that when I write out the WAV file,
the bytes are in the order the player expects??
Question #4: Do I have to do anything special to write out a binary
file as opposed to an ASCII text file? Can I just use fputc() to
iteratively drop the contents of the WAV chunk structs into a file? Do
I need to do anything at the top of the file to set the mime type?
Thanks in advance for your advice,
[medic]Dave
I'm new to this group, and almost-as-new to asking programming
questions publicly, so please forgive me if I miss a convention or two!
I have a text file, around 40,000 lines long, where each line is a
string of 4 ASCII characters corresponding to a 12-bit hexadecimal
audio sample. The file reads something like this...
081F
081C
081A
0818
080E
etc...
I would like to write a simple C program in a Linux environment that
will read in this file, convert the strings to signed 2's-compliment
int samples, and output a simple WAV audio file. I've found several
resources on "The Canonical WAV format" via Google, and they describe
the format pretty well.
I already have a program reading in the file and fprintf'ing each line
out to stdout, as a stub. Now I need to build the WAV file.
Question #1: Am I reinventing the wheel? Does anyone know of another
piece of code out there that could do this out-of-the-box? I saw that
ogg123 seems to have a "raw" device option, but there doesn't seem to
be much documentation as to what it expects as a raw sample stream.
Question #2, for those familiar with WAV files: The WAV docs seem to
indicate that there can be only one DATA chunk in each WAV file. In a
DATA chunk, you get 4 bytes to give the size of your data... But what
if you have more data bytes than you can drop into an unsigned 4-byte
int?
Question #3, which is more C-language related: The WAV format uses
little-endian bit orders for all data, but the byte-order of several of
the multibyte (either 2-byte or 4-byte) variables is big-endian. So for
an int, the most-significant-byte would be stored in the first byte of
memory, the next-most-significant byte would follow it, and so on...
What is the byte order used by x86/gnu-linux? How can I flip around the
byte order of certain variables so that when I write out the WAV file,
the bytes are in the order the player expects??
Question #4: Do I have to do anything special to write out a binary
file as opposed to an ASCII text file? Can I just use fputc() to
iteratively drop the contents of the WAV chunk structs into a file? Do
I need to do anything at the top of the file to set the mime type?
Thanks in advance for your advice,
[medic]Dave