Example #1
0
def main():
    from pyo import Sine
    from bl.dsp import startPYO
    s = startPYO()

    from twisted.internet import reactor
    from txosc.dispatch import Receiver
    from txosc. async import DatagramServerProtocol

    receiver = Receiver()
    reactor.listenUDP(17779,
                      DatagramServerProtocol(receiver),
                      interface='0.0.0.0')

    sineMulMul = Sine(1)
    sineMul = Sine(1, mul=sineMulMul)
    sine = Sine([110, 110 + (55 / 32.)], mul=sineMul)

    def cb(x, y, z):
        sine.freq = [x * 220, x * 220 + (55 / 32.)]
        sine.mul.freq = y * 55
        sine.mul.mul.freq = z * 55

    ori = Ori(receiver, cb)
    acc = Acc(receiver, cb)
    return s, ori, acc, sine
Example #2
0
    def __init__(self, freq=1000, trig=PyoObject, dur=3.78, mul=1):
        PyoObject.__init__(self, mul)
        self._freq = freq
        self._trig = trig
        self._dur = dur
        self._mul = mul

        freq, trig, dur, mul, lmax = convertArgsToLists(freq, trig, dur, mul)

        # LFO signal chain.
        # This envelope drives the LFO which creates the vibrato effect. Its
        # volume stays very low until just before it ends.
        lfoEnvTable = CosTable([(0, 0.0), (2457, 0.0), (6481, 0.3),
                                (7350, 0.0), (8191, 0.0)])
        # lfoEnvTable.graph()
        self._lfoEnv = TrigEnv(self._trig, lfoEnvTable, dur=self._dur)
        self._lfo = Sine(4.27, mul=self._lfoEnv)

        # Triangle oscillator signal chain.
        triEnvTable = CosTable([(0, 0.0), (1535, 1.0), (2046, 0.95),
                                (6143, 0.95), (8191, 0.0)])
        # triEnvTable.graph()
        self._triEnv = TrigEnv(self._trig, triEnvTable, dur=self._dur)

        # TriTable Table oscillator from the pyo docs.
        triTable = TriTable(order=50, size=24000).normalize()

        self._osc = Osc(triTable, self._freq, interp=4,
                        mul=((self._triEnv + self._lfo) * self._mul))
        self._whale = EQ(self._osc, freq=self._freq * 16, q=1, type=1)
        self._base_objs = self._whale.getBaseObjects()
Example #3
0
def main(stdscr):
    server = setup_audio_server()
    signal = Sine(100).out()
    #    env = Fader(fadein=0.01, fadeout=1.5, dur=2, mul=0.3)

    key_map = generate_keyboard_map()
    c = None
    stdscr.clear()
    while c != 27:
        # Store the key value in the variable `c`
        c = stdscr.getch()
        # Clear the terminal
        if c == 127:
            y, x = stdscr.getyx()
            stdscr.addstr(y, x - 1, '')
        else:
            key = chr(c)
            note = key_map.get(key)
            if note is not None:
                signal.freq = note


#            interpret_key(key, signal=signal)
            stdscr.addstr(key)
    server.stop()
    server.shutdown()
Example #4
0
 def playChord(self, lista):
     f = Fader(fadein=0.1, fadeout=0.1, dur=3, mul=.5)
     m = []
     for fr in lista:
         m.append(Sine(freq=fr, mul=f).out())
     f.play()
     time.sleep(3)
def e_minor_heartbeat():
    mul = 0.05
    ind = LFO(freq=1, type=1, mul=.5, add=.5)
    for _key in ThreeKeys:
        kwargs = {'freq': _key.freq, 'mul': mul}
        if _key == Keys.E2:
            kwargs['mul'] = mul * ind * 10
        all_waves.append(Sine(**kwargs).out())
Example #6
0
 def playScale(self, lista):
     for fr in lista:
         f = Fader(fadein=0.1, fadeout=0.1, dur=1, mul=.5)
         osc = Sine(freq=fr, mul=f).out()
         f.play()
         time.sleep(1)
