How to Fade-In/Fade-Out a Sampled/Repeating/Mixed Sound

Rob Rothwell r.j.rothwell at gmail.com
Sat May 6 03:03:13 UTC 2006


Dean,

Thanks for all your help trying to figure this out.  However, I am still not
able to create any effect on even a SampledSound with a VolumeEnvelope like
you suggested.  To help hear what is going on I have created a new method,
newExponentialDecay in the  Envelope class where I have changed:

    mSecsPerStep := 10.

    to:   mSecsPerStep := 50.

just to drag out the decay a little longer.  When I do that,

snd := FMSound new.
snd addEnvelope: (VolumeEnvelope newExponentialDecay: 0.96).
snd setPitch: 200 dur: 5.0 loudness: 0.25.
snd play.

fades out as expected, but then when I turn that tone into a WAV and read it
back in:

snd := FMSound new.
snd setPitch: 200 dur: 5.0 loudness: 0.25.
snd storeWAVOnFileNamed: 'tone.wav'.
snd := (SampledSound fromWaveFileNamed: 'tone.wav').
snd addEnvelope: (VolumeEnvelope newExponentialDecay: 0.96).
snd play.

The tone just plays at a constant volume!  Things that make you go...hmm...

Thanks again,

Rob

On 5/5/06, Dean_Swan at mitel.com <Dean_Swan at mitel.com> wrote:
>
>
> OK,  Here is the answer:
>
> There are three implementors of 'storeSampleCound:bigEndian:on:' :
>
>         AbstractSound>>storeSampleCount: samplesToStore bigEndian:
> bigEndianFlag on: aBinaryStream
>
>         LoopedSampledSound>>storeSampleCount: samplesToStore bigEndian:
> bigEndianFlag on: aBinaryStream
>
>         SampledSound>>storeSampleCount: samplesToStore bigEndian:
> bigEndianFlag on: aBinaryStream
>
> The AbstractSound implementation does what you want, while the other two
> (which are identical) do not account for the envelopes.  These were all
> present as of December 2001,  attributed to John Maloney and were modified
> by Stephane Ducasse in 2003 to clean up the way that the current endianness
> is checked.
>
> I don't know why there are two essentially different implementations.  My
> initial inclination is that the 'LoopedSampledSound' and 'SampledSound'
> implementaions are unnecessary and should be removed, but I really don't
> know what John was thinking about, and the comments don't really say.  Does
> anybody know the history on this?  I don't know if it would break any extant
> code if only the 'AbstractSound' implementation were kept.
>
> Regarding 'RepeatingSound', that will take some more digging.  I can say
> that if you add the envelope to the SampledSound that is created from the
> wave file, then create a RepeatingSound using the SampledSound that has an
> amplitude envelope, you will hear the envelope for each repetition.
>
> This might be a weakness in how envelopes are used for playback.
>  Presumably, an envelope applied to the 'RepeatingSound' should control the
> overall volume of the composite sound, but that doesn't seem to be what is
> happening.
>
> As Chris mentioned, the debugger is your friend.  Add "self halt." before
> a message send you want to debug, click on 'Debug' when the 'Halt'
> notification window pops up and then use the 'Over' and 'Into' buttons to
> single step through the code.
>
>         -Dean
>
>
> Hi Rob,
>
> If you try this:
>
>        snd := (SampledSound fromWaveFileNamed: 'aWAVFile.wav').
>       snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.96).
>        snd play.
>
> You will hear the effect of the envelope, as desired.
>
> This:
>
>        snd storeWAVOnFileNamed: ' out.wav'.
>
> should have done what you want, but obviously it does not.  I have spent a
> little time tracking this, but I haven't found the problem yet.
>
> I will send another reply when I figure this out (maybe today, or later
> this weekend).
>
>
>        -Dean
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20060505/76965461/attachment.htm


More information about the Squeak-dev mailing list