News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Programming sound effects

Started by piotrus, March 01, 2007, 03:09:37 PM

Previous topic - Next topic

Tedd

No snowflake in an avalanche feels responsible.

sebart7

Sound effects is a wide topic but ill try to make it as short as possible.
Large amount of Sound effects including echo, ambient efect, flanger, horus, ect,
is created by multiple phase shifting of base sample data.
Theoreticaly it can be done by just one universal simple routine to where You pass fiew
input parameters and receive certain effect as output.

Heres example picture :


Red is a base sample. Green is shifted base sample mixed together with it self (in example multiple times)
Before mixing shifted sample with base sample You may process it also somehow (fade in time ect)

Lets say example FX routine call may looks like  invoke DoSoundFX1,delayTime,valFade,valRepeat

Where :
delayTime is amount of shift.
valFade is for example how fast shifted sample will fade to silence (process it before mix with base sample)
valRepeat is how many times to repeat (picture shows 2x repeat)
Of course in time and researches You may add more parameters and make it much more complex.

Here fun starts, By providing diferent parameters You may get realy cool effects.
1000,0,1 will give FX similar to just ading sample to end of buffer like You did before
250,100,5 will give realy nice advanced echo effect.
20,40,300 may give corridor like echo efect. Ect ect....

Also You may consider to add more advanced parameters like sinShift. (look at small sinus betwin samples at picture above)
Idea is to add sinus values that change in time to delayTime. This way each shift will be a little unregular.
If You use parameter sinShift > 0 (enabled) You should use small value for delayTime that together will
create nice, drifting alike, flanger effect.

Mixing 2 samples is like
(byteSample1 + byteSample2) / 2 , dont forget to sub 080h it and add 080h before and after.
it can be:

; AL is sample1Byte
; BL is sample1Byte

    and EAX,0ffh   ; leave only AL data (but wee need all EAX)
    sub EAX,080h  ; make sample1 as  -127 +127 range
    and EBX,0ffh   ; leave only BL data (but wee need all EBX)
    sub EBX,080h  ; make sample2 as  -127 +127 range
    add EAX,EBX   ; mix both sampleBytes
    shr  EAX,1       ; shifting bits right is alike divide by 2
    add EAX,080h  ; make it back 0 to 255 range

; here You have In AL mixed byteSample