Example #7
0
# Initialize Audio Server
server = Server(audio="portaudio",nchnls=1).boot()
server.start()

# Initialize Audio Feed
audio_in = Input(chnl=0)

# Initialize Effect Variables
depth = 0.5
feedback = 0.5
bal = 0.5

# Pedal Effect Initialization
input = audio_in
chorus = Chorus(audio_in, depth=depth, feedback=feedback, bal=bal)
lfo = Sine(freq=4,phase=.5,mul=.5,add=.3)
delay = Delay(audio_in, delay=0.25, feedback=lfo, maxdelay=3)

# Output
input.out()
chorus.out()
delay.out()

# GUI Effect Controllers
audio_in.ctrl()
chorus.ctrl(title="Chorus")
lfo.ctrl(title="Sine")
delay.ctrl(title="Delay")

server.gui(locals())
Example #8
0
from pyo import Server, Sine

server = Server()
server.setMidiInputDevice(2)  # Change as required
server.boot()

if __name__ == '__main__':
    server.start()
    audio = Sine().out()
    server.gui(locals())
from pyo import Server, Sine, LFO

s = Server().boot()
s.start()
t = CosTable([(0,0), (100,1), (500,.3), (8191,0)])
beat = Beat(time=.125, taps=16, w1=[90,80], w2=50, w3=35, poly=1).play()
trmid = TrigXnoiseMidi(beat, dist=12, mrange=(60, 96))
trhz = Snap(trmid, choice=[0,2,3,5,7,8,10], scale=1)
tr2 = TrigEnv(beat, table=t, dur=beat['dur'], mul=beat['amp'])
a = Sine(freq=trhz, mul=tr2*0.3).out()

s.gui(locals())
Example #10
0
class Whale(PyoObject):
    """
    Whale 1.0

    Signal chain:
    lfo -> lfoEnv -> triOsc -> triEnv -> out

    The concept is that of a low-frequency instrument which has a
    delayed-onset vibrato. It is meant to be used at low tempos, to allow
    the vibrato to fade in slowly.

    :Parent: :py:class:`PyoObject`

    :Args:

        freq : PyoObject
            Frequency to generate.
        trig : PyoObject
            A trigger to drive note-ons.
        dur : float
            Time in seconds for the instrument to play once triggered.

    """
    def __init__(self, freq=1000, trig=PyoObject, dur=3.78, mul=1):
        PyoObject.__init__(self, mul)
        self._freq = freq
        self._trig = trig
        self._dur = dur
        self._mul = mul

        freq, trig, dur, mul, lmax = convertArgsToLists(freq, trig, dur, mul)

        # LFO signal chain.
        # This envelope drives the LFO which creates the vibrato effect. Its
        # volume stays very low until just before it ends.
        lfoEnvTable = CosTable([(0, 0.0), (2457, 0.0), (6481, 0.3),
                                (7350, 0.0), (8191, 0.0)])
        # lfoEnvTable.graph()
        self._lfoEnv = TrigEnv(self._trig, lfoEnvTable, dur=self._dur)
        self._lfo = Sine(4.27, mul=self._lfoEnv)

        # Triangle oscillator signal chain.
        triEnvTable = CosTable([(0, 0.0), (1535, 1.0), (2046, 0.95),
                                (6143, 0.95), (8191, 0.0)])
        # triEnvTable.graph()
        self._triEnv = TrigEnv(self._trig, triEnvTable, dur=self._dur)

        # TriTable Table oscillator from the pyo docs.
        triTable = TriTable(order=50, size=24000).normalize()

        self._osc = Osc(triTable, self._freq, interp=4,
                        mul=((self._triEnv + self._lfo) * self._mul))
        self._whale = EQ(self._osc, freq=self._freq * 16, q=1, type=1)
        self._base_objs = self._whale.getBaseObjects()

    def setFreq(self, x):
        """
        Replace the `freq` attribute.

        :Args:

            x : float or PyoObject
                New `freq` attribute.

        """
        self._freq = x

    def setTrig(self, x):
        """
        Replace the `trig` attribute.

        :Args:

            x : PyoObject
                New `trig` attribute.

        """
        self._trig = x
        self._lfoEnv.trig = x
        self._triEnv.trig = x

    def setDur(self, x):
        """
        Replace the `dur` attribute.

        :Args:

            x : PyoObject
                New `dur` attribute.

        """
        self._dur = x
        self._lfoEnv.dur = x
        self._triEnv.dur = x

    @property
    def freq(self):
        """float or PyoObject. Frequency."""
        return self._freq

    @freq.setter
    def freq(self, x):
        self.setFreq(x)

    @property
    def trig(self):
        """PyoObject. Trigger the instrument."""
        return self._trig

    @trig.setter
    def trig(self, x):
        self.setTrig(x)

    @property
    def dur(self):
        """float. Duration in seconds."""
        return self._dur

    @dur.setter
    def dur(self, x):
        self.setDur(x)

    def play(self, dur=0, delay=0):
        self._lfoEnv.play(dur, delay)
        self._lfo.play(dur, delay)
        self._triEnv.play(dur, delay)
        self._osc.play(dur, delay)
        return PyoObject.play(self, dur, delay)

    def stop(self):
        self._lfoEnv.stop()
        self._lfo.stop()
        self._triEnv.stop()
        self._osc.stop()
        return PyoObject.stop(self)

    def out(self, chnl=0, inc=1, dur=0, delay=0):
        self._lfoEnv.out(dur, delay)
        self._lfo.out(dur, delay)
        self._triEnv.out(dur, delay)
        self._osc.out(dur, delay)
        return PyoObject.out(self, chnl, inc, dur, delay)
