[squeak-dev] Sound mixing makes nasty noises

Herbert König herbertkoenig at gmx.net
Sun Dec 27 22:03:09 UTC 2020


I changed SoundPlayer class playLoop which I figured is what passes the
samples to the OS like attached, writing 1 mega samples to an aiff file.
TSTTCPW.
I must have made a mistake because I suddenly get lost buffers but
frankly I had some wine :-).

I used Tim's first snippet:

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

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

It's repeatable the sound seems to have the right length but the
discontinuity marked red usually happens if the sound system of the OS
looses a buffer. I had my laptop run at 4 GHZ, the audio output sounded
normally bad and the loss is in the first second, where the audio is
still ok. Playing the recorded file reveals the additional distortions.

I just want to save another trip through the time zones so I put it out
buggy as it is. Maybe I just used the wrong place to do my recording,
maybe I recorded mono from a stereo buffer, whatever.

Be mild :-)

Herbert




Am 27.12.2020 um 19:49 schrieb Herbert König:
> Next step is to try to record the output before it goes to the OS and
> see if the image or some primitive creates the problem.
>
> Cheers,
>
> Herbert
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20201227/7eb4bd7f/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hlgkbmcgckmbaocp.png
Type: image/png
Size: 10485 bytes
Desc: not available
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20201227/7eb4bd7f/attachment-0001.png>
-------------- next part --------------
'From Squeak5.3alpha of 4 October 2019 [latest update: #19044] on 27 December 2020 at 10:36:13 pm'!

!SoundPlayer class methodsFor: 'player process' stamp: 'hk 12/27/2020 22:36'!
playLoop
	"The sound player process loop."
	| bytesPerSlice count willStop mayStop recordBuffer recIndex file|
	mayStop := self stopSoundWhenDone.
	bytesPerSlice := Stereo ifTrue: [4] ifFalse: [2].
	"Herbert debugging clip and wrap"
	recordBuffer := SoundBuffer newStereoSampleCount: 1000000.
	recordBuffer primFill: 0.
	recIndex := 1.
	[
		[(count := self primSoundAvailableBytes // bytesPerSlice) > 100]
			whileFalse: [ReadyForBuffer wait].

		count := count min: Buffer stereoSampleCount.
		PlayerSemaphore critical: [
			ActiveSounds := ActiveSounds select: [:snd | snd samplesRemaining > 0].
			ActiveSounds do: [:snd |
				snd ~~ SoundJustStarted ifTrue: [
					snd playSampleCount: count into: Buffer startingAt: 1]].
			ReverbState == nil ifFalse: [
				ReverbState applyReverbTo: Buffer startingAt: 1 count: count].
			"HK debugging"
			1 to: count do: [:i|
				recordBuffer at: recIndex put: (Buffer at: i).
				recIndex := recIndex + 1.
				].
			self primSoundPlaySamples: count from: Buffer startingAt: 1.
			willStop := mayStop and:[
						(ActiveSounds size = 0) and:[
							self isAllSilence: Buffer size: count]].
			LastBuffer ifNotNil:[
				LastBuffer replaceFrom: 1 to: LastBuffer size with: Buffer startingAt: 1.
			].
			willStop
				ifTrue:[self shutDown: true. PlayerProcess := nil]
				ifFalse:[Buffer primFill: 0].
			SoundJustStarted := nil].
		willStop ifTrue:[
			"HK debugging"
			file := (FileStream fileNamed: '#playedSamples.aiff') binary.
			recordBuffer saveAsAIFFFileSamplingRate: 44100 on: file.
			file close.
			^self] ] repeat
! !


More information about the Squeak-dev mailing list