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

Dean_Swan at Mitel.COM Dean_Swan at Mitel.COM
Sat May 6 03:48:48 UTC 2006

Hi Rob,

This begs the question:  "What version of Squeak are you running, and on 
what platform?"

I just tried your example on Squeak 3.7-5989 on my G4 iBook (OS X 10.4.6, 
Squeak 3.8.12beta4U VM), and your example works fine.  It writes out the 
tone to a file without any decay, then the SampledSound plays with the 
decay after reading the tone back in and adding the envelope.

Your earlier problem really is a problem.  We'll have to see what the 
others say for future versions, but for now you could just make a new 
method on SampledSound, something like:

        SampledSound>>myStoreSampleCount: samplesToStore bigEndian: 
bigEndianFlag on: aBinaryStream
                super storeSampleCount: samplesToStore bigEndian: 
bigEndianFlag on: aBinaryStream.

which would just execute the AbstractSound implementation.

So, I'll need some help trying to reproduce your current problem.


"Rob Rothwell" <r.j.rothwell at>
05/05/2006 11:03 PM
Please respond to rjriv

        To:     "Dean_Swan at" <Dean_Swan at>
        cc:     "The general-purpose Squeak developers list" 
<squeak-dev at>, Dan at, 
jmaloney at, squeak-dev-bounces at
        Subject:        Re: How to Fade-In/Fade-Out a Sampled/Repeating/Mixed Sound


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 

Thanks again,


On 5/5/06, Dean_Swan at <Dean_Swan at > 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 

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. 


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. 


       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). 


-------------- next part --------------
An HTML attachment was scrubbed...

More information about the Squeak-dev mailing list