Example #11
0
from pyo import midiToHz, Choice, Port, Sine, SuperSaw, FM, Delay, STRev  # pylint: disable=E0611

from load_data import fetch_data_iter
from pyo_server import server as s

means = [np.mean(m) for m in fetch_data_iter]
range_ = [(i - np.min(means)) / np.ptp(means) for i in means]
means = [(i * 100) for i in range_]

pitches = [midiToHz(m) for m in means]

# Add more voices here to generate a simple counterpoint
choice = Choice(choice=pitches, freq=1)

# Two simple instruments
lfdetune = Sine(freq=0.1, mul=.07, add=.07)
instrument1 = SuperSaw(freq=choice, detune=lfdetune, mul=.8)
lfind = Sine(freq=0.5, phase=0.5, mul=3, add=3)
instrument2 = FM(carrier=choice, ratio=1.0025, index=lfind, mul=.8)

# Send instruments output to delay
src_sum = instrument1.mix(2) + instrument2.mix(2)
lfdel = Sine(.1, mul=.003, add=.005)
comb = Delay(src_sum, delay=lfdel, feedback=.5)

# Send two resulting signals to reverb and output
out_sum = src_sum + comb
rev = out_sum.out()

s.start()
s.gui(locals())
Example #12
0
def play_note(hz):
    out = Sine(hz).out()
    return out
