コード例 #1
0
ファイル: sounds.py プロジェクト: roaldarbol/autopilot
    def init_sound(self):
        """
        Create a table of Noise using pyo or numpy, depending on the server_type
        """

        if self.server_type == 'pyo':
            noiser = pyo.Noise(mul=self.amplitude)
            self.table = self.table_wrap(noiser)
        elif self.server_type == 'jack':
            self.get_nsamples()
            # rand generates from 0 to 1, so subtract 0.5, double to get -1 to 1,
            # then multiply by amplitude.
            self.table = (self.amplitude *
                          np.random.uniform(-1, 1, self.nsamples)).astype(
                              np.float32)
            self.chunk()

        self.initialized = True
コード例 #2
0
 def out(self, file_path=imsend_sound_path):
     if self.choice <= 0.33:
         self.section_one = Section_One(self.count)
         self.section_one.out()
     elif self.choice > .33 and self.choice <= .67:
         self.section_two = Section_Two(self.message, self.count)
         self.section_two.out()
     else:
         snd = pyo.SndTable(file_path)
         env = pyo.HannTable()
         pos = pyo.Phasor(snd.getRate() * .25, 0, snd.getSize())
         dur = pyo.Noise(.001, .1)
         g = pyo.Granulator(snd, env, [1, 1.001], pos, dur, 24, mul=1)
         panner = pyo.Pan(g,
                          outs=2,
                          pan=random.random(),
                          spread=random.random()).out()
         time.sleep(2)
         g.stop()
コード例 #3
0
    def __init__(self, sequence, amp=1, pan=0.5):
        BaseSynth.__init__(self, sequence, amp, pan)
        self.env = pyo.CosTable([(0,0.0000),(123,0.9896),(2701,0.4870),(6479,0.2746),(8192,0.0000)])
        self.env_reader = pyo.TrigEnv(self.trig, self.env, dur=pyo.Max(self.dur, comp=0.3125))
        sine_freqs = []
        for i in range(-1,1):
            freqs = [self.freq*j*(1+0.008*i) for j in range(1,8)]
            sine_freqs.extend(freqs)
        harm_amps = [1,0.3,0.4,0.2,0.1,0.04,0.04,0.03,0.02]
        self.osc = pyo.Sine(freq=sine_freqs, mul=[self.env_reader*harm_amps[i] for i in range(8)])

        self.trans_env = pyo.ExpTable([(0,0.3938),(8192,0.0000)])
        self.trans_env_reader = pyo.TrigEnv(self.trig, self.trans_env, dur=0.25)
        self.trans = pyo.Noise(mul=self.trans_env_reader)
        self.trans_filter = pyo.Biquad(self.trans, freq=1690)
        self.trans_resonator = pyo.Delay(pyo.Denorm(self.trans_filter), feedback=0.90, delay=(self.freq**-1))
        self.chorus = pyo.Chorus(self.trans_resonator, depth=0.13, feedback=0.84)
        self.master_filter = pyo.Biquad((self.chorus+self.osc).mix(0), freq=3900)
        self.panner = pyo.Pan(self.master_filter, mul=(0.1)*self.master_amp, pan=self.master_pan)
        self.last_audio_object = self.panner
コード例 #4
0
ファイル: fft.py プロジェクト: chronopoulos/cyclophone
import pyo

s = pyo.Server().boot()
s.start()

#audioIn = pyo.Input(chnl=[0,1], mul=0.7)
a = pyo.Noise(.25)

fft = pyo.FFT(a, size=1024, overlaps=1, wintype=2)
re = fft['real']
im = fft['imag']
bin = fft['bin']
mag = pyo.Sqrt(re * re + im * im)

magTable = pyo.NewTable(1024)
tablerec = pyo.TableRec(mag, magTable)

refreshTrig = pyo.Select(bin, value=0)
pyo.TrigFunc(refreshTrig, tablerec.play)

value = pyo.TableIndex(magTable, bin)

s.gui(locals())
コード例 #5
0
octaves = 0.5
soundAmp = 0.3
modRate = 10
centerFreq = 2000

freqhigh = centerFreq * np.power(2, octaves / 2)
freqlow = centerFreq / np.power(2, octaves / 2)
envelope = pyo.Sine(freq=modRate,
                    mul=soundAmp / 2,
                    add=soundAmp / 2,
                    phase=0.75)
