Beispiel #1
0
def filtered_saw(delay, note, amp, dur=1.):
    t = pyo.SawTable(order=15).normalize()

    dur *= 2.

    env = pyo.Fader(fadein=.02, fadeout=0.02, dur=dur * 0.9,
                    mul=amp).play(dur=2.5 * dur, delay=delay)

    adsr = pyo.Adsr(attack=dur * 0.05,
                    decay=0.05 * dur,
                    sustain=0.3,
                    release=dur * 0.7,
                    dur=dur * 0.9,
                    mul=amp).play(dur=2.5 * dur, delay=delay)
    osc = pyo.Osc(t, freq=pyo.midiToHz(note), mul=adsr).mix(1)

    rev = pyo.Freeverb(osc, size=1., damp=0.5, bal=1.,
                       mul=env).play(dur=2.5 * dur, delay=delay)
    # rev.out(delay=delay, dur=dur)

    eq = pyo.Biquad(rev, freq=800, q=1., type=0).play(dur=2.5 * dur,
                                                      delay=delay)
    eq.out(delay=delay, dur=dur)
    # eq = None

    return osc, env, rev, eq
Beispiel #2
0
    def __init__(self):
        # Register 0: $4000 / $4004
        self.duty_cycle: int = 0
        self.length_ctr_halt: bool = False
        self.constant_volume: bool = False
        self.volume_envelope: int = 0

        # Register 1: $4001 / $4005
        self.sweep_enabled: bool = False
        self.sweep_period: int = 0
        self.sweep_negate: bool = False
        self.sweep_shift: int = 0

        # Register 2: $4002 / $4006
        self.timer_low: int = 0

        # Register 3: $4003 / $4007
        self.timer_high: int = 0
        self.length_ctr_load = 0

        self._length_ctr: int = 0

        # Create one table per duty cycle value
        self.sequence = [
            [(0, 0.), (7, 0.), (8, 1.), (16, 1.), (17, 0.)],  # 12.5% Duty
            [(0, 0.), (7, 0.), (8, 1.), (24, 1.), (25, 0.)],  # 25% Duty
            [(0, 0.), (7, 0.), (8, 1.), (40, 1.), (41, 0.)],  # 50% Duty
            [(0, 1.), (7, 1.), (8, 0.), (16, 0.), (17, 1.)]
        ]  # 75% Duty

        self.linear_table = pyo.LinTable(self.sequence[2], size=64)

        # Pulse wave output
        self.output = pyo.Osc(self.linear_table, 0, interp=1, mul=0)
Beispiel #3
0
def filtered_square(delay, note, amp, dur=1.):

    a = np.sqrt(np.linspace(1., 0., 15))
    t = pyo.HarmTable(a.tolist())

    dur *= 2.

    env = pyo.Fader(fadein=.02, fadeout=0.02, dur=dur * 0.9,
                    mul=amp).play(dur=2.5 * dur, delay=delay)

    adsr = pyo.Adsr(attack=dur * 0.05,
                    sustain=0.707,
                    decay=0.1 * dur,
                    release=dur * 0.7,
                    dur=dur * 0.9,
                    mul=amp).play(dur=2.5 * dur, delay=delay)
    osc = pyo.Osc(t, freq=pyo.midiToHz(note), mul=adsr).mix(1)

    rev = pyo.Freeverb(osc, size=1., damp=0.5, bal=1.,
                       mul=env).play(dur=2.5 * dur, delay=delay)
    # rev.out(delay=delay, dur=dur)

    eq = pyo.Biquad(rev, freq=500, q=1., type=2).play(dur=2.5 * dur,
                                                      delay=delay)
    eq.out(delay=delay, dur=dur)
    # eq = None

    return osc, env, rev, eq
Beispiel #4
0
 def __init__(self):
    self.trig = pyo.Trig()
    decaytable = pyo.LinTable(list=[(0, 1.0), (8191, 0.0)])
    self.env = pyo.TrigEnv(self.trig, table=decaytable, dur=0.6, mul=.25)
    waveform = pyo.SquareTable()
    self.osc = pyo.Osc(waveform, freq=[0.,0.], mul=self.env[0])
    self.output = self.osc.out()
Beispiel #5
0
 def create_synth_sawtooth_line(self):
     '''Create a sawtooth wave synthesizer using the PYO
     LinTable module.'''
     self.log.debug('creating sawtooth synth [lintable]')
     t = pyo.LinTable([(0, 1), (8191, -1)])
     return pyo.Osc(table=t,
                    mul=0,
                    freq=[FREQ_C4, FREQ_C4])
Beispiel #6
0
 def __init__(self):
    self.trig = pyo.Trig()
    decaytable = pyo.LinTable(list=[(0,0), (100, 1.0), (8191, 0.0)])
    self.env = pyo.TrigEnv(self.trig, table=decaytable, dur=0.6, mul=[0,0])
    self.spectrum = [1.]+[0.]*15  # 16 total
    self.waveform = pyo.HarmTable(self.spectrum)
    self.osc = pyo.Osc(self.waveform, freq=[0.,0.], mul=self.env)
    self.filter = pyo.Biquad(self.osc, freq=[300.,300.], type=2, q=2.)
    self.output = self.filter.out()
Beispiel #7
0
 def create_synth_sawtooth(self):
     '''Create a sawtooth wave synthesizer as a sum of sines
     using the PYO SawTable module (which internally
     calls HarmTable).'''
     self.log.debug('creating sawtooth synth [additive]')
     t = pyo.SawTable(order=self.nharmonics, size=self.tsize)
     return pyo.Osc(table=t,
                    mul=0,
                    freq=[FREQ_C4, FREQ_C4])
