r3wp [groups: 83 posts: 189283]

# World: r3wp

## [Sound] discussion about sound and audio implementation in REBOL

 older first Rebolek20-Apr-2009[216] ```it uses vector! for storing sound data ``` ICarii20-Apr-2009[217] ```i thought vector was broken? - ive been avoiding it since i heard that ``` Rebolek20-Apr-2009[218] ```Well vector has its limitations but if you try hard enough, it's usable :) ``` ICarii20-Apr-2009[219] ```noticed an Endian bug in bitrates of 16+ when saving to wav files - will fix this in next release. ``` ICarii21-Apr-2009[220] ```ok - im trying to calc the optimal intersection point where 3 different frequency sine waves create the highest complex wave - w1: freq 440.0Hz w2: freq 530.0Hz w3: freq 720.0Hz i was using: sine (90 * w2 / w3) + sine (90 * w1 / w3) + 1.0 this was under the assumption that the greatest cumulative distance from 0 would be at the 90degree mark from the highest freq wave - unfortunately this is not the case :( does anyone have a nice (or not too nasty) formula that will find the optimum value? - i will post this in maths too ``` Anton21-Apr-2009[221] ```Do you mean you are trying to find the repeating period of the three sine waves, once they are combined ? I think that means finding the lowest common denominator. ``` ICarii21-Apr-2009[222] ```i am trying to find the maximum amplitude of the complex wave ``` Anton21-Apr-2009[223] ```Ok, different problem than I thought.. ``` ICarii21-Apr-2009[224] ```sorry - wasnt very clear in my original post ``` Anton21-Apr-2009[225] ```So you want to calculate it in advance. ``` ICarii21-Apr-2009[226] ```yes - it is a huge time save when i go to do loudness balancing ``` Pekr21-Apr-2009[227] ```just a note to Sound. Some time ago, when Cyphre tried to do media player in REBOL for us, he complained about some bugs in smooth playback. Carl released C code for the sound system in REBOL - this is some 2 - 3 pages of C code (mostly wrappers) IIRC? Maybe we could fix few things for next R2 release? ``` ICarii21-Apr-2009[228] ```sounds good - now all we need is a coding sound engineer ;) ``` Geomol21-Apr-2009[229] ```The max amplitude, you find, depends on how long you play the sound, doesn't it? If you play it long enough, you might get max for each of the sin added together, which is 3. ``` Anton21-Apr-2009[230] ```If your 3 waves happen to peak all at the same time, then the maximum amplitude is simply the addition of all three amplitudes. If not, then the max amplitude is some lesser value. Calculating this seems complicated to me.. ``` ICarii21-Apr-2009[231x2] ```i cheated and used the number of waves ``` ```its not strictly correct though depending on the start phase etc ``` Anton21-Apr-2009[233] ```As you add together a larger number of waves, you will find the maximum amplitude is typically much less than the total of all the wave amplitudes. It might be easier to generate all the samples of the complex wave (using decimal!/float), keeping track of the maximum value, then scaling it to 8 or 16 bit integers afterwards. It would be nice to have a precise mathematical way of calculating the maximum peak values in advance, though... ``` ICarii21-Apr-2009[234] ```yes - that would be nice. Ill have a hunt about see what i can find. I know a couple of sound engineers who might know ``` Geomol21-Apr-2009[235] ```It makes me think of something called Fourier Transformations: http://en.wikipedia.org/wiki/Fourier_transform ``` ICarii21-Apr-2009[236] ```yes - they are good for decomposing waves. very math/processor intensive though ``` Steeve21-Apr-2009[237] ```hey guys, I have somewhere an FFT implementation in Rebol, interested ? ``` Anton21-Apr-2009[238] ```Steeve, what did you use it for? Just experimenting? ``` Steeve21-Apr-2009[239] ```it shows frenquencies for a sample, but i don't remember how i did that, i can post the demo ``` ICarii21-Apr-2009[240] ```would be interesting to see one :) My next project is to decompose complex waves into sheet music :) ``` Steeve21-Apr-2009[241] ```FFT = Fast fourier transform ``` ICarii21-Apr-2009[242] ```of course - thats about a month away at the rate of my current project :) ``` Anton21-Apr-2009[243] ```Hoho! ``` Steeve21-Apr-2009[244x3] ```ok i upload the old demo ``` ```*** UPLOAD at http://sites.google.com/site/rebolish/Home (see FFT.R at the end of the page) ``` ```you have to load a wav sample ``` Anton21-Apr-2009[247x2] ```Wow - first use of CP (alias of COPY) I ever saw. I override CP to be a unixiod file copy function. ``` ```long wave file .... crunch crunch... ``` Steeve21-Apr-2009[249] ```it's an old script Anton ``` Anton21-Apr-2009[250] ```I see a little graph :) ``` Steeve21-Apr-2009[251] ```yep, it show a graph with some frequencies, don't remember why... ``` Anton21-Apr-2009[252x2] ```:) ``` ```I've got an old script which uses FMOD library to show a spectrum window in rebol while a sound is playing. It's a Windows DLL but it works in wine. do-thru http://anton.wildit.net.au/rebol/audio/fmod/play-rebol-sound.r ``` Rebolek21-Apr-2009[254] ```Icarii, calculate RMS of the sound. ``` Oldes21-Apr-2009[255] ```Anton: ** Script Error: cv has no value ** Where: do-parse ** Near: cv mold type-converter/c-to-rebol-map ``` Rebolek21-Apr-2009[256] ```Steeve, thanks for the FFT, I'm really interested. I had only DFT running for my modular synth. And maybe iFFT also, I don't remember, I hope the sources are still somewhere in deeps of the Internets. ``` Steeve21-Apr-2009[257] ```Anton, you asked why i had an FFT implementation... Because, i made some tests to extract frequencies from wav sounds, to be able to play sounds on an old 8bit sound chip. And also, i wanted to use FFT to make an image compressor. Geez, so much projects vanished... ``` Anton21-Apr-2009[258] ```Oldes, thanks. Do this load-thru/update http://anton.wildit.net.au/rebol/os/make-external-library-interface.r then try again. ``` ICarii22-Apr-2009[259] ```new version of synth almost ready - added an oscilloscope so i can see where my complex waves are not behaving .. lol ``` Maxim14-May-2009[260x4] ```just realized that altme (probably rebol itself..) fucks up my system volume :-( ``` ```when it pings, my sound driver's "WAVE" slider resets to 33% >:-( ``` ```has anyone noticed this side-effect with rebol before? ``` ```it should just set its own volumn, not the system's wave volume.. ``` Henrik14-May-2009[264] ```Maxim, RAMBO #4239 ``` Maxim14-May-2009[265:last] ```ah thanks. ``` older first