Hello,
I have tried this in coder and builder view. For simplicity sake I’ll actually explain the builder view. I want a sound to play every 3s for 200ms. During the trial, I added a code component to play a beep.
In ‘Before the experiment’, I initialized a sound.
sound_1 = sound.Sound('A', secs=-1, stereo=True, hamming=True, name='sound_1')
sound_1.setVolume(1.0)
In ‘Begin experiment’, I initialized some more things including clocks, tone_duration and tone_iti:
# Initialize sound parameters
# tone_playing = False
tone_duration = 0.2
tone_iti = 3.0
# Initialize the clock
experimentClock = core.Clock()
trial_clock = core.Clock()
in ‘Each Frame’ I’m trying to get the sound to play if it’s in the right interval with the np.mod function:
math = np.mod(experimentClock.getTime(), tone_iti)
if math < tone_duration:
if sound_1.status == NOT_STARTED:
print(sound_1.status)
now = core.getTime()
sound_1.play(when=now)
print(sound_1.status)
else:
sound_1.stop()
print(sound_1.status)
Before the first sound is played, the sound_1.status is printed as ‘0’. when the first sound starts playing, the status is returned/printed as ‘1’, and after sound_1.stop() is called, the status is returned as -1. This doesn’t work for my code, because it’s expecting the status to have resumed to NOT_STARTED after sound_1.stop() is called.
Questions: 1. Why is the status being returned as numbers instead of words, and is this a problem?
2. why doesn’t stopping a sound turn its status to NOT_STARTED, and what should i be doing if i want to turn a sound on and off depending on timing? I tried adding reset=True, but that did not work.
Thank you!