Beispiel #8
0
 def create_synth_triangle_line(self):
     '''Create a triangle wave synthesizer using the PYO
     LinTable module.'''
     self.log.debug('creating triangle synth [lintable]')
     t = pyo.LinTable([(0, 0), (8192//4, 1), (8192//2, 0),
                       (3*(8192//4), -1), (8191, 0)])
     return pyo.Osc(table=t,
                    mul=0,
                    freq=[FREQ_C4, FREQ_C4])
Beispiel #9
0
 def __init__(self):
     self.env = pyo.Adsr(attack=.01,
                         decay=.6,
                         sustain=.0,
                         release=.6,
                         dur=1,
                         mul=.5)
     sq = pyo.SawTable()
     self.osc = pyo.Osc(table=sq, mul=self.env, freq=440)
     self.lowpass = pyo.MoogLP(self.osc, 1000, self.env)
     self.lowpass.out()
Beispiel #10
0
 def create_synth_triangle(self):
     '''Create a sawtooth wave synthesizer as a sum of sines
     using the PYO HarmTable module.'''
     self.log.debug('creating triangle synth [additive]')
     c = cycle([1, -1])
     l = [next(c)/(i*i) if i % 2 == 1 else 0
          for i in range(1, (2*self.nharmonics))]
     t = pyo.HarmTable(list=l, size=self.tsize)
     return pyo.Osc(table=t,
                    mul=0,
                    freq=[FREQ_C4, FREQ_C4])
Beispiel #11
0
    def __init__(self, input, buf_size=8192, overlap=1024):
        self.input = input
        self.overlap = overlap
        self.buf_size = buf_size
        self.table_count = 3

        self.data = []
        self.np_emitter = NpBuffer(self.input, buf_size=self.buf_size, overlap=self.overlap)
        self.trig = pyo.TrigFunc(self.np_emitter['trig'], self.get_data_rt)
        self.tables = self.table_count * [pyo.DataTable(self.buf_size)]
        self.faders = self.table_count * [pyo.Fader(fadein=overlap/SAMPLE_RATE, fadeout=overlap/SAMPLE_RATE, dur=buf_size/SAMPLE_RATE, mul=0.5)]
        self.oscs = [pyo.Osc(t, freq=SAMPLE_RATE / self.buf_size, mul=f) for t, f in zip(self.tables, self.faders)]
        # TODO add oscs
        self._base_objs = self.input.getBaseObjects()
Beispiel #12
0
    def __init__(self):
        super().__init__()

        self.sine = pyo.CosTable([(0, 0), (100, 1), (1000, .25), (8191, 0)])
        self.square = pyo.SquareTable()
        self.saw = pyo.SawTable()
        self.synth = pyo.NewTable(8192 / 44100)

        self.pointer = pyo.Sig(0)
        self.morph = pyo.TableMorph(self.pointer, self.synth,
                                    [self.sine, self.square, self.saw])
        self.osc = pyo.Osc(self.synth, 440)
        self.filter = pyo.Biquad(self.osc)
        self.verb = pyo.WGVerb(self.filter).mix(2)
Beispiel #13
0
    def __init__(self):
        # Register 0 ($400C)
        self.length_ctr_halt: bool = False
        self.constant_volume: bool = False
        self.volume_envelope: int = 0

        # Register 1 ($400E)
        self.mode: int = 0
        self.period: int = 0

        # Register 2 ($400F)
        self.length_ctr_load: int = 0

        self._length_ctr: int = 0

        # Nasty tricks will have to be used here...

        print("Generating noise wave tables...")

        seq_0 = []
        sr = 1
        prev_val = -1
        for i in range(0, 32767 * 2, 2):
            val = (sr & 1) ^ 1
            if val != prev_val:
                seq_0.append((i, val))
                seq_0.append((i + 1, val))

            feedback = ((sr & 1) ^ ((sr >> 1) & 1)) % 2
            sr = (sr >> 1) | (feedback << 14)

        seq_1 = []
        prev_val = -1
        for i in range(0, 93 * 2, 2):
            val = (sr & 1) ^ 1
            if val != prev_val:
                seq_1.append((i, val))
                seq_1.append((i + 1, val))

            feedback = ((sr & 1) ^ ((sr >> 6) & 1)) % 2
            sr = (sr >> 1) | (feedback << 14)

        self.table = []
        self.table.append(pyo.LinTable(seq_0, 32767 * 2))
        self.table.append(pyo.LinTable(seq_1, 93 * 2))

        print("...done!")

        self.output = pyo.Osc(self.table[0], freq=0, phase=0, interp=1, mul=0)
Beispiel #14
0
    def __init__(self):
        super().__init__()

        self.wv1 = pyo.CosTable([(0, 0), (4060, 1), (8191, 0)])
        self.wv2 = pyo.CosTable([(0, 0.00), (2074, 0.59), (4060, 1.00),
                                 (8191, 0.00)])
        self.wv3 = pyo.CosTable([(0, 0.00), (2074, 0.59), (4060, 1.00),
                                 (6117, 0.60), (8191, 0.00)])
        self.wv4 = pyo.CosTable([(0, 0.00), (2039, 0.29), (2039, 0.60),
                                 (4060, 1.00), (6117, 0.60), (6117, 0.30),
                                 (8191, 0.00)])
        self.wv5 = pyo.CosTable([(0, 0.00), (2039, 0.29), (2039, 0.60),
                                 (3255, 0.29), (4060, 1.00), (4900, 0.30),
                                 (6117, 0.60), (6117, 0.30), (8191, 0.00)])
        self.wv6 = pyo.CosTable([(0, 0.00), (769, 1.00), (2039, 0.29),
                                 (2039, 0.60), (3255, 0.29), (4060, 1.00),
                                 (4900, 0.30), (6117, 0.60), (6117, 0.30),
                                 (7333, 1.00), (8191, 0.00)])
        self.wv7 = pyo.CosTable([(0, 0.00), (769, 0.00), (769, 1.00),
                                 (2039, 0.29), (2039, 0.60), (3255, 0.29),
                                 (4060, 1.00), (4900, 0.30), (6117, 0.60),
                                 (6117, 0.30), (7333, 1.00), (7333, 0.00),
                                 (8191, 0.00)])
        self.wv8 = pyo.CosTable([(0, 0.00), (769, 0.00), (769, 1.00),
                                 (2039, 0.29), (2039, 0.60), (3255, 0.29),
                                 (3255, 1.00), (4900, 1.00), (4900, 0.30),
                                 (6117, 0.60), (6117, 0.30), (7333, 1.00),
                                 (7333, 0.00), (8191, 0.00)])
        self.synth = pyo.NewTable(8192 / 44100)

        self.pointer = pyo.Sig(0)
        self.morph = pyo.TableMorph(self.pointer, self.synth, [
            self.wv1, self.wv2, self.wv3, self.wv4, self.wv5, self.wv6,
            self.wv7, self.wv8
        ])
        self.osc = pyo.Osc(self.synth, 440)
        self.filter = pyo.Biquad(self.osc)
        self.verb = pyo.WGVerb(self.filter).mix(2)
Beispiel #15
0
    def playback2(self):
        print('pb2')
        fader = pyo.Fader(fadein=0.2, fadeout=0.2, dur=5, mul=.2)
        table = pyo.HarmTable([1, 2, 2, 5, 9])
        glissando = pyo.SigTo(value=self.message_translation[0],
                              time=0.1,
                              init=self.message_translation[0])
        osc = pyo.Osc(
            table=table,
            freq=[glissando / 2, (glissando - 1) / 2, (glissando + 100) / 2],
            mul=fader)
        panner = pyo.Pan(osc,
                         outs=2,
                         pan=random.random(),
                         spread=random.random()).out()

        def pat():
            freq = random.choice(self.message_translation)
            glissando.value = freq

        p = pyo.Pattern(pat, [self.message_length, .25, .75]).play()
        fader.play()
        time.sleep(fader.dur + .05)
        osc.stop()
Beispiel #16
0
 def create_sound(self, soundParams):
     '''
     NOTE: This methods needs to return both the soundObj and soundwaveObj to be able to
     play the sound form elsewhere. If soundwaveObj is not returned, it will not exist
     outside this scope, and the pyo server plays nothing on soundObj.play()
     '''
     if isinstance(soundParams['amplitude'], list) or isinstance(
             soundParams['amplitude'], np.ndarray):
         soundAmp = list(soundParams['amplitude'])
     else:
         soundAmp = 2 * [soundParams['amplitude']]
     # -- Define sound according to type --
     if soundParams['type'] == 'tone':
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=soundAmp)
         soundwaveObj = pyo.Sine(freq=float(soundParams['frequency']),
                                 mul=soundObj).out()
         return (soundObj, soundwaveObj)
     elif soundParams['type'] == 'chord':
         nTones = soundParams['ntones']  # Number of components in chord
         factor = soundParams[
             'factor']  # Components will be in range [f/factor, f*factor]
         centerFreq = soundParams['frequency']
         freqEachComp = np.logspace(np.log10(centerFreq / factor),
                                    np.log10(centerFreq * factor), nTones)
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=soundAmp)
         soundwaveObjs = []
         for indcomp in range(nTones):
             #soundwaveObjs.append(pyo.Sine(freq=freqEachComp[indcomp],
             #                              mul=soundObj).mix(2).out())
             soundwaveObjs.append(
                 pyo.Sine(freq=float(freqEachComp[indcomp]),
                          mul=soundObj).out())
         return (soundObj, soundwaveObjs)
     elif soundParams['type'] == 'noise':
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=soundAmp)
         #soundwaveObj = pyo.Noise(mul=soundObj).mix(2).out()
         soundwaveObj = pyo.Noise(mul=soundObj).out()
         return (soundObj, soundwaveObj)
     elif soundParams['type'] == 'AM':
         if isinstance(soundAmp, list):
             halfAmp = [0.5 * x for x in soundAmp]
         else:
             halfAmp = 0.5 * soundAmp
         envelope = pyo.Sine(freq=soundParams['modFrequency'],
                             mul=halfAmp,
                             add=halfAmp,
                             phase=0.75)
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=envelope)
         soundwaveObj = pyo.Noise(mul=soundObj).out()
         return (soundObj, [envelope, soundwaveObj])
         '''
         soundObj = pyo.Fader(fadein=self.risetime, fadeout=self.falltime,
                              dur=soundParams['duration'], mul=soundAmp)
         envelope = pyo.Sine(freq=soundParams['modFrequency'],mul=soundObj,add=soundAmp,phase=0)
         soundwaveObj = pyo.Noise(mul=envelope).out()
         return(soundObj,[envelope,soundwaveObj])
         '''
     elif soundParams['type'] == 'tone_AM':
         if isinstance(soundAmp, list):
             halfAmp = [0.5 * x for x in soundAmp]
         else:
             halfAmp = 0.5 * soundAmp
         nTones = soundParams['ntones']  # Number of components in chord
         factor = soundParams[
             'factor']  # Components will be in range [f/factor, f*factor]
         centerFreq = soundParams['frequency']
         freqEachComp = np.logspace(np.log10(centerFreq / factor),
                                    np.log10(centerFreq * factor),
                                    nTones) if nTones > 1 else [centerFreq]
         envelope = pyo.Sine(freq=soundParams['modRate'],
                             mul=halfAmp,
                             add=halfAmp,
                             phase=0.75)
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=envelope)
         soundwaveObjs = []
         for indcomp in range(nTones):
             soundwaveObjs.append(
                 pyo.Sine(freq=float(freqEachComp[indcomp]),
                          mul=soundObj).out())
         return (soundObj, [envelope, soundwaveObjs])
     elif soundParams['type'] == 'band':
         frequency = soundParams['frequency']
         octaves = soundParams['octaves']
         freqhigh = frequency * np.power(2, octaves / 2)
         freqlow = frequency / np.power(2, octaves / 2)
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=soundAmp)
         freqcent = (freqhigh + freqlow) / 2
         bandwidth = freqhigh - freqlow
         n = pyo.Noise(mul=soundObj)
         soundwaveObj = pyo.IRWinSinc(n,
                                      freq=freqcent,
                                      bw=bandwidth,
                                      type=3,
                                      order=400).out()
         return (soundObj, soundwaveObj)
     elif soundParams['type'] == 'band_AM':
         if isinstance(soundAmp, list):
             halfAmp = [0.5 * x for x in soundAmp]
         else:
             halfAmp = 0.5 * soundAmp
         frequency = soundParams['frequency']
         octaves = soundParams['octaves']
         freqhigh = frequency * np.power(2, octaves / 2)
         freqlow = frequency / np.power(2, octaves / 2)
         envelope = pyo.Sine(freq=soundParams['modRate'],
                             mul=halfAmp,
                             add=halfAmp,
                             phase=0.75)
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=soundParams['duration'],
                              mul=envelope)
         freqcent = (freqhigh + freqlow) / 2
         bandwidth = freqhigh - freqlow
         n = pyo.Noise(mul=soundObj)
         soundwaveObj = pyo.IRWinSinc(n,
                                      freq=freqcent,
                                      bw=bandwidth,
                                      type=3,
                                      order=400).out()
         return (soundObj, [envelope, soundwaveObj])
     elif soundParams['type'] == 'fromfile':
         tableObj = pyo.SndTable(soundParams['filename'])
         samplingFreq = tableObj.getRate()
         if soundParams.get('duration'):
             duration = soundParams['duration']
         else:
             duration = tableObj.getDur()
         if soundParams.get('channel') == 'left':
             fs = [samplingFreq, 0]
         elif soundParams.get('channel') == 'right':
             fs = [0, samplingFreq]
         else:
             fs = 2 * [samplingFreq]
         soundObj = pyo.Fader(fadein=self.risetime,
                              fadeout=self.falltime,
                              dur=duration,
                              mul=soundAmp)
         print duration
         print fs
         soundwaveObj = pyo.Osc(table=tableObj, freq=fs, mul=soundObj).out()
         return (soundObj, soundwaveObj)
     else:
         raise TypeError(
             'Sound type "{0}" has not been implemented.'.format(
                 soundParams['type']))
 def __init__(self, fport=250, fmod=100, amp=.3):
     self.mod = pyo.Osc(tab_m, freq=fmod, mul=amp)
     self.port = pyo.Osc(tab_p, freq=fport, mul=self.mod)