Fastest way to add a lot of data... adding wavs

BlitzPlus Forums/BlitzPlus Programming/Fastest way to add a lot of data... adding wavs

RexRhino(Posted 2004) [#1]
I need to add a whole lot of data together. Specificly, I am rendering songs by combining individual wav files. Right now I am storing the wav files in a bank, and I am going to each two byte block and adding them in a for next loop.

This is EXTREMLY SLOW. What takes about 30 seconds to render in fruityloops with effects takes about a day and a half to be rendered with my blitz program.

I am assuming that for-next loops are just extremly slow, but is there some other way in blitz to add banks (or arrays) together. Is there some mass bank adding function?


CS_TBL(Posted 2004) [#2]
not that I know of ..

..but MY GOD, what are your intentions? making a tracker or what? :)


RexRhino(Posted 2004) [#3]
..but MY GOD, what are your intentions? making a tracker or what? :)

Kind of. My intention is to create a program that generates music, so that that huge music files do not need to be downloaded.

Your game program would generate audio files on install, and you would have full quality CD sound music files in a 1.5 meg download (I would also convert them to .ogg with an included external program).

The problem is that it is just TOO SLOW! I mean, it is insanely slow. I have tried everything I know in order to speed it up, but I cannot speed it up. This is definitly some flaw in Blitz, because, like I said, I have other programs that can do the exact same thing in less than 30 seconds.


soja(Posted 2004) [#4]
You're sure debug mode isn't enabled? ;)

Do you have to worry about overflow when working with the bytes?


RexRhino(Posted 2004) [#5]
Debug definitly isn't enabled!!! :) First thing to check!

I don't have to worry about overflow, or at least not now. I AM checking for overflow and limiting that, but that isn't the slow part (I tried removing it, and it was still slow).


CS_TBL(Posted 2004) [#6]
Kind of. My intention is to create a program that generates music, so that that huge music files do not need to be downloaded.


kinda like I did -years ago- for Gizmozone inc .. but then with downloadfiles of 1..20kb :) (www.gizmozone.com .. search the ixs player and the ixs files)

I might even do some music-generating things (conventional music, not art-stuff :), but I'd just generate the notes then. I would write the notes to some format (like a trackerformat) so that all notes appear in my pattern editor, and then I'll add the instruments myself .. but I guess this is not exactly what you wish :)


Oso(Posted 2004) [#7]
Out of curiosity I just tried looping through two banks of 1,000,000 bytes each and doing a few additions and a division with them. (Using peek and poke) It takes about 60 milliseconds on this fairly old computer here at work where I am now. Do you do a tremendous heap of interpolation using polynomials or something similar ? There must be more to it than adding two banks together.


RexRhino(Posted 2004) [#8]
Hmmm... Maybe I am doing something wrong. The files I am using would be a lot bigger...

44100(samples per second) * 5(minutes per song) * 60(seconds per minute) * 2(channels) * 2(2 bytes per 16 bit word) * 10(tracks per song) = 529200000

So it would be 529 times as long as your 1,000,000 iterations... but still 529 at 60 milliseconds would be about 31740 milliseconds (or about 30 seconds, same as it takes with fruityloops)...

I guess there is something I am not catching in my code!


skidracer(Posted 2004) [#9]
Doing all 10 tracks in parallel will put a lot more strain on virtual memory than allocating just two banks accumulating each track sequentially.


RexRhino(Posted 2004) [#10]
I solved the problem (thanks you guys for the help)!!!

Here is the problem:
I was calling a function to do the addition, which was calling several other functions, which was calling several other functions...

I simply copied and pasted the code from those other functions into the loop (so it wasn't making any function calls in the loop), and low and behold, it is rendering the sound in about 30 seconds!!!

I didn't know that all those function calls really slowed things down so much!


Oso(Posted 2004) [#11]
I think we've all done that, Rex. Using functions recursively is no doubt very structurally elegant, but get one variable wrong and it can produce a hell of a mess. In the old days of IBM34 at work (not at IBM itself, I hasten to add)I wrote a procedure which called itself twice from each parent. The whole system ground to a halt in a few seconds and had to be switched off and on to make it work. Funny how the ones most interested in getting a copy of it were the IBM engineers themselves.

I'm pleased you solved everything.


skn3(Posted 2004) [#12]
hehehehehe at 600,00,000 calls to a function, you tend to get slow down aye ^_^ ?

your system sounds like a clever idea. Somone from Acoders wrote a mod file format similar, that packs all the samples from your whole soundtrack into 1 data file. Then your music files will be a 1k music sheet that tells the engine how to play.

http://syntesis.ath.cx/docs/wsf/html/

Theres a library + dll that can be used (with userlib) in blitz. Just goto the download page :)