[squeak-dev] The Inbox: Sound-dtl.67.mcz
Stéphane Rollandin
lecteur at zogotounga.net
Wed Dec 11 12:47:28 UTC 2019
>> + leftVol: leftVol * scaledVol // ScaleFactor
>> + rightVol: rightVol * scaledVol // ScaleFactor.
>
> Since this method is sent with Float leftVol and rightVol arguments,
> perhaps it's worth keeping precision by not truncating to integers here
> too.
On a related note, I saw when profiling sound-synthesis code that quite
some time is spent truncating values and checking for possible overflow
in sound buffers.
I implemented the following in SoundBuffer:
at: index add: aNumber
| s |
s := (self at: index) + aNumber truncated.
s > 32767 ifTrue: [s := 32767]. "clipping!"
s < -32767 ifTrue: [s := -32767]. "clipping!"
self at: index put: s
and also
at: index mult: aNumber
| s |
s := ((self at: index) * aNumber) truncated.
s > 32767 ifTrue: [s := 32767]. "clipping!"
s < -32767 ifTrue: [s := -32767]. "clipping!"
self at: index put: s
It would be nice if those where available as primitives. I guess they
would be much faster, and those operations are always required somewhere
in the chain when working with sound buffers, so I think such primitives
would be quite useful in general.
Stef
More information about the Squeak-dev
mailing list
|