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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Rob Rothwell
Does anyone know how to fade a mixed sound?  I am creating a MixedSound which includes both a RepeatingSound (based on a looped SampledSound from a WAV file), and an FMSound. 

I pretty much know how to apply a VolumeEnvelope to an FMSound by looking at the exponentialDecay method, but applying a VolumeEnvelope to a SampledSound, RepeatingSound, or MixedSound seems to have no effect.

For example...

snd := RepeatingSound new.
snd setSound: (SampledSound fromWaveFileNamed: 'aWAVFile.wav') iterations: 1.
snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.96).
snd storeWAVOnFileNamed: ' out.wav'.

...shows no effect on the waveforms in the resulting WAV file, even if I change the step size of the increments in the exponentialDecay to drag the decay out much further...

Do I need to write a method to modify the SoundBuffer values of the SampledSound directly?  If so, I'm afraid I will need much more help!

I just don't know enough technically about sound generation to trace my way through the updateTargetAt method of the VolumeEnvelope class to figure out what is going on with a non-FMSound...

Thanks,

Rob




Reply | Threaded
Open this post in threaded view
|

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

Dan Ingalls
Hi, Rob -

I can't vouch for storeWAVOn, but I have used the following to build some pretty cool wind chimes...
        | snd |
        snd _ FMSound new.
        snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.985).
        (snd setPitch: 2000 dur: 4.0 loudness: 0.5) play

Well, actually I did just try it and got a .wav file that sounded right...
        | snd |
        snd _ FMSound new.
        snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.985).
        (snd setPitch: 2000 dur: 4.0 loudness: 0.5) storeWAVOnFileNamed: ' out.wav'.

Hope this helps.

        - Dan

>Does anyone know how to fade a mixed sound?  I am creating a MixedSound which includes both a RepeatingSound (based on a looped SampledSound from a WAV file), and an FMSound.
>
>I pretty much know how to apply a VolumeEnvelope to an FMSound by looking at the exponentialDecay method, but applying a VolumeEnvelope to a SampledSound, RepeatingSound, or MixedSound seems to have no effect.
>
>For example...
>
>snd := RepeatingSound new.
>snd setSound: (SampledSound fromWaveFileNamed: 'aWAVFile.wav') iterations: 1.
>snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.96).
>snd storeWAVOnFileNamed: ' out.wav'.
>
>...shows no effect on the waveforms in the resulting WAV file, even if I change the step size of the increments in the exponentialDecay to drag the decay out much further...
>
>Do I need to write a method to modify the SoundBuffer values of the SampledSound directly?  If so, I'm afraid I will need much more help!
>
>I just don't know enough technically about sound generation to trace my way through the updateTargetAt method of the VolumeEnvelope class to figure out what is going on with a non-FMSound...
>
>Thanks,
>
>Rob


Reply | Threaded
Open this post in threaded view
|

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

Dan Ingalls
Hi, again, Rob -

>Well, actually I did just try it and got a .wav file that sounded right...
> | snd |
> snd _ FMSound new.
> snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.985).
> (snd setPitch: 2000 dur: 4.0 loudness: 0.5) storeWAVOnFileNamed: ' out.wav'.

Doggone.  I see now that you had this figured out and were having problem with sampled sounds.

The one thought I have without getting into it deeply is that you might be able to initialize an FMSound in such a way that its buffer comes from  'aWAVFile.wav, and its various parameters cause it simply to be played through once with no FM (ie the degenerate case is basically like a SampledSound.  Then I think the envelope logic should work.

Hopefully you'll hear more from one of the real sound jocks.

        - Dan

Reply | Threaded
Open this post in threaded view
|

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

Dean_Swan
In reply to this post by Rob Rothwell

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





"Rob Rothwell" <[hidden email]>
Sent by: [hidden email]

05/03/2006 10:25 PM
Please respond to rjriv; Please respond to The general-purpose Squeak developers list        

       
        To:        [hidden email]
        cc:        
        Subject:        How to Fade-In/Fade-Out a Sampled/Repeating/Mixed Sound



Does anyone know how to fade a mixed sound?  I am creating a MixedSound which includes both a RepeatingSound (based on a looped SampledSound from a WAV file), and an FMSound.  

I pretty much know how to apply a VolumeEnvelope to an FMSound by looking at the exponentialDecay method, but applying a VolumeEnvelope to a SampledSound, RepeatingSound, or MixedSound seems to have no effect.

For example...

snd := RepeatingSound new.
snd setSound: (SampledSound fromWaveFileNamed: 'aWAVFile.wav') iterations: 1.
snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.96).
snd storeWAVOnFileNamed: ' out.wav'.

