Sound!

hi there,
previously, i learn about digital audio...now im trying to play a sound using SDL library...I have a problem on processing the sound.
Now im trying to add delay for my sound..so my sound will sounds like slow motion..
My question is: to make my sound delay, do i need to add more samples? Like @ is 1 sound samples. So, if i wan add delay to this audio do i just duplicate @ to @ @ ? (hope u get wat i mean)
Because to make the sound delay, surely the time will increase. Is my logic correct? or there's other way to do it...
I'm not sure what effect changing the sample rate will have. Changing the frequency will affect the speed, but the sound won't sound smooth any more so this probably isn't what you're looking for.

I don't know much about sound mixing but I fiddled with SDL sound once and it's slightly perplexing that you have to code all of the loading, mixing and playing yourself, I don't know why they don't provide that functionality in the library. Still, it's fun to play around with, and if you know what you're doing I guess it will give you a lot of flexibility.
Last edited on
Because to make the sound delay, surely the time will increase. Is my logic correct?

Yes. More samples = longer audio. If you're going to duplicate the number of samples you're playing, the audio will be twice as long.

So, if i wan add delay to this audio do i just duplicate @ to @ @ ? (hope u get wat i mean)


This will have the desired effect. A side effect of this is that everything will play an octave lower (think of an old cassette player with the battery dying -- it's slow and low pitched).

If you look at the wave you're generating you can see why. For example let's say you have a simple square wave:

(1 digit = 1 sample)
00005555000055550000555500005555

Here we have a wave that repeats every 8 samples, and cycles 4 times (IE: a tone of 4 Hz)

Duplicating the samples get's you this:
00000000555555550000000055555555

Now we have a wave that repeats every 16 samples, and cycles only 2 times in the same window of time (a tone of 2 Hz -- half of what we had before)


This is a simplistic example, of course, but the concept applies to complex waveforms also.


If you want to slow the audio down without changing the pitch, there are ways to do it, but they're pretty involved. If interested, I can get into it but for now I'll just assume the above is what you're looking for.


EDIT:


For what it's worth, I should mention the above method will work, but is naive. A better method would employ linear interpolation when adding samples. Basically this means to "blend" the samples together so the transitions are smoother. This makes for a better sound:

For example consider the below audio:
02573461 original
0022557733446611 naive duplicate
0123567533456311 interpolated
Last edited on
Sry for coming back late..=(
but, Wow thx for the reply I got what u mean.
anyway, i found the solution for it:
SDL is quite interesting, because i found out if want to slow down the sound or add delay we can simply set the sound's frequency, beside i never thought or mixing sound to increase the effectiveness of sound delay.
For example,
I got 1 sound with the samples below:

0000 0000 0000
*space indicate the frequency rate, 4Hz for 1 cycle.
By creating sound delay, first I reduce the frequency rate:

000 000 000 000
Now is 3Hz for 1 cycle.Yes it will take longer time to finish playing.

Now I want to make my sound a little bit echo to increase the effective of delay using SLD_AudioMixer.
To do this, i will need to create more sounds which same as my 1st sound.

111 111 111 111
and

222 222 222 222
and mix up the sound with little delay:

1
2
3
000 000 000 000
d111 111 111 111
dd222 222 222 222

*d indicate as delay, my 2nd and 3rd sound start after d...

I dunno how actually SDL_AudioMixer work on the samples, but it works well.. =)
Last edited on
Topic archived. No new replies allowed.