[squeak-dev] The Inbox: Sound-dtl.67.mcz
commits at source.squeak.org
commits at source.squeak.org
Wed Dec 11 03:51:05 UTC 2019
David T. Lewis uploaded a new version of Sound to project The Inbox:
http://source.squeak.org/inbox/Sound-dtl.67.mcz
==================== Summary ====================
Name: Sound-dtl.67
Author: dtl
Time: 10 December 2019, 10:51:04.985835 pm
UUID: ca970845-8428-41f9-b83c-f64a6cc732c1
Ancestors: Sound-eem.66
Sound mixing improvements by Stéphane Rollandin (spfa).
Allow adjusting volume of mixed sounds while playing.
Original discussion at http://forum.world.st/Adjusting-the-volume-of-a-sound-as-it-s-playing-td5102562.html
Patches posted to squeak-dev at http://lists.squeakfoundation.org/pipermail/squeak-dev/2019-December/205440.html
=============== Diff against Sound-eem.66 ===============
Item was changed:
----- Method: AbstractSound>>loudness (in category 'volume') -----
loudness
"Answer the current volume setting for this sound."
+ self hasVolumeEnvelope ifTrue: [^ self volumeEnvelope scale].
+
+ ^ scaledVol asFloat / ScaleFactor!
- ^ scaledVol asFloat / ScaleFactor asFloat!
Item was changed:
----- Method: MixedSound>>mixSampleCount:into:startingAt:leftVol:rightVol: (in category 'sound generation') -----
mixSampleCount: n into: aSoundBuffer startingAt: startIndex leftVol: leftVol rightVol: rightVol
"Play a number of sounds concurrently. The level of each sound can be set independently for the left and right channels."
| snd left right |
1 to: sounds size do: [:i |
(soundDone at: i) ifFalse: [
snd := sounds at: i.
+ left := (leftVol * (leftVols at: i) * scaledVol / ScaleFactor) // ScaleFactor.
+ right := (rightVol * (rightVols at: i) * scaledVol / ScaleFactor) // ScaleFactor.
- left := (leftVol * (leftVols at: i)) // ScaleFactor.
- right := (rightVol * (rightVols at: i)) // ScaleFactor.
snd samplesRemaining > 0
ifTrue: [
snd mixSampleCount: n into: aSoundBuffer startingAt: startIndex leftVol: left rightVol: right]
ifFalse: [soundDone at: i put: true]]].
!
Item was changed:
----- Method: RepeatingSound>>mixSampleCount:into:startingAt:leftVol:rightVol: (in category 'sound generation') -----
mixSampleCount: n into: aSoundBuffer startingAt: startIndex leftVol: leftVol rightVol: rightVol
"Play a collection of sounds in sequence."
"(RepeatingSound new
setSound: FMSound majorScale
iterations: 2) play"
| i count samplesNeeded |
iteration <= 0 ifTrue: [^ self].
i := startIndex.
samplesNeeded := n.
[samplesNeeded > 0] whileTrue: [
count := sound samplesRemaining min: samplesNeeded.
count = 0 ifTrue: [
iterationCount == #forever
ifFalse: [
iteration := iteration - 1.
iteration <= 0 ifTrue: [^ self]]. "done"
sound reset.
count := sound samplesRemaining min: samplesNeeded.
count = 0 ifTrue: [^ self]]. "zero length sound"
sound mixSampleCount: count
into: aSoundBuffer
startingAt: i
+ leftVol: leftVol * scaledVol // ScaleFactor
+ rightVol: rightVol * scaledVol // ScaleFactor.
- leftVol: leftVol
- rightVol: rightVol.
i := i + count.
samplesNeeded := samplesNeeded - count].
!
Item was changed:
----- Method: SequentialSound>>mixSampleCount:into:startingAt:leftVol:rightVol: (in category 'sound generation') -----
mixSampleCount: n into: aSoundBuffer startingAt: startIndex leftVol: leftVol rightVol: rightVol
"Play a collection of sounds in sequence."
"PluckedSound chromaticScale play"
+ | finalIndex i snd remaining count leftScaledVol rightScaledVol |
- | finalIndex i snd remaining count |
currentIndex = 0 ifTrue: [^ self]. "already done"
+
+ leftScaledVol := leftVol * scaledVol /// ScaleFactor.
+ rightScaledVol := rightVol * scaledVol /// ScaleFactor.
+
finalIndex := (startIndex + n) - 1.
i := startIndex.
[i <= finalIndex] whileTrue: [
snd := (sounds at: currentIndex).
[(remaining := snd samplesRemaining) <= 0] whileTrue: [
"find next undone sound"
currentIndex < sounds size
ifTrue: [
currentIndex := currentIndex + 1.
snd := (sounds at: currentIndex)]
ifFalse: [
currentIndex := 0.
^ self]]. "no more sounds"
count := (finalIndex - i) + 1.
remaining < count ifTrue: [count := remaining].
+ snd mixSampleCount: count into: aSoundBuffer startingAt: i
+ leftVol: leftScaledVol
+ rightVol: rightScaledVol.
- snd mixSampleCount: count into: aSoundBuffer startingAt: i leftVol: leftVol rightVol: rightVol.
i := i + count].
!
More information about the Squeak-dev
mailing list
|