aseba icon indicating copy to clipboard operation
aseba copied to clipboard

improve clap block in VPL by avoiding self-generated music

Open riedo opened this issue 5 years ago • 2 comments

many people complain that clap event" music action = buzzing noise. We could change the code for clap event and music action to: (see lines concerning sound_is_playing)

(clap event)

# setup threshold for detecting claps
mic.threshold = 250

onevent mic
        if !sound_is_playing then
              #whatever code
        end

(music action)

# sound playing flag
var sound_is_playing=0
# variables for notes
var notes[6]
var durations[6]
var note_index = 6
var note_count = 6
var wave[142]
var i
var wave_phase
var wave_intensity

# compute a sinus wave for sound
for i in 0:141 do
	wave_phase = (i-70)*468
	call math.cos(wave_intensity, wave_phase)
	wave[i] = wave_intensity/256
end
call sound.wave(wave)

# when a note is finished, play the next note
onevent sound.finished
	if note_index != note_count then
		call sound.freq(notes[note_index], durations[note_index])
		note_index += 1
        else
                sound_is_playing = 0
	end

onevent Whatever
	call math.copy(notes[0:5], [whatever notes])
	call math.copy(durations[0:5], [whatever durations])
	note_index = 1
	note_count = 6
	call sound.freq(notes[0], durations[0])
	sound_is_playing=1

riedo avatar Mar 01 '19 14:03 riedo

I agree it can help current user. we were more to not change anymore VPL, but I can agree it can be done in this case. @cor3ntin is it easy to implement?

mbonani avatar Mar 04 '19 20:03 mbonani

i have no idea...

cor3ntin avatar Mar 04 '19 23:03 cor3ntin