[squeak-dev] Sound mixing makes nasty noises

tim Rowledge tim at rowledge.org
Wed Dec 16 22:52:07 UTC 2020


I've discovered that playing two or more sounds simultaneously can make truly appalling noises. I'm hoping somebody has a good solution.

The problem started with playing a sound and using the pianokeyboardmorph at the same time. Ouch! Also, swizzling the mouse across the keyboard causes occasional quite audible 'scratchy-clicks' somehow. There can also be a quite noticeable sound between notes, not easily describable but sort of a 'dull thump'.

I thought it was some issue with how the sound was played, maybe the note-end process as each piano key was released and the next pressed, timing issues.. but none of that had very much effect.

The AbstractSound>>#stopGracefully method does seem to have a small bug, in that the decayInMs value surely ought not be the sum of the attack & decay times from the envelope? But carefully fudging the note shutdown to be faster didn't help a lot.

After too much messing around I discovered that at least some of the problem is the mixing of sounds. 

Now, I know we did a small change to MixedSound>>#add:pan:volume: since 5.3, and that we made a small change to the SampledSound>>#mixSampleCount:into:startingAt:leftVol:rightVol: primitive. However, I'm running on a VM that has the prim change, and I've ported across the add:pan... change, with no real difference. This is, of course, on a Pi, but the same issue is audible on my iMac as well. 

Eventually I cottoned on to the fact that I was mixing two sounds with volumes set to 100%. Changing to 50% for both actually results in a perfectly fine end result - Yay! This doesn't seem like a robust solution though. What if I have four sounds playing each set to 40%? Why does it seem to work perfectly well for AbstractSound>>#stereoBachFugue play, which uses four?

To make life even more fun, it doesn't seem like there is any volume control once a sound is playing. The AbstractSound>>#adjustVolumeTo:overMSecs: method appears to be the one to use but it has no audible effect. There is also #loudness: which does work, but produces pretty much exactly the glitch I hear from glissandoing(?) the keyboard.

So - some workspace code to illustrate

"awful noise when mixing"
|snd|
snd := FMSound organ1.
snd setPitch: 440 dur: 10 loudness: 0.9;
	play.
1 second wait.

FMSound brass1 setPitch: 470 dur:2 loudness: 0.9;
	play.
1 second wait.
snd stopGracefully

"OK, because both  sound defualt to quieter"
|snd |
snd := FMSound organ1.
snd
	duration: 5;
	play.
1 second wait.

FMSound brass1
	play.
	
1 second wait.
snd stopGracefully.

"nasty glitch using #loudness: plus mixing graunch"
|snd |
snd := FMSound organ1.
snd duration: 5;
	play.
1 second wait.
snd loudness: 1.0 .
	
1 second wait.
FMSound brass1
	play.
	
1 second wait.
snd stopGracefully.


"no effect from adjustVol..."
|snd |
snd := FMSound organ1.
snd
	duration: 5;
	play.
1 second wait.
snd adjustVolumeTo: 1.0 overMSecs: 500.
1 second wait.
FMSound brass1
	play.
	
1 second wait.
snd stopGracefully.

Aargh!

tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
A computer program does what you tell it to do, not what you want it to do.




More information about the Squeak-dev mailing list