Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / 2+ wav files merge into 1

Author
Message
Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 8th Nov 2009 22:43
I'm looking for a way to merge multiple wave files into 1.

I want to make an music program that uses wave files as samples. I want to put them into a single new wave file on the exact ms I want to. Also it must be possible to have several wave files layed over each other. All extra stuff like pan and volume would be nice to have to.

Is there anyone who knows how to do this in DBP?

Thanks

sorry for my English. I'm Dutch and I did get some sleep during English-class.

I am part of the problem and will always be.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Nov 2009 04:02
The only method I'm aware of would depend on several things. Samples would have to be the same bitrate, and possibly same number of channels.

Here's a good thread to start your research:
http://forum.thegamecreators.com/?m=forum_view&t=152797&b=1

Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 9th Nov 2009 09:35
Possible, yes.
Just pitching in that making a full song that way will probably take a long while.

The first thing to watch out for is the audio data length; the mixdown storage must be large enough to hold the complete output, so pre-calculating the needed length and then convert that into bytes should be a clever thing.

Secondly, for (stereo) panning purposes, you simply need two channels on your mixdown memory. (Surround panning is a pain).

I've never actually tried to blend more than two audio signals at once, but I believe that the way to go about it in order not to distort it would be to normalize all blended tracks to
full amplitude / number of simultaneous audio signals.
(That would be tricky to get good if only a fraction of all blended audio tracks actually play at once - you could always try amplifying the result back up afterwards in that case though; may not come out that bad).
What you would do then is simply to step through all audio samples from each signal to be blended, take the average of their values and write that to the specific position of the master memory location. (There are obviously smoother ways than just the mean average value, but it should work decently enough if you are working with 16-bit sounds).

Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 9th Nov 2009 16:15
OK. thank you both. That's a start.

@Rudolpho

It may take some time. It is only to export the soundfile when you're done making it. While still in the program, it will play using the timer function and play sound. I've already tested that part and it works great. But there is a little downside. You need the program to if you want others to lissen to the file. Wave and MP3 everybody can play. So than you want to export the file. Exporting in Cubase takes some while to.

I am part of the problem and will always be.

About my Enligh. No I can not write it very well.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Nov 2009 20:02
Download Audacity.

It's free.
Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 9th Nov 2009 20:21
@Green gandalf

Thanks, but no. It can not create sheetmusic from your music. And you can not use sheetmusic-like input to create the wave file.

There are several programs with midi to do that, but not with your own sounds, that I know of.

And, an other thing. Writing your own programs is a lot more fun.

I am part of the problem and will always be.

About my Enligh. No I can not write it very well.
Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 14th Nov 2009 15:16 Edited at: 14th Nov 2009 16:24
After some metal crashes I managed to read a 440hz tune in a mono 16 bit wave file. Understandig how a wave-file is build up, is the first part for editing wavefiles.

The maximum Amplitude (volume) is 32767
but in a wavefile the maximum number is 65535. It toke me al while to figure out that this is the negative side of an wave-amplitude.

To read this number you must know that 32768 is -1. (maybe I am wrong in this number, correct me where possible)

To calculate the right amplitude you must use 65535 - <readed number> * -1.0

This only works for 16 bit files. Here is the code I found




download the tone.wav if you don't have a 16-bit soundfile

I am part of the problem and will always be.

About my Enligh. No I can not write it very well.

Attachments

Login to view attachments
Kira Vakaan
16
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 14th Nov 2009 15:51 Edited at: 14th Nov 2009 15:58
Hm, I dunno about that. It makes most sense to me that 65535 would be -1.
The largest number you can store inside two bytes (16 bits) is 65535. In C/C++, a short variable is two bytes long, and comes in two varieties, signed and unsigned and have ranges of -32768 to 32767 and 0 to 65535 respectively. If the last bit of a signed variable is set, the value of the variable can be determined by subtracting the inverse of the variable from -1. For example:


Edit: Thought of a better way to phrase it.
Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 14th Nov 2009 16:06
I changed the code. In stead of * -1 I now simple do - 65535. So the formula would be:

<readed number> - 65535

It makes more sense this way. Am I right?

I am part of the problem and will always be.

About my Enligh. No I can not write it very well.
Kira Vakaan
16
Years of Service
User Offline
Joined: 1st Dec 2008
Location: MI, United States
Posted: 14th Nov 2009 16:20
Almost. I think it should be <number> - 65536.
Thus, 65535-65536=-1, 65531-65536=-5, and 47616-65536=-17920.
Rudolpho
19
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 14th Nov 2009 16:31
I would have guessed <number> - 32768
But just try it, if it works, then it should obviously be right.

Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 14th Nov 2009 16:35
@ Rudolpho

I have tried to reduce the number I found using WORD - 32768 but that didn't work. For some reason the negative side of the Amplitude are the higher numbers. Just minus would give strange values.

-30000 would not be 2768 in a wave file.

I am part of the problem and will always be.

About my Enligh. No I can not write it very well.
Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 14th Nov 2009 17:31 Edited at: 14th Nov 2009 17:36
Now I can merge sounds. It's not perfect (yet), but it works. The volume is a little lower than normal, so I've got to figure out how to get the volume back to normal again.



I am part of the problem and will always be.

About my Enligh. No I can not write it very well.

Attachments

Login to view attachments
Quickwim
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: Lost in my own disturbed mind
Posted: 14th Nov 2009 19:37 Edited at: 14th Nov 2009 19:42
Thanks to jinzai in this tread http://forum.thegamecreators.com/?m=forum_view&t=124099&b=20 I now can create wav files that can be readed by WMP.



I am part of the problem and will always be.

About my Enligh. No I can not write it very well.

Login to post a reply

Server time is: 2025-05-08 07:59:37
Your offset time is: 2025-05-08 07:59:37