...shows no effect on the waveforms in the resulting WAV file, even if I change the step size of the increments in the exponentialDecay to drag the decay out much further...

Do I need to write a method to modify the SoundBuffer values of the SampledSound directly?  If so, I'm afraid I will need much more help!

I just don't know enough technically about sound generation to trace my way through the updateTargetAt method of the VolumeEnvelope class to figure out what is going on with a non-FMSound...

Thanks,

Rob






Reply | Threaded
Open this post in threaded view
|

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

Dean_Swan
In reply to this post by Rob Rothwell

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



[hidden email]
Sent by: [hidden email]

05/05/2006 05:11 PM
Please respond to The general-purpose Squeak developers list        

       
        To:        [hidden email], The general-purpose Squeak developers list <[hidden email]>
        cc:        [hidden email], [hidden email]
        Subject:        Re: How to Fade-In/Fade-Out a Sampled/Repeating/Mixed Sound




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





"Rob Rothwell" <[hidden email]>
Sent by: [hidden email]

05/03/2006 10:25 PM
Please respond to rjriv; Please respond to The general-purpose Squeak developers list        

       
       To:        [hidden email]

       cc:        

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




Does anyone know how to fade a mixed sound?  I am creating a MixedSound which includes both a RepeatingSound (based on a looped SampledSound from a WAV file), and an FMSound.  

I pretty much know how to apply a VolumeEnvelope to an FMSound by looking at the exponentialDecay method, but applying a VolumeEnvelope to a SampledSound, RepeatingSound, or MixedSound seems to have no effect.

For example...

snd := RepeatingSound new.
snd setSound: (SampledSound fromWaveFileNamed: 'aWAVFile.wav') iterations: 1.
snd addEnvelope: (VolumeEnvelope exponentialDecay: 0.96).
snd storeWAVOnFileNamed: ' out.wav'.

...shows no effect on the waveforms in the resulting WAV file, even if I change the step size of the increments in the exponentialDecay to drag the decay out much further...

Do I need to write a method to modify the SoundBuffer values of the SampledSound directly?  If so, I'm afraid I will need much more help!

I just don't know enough technically about sound generation to trace my way through the updateTargetAt method of the VolumeEnvelope class to figure out what is going on with a non-FMSound...

Thanks,


Rob








Reply | Threaded
Open this post in threaded view
|

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

Rob Rothwell
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, [hidden email] <[hidden email]> 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



Reply | Threaded
Open this post in threaded view
|

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

Rob Rothwell
Sorry--

Something somewhere is amiss with my image.  If I use a clean 3.8 image, my example below works as expected, but still does not output properly to a WAV...

Rob

On 5/5/06, Rob Rothwell <[hidden email]> wrote:
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



Reply | Threaded
Open this post in threaded view
|

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

Dean_Swan
In reply to this post by Rob Rothwell

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.

        -Dean



"Rob Rothwell" <[hidden email]>

05/05/2006 11:03 PM
Please respond to rjriv

       
        To:        "[hidden email]" <[hidden email]>
        cc:        "The general-purpose Squeak developers list" <[hidden email]>, [hidden email], [hidden email], [hidden email]
        Subject:        Re: How to Fade-In/Fade-Out a Sampled/Repeating/Mixed Sound



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@... <Dean_Swan@... > 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




Reply | Threaded
Open this post in threaded view
|

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

Dean_Swan
In reply to this post by Rob Rothwell

Oops, This would only work if you were directly sending 'myStoreSampleCount:bigEndian:on:', which you aren't.

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


For now, I would just say rename

        SampledSound>>storeSampleCount: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream

to something like:

        SampledSound>>oldStoreSampleCount: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream

and make sure that SampledSound no longer has a 'storeSampleCount:bigEndian:on:' method.  To test this, I just removed the method from SampledSound.

You could also get into silliness like make a proxy for 'SampledSound' (e.g.. 'MySampledSound') that redirects everything except 'storeSampleCount:bigEndian:on:' to 'SampledSound', but that's a bit much, in my opinion.  I would really just remove the method from SampledSound, unless you really nead to be able to write the sound to a file with and without the envelope.

        -Dean



[hidden email]
Sent by: [hidden email]

05/05/2006 11:48 PM
Please respond to The general-purpose Squeak developers list        

       
        To:        [hidden email]
        cc:        [hidden email]
        Subject:        Re: How to Fade-In/Fade-Out a Sampled/Repeating/Mixed Sound




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.


       -Dean



"Rob Rothwell" <[hidden email]>

05/05/2006 11:03 PM
Please respond to rjriv

       
       To:        "[hidden email]" <[hidden email]>

       cc:        "The general-purpose Squeak developers list" <[hidden email]>, [hidden email], [hidden email], [hidden email]

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




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@... <Dean_Swan@... > 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






