I think what you're looking for is in Scratch-Objects > SoundMedia > accessing > loadFile:.

Offline
Nice, I managed to cut out the converting-to-mono part which is awesome. But maybe it'd be good to have a prompt asking whether I want to convert it or not. (just one of those context menus maybe?) How would I do that?
Offline
JSO wrote:
Nice, I managed to cut out the converting-to-mono part which is awesome. But maybe it'd be good to have a prompt asking whether I want to convert it or not. (just one of those context menus maybe?) How would I do that?
To prompt the user before converting:
snd ifNotNil: [
snd isStereo ifTrue: [
t1 _ DialogBoxMorph ask: 'Convert sound to mono?'.
t1 ifTrue:["merge stereo to mono"
bar value: 'Converting ', sndName, 'to mono...'.
mergedBuf _ snd sounds first samples.
mergedBuf mixIn: snd sounds second samples.
snd _ SampledSound
samples: mergedBuf
samplingRate: snd sounds first originalSamplingRate]].and at the top:
| snd errorString sndName mergedBuf t1 |
Last edited by jvvg (2012-02-04 18:24:27)
Offline
Thanks so much jvvg! It worked
I was experimenting in the official 1.4 image so the arguments were named differently but everything went well
Edit: hmm; I added dialogboxes for both the downsampling and the mono conversion, and it seems to skip the conversion steps. (It doesn't show 'converting to mono...' for example, so I'm guessing it's succeeding.)
However, the sound is still heavily reduced in quality - the result remains the same no matter what I select. It always becomes mono
Any idea? Doesn't Scratch allow stereo playback?
edit2: 'Scratch-Objects > SoundMedia > scratch ops > playFrom:To:' says something about mono
any help would be greatly appreciated.
Offline
JSO wrote:
Thanks so much jvvg! It worked
![]()
I was experimenting in the official 1.4 image so the arguments were named differently but everything went well![]()
Edit: hmm; I added dialogboxes for both the downsampling and the mono conversion, and it seems to skip the conversion steps. (It doesn't show 'converting to mono...' for example, so I'm guessing it's succeeding.)
However, the sound is still heavily reduced in quality - the result remains the same no matter what I select. It always becomes monoAny idea? Doesn't Scratch allow stereo playback?
edit2: 'Scratch-Objects > SoundMedia > scratch ops > playFrom:To:' says something about monoany help would be greatly appreciated.
Yeah, I think Scratch just doesn't support stereo audio, which is why it converted to mono.
Offline
Seems to be true. The code does seem to support a "pan" or "balance" feature, that would allow you to play a mono sound through only one speaker (or louder through one speaker than through another). If I could turn this into a block somehow, I could just split up my stereo song, and import both 'sides' in Scratch in different sprites.
And 'balance' sound blocks would be awesome for many reasons :p
Offline
JSO wrote:
Seems to be true. The code does seem to support a "pan" or "balance" feature, that would allow you to play a mono sound through only one speaker (or louder through one speaker than through another). If I could turn this into a block somehow, I could just split up my stereo song, and import both 'sides' in Scratch in different sprites.
And 'balance' sound blocks would be awesome for many reasons :p
Yeah, I was looking into removing the mono-ising and downsampling a while back and found there isn't really anything you can do
Offline
I did manage to create (balance) and 'set balance to ()'
Everything is already in there, it's quite easy.
At first I wanted to make it exactly like the volume blocks, so I added 'balance _ 50' in scriptablescratchmorph>initialization>initialize, but it refused to save saying 'variable undefined'. Isn't that where you *declare* variables? :S Why does it refuse to do it?
I made it work by having the 'balance' and 'setbalanceto:' methods reference the properties of the actual sound object thing. That's different from the way the volume blocks work but, I could pan sounds across my speakers
So now I can just import the left and right track separately, play them in different sprites: 1 with balance set to 0, the other with balance set to 100.
They should fix that in Scratch 2.0
edit: here's a link to what I have now
http://www.mediafire.com/?zbyt59l9tm8u7ns
Last edited by JSO (2012-02-05 15:43:40)
Offline
It's a good idea. Unfortunately Scratch is well known for its inability to process sounds at exact speeds, which means your left and right tracks, now independent of each other could quite quickly end up out of sync. This will obviously cause problems.
Offline
JSO wrote:
IAt first I wanted to make it exactly like the volume blocks, so I added 'balance _ 50' in scriptablescratchmorph>initialization>initialize, but it refused to save saying 'variable undefined'. Isn't that where you *declare* variables? :S Why does it refuse to do it?
Usually, it offers to declare it as an instance variable for you, but, failing that, you can open another browser on the class (don't select a method or category) and add an item to the "instanceVariables: '...' " section in the editor pane.
Offline
JSO wrote:
ah - confusing. why is "instanceVariables: '...'" empty when browsing then?
Sorry, it should look something like this:
ScriptableScratchMorph subclass: #ScratchSpriteMorph
instanceVariableNames: 'scalePoint rotationDegrees rotationStyle rotatedForm offsetWhenRotated draggable penDown penSize penColor penHue penShade <insert additional space-separated instance vars here>'
classVariableNames: ''
poolDictionaries: ''
category: 'Scratch-Objects'
Change whatever you want about the class, then accept your changes (like you would when editing a method).
Last edited by nXIII (2012-02-05 17:49:08)
Offline
Oh I see now. Thanks so much for the help! (although it works - would it be useful to give scriptablescratchmorph a balance instance variable?)
Also (sorry for being such a source code noob :p) why does squeak change my named local variables to t1 t2 t3 etc when I click accept? fairly annoying actually :S
Offline
JSO wrote:
Oh I see now. Thanks so much for the help! (although it works - would it be useful to give scriptablescratchmorph a balance instance variable?)
The only reason I could see to do this is if you wanted to retain a local volume even if some other object changed the sound's balance.
Also (sorry for being such a source code noob :p) why does squeak change my named local variables to t1 t2 t3 etc when I click accept? fairly annoying actually :S
This is because Squeak is discarding the actual method source (it doesn't have anywhere to put it; you can add a .sources file to fix this) and decompiling the compiled (bytecode) method when you view it.
Offline