Re: [linux-audio-dev] reading sound file

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] reading sound file
From: Paul Barton-Davis (pbd_AT_Op.Net)
Date: pe helmi  11 2000 - 10:22:59 EST


> Ok, I know I asked this question a little while ago, but I guess
>this one is more specific. If I have a file pointer (FILE *fp) Pointing to
>the begging of the wave data in a sound file, and I know the total length
>of the sound data, can someone give me a little bit of code that will read
>the sound data into memory? Thanks.

If you don't know how to do this, I'm not sure you should be writing
the program you're working on at this point in time. Perhaps there is
some to what you're doing that has convinced you that its more complex
than it really is. Anyway:

    unsigned char *soundbuf;

    soundbuf = (unsigned char *) malloc (total_size_of_sound_data_in_bytes);
    fread (soundbuf, total_size_of_sound_data_in_bytes, sound_data_file);

This is not a particularly robust way to handle a soundfile unless you
know that it is short enough to fit into memory. It also doesn't take
byte swapping into account.

More broadly, why don't you go get libaudiofile, which will take care
of this kind of thing for you. There are many other fine (better, some
might say) audio file libraries too - see Dave Phillips Linux Sound &
MIDI page for URLs.

The only reason to be writing code to do this is if you need a feature
that existing libraries don't have (e.g. mmap read access,
non-interleaved access to channels, more than 2 channels, etc.)

--p


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:23:27 EST