After stopping sound, I want it to reset so its status is NOT_STARTED but I can't get it to work like that..?


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')

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:
        now = core.getTime()

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!

  1. The words are actually variables that have the integer values you see (NOT_STARTED = 0, PLAYING = 1, STOPPED = -1). This is not a problem.
  2. The status is changed to STOPPED. If you want to replay the sound, you could probably set the flag yourself: sound_1.status = NOT_STARTED after you stop it. This would enable another component to trigger it to play again.

Not sure if that’s best practice, but it works (I’ve done it).

1 Like

Thanks! I figured that out like an hour after I posted. I don’t know why but the documentation for Sound, does not include STOPPED as an option for status. I just intuited that the numbers probably were interpreted as those words and tried STOPPED.