Thread: How to piece together multiple sound files into one streamed .wav or .mp3 file?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Complete Beginner
    Join Date
    Feb 2009
    Posts
    312
    Is your nick supposed to mean "Hagbard Celine"? In this case, I'd say "Think for yourself, schmuck!" ;-)

    Assembling a .wav file that contains 18000 spoken characters is not a good idea. It will be huge, and it's far more elegant to write a program that reads the file and produces the corresponding sound on-the-fly:

    Code:
    char file[10];
    
    while((c = fgetc(fp)) != EOF) {
            sprintf(file, "%c.wav", c);
            call_external_program("my_wavplayer %s", file);
    }
    If you just want to let the world know about the DNA sequence of a mitochondrion, it's probably more convenient to assemble a MIDI file where each instrument corresponds to a nucleoside. It will be much less boring to listen to, and it's easier to remember ;-)

    MP3 is a streaming format, so simply appending two mp3 files should also work. On my system, I tested it with "cat a.mp3 b.mp3 >> c.mp3 && mpg123 c.mp3" and it worked perfectly. Don't forget to remove the ID3 tag from a.mp3 (i.e. the last 128 bytes), if it has one. You can easily do this with a hex editor, because the first three bytes of the ID3 tag are 'T', 'A' and 'G', if I remember correctly.

    If you still insist on generating .wav files, I'd suggest using a library that reads and understands .wav files. Maybe SDL is a good starting point, but actually I don't know anything about graphics and sound programming. If this is supposed to be a short hack, I'd use Perl and whatever module that implements .wav support.

    Greets,
    Philip
    Last edited by Snafuist; 03-22-2009 at 06:43 PM.
    All things begin as source code.
    Source code begins with an empty file.
    -- Tao Te Chip

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Searching Binary Files for a Pattern
    By CaptainMorgan in forum C Programming
    Replies: 16
    Last Post: 06-17-2007, 06:04 PM
  3. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM