def synth(experiment, osc="sine", freq=440, length=100, attack=0, decay=5): """ desc: | A factory that synthesizes a sound and returns it as a `sampler object`. For a full description of keywords, see `python_workspace_api.synth`. For backwards compatibility, this function behaves as though it is a back-end. arguments: experiment: desc: The experiment object. type: experiment returns: desc: A SAMPLER object. type: sampler """ if np is None: raise osexception( u'The synth is not available, because numpy is missing.') if attack < 0 or attack > length: raise osexception( u'Attack must be a numeric value between 0 and the sound length') if decay < 0 or decay > length: raise osexception( u'Decay must be a numeric value between 0 and the sound length') # We need to multiply the rate by two to get a stereo signal rate = 2*experiment.var.get(u'sampler_frequency', 48100) signal = osc_gen(osc, key_to_freq(freq), length, rate) _envelope = envelope(length, attack, decay, rate) sound = to_int_16(signal * _envelope) return sampler(experiment, sound)
def synth(experiment, osc="sine", freq=440, length=100, attack=0, decay=5): """ desc: | A factory that synthesizes a sound and returns it as a `sampler object`. For a full description of keywords, see `python_workspace_api.synth`. For backwards compatibility, this function behaves as though it is a back-end. arguments: experiment: desc: The experiment object. type: experiment returns: desc: A `sampler` object. type: sampler """ if np is None: raise osexception( u'The synth is not available, because numpy is missing.') if attack < 0 or attack > length: raise osexception( u'Attack must be a numeric value between 0 and the sound length') if decay < 0 or decay > length: raise osexception( u'Decay must be a numeric value between 0 and the sound length') # We need to multiply the rate by two to get a stereo signal rate = 2*experiment.var.get(u'sampler_frequency', 48100) signal = osc_gen(osc, key_to_freq(freq), length, rate) _envelope = envelope(length, attack, decay, rate) sound = to_int_16(signal * _envelope) return sampler(experiment, sound)
def __init__(self, form): self.form = form if self.form.clicks: from openexp.sampler import sampler import os self.click_sound = sampler(self.form.experiment, self.form.experiment.resource(os.path.join( 'widgets', 'interaction.ogg')), duration=0, volume=.5)
def __init__(self, experiment, osc="sine", freq=440, length=100, attack=0, decay=5): """ desc: Initializes the synthesizer. arguments: experiment: desc: The experiment object. type: experiment keywords: osc: desc: Oscillator, can be "sine", "saw", "square" or "white_noise". type: [str, unicode] freq: desc: Frequency, either an integer value (value in hertz) or a string ("A1", "eb2", etc.). type: [str, unicode, int, float] length: desc: The length of the sound in milliseconds. type: [int, float] attack: desc: The attack (fade-in) time in milliseconds. type: [int, float] decay: desc: The decay (fade-out) time in milliseconds. type: [int, float] example: | from openexp.synth import synth my_synth = synth(exp, freq='b2', length=500) """ import numpy as np from scipy import signal global np global signal self.experiment = experiment # We need to multiply the rate by two to get a stereo signal rate = 2 * self.experiment.get_check(u'sampler_frequency', 48100) if not hasattr(self, u'osc_%s' % osc): raise osexception(u'Invalid oscillator for synth: %s' % osc) osc_fnc = getattr(self, u'osc_%s' % osc) signal = osc_fnc(self.key_to_freq(freq), length, rate) envelope = self.envelope(length, attack, decay, rate) sound = self.to_int_16(signal * envelope) self.sampler = sampler(experiment, sound)
def __init__(self, experiment, osc="sine", freq=440, length=100, attack=0, decay=5): """ desc: Initializes the synthesizer. arguments: experiment: desc: The experiment object. type: experiment keywords: osc: desc: Oscillator, can be "sine", "saw", "square" or "white_noise". type: [str, unicode] freq: desc: Frequency, either an integer value (value in hertz) or a string ("A1", "eb2", etc.). type: [str, unicode, int, float] length: desc: The length of the sound in milliseconds. type: [int, float] attack: desc: The attack (fade-in) time in milliseconds. type: [int, float] decay: desc: The decay (fade-out) time in milliseconds. type: [int, float] example: | from openexp.synth import synth my_synth = synth(exp, freq='b2', length=500) """ import numpy as np from scipy import signal global np global signal self.experiment = experiment # We need to multiply the rate by two to get a stereo signal rate = 2*self.experiment.get_check(u'sampler_frequency', 48100) if not hasattr(self, u'osc_%s' % osc): raise osexception(u'Invalid oscillator for synth: %s' % osc) osc_fnc = getattr(self, u'osc_%s' % osc) signal = osc_fnc(self.key_to_freq(freq), length, rate) envelope = self.envelope(length, attack, decay, rate) sound = self.to_int_16(signal * envelope) self.sampler = sampler(experiment, sound)
def sampler(src, **playback_args): """ desc: | A convenience function that creates a new `sampler` object. For a description of possible keywords, see: - %link:manual/python/sampler% returns: desc: A SAMPLER object. type: sampler example: | src = exp.pool['bark.ogg'] my_sampler = sampler(src, volume=.5, pan='left') my_sampler.play() """ from openexp.sampler import sampler return sampler(experiment, src, **playback_args)
def sampler(src, **playback_args): """ desc: | A convenience function that creates a new `sampler` object. For a description of possible keywords, see: - [/python/sampler/](/python/sampler/) returns: desc: A `sampler` object. type: sampler example: | src = exp.pool['bark.ogg'] my_sampler = sampler(src, volume=.5, pan='left') my_sampler.play() """ from openexp.sampler import sampler return sampler(experiment, src, **playback_args)
if cases[28] == 1: myCanvas.image(crossFull, y=482, x=-652, center=False) myCanvas.show() if cases[29] == 1: myCanvas.image(crossFull, y=515, x=-652, center=False) myCanvas.show() else: if index == 0: if interruption0 == 1: interruption0 = 0 resumptionLag12 = self.time() - startTime totalTime += self.time() - startTime self.log(",Poubelle," + str(self.time() - startTime)) src = exp.get_file('corbeilleXP.wav') my_sampler = sampler(exp, src) my_sampler.play() if endInterruption: endInterruption = False resumptionLag1 = self.time() - resumptionLag1_startTime else: if en_colonne: if cases[index - 1] == 0: cases[index - 1] = 1 goodClicks += 1 croix = crossFull else: goodClicks -= 1 cases[index - 1] = 0 croix = crossEmpty myCanvas.image(croix, y=y, x=-652, center=False)