[squeak-dev] The Trunk: Sound-eem.91.mcz
commits at source.squeak.org
commits at source.squeak.org
Tue Aug 9 00:19:42 UTC 2022
Eliot Miranda uploaded a new version of Sound to project The Trunk:
http://source.squeak.org/trunk/Sound-eem.91.mcz
==================== Summary ====================
Name: Sound-eem.91
Author: eem
Time: 8 August 2022, 5:19:40.710296 pm
UUID: 0396e865-eb12-410b-9fc7-cf7e62e48327
Ancestors: Sound-eem.90
Fix the length of WAV files produced by AbstractSound>>storeSampleCount:bigEndian:on:. The old code incorrectly rounded up the output size to the buffer size (2 * samplingRate).
=============== Diff against Sound-eem.90 ===============
Item was changed:
----- Method: AbstractSound>>storeSampleCount:bigEndian:on: (in category 'file i/o') -----
storeSampleCount: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream
"Store my samples on the given stream at the current SoundPlayer sampling rate. If bigFlag is true, then each 16-bit sample is stored most-significant byte first (AIFF files), otherwise it is stored least-significant byte first (WAV files). If self isStereo is true, both channels are stored, creating a stereo file. Otherwise, only the left channel is stored, creating a mono file."
| bufSize stereoBuffer reverseBytes streamDirect |
self reset.
bufSize := (2 * self samplingRate rounded) min: samplesToStore. "two second buffer"
stereoBuffer := SoundBuffer newStereoSampleCount: bufSize.
streamDirect := aBinaryStream isKindOf: StandardFileStream.
reverseBytes := (bigEndianFlag xor: Smalltalk isBigEndian) xor: streamDirect not.
'Storing audio...'
displayProgressFrom: 0 to: samplesToStore during: [:bar | | remaining out |
remaining := samplesToStore.
[remaining > 0] whileTrue: [
bar value: samplesToStore - remaining.
stereoBuffer primFill: 0. "clear the buffer"
self playSampleCount: (bufSize min: remaining) into: stereoBuffer startingAt: 1.
out := self isStereo
ifTrue: [stereoBuffer]
ifFalse: [stereoBuffer extractLeftChannel].
reverseBytes ifTrue: [out reverseEndianness].
streamDirect
+ ifTrue: "optimization for files: write sound buffer directly to file"
+ [aBinaryStream next: (out size // 2 min: remaining) putAll: out startingAt: 1] "size in words"
+ ifFalse: "for non-file streams:"
+ [1 to: (out monoSampleCount min: remaining) do: [:i | aBinaryStream int16: (out at: i)]].
- ifTrue: [ "optimization for files: write sound buffer directly to file"
- aBinaryStream next: (out size // 2) putAll: out startingAt: 1] "size in words"
- ifFalse: [ "for non-file streams:"
- 1 to: out monoSampleCount do: [:i | aBinaryStream int16: (out at: i)]].
remaining := remaining - bufSize]].!
More information about the Squeak-dev
mailing list
|