Synth cannot play G# (G-sharp)
Hi, using Synth to play sounds. It works fine except it refuses to play G-sharp (g#). Using OS4
Calling my_sound = Synth(osc=u'sine', freq=u'g#1', length=200, attack=0, decay=20) results in a crash with the following message:
UnboundLocalError: cannot access local variable 'f' where it is not associated with a value
Octave does not matter. g0# and g2# also fail.
Other tones, like f# are fine (I have tested them all, only g# fails)
my_sound = Synth(osc=u'sine', freq=u'f#1', length=200, attack=0, decay=20)
Also replacing g# with its frequency (861 Hz) works fine:
my_sound = Synth(osc=u'sine', freq=861, length=200, attack=0, decay=20)
So I have this workaround, but I thought it's still worth reporting this quirk.
Also, what is the symbol for flat, as in B-flat, if there is any?
thanks, best,
Chris
Comments
Hi Chris,
Yes that's a small bug in the source code. Thanks for spotting. I suggested a fix and probably it is going to be resolved in the next maintenance release.
Also, what is the symbol for flat, as in B-flat, if there is any?
Flat is just a
b.So, gb for g flat. In case you wanted to replace g# with ab, that is not going to work at the moment, as the bug affects that one as well.
Octave does not matter. g0# and g2# also fail.
Small note here, the
#must be before the octave. So this order would not work for any of the tones.Thanks,
Eduard
@eduard Thanks for fixing this!
Check out SigmundAI.eu for our OpenSesame AI assistant!
@eduard @sebastiaan
Thanks guys! I seem to hit another snag:
my_sound.volume(0.5) results in "TypeError: 'float' object is not callable"
my_sound is defined as a synth object, and is playing. other functions work fine, like my_sound.play() and my_sound.wait().
Hi Chris,
I don't think this is how you set the volume. You probably want to use the
set_config()method or pass it as keyword argument to play.Synth objects are essentially Sampler objects for which the sound is generated first. So, check out the the sampler docs to see some usage examples.
Eduard
Hi Eduard,
Thanks, but while sampler accepts a volume key word, synth does not.
what does seem to work is:
best
chris
Hi Chris,
Doing it like this works:
my_sound = Synth(osc=u'sine', freq=u'f1', length=200, attack=0, decay=20) my_sound.set_config(**{"volume":0.1}) my_sound.play()However, I realized that using the psychopy backend no sound is played, whereas for legacy and expyriment it is. @sebastiaan are you aware of this?
Eduard
Hi @chris_olivers and @eduard ,
The standard way to change the volume is by setting the
volumeproperty, as Chris already found out:Alternatively, you can pass the
volumekeyword when initializing theSynthorSampleror when calling theplay()function. (However, there is indeed a bug in theSynthobject such that it doesn't accept this keyword during initialization. I'll fix that shortly.)See also:
The
set_config()function is mainly for internal use. It works, but I wouldn't use it because it's not very readable.The
set_volume()function (and other similarly named functions) were already deprecated for a long time and were finally removed in OpenSesame 4.0.However, I realized that using the psychopy backend no sound is played, whereas for legacy and expyriment it is. @sebastiaan are you aware of this?
I suspect that this is specific to your system. Are you missing some of the libraries that psychopy uses for sound playback?
— Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hi Sebastiaan,
Thanks for clarifying.
The standard way to change the volume is by setting the
volumeproperty, as Chris already found out:My bad! I misread Chris' post, thinking that this didn't work.
Eduard