Question about SoundGenerationPlugin/mixSampleCount

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Question about SoundGenerationPlugin/mixSampleCount

Christoph Thiede

Hi all,


for a test, I am storing sounds into a ByteArray and read them again. This works well for PluckedSounds, for example, but I found some strange behavior when doing the same with SampledSounds:


sound := SampledSound new

setSamples: SampledSound coffeeCupClink

samplingRate: 12000.


bytes := ByteArray streamContents: [:stream |

sound storeWAVSamplesOn: stream].


outputSound := SampledSound fromWaveStream: bytes readStream binary.


After running this script, I would expect outputSound to have the same samples as sound. But actually, every byte in the SoundBuffer appears twice! Still, playing the sound does not sound differently in my ears. I traced the issue down and found out that #mixSampleCount:into:startingAt:leftVol:rightVol: is writing every byte four times on the stream - two would be okay for left and right channel, but I do not understand the four. I reproduced the issue both on Windows and Ubuntu (WSL). Disabling the primitive did not help either.


So I am wondering: Is this a bug or totally fine (because you cannot hear a difference anyway)? If the latter is the case, how can I compare the sounds else in a reliable way? If I store outputSound again, the number of bytes is doubled again, so if you do certain operations, your image will blow up exponentially ...



Best,
Christoph


Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: Question about SoundGenerationPlugin/mixSampleCount

Christoph Thiede
As a workaround, in my test I compare the ByteArray representations of my
sounds rather than their samples, so there is no urgency from my side.
Still, this behavior looks suspicious to me ...



--
Sent from: http://forum.world.st/Squeak-Dev-f45488.html

Carpe Squeak!
Reply | Threaded
Open this post in threaded view
|

Re: Question about SoundGenerationPlugin/mixSampleCount

Herbert König
In reply to this post by Christoph Thiede
Hi Christoph,

maybe you hit upon a stereo representation with interleaved channels? But then it should be 16 bit words, so not sure.

Cheers,

Herbert

storeWAVSamplesOn: aBinaryStream
    "Store this sound as a 16-bit Windows WAV file at the current SoundPlayer sampling rate. Store both channels if self isStereo is true; otherwise, store the left channel only as a mono sound."

Am 09.10.2020 um 18:19 schrieb Thiede, Christoph:

Hi all,


for a test, I am storing sounds into a ByteArray and read them again. This works well for PluckedSounds, for example, but I found some strange behavior when doing the same with SampledSounds:


sound := SampledSound new
setSamples: SampledSound coffeeCupClink
samplingRate: 12000.

bytes := ByteArray streamContents: [:stream |
sound storeWAVSamplesOn: stream].

outputSound := SampledSound fromWaveStream: bytes readStream binary.


After running this script, I would expect outputSound to have the same samples as sound. But actually, every byte in the SoundBuffer appears twice! Still, playing the sound does not sound differently in my ears. I traced the issue down and found out that #mixSampleCount:into:startingAt:leftVol:rightVol: is writing every byte four times on the stream - two would be okay for left and right channel, but I do not understand the four. I reproduced the issue both on Windows and Ubuntu (WSL). Disabling the primitive did not help either.


So I am wondering: Is this a bug or totally fine (because you cannot hear a difference anyway)? If the latter is the case, how can I compare the sounds else in a reliable way? If I store outputSound again, the number of bytes is doubled again, so if you do certain operations, your image will blow up exponentially ...



Best,
Christoph


    



Reply | Threaded
Open this post in threaded view
|

Re: Question about SoundGenerationPlugin/mixSampleCount

Karl Ramberg
In reply to this post by Christoph Thiede
Eliot did some rework on the sound plugin a few months back. How new is your VM ?

Best,
Karl


On Fri, Oct 9, 2020 at 6:19 PM Thiede, Christoph <[hidden email]> wrote:

Hi all,


for a test, I am storing sounds into a ByteArray and read them again. This works well for PluckedSounds, for example, but I found some strange behavior when doing the same with SampledSounds:


sound := SampledSound new

setSamples: SampledSound coffeeCupClink

samplingRate: 12000.


bytes := ByteArray streamContents: [:stream |

sound storeWAVSamplesOn: stream].


outputSound := SampledSound fromWaveStream: bytes readStream binary.


After running this script, I would expect outputSound to have the same samples as sound. But actually, every byte in the SoundBuffer appears twice! Still, playing the sound does not sound differently in my ears. I traced the issue down and found out that #mixSampleCount:into:startingAt:leftVol:rightVol: is writing every byte four times on the stream - two would be okay for left and right channel, but I do not understand the four. I reproduced the issue both on Windows and Ubuntu (WSL). Disabling the primitive did not help either.


So I am wondering: Is this a bug or totally fine (because you cannot hear a difference anyway)? If the latter is the case, how can I compare the sounds else in a reliable way? If I store outputSound again, the number of bytes is doubled again, so if you do certain operations, your image will blow up exponentially ...



Best,
Christoph



Reply | Threaded
Open this post in threaded view
|

Re: Question about SoundGenerationPlugin/mixSampleCount

Eliot Miranda-2
In reply to this post by Herbert König
Hi Herbert, Hi Christoph,

On Oct 9, 2020, at 12:33 PM, Herbert König <[hidden email]> wrote:

 Hi Christoph,

maybe you hit upon a stereo representation with interleaved channels? But then it should be 16 bit words, so not sure.

That’s right.  The sound output primitive takes interleaved (alternating left/right, signed) 16-bit samples.  So the mix down methods mix from whatever the representation into this stereo representation.


Cheers,

Herbert

storeWAVSamplesOn: aBinaryStream
    "Store this sound as a 16-bit Windows WAV file at the current SoundPlayer sampling rate. Store both channels if self isStereo is true; otherwise, store the left channel only as a mono sound."

Am 09.10.2020 um 18:19 schrieb Thiede, Christoph:

Hi all,


for a test, I am storing sounds into a ByteArray and read them again. This works well for PluckedSounds, for example, but I found some strange behavior when doing the same with SampledSounds:


sound := SampledSound new
setSamples: SampledSound coffeeCupClink
samplingRate: 12000.

bytes := ByteArray streamContents: [:stream |
sound storeWAVSamplesOn: stream].

outputSound := SampledSound fromWaveStream: bytes readStream binary.


After running this script, I would expect outputSound to have the same samples as sound. But actually, every byte in the SoundBuffer appears twice! Still, playing the sound does not sound differently in my ears. I traced the issue down and found out that #mixSampleCount:into:startingAt:leftVol:rightVol: is writing every byte four times on the stream - two would be okay for left and right channel, but I do not understand the four. I reproduced the issue both on Windows and Ubuntu (WSL). Disabling the primitive did not help either.


So I am wondering: Is this a bug or totally fine (because you cannot hear a difference anyway)? If the latter is the case, how can I compare the sounds else in a reliable way? If I store outputSound again, the number of bytes is doubled again, so if you do certain operations, your image will blow up exponentially ...



Best,
Christoph