[squeak-dev] MixedSound (& consequently stereo) is badly broken in both 32-bit and 64-bit versions

Eliot Miranda eliot.miranda at gmail.com
Sat Sep 19 13:28:09 UTC 2020


Hi Stef, Hi Levente,

On Sat, Sep 19, 2020 at 2:27 AM Stéphane Rollandin <lecteur at zogotounga.net>
wrote:

> Ok, it looks like your choice of frequency let a bug surface.
>
> In SampledSound>>#reset, the computation of scaledIncrement depends on
> the sampling rate. But scaledIncrement is also supposed to be somewhat
> commensurate with ScaledIndexOverflow which has a fixed value set in the
> class-side initialize.
>
> So I guess the whole LargePositiveIntegers avoidance scheme is bogus. If
> you get rid of it altogether, which in
> SampledSound>>#mixSampleCount:into:startingAt:leftVol:rightVol:
> translates as follow (primitive uncommented):
>

Stef, thanks for looking at the overflow arithmetic.  In 64-bits we may not
need it at all, and so I could add an ifTrue:ifFalse: based on the value of
SmallInteger maxVal that would avoid the complex arithmetic on 64-bits.
What do you think?


> -----
>
> mixSampleCount: n into: aSoundBuffer startingAt: startIndex leftVol:
> leftVol rightVol: rightVol
>         "Mix the given number of samples with the samples already in the
> given
> buffer starting at the given index. Assume that the buffer size is at
> least (index + count) - 1."
>
>         | lastIndex outIndex sample i s |
> "       <primitive:'primitiveMixSampledSound'
> module:'SoundGenerationPlugin'>
>         <var: #aSoundBuffer declareC: 'short int *aSoundBuffer'>
>         <var: #samples declareC: 'short int *samples'>
> "
>         lastIndex := (startIndex + n) - 1.
>         outIndex := startIndex.    "index of next stereo output sample
> pair"
>
>         [(outIndex <= samplesSize) and: [outIndex <= lastIndex]]
> whileTrue: [
>                 sample := ((samples at: outIndex) * scaledVol) //
> ScaleFactor.
>                 leftVol > 0 ifTrue: [
>                         i := (2 * outIndex) - 1.
>                         s := (aSoundBuffer at: i) + ((sample * leftVol) //
> ScaleFactor).
>                         s >  32767 ifTrue: [s :=  32767].  "clipping!"
>                         s < -32767 ifTrue: [s := -32767].  "clipping!"
>                         aSoundBuffer at: i put: s].
>                 rightVol > 0 ifTrue: [
>                         i := 2 * outIndex.
>                         s := (aSoundBuffer at: i) + ((sample * rightVol)
> // ScaleFactor).
>                         s >  32767 ifTrue: [s :=  32767].  "clipping!"
>                         s < -32767 ifTrue: [s := -32767].  "clipping!"
>                         aSoundBuffer at: i put: s].
>
>                 scaledVolIncr ~= 0 ifTrue: [
>                         scaledVol := scaledVol + scaledVolIncr.
>                         ((scaledVolIncr > 0 and: [scaledVol >=
> scaledVolLimit]) or:
>                          [scaledVolIncr < 0 and: [scaledVol <=
> scaledVolLimit]])
>                                 ifTrue: [  "reached the limit; stop
> incrementing"
>                                         scaledVol := scaledVolLimit.
>                                         scaledVolIncr := 0]].
>
>                 outIndex := outIndex + 1].
>         count := count - n.
>
> -----
>
> then you get a nice sine wave (which still play badly in my Squeak image
> but now only because it is too slow to generate without a primitive).
>
> Stef
>
>

-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20200919/2dbb1e27/attachment.html>


More information about the Squeak-dev mailing list