soundObj = pyo.Fader(fadein=0.002, fadeout=0.002, dur=duration, mul=envelope)
freqcent = float((freqhigh + freqlow) / 2)
bandwidth = float(freqhigh - freqlow)

n = pyo.Noise(mul=soundObj)
soundwaveObj = pyo.IRWinSinc(n, freq=freqcent, bw=bandwidth, type=3,
                             order=400).out()
#soundwaveObj = pyo.IRWinSinc(n, freq=centerFreq, bw=centerFreq, type=3, order=400).out()

# -- Set recording parameters --
soundFilename = '/home/jarauser/workspace/sounds/{0}octaves.wav'.format(
    octaves)
ss.recordOptions(dur=duration,
                 filename=soundFilename,
                 fileformat=0,
                 sampletype=0)

soundObj.play()
ss.start()
コード例 #6
0
    subprocess.run("qjackctl -a patchbay-new.xml -s &", shell=True)
    time.sleep(0.5)

    SERVER = pyo.Server(
        audio="jack",
        midi="jack",
        nchnls=N_CHANNELS,
    )

    # starting server
    SERVER.boot()

    # starting sound loop
    _speaker_cycle = itertools.cycle(range(INCREMENT, N_CHANNELS + INCREMENT))

    ALLOWED_TYPES = {"noise": pyo.Noise(), "sine": pyo.Sine(freq=400)}
    try:
        SIGNAL = ALLOWED_TYPES[TYPE]
    except KeyError:
        msg = "Unknown type '{}'. Valid types would be '{}'.".format(
            TYPE, ALLOWED_TYPES)
        raise NotImplementedError(msg)

    FADER = pyo.Fader(fadein=0.07, fadeout=0.07, dur=TIME, mul=MUL)
    SIGNAL.mul = FADER

    # red & bold printing
    print(
        "\033[91m",
        "\033[1m",
        "\n",
コード例 #7
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']))
コード例 #8
0
 def build(self):
     self.noise = pyo.Noise()
コード例 #9
0
import numpy as np

# Run this the first time
if 1:
    ss = pyo.Server(audio="offline")
    ss.boot()


# make a fader

duration = 2.0
soundAmp = [0.05, 0.05]

soundObj = pyo.Fader(fadein=0, fadeout=0, dur=duration, mul=soundAmp)

a = pyo.Noise(mul=soundObj).out()

# play the fader.
# -- Set recording parameters --
soundFilename = '/tmp/test.wav'
ss.recordOptions(dur=duration, filename=soundFilename,
                fileformat=0, sampletype=0)

soundObj.play()
ss.start()

# # -- Shutdown the server and delete the variable --
ss.shutdown()
del ss

os.system('aplay {0}'.format(soundFilename))
コード例 #10
0
 def __init__(self):
     super().__init__()
     self.noi = pyo.Noise()
     self.synth = pyo.Waveguide(self.noi, 200, .7)
     self.filter = pyo.Biquad(self.synth)
     self.verb = pyo.WGVerb(self.filter).mix(2)
コード例 #11
0
    apu.pulse_0.write_reg0(0x30)
    # apu.pulse_0.write_reg1(0x00)
    apu.pulse_0.write_reg2(0x20)
    apu.pulse_0.write_reg3(0x01)

    apu.triangle.write_reg0(0xFF)
    apu.triangle.write_reg2(0xFB)
    apu.triangle.write_reg3(0xF1)

    apu.noise.write_reg0(0x3F)
    apu.noise.write_reg2(0x04)
    apu.noise.write_reg3(0x01)

    server.start()

    pyo.Noise()

    # Change values every 1/60th of a second
    change = pyo.Pattern(function=write_values, time=0.0166, arg=apu).play()

    selector = pyo.Selector([
        apu.pulse_0.output, apu.pulse_1.output, apu.triangle.output,
        apu.noise.output
    ]).out()
    selector.setMode(1)
    selector.ctrl()

    # view = pyo.Spectrum(apu.pulse_0.output)
    view = pyo.Scope(
        [apu.pulse_0.output, apu.triangle.output, apu.noise.output])
コード例 #12
0
import numpy as np

# Run this the first time
if 1:
    ss = pyo.Server(audio="offline")
    ss.boot()


# make a fader

duration = 2.0
soundAmp = 0.2
soundObj = pyo.Fader(fadein=0.002, fadeout=0.002, dur=duration, mul=soundAmp)

# Make 2 sounds, out to diff channels, mul by the fader
a = pyo.Noise(mul=soundObj).out(chnl=0)
b = pyo.Sine(freq=2000, mul=soundObj).out(chnl=1)

# play the fader.
# -- Set recording parameters --
soundFilename = '/tmp/test.wav'
ss.recordOptions(dur=duration, filename=soundFilename,
                fileformat=0, sampletype=0)

soundObj.play()
ss.start()

# # -- Shutdown the server and delete the variable --
ss.shutdown()
del ss
コード例 #13
0
if case == 1:
    soundObj = pyo.Fader(fadein=risetime,
                         fadeout=falltime,
                         dur=duration,
                         mul=soundAmp)
    soundWaveObjs.append(pyo.Sine(2000, mul=soundObj).out())

if case == 2:
    modFreq = 8
    halfAmp = [0.5 * x for x in soundParams['amplitude']]
    envelope = pyo.Sine(freq=modFreq, mul=halfAmp, add=halfAmp, phase=0.75)

    soundObj = pyo.Fader(fadein=risetime, fadeout=falltime, dur=duration)
    soundWaveObjs.append(envelope)
    soundWaveObjs.append(pyo.Noise(mul=envelope).out())

if SOUND_SYNC_CHANNEL is not None:
    syncAmp = [0, 0]
    syncAmp[
        SOUND_SYNC_CHANNEL] = SYNC_SIGNAL_AMPLITUDE  #Only set the sync signal to play in the sync channel
    syncFreq = SYNC_SIGNAL_FREQUENCY
    soundWaveObjs.append(pyo.Sine(float(syncFreq), mul=syncAmp).out())

soundFilename = '/tmp/original_method.wav'
ss.recordOptions(dur=duration,
                 filename=soundFilename,
                 fileformat=0,
                 sampletype=0)

soundObj.play()
コード例 #14
0
tone = True

halfAmp = 0.5 * soundAmp
envelope = pyo.Sine(freq=modRate, mul=halfAmp, add=halfAmp, phase=0.75)
noiseSoundObj = pyo.Fader(fadein=0.002,
                          fadeout=0.002,
                          dur=duration,
                          mul=envelope)
toneSoundObj = pyo.Fader(fadein=0.002,
                         fadeout=0.002,
                         dur=duration,
                         mul=(soundAmp / 16.0) * toneAmp)
#noiseFaderObj = pyo.Fader(dur=duration, mul=envelope)
#toneFaderObj = pyo.Fader(dur=duration, mul=toneAmp)
if np.isinf(octaves):
    masker = pyo.Noise(mul=noiseSoundObj).mix(2).out()
else:
    freqcent = (freqhigh + freqlow) / 2
    bandwidth = freqhigh - freqlow
    n = pyo.Noise(mul=noiseSoundObj)
    masker = pyo.IRWinSinc(n, freq=freqcent, bw=bandwidth, type=3,
                           order=400).mix(2).out()

if tone:
    soundwaveObjs = []
    soundwaveObjs.append(
        pyo.Sine(freq=frequency, mul=toneSoundObj).mix(2).out())
    soundwaveObjs.append(masker)
else:
    soundwaveObj = masker
コード例 #15
0
'''

import pyo
import os
import numpy as np

# Run this the first time
if 1:
    ss = pyo.Server(audio="offline")
    ss.boot()

duration = 2.0
soundAmp = 0.3

soundObj = pyo.Fader(fadein=0.002, fadeout=0.002, dur=duration, mul=soundAmp)
soundWaveObj = pyo.Noise(mul=soundObj).out()
#n = pyo.Noise(mul=soundObj)
#soundWaveObj = pyo.EQ(n, freq=14000, q=10, boost=10, type=0).out()

# -- Set recording parameters --
soundFilename = '/home/jarauser/tmp/calibration.wav'
ss.recordOptions(dur=duration,
                 filename=soundFilename,
                 fileformat=0,
                 sampletype=0)

soundObj.play()
ss.start()

# -- Shutdown the server and delete the variable --
ss.shutdown()