class S3Synth:
    """Main Synth Class that manages backend of Synthesiser"""
    def __init__(self, wavecoef_: np.ndarray, transpo=1, mul=1):
        # Transposition factor.
        self.transpo = Sig(transpo)
        # Receive midi notes, convert pitch to Hz and manage 10 voices of polyphony.
        self.note = Notein(poly=10, scale=1, first=0, last=127)
        self.note.keyboard()
        # Handle pitch and velocity (Notein outputs normalized amplitude (0 -> 1)).
        self.pit = self.note['pitch'] * self.transpo
        print(self.note.get('pitch'))
        self.amp = MidiAdsr(0.5 * self.note['velocity'],
                            attack=0.1,
                            decay=1,
                            sustain=.5,
                            release=2,
                            mul=.4)
        self.amp.ctrl(title="Envelope Control")
        # Anti-aliased stereo square waves, mixed from 10 streams to 1 stream
        # to avoid channel alternation on new notes.

        # Create harmonic table of two parts
        self.t = HarmTable(list(wavecoef_[0:80]))
        self.t2 = HarmTable(list(wavecoef_[80:159]))

        # Create Oscilattor
        self.osc1 = Osc(table=self.t, freq=self.pit, mul=self.amp)
        self.osc2 = Osc(table=self.t2, freq=self.pit, phase=0.25, mul=self.amp)
        self.osc22 = Osc(table=self.t2,
                         freq=self.pit + np.pi / 2,
                         mul=self.amp)
        # self.scope1=Scope(Mix([-1*self.osc1,-1*self.osc2]))
        # self.scope1.g

        # Selector takes multiple inputs and interpolates
        # between them to generate a single output.
        self.osccos = Selector([self.osc2, self.osc22], voice=0.15)
        self.osccos.ctrl(title="Shift modulation amount")

        # Stereo mix using Band-limited Low Frequency Oscillator
        # with different wave shapes.
        self.osc3 = LFO(self.pit, sharp=0.5, type=2, mul=self.amp)
        self.osc3.ctrl(
            title=
            'Osc3 type 0=saw u 1=saw d 2=sq 3=tri 4=pulse 5=bipulse 6=s&h 7=Sine'
        )

        self.osc4 = LFO(self.pit, sharp=0.5, type=0, mul=self.amp)
        self.osc4.ctrl(
            title=
            "Osc4 type 0=saw u 1=saw d 2=sq 3=tri 4=pulse 5=bipulse 6=s&h 7=Sine"
        )

        self.extrasel = Selector(
            [self.osc3.mix(1), self.osc4.mix(1)], mul=0.05, voice=0.5)
        self.mainsel = Selector(
            [self.osc1.mix(1), self.osccos.mix(1)], mul=1, voice=0.5)
        self.mainsel.ctrl(title="Main Oscillator Volume")
        self.extrasel.ctrl(title="Extra Oscillator Volume Ctrl")

        # Mix audio streams
        self.mix = Mix([self.mainsel.mix(1), self.extrasel.mix(1)], voices=2)

        # High frequencies damping.
        self.damp = ButLP(self.mix, freq=5000)

        # Moving notches, using two out-of-phase sine wave oscillators.
        self.lfo = Sine(.2, phase=[random(), random()]).range(250, 4000)
        self.lfo.ctrl(title=" Modulation")
        self.notch = ButBR(self.damp, self.lfo, mul=mul).mix(1)

        self.eq = Biquad(self.notch, freq=20000)
        self.eq.ctrl(title="Equaliser type 0=lp 1=hp 2=bp 3=br 4=ap")

        self.harmonized = Harmonizer(self.eq,
                                     mul=0.1,
                                     transpo=-12,
                                     feedback=0.25)
        self.harmonized.ctrl(title="Harmonizer 1")

        self.harmonized1 = Harmonizer(self.eq,
                                      mul=0.1,
                                      transpo=12,
                                      feedback=0.25)
        self.harmonized1.ctrl(title="Harmonizer 2")

        self.harmonized2 = Harmonizer(self.eq,
                                      mul=0,
                                      transpo=-6,
                                      feedback=0.25)
        self.harmonized2.ctrl(title="Harmonizer 3")

        # Apply distortion
        self.distortion = Disto(self.eq, drive=0)
        self.distortion.ctrl()
        self.pfx = Mix([
            self.distortion, self.harmonized, self.harmonized1,
            self.harmonized2
        ],
                       voices=1)

        # 8 modulated delay lines chorus processing
        self.chor = Chorus(self.pfx, bal=0)
        self.chor.ctrl()

        # Stereo reverb
        self.rev = STRev(self.pfx, bal=0)
        self.rev.ctrl()

        self.sel = Selector([self.rev, self.chor], 0.5)
        self.sel.ctrl(title="Chorus vs Reverb")
        self.final = Mix(self.sel, voices=2, mul=1)
        self.spec = Spectrum(self.final, size=512, wintitle='Spectrum')
        self.scope = Scope(self.final)

    def out(self):
        '''Sends the synth's signal to the audio output and return the object itself.'''

        self.final.out()
        return self

    def sig(self):
        '''Returns the synth's signal for future processing.'''

        return self.sel