Creating a soundtrack (and saving it)

Just starting out? Need help? Post your questions and find answers here.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Creating a soundtrack (and saving it)

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Creating a soundtrack (and saving it)

Post 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?
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Creating a soundtrack (and saving it)

Post 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).
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Creating a soundtrack (and saving it)

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Creating a soundtrack (and saving it)

Post 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 8), 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 :x ... Maybe in the near future.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Creating a soundtrack (and saving it)

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Creating a soundtrack (and saving it)

Post by kenmo »

I messaged you 1600 lines of code 8)
User avatar
oryaaaaa
Enthusiast
Enthusiast
Posts: 791
Joined: Mon Jan 12, 2004 11:40 pm
Location: Okazaki, JAPAN

Re: Creating a soundtrack (and saving it)

Post 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).
User avatar
waffle
Enthusiast
Enthusiast
Posts: 127
Joined: Mon May 12, 2003 1:34 pm
Location: USA
Contact:

Re: Creating a soundtrack (and saving it)

Post 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 :idea:
Code is good... Its an international language.
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Creating a soundtrack (and saving it)

Post 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.
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Post Reply