The Trunk: Sound-eem.72.mcz

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

The Trunk: Sound-eem.72.mcz

commits-2
Eliot Miranda uploaded a new version of Sound to project The Trunk:
http://source.squeak.org/trunk/Sound-eem.72.mcz

==================== Summary ====================

Name: Sound-eem.72
Author: eem
Time: 19 September 2020, 6:41:04.690078 am
UUID: 993decea-486a-4d07-badb-dda290a3194e
Ancestors: Sound-ct.71

Fix an annopying behaviour in MixedSound.  If the same SampledSound is added more than once to a MixedSound then mix-down will produce weird results.  Fix by checking for duplicates in MixedSound>>add:pan:volume: and silently taking a copy.  Levente, if this is the wrong approach LMK and I can commit a version that raises an error instead.

=============== Diff against Sound-ct.71 ===============

Item was changed:
  ----- Method: MixedSound>>add:pan:volume: (in category 'composition') -----
  add: aSound pan: leftRightPan volume: volume
  "Add the given sound with the given left-right pan, where 0.0 is full left, 1.0 is full right, and 0.5 is centered. The loudness of the sound will be scaled by volume, which ranges from 0 to 1.0."
 
  | pan vol |
  pan := ((leftRightPan * ScaleFactor) asInteger max: 0) min: ScaleFactor.
  vol := ((volume * ScaleFactor) asInteger max: 0) min: ScaleFactor.
+ "Sounds have state.  If a sound occurs more than once in sounds then mixing can produce some very strange results"
+ sounds := sounds copyWith: ((sounds includes: aSound) ifTrue: [aSound copy] ifFalse: [aSound]).
- sounds := sounds copyWith: aSound.
  leftVols := leftVols copyWith: ((ScaleFactor - pan) * vol) // ScaleFactor.
+ rightVols := rightVols copyWith: (pan * vol) // ScaleFactor!
- rightVols := rightVols copyWith: (pan * vol) // ScaleFactor.
- !


Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Sound-eem.72.mcz

Stéphane Rollandin
> Eliot Miranda uploaded a new version of Sound to project The Trunk:

> http://source.squeak.org/trunk/Sound-eem.72.mcz
>
> ==================== Summary ====================
>
> Name: Sound-eem.72
> Author: eem
> Time: 19 September 2020, 6:41:04.690078 am
> UUID: 993decea-486a-4d07-badb-dda290a3194e
> Ancestors: Sound-ct.71
>
> Fix an annopying behaviour in MixedSound.  If the same SampledSound is added more than once to a MixedSound then mix-down will produce weird results.  Fix by checking for duplicates in MixedSound>>add:pan:volume: and silently taking a copy.  Levente, if this is the wrong approach LMK and I can commit a version that raises an error instead.
Actually there is another conceptual problem with
MixedSound>>add:pan:volume:

It does not check whether the added sound is mono or stereo.

As a consequence, when using MixedSound>>add: (which applies a pan of
0.5) with a stereo sound as argument, that sound overall volume gets
decreased because the corresponding leftVols and rightVols values are
set to obey the pan law.

But I would expect the values added to leftVols and rightVols to be
ScaleFactor so that the newly added sound is mixed as is, with no change
in volume.

To see (well, hear) the problem, use the attached stereo sound as follow:

        snd := SampledSound fromWaveFileNamed: 'sound.wav'.

        ms := MixedSound new.
        ms add: snd.

        snd play. "correct volume"
        ms play. "lower volume"

Stef



sound.wav (448K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: The Trunk: Sound-eem.72.mcz

Stéphane Rollandin
> Actually there is another conceptual problem with

> MixedSound>>add:pan:volume:
>
> It does not check whether the added sound is mono or stereo.
>
> As a consequence, when using MixedSound>>add: (which applies a pan of
> 0.5) with a stereo sound as argument, that sound overall volume gets
> decreased because the corresponding leftVols and rightVols values are
> set to obey the pan law.
>
> But I would expect the values added to leftVols and rightVols to be
> ScaleFactor so that the newly added sound is mixed as is, with no change
> in volume.
>
> To see (well, hear) the problem, use the attached stereo sound as follow:
>
> snd := SampledSound fromWaveFileNamed: 'sound.wav'.
>
> ms := MixedSound new.
> ms add: snd.
>
> snd play. "correct volume"
> ms play. "lower volume"

Fix attached.

It keeps the same behaviour as before if the added sound is mono, or if
the pan argument is not 0.5

In the other cases, that is for adding a stereo sound centered in the
mix, it just bypasses any panning calculation.

Note that I am not proposing this fix to be included as is, only tested
and examined, because it also changes the way panning is computed by
implementing a -4.5db power law (rationale here:
http://www.cs.cmu.edu/~music/icm-online/readings/panlaws/index.html)
which is the one I use in muO.

Stef




sound mixing.1.cs (3K) Download Attachment