Page 1 of 1
Creating a soundtrack (and saving it)
Posted: Tue Feb 07, 2012 5:44 am
by Seymour Clufley
I want to create a WAV file from scratch, specifying other WAV files to be mixed into it at different times. Something like:
Code: Select all
total length = 13seconds
start clip1.wav at 2seconds
start clip2.wav at 7seconds
save mix to my_soundtrack.wav
I've never worked with PB and audio before. Can anyone tell me the simplest way to get this done?
Thanks,
Seymour.
Re: Creating a soundtrack (and saving it)
Posted: Tue Feb 07, 2012 7:01 am
by Guimauve
Re: Creating a soundtrack (and saving it)
Posted: Tue Feb 07, 2012 8:48 am
by Seymour Clufley
Thanks for the links, but they don't give any information about how to mix several sounds. Does anybody have experience of doing this in PB?
Re: Creating a soundtrack (and saving it)
Posted: Tue Feb 07, 2012 3:44 pm
by kenmo
I actually wrote some code that may be exactly what you need... I can post it tonight when I am home.
It never became a complete WAV library like I planned, but it can load basic WAVs, mix them, and save to files (or you can use CatchSound() directly).
Re: Creating a soundtrack (and saving it)
Posted: Tue Feb 07, 2012 4:28 pm
by Seymour Clufley
That sounds really good, Kenmo.
Using the code linked by Guimauve, I did eventually get the job done, but the sounds aren't mixed. Each one stops when the next one starts - result is clicks and pops, but it's better than nothing.
But I would be very interested in the code you mentioned.
Re: Creating a soundtrack (and saving it)
Posted: Wed Feb 08, 2012 4:55 am
by kenmo
Hmmm, I looked over my old code... and I don't like it. (I could send you it if you'd like to look through it.)
It works, but it's really slow, because I wrote it to be TOO general... every sample you modify (millions) checks for mismatches in bit depth (16 or

, number of channels, etc. and compensates accordingly.
Now I remember thinking "this must be why pro audio software just loads every input file into a stereo floating-point buffer..."
I'm tempted to rewrite a nicer, floating-point WAV library (which would simplify all the processing)... but I'm busy the rest of this week

... Maybe in the near future.
Re: Creating a soundtrack (and saving it)
Posted: Wed Feb 08, 2012 7:55 am
by Seymour Clufley
Kenmo,
How about just making it a rule that all files used must be the same bitdepth/samplerate etc? Then you could get rid of the checking and compensating. Or as you say, you could convert all files upon loading to a uniform bitdepth/samplerate, and again, get rid of the constant checks. Wouldn't that speed it up?
Either way, yes I'd like you to send me it. That'd be great.
Seymour.
Re: Creating a soundtrack (and saving it)
Posted: Thu Feb 09, 2012 12:43 am
by kenmo
I messaged you 1600 lines of code

Re: Creating a soundtrack (and saving it)
Posted: Mon Feb 13, 2012 4:14 am
by oryaaaaa
My audio souce code (I needed 4 month 24/7)
http://purebasic.coolverse.jp/_userdata/nr3.7z
Format
CreateFile
<WAV header>
FlushFileBuffers(#File)
<WAV RAW1>
FlushFileBuffers(#File)
<WAV RAW2>
FlushFileBuffers(#File)
<WAV RAW3>
FlushFileBuffers(#File)
CloseFile
I recomend FileBuffersSize(#File, Size). Size is 10MB over.
If you fail creating Raw wave data, then you should use Audacity Import RAW-WAV for Test.
My souce is very crazy. Supported CD-RIP, FLAC Import, FLAC Encode, FLAC Decode,
Up Sampling, Waveout, and CDDA PLAY (and Copy control CD supported).
Re: Creating a soundtrack (and saving it)
Posted: Thu Jan 10, 2013 9:16 am
by waffle
wow, I have been struggling for 4 days on this, and just found the answer here

Thanks for the help. Basically, I hacking Doom1.WAD for sound information that is in raw format.
The PC format is fun too, but I choose to ignore that, the newer (DOOM2.WAD +++) do not use
PC speakers because sound cards were available then. But thanks again.
Maybe I will update my website with the new doom browser when I get this working...
And, NO, I do not export the sounds to a .wav file, I only want to play them.
Maybe for extra fun, I will try and decifer the MIDI files

Re: Creating a soundtrack (and saving it)
Posted: Sun May 02, 2021 2:05 pm
by Seymour Clufley
Just in case anyone else is looking for this kind of thing, it can now be done very easily using
PureSoX. There is a dedicated procedure for it, SoX_GenerateSoundtrack(), and demo code can be found in that thread.