Reply | Threaded
Open this post in threaded view
|

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

Rob Rothwell
In reply to this post by Dean_Swan
Hello Dean,

As I said before, something was funky with my image.  In a clean 3.8 image (although I have changed the SoundPlayer SamplingRate to 44100), I created a new storeWAVOnFileNamed method for a SampledSound as you suggested, and that worked!  However, when I tried it with the pre-existing WAV sample I originally wanted to use, it didn't work--which led me to the following:

"This works when creating a mono sound"
snd := FMSound new.
snd setPitch: 200 dur: 5.0 loudness: 0.25.
snd storeWAVOnFileNamed: 'monotone.wav'.
snd := (SampledSound fromWaveFileNamed: 'monotone.wav ').
snd addEnvelope: (VolumeEnvelope newExponentialDecay: 0.96).
snd play.

"It does not work for stereo..."
snd := FMSound new.
snd setPitch: 200 dur: 5.0 loudness: 0.25.

"Turn the sound into a stereo sound and save it as a WAV"
mix := MixedSound new.
mix add: snd.
mix storeWAVOnFileNamed: 'stereotone.wav'.

"Read a STEREO sound from a WAV as a SampledSound and try to modify it"
snd := (SampledSound fromWaveFileNamed: ' stereotone.wav').
snd addEnvelope: (VolumeEnvelope newExponentialDecay: 0.96).
snd play.

It would seem that the answer lies somewhere in how stereo vs mono sounds are handled.  Ultimately, I want to use a VolumeEnvelope on a MixedSound that contains both a stereo RepeatingSound, a Left channel FMSound, and a Right channel FMSound.  I am actually starting to think that will be possible!

Thanks again.  I feel like I am finally starting to "understand" Squeak a bit...thanks to a good problem that I have a desire to solve!

--Rob

On 5/5/06, [hidden email] <[hidden email]> wrote:

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.

        -Dean



Reply | Threaded
Open this post in threaded view
|

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

Rob Rothwell
Dean,

Ok, I *think* I can probably do this on my own now...

I was just not understanding some of the basic "rules:"

1.  Envelopes are not rules that you apply to a sound, they are objects that "go with" the sound, and you must have a separate envelope for each sound.  You can't apply the same envelope twice ( i.e. to the left channel and right channel of a MixedSound).  I did this by accident with PitchEnvelopes, because I needed separate envelopes for each channel to do what I wanted to do, but I didn't make the connection.

2.  MixedSounds are just weird.  Don't mix two MixedSounds.  It will dilute the volume or the time of the final product, depending on how you do it.  Mix "pure" sounds instead.  Also, many classes like SampledSound and RepeatingSound actually return MixedSounds upon creation, depending on whether or not you are working with stereo sounds or not.  Sometimes they force them into MONO because they are derived from AbstractSound, which returns isStereo := false.  Anyway, you need to break them down into their left and right channels before mixing them with other sounds or else you run into the MixedSound dilution problem.

3.  All in all, it is best just to create a separate envelope for each channel of each sound you are working with when dealing with stereo sounds, and then mix them together at the end.  Of course, you can create classes that do some of this for you, but they need to make a COPY of the envelope you wish to apply to both channels, not use the same one twice.

Thank again for all your help; I'm pretty sure I can get there from here!

--Rob

On 5/6/06, Rob Rothwell <[hidden email]> wrote:
Hello Dean,

As I said before, something was funky with my image.  In a clean 3.8 image (although I have changed the SoundPlayer SamplingRate to 44100), I created a new storeWAVOnFileNamed method for a SampledSound as you suggested, and that worked!  However, when I tried it with the pre-existing WAV sample I originally wanted to use, it didn't work--which led me to the following:

"This works when creating a mono sound"

snd := FMSound new.
snd setPitch: 200 dur: 5.0 loudness: 0.25.
snd storeWAVOnFileNamed: 'monotone.wav'.
snd := (SampledSound fromWaveFileNamed: 'monotone.wav ').

snd addEnvelope: (VolumeEnvelope newExponentialDecay: 0.96).
snd play.

"It does not work for stereo..."

snd := FMSound new.
snd setPitch: 200 dur: 5.0 loudness: 0.25.

"Turn the sound into a stereo sound and save it as a WAV"
mix := MixedSound new.
mix add: snd.
mix storeWAVOnFileNamed: 'stereotone.wav'.

"Read a STEREO sound from a WAV as a SampledSound and try to modify it"
snd := (SampledSound fromWaveFileNamed: ' stereotone.wav').

snd addEnvelope: (VolumeEnvelope newExponentialDecay: 0.96).
snd play.