Christoph Thiede uploaded a new version of Sound to project The Trunk: http://source.squeak.org/trunk/Sound-ct.94.mcz
==================== Summary ====================
Name: Sound-ct.94 Author: ct Time: 12 October 2023, 7:04:09.945818 pm UUID: 6f15da49-9689-7148-9b86-e9f11ac8db27 Ancestors: Sound-tpr.93
Merges and revises Sound-mad.90, which fixes endianness issues for storing SampledSounds analogously to Sound-ct.71.
Revision: Also fixes this issue for LoopedSampledSound. Extracts AbstractSound>>#storeSamples:count:bigEndian:on:.
Note: I had to move Sound-mad.90 to the treated inbox because it snapshot only contained the patched version.
=============== Diff against Sound-tpr.93 ===============
Item was added: + ----- Method: AbstractSound>>storeSamples:count:bigEndian:on: (in category 'file i/o') ----- + storeSamples: samples count: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream + + | reverseBytes streamDirect | + streamDirect := aBinaryStream isKindOf: StandardFileStream. + reverseBytes := (bigEndianFlag xor: Smalltalk isBigEndian) xor: streamDirect not. + reverseBytes ifTrue: [samples reverseEndianness]. + streamDirect + ifTrue: "optimization for files: write sound buffer directly to file" + [aBinaryStream next: (samples size // 2 min: samplesToStore // 2) putAll: samples startingAt: 1] "size in words" + ifFalse: "for non-file streams:" + [1 to: (samples monoSampleCount min: samplesToStore) do: [:i | aBinaryStream int16: (samples at: i)]]. + reverseBytes ifTrue: [samples reverseEndianness]. "restore to original endianness"!
Item was changed: ----- Method: LoopedSampledSound>>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." - "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)."
+ (self isStereo or: [scaledIndexIncr ~= LoopIndexScaleFactor]) ifTrue: [ - | reverseBytes | - (self isStereo or: [self samplingRate ~= originalSamplingRate]) ifTrue: [ ^ super storeSampleCount: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream].
"optimization: if I'm not stereo and sampling rates match, just store my buffer" + ^ self storeSamples: leftSamples count: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream! - reverseBytes := bigEndianFlag ~= Smalltalk isBigEndian. - reverseBytes ifTrue: [leftSamples reverseEndianness]. - (aBinaryStream isKindOf: StandardFileStream) - ifTrue: [ "optimization for files: write sound buffer directly to file" - aBinaryStream next: (leftSamples size // 2) putAll: leftSamples startingAt: 1] "size in words" - ifFalse: [ "for non-file streams:" - 1 to: leftSamples monoSampleCount do: [:i | aBinaryStream int16: (leftSamples at: i)]]. - reverseBytes ifTrue: [leftSamples reverseEndianness]. "restore to original endianness" - !
Item was changed: ----- Method: SampledSound>>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)."
- | reverseBytes | self samplingRate ~= originalSamplingRate ifTrue: [ ^ super storeSampleCount: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream]. + - "optimization: if sampling rates match, just store my buffer" + ^ self storeSamples: samples count: samplesToStore bigEndian: bigEndianFlag on: aBinaryStream! - reverseBytes := bigEndianFlag ~= Smalltalk isBigEndian. - reverseBytes ifTrue: [samples reverseEndianness]. - (aBinaryStream isKindOf: StandardFileStream) - ifTrue: [ "optimization for files: write sound buffer directly to file" - aBinaryStream next: (samples size // 2) putAll: samples startingAt: 1] "size in words" - ifFalse: [ "for non-file streams:" - 1 to: samples monoSampleCount do: [:i | aBinaryStream int16: (samples at: i)]]. - reverseBytes ifTrue: [samples reverseEndianness]. "restore to original endianness" - !
packages@lists.squeakfoundation.org