Example #1
0
 def __init__(self, dur=1, refreshRate=.02):
     self.dur = dur
     self.refreshRate = refreshRate
     self.table = pyo.SndTable()
     self.tableOG = pyo.SndTable()
     self.durOG = 1
     self.input = pyo.Input()
     self.tabFill = pyo.TableFill(self.input, self.table)
Example #2
0
    def __init__(self):
        self.KEMARDATA = "data/"

        self.elev = [
            "-40", "-30", "-20", "-10", "0", "10", "20", "30", "40", "50",
            "60", "70", "80", "90"
        ]

        # This is really the "least worst" way of doing it... load all filenames into a matrix
        self.elevData_l = [
            glob.glob(self.KEMARDATA + "elev-40/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev-30/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev-20/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev-10/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev0/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev10/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev20/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev30/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev40/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev50/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev60/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev70/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev80/left/*.wav"),
            glob.glob(self.KEMARDATA + "elev90/left/*.wav")
        ]

        self.elevData_r = [
            glob.glob(self.KEMARDATA + "elev-40/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev-30/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev-20/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev-10/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev0/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev10/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev20/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev30/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev40/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev50/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev60/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev70/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev80/right/*.wav"),
            glob.glob(self.KEMARDATA + "elev90/right/*.wav")
        ]

        ### Init lists of SndTable objects ###
        self.elevData_l_tables = []
        self.elevData_r_tables = []
        # As good as GLOB is, it doesn't sort the data...
        for items in self.elevData_l:
            self.elevData_l_tables.append([])
            items.sort()
            for item in items:
                self.elevData_l_tables[-1].append(pyo.SndTable(item))
        for items in self.elevData_r:
            self.elevData_r_tables.append([])
            items.sort()
            for item in items:
                self.elevData_r_tables[-1].append(pyo.SndTable(item))
Example #3
0
 def refresh(self):
     self.table = pyo.SndTable(path=self.sound,
                               chnl=0,
                               start=self.start,
                               stop=self.stop,
                               initchnls=0)
     self.dur = self.table.getDur()
     self.tableOG = pyo.SndTable(path=self.sound,
                                 chnl=0,
                                 start=0,
                                 stop=None,
                                 initchnls=0)
     self.durOG = self.tableOG.getDur()
     self.OGTable = pyo.SndTable(path=self.sound, chnl=0, initchnls=0)
     self.OGDur = self.OGTable.getDur()
Example #4
0
    def _enter(self):
        if _pyo_server is None:
            # try and init it with defaults
            # print some warning
            init_audio_server()

        # process the vars
        sound_file = val(self.sound_file)
        start = val(self.start)
        stop = val(self.stop)

        # init the sound table (two steps to get mono in both speakers)
        sndtab = pyo.SndTable(initchnls=_pyo_server.getNchnls())
        sndtab.setSound(path=sound_file, start=start, stop=stop)

        # set the duration if not looping
        if val(self.loop):
            # set callback for stopping sound
            raise NotImplemented("Looping sounds is currently not supported.")
        else:
            self.duration = sndtab.getDur()

        # read in sound info
        self._snd = pyo.TableRead(sndtab,
                                  freq=sndtab.getRate(),
                                  loop=val(self.loop),
                                  mul=val(self.volume))
Example #5
0
 def playback5(self, file_path=icq_uh_oh):
     print('pb5')
     count = self.count
     fade = pyo.Fader(fadein=.1, fadeout=0.1, dur=3).play()
     select = random.random()
     snd = pyo.SndTable(file_path)
     env = pyo.HannTable()
     pos = pyo.Phasor(snd.getRate() * .25, random.random(), snd.getSize())
     dur = pyo.Noise(.05, .1)
     g = pyo.Granulator(
         snd,
         env, [self.granulated_pitch, self.granulated_pitch + .001],
         pos,
         dur,
         24,
         mul=fade)
     panner = pyo.Pan(g,
                      outs=2,
                      pan=random.random(),
                      spread=random.random()).out()
     self.granulated_pitch -= .05
     if self.granulated_pitch < .049:
         self.granulated_pitch = .05
     time.sleep(fade.dur + .05)
     g.stop()
Example #6
0
 def __init__(self, son):
     super().__init__()
     self.file = son
     self.son = pyo.SndTable(self.file)
     self.synth = pyo.TableRead(self.son, 1 / self.son.getDur(), 1).play()
     self.filter = pyo.Biquad(self.synth)
     self.verb = pyo.WGVerb(self.filter).mix(2)
Example #7
0
    def _enter(self):
        super(SoundFile, self)._enter()
        default_init_audio_server()
        self._sound_start_time = None

        # init the sound table (two steps to get mono in both speakers)
        sndtab = pyo.SndTable(initchnls=_pyo_server.getNchnls())
        sndtab.setSound(path=self._filename,
                        start=self._start,
                        stop=self._stop)

        # set the end time
        if not self._loop:
            self.cancel(self._start_time + sndtab.getDur())

        # read in sound info
        self.__snd = pyo.TableRead(sndtab,
                                   freq=sndtab.getRate(),
                                   loop=self._loop,
                                   mul=self._volume)
        if self.__snd is None:
            raise RuntimeError("Could not load sound file: %r" %
                               self._filename)

        # schedule playing the sound
        clock.schedule(self._start_sound, event_time=self._start_time)

        # schedule stopping the sound
        if self._end_time is not None:
            clock.schedule(self._stop_sound, event_time=self._end_time)
Example #8
0
 def _fromFile(self, fileName):
     # want mono sound file played to both speakers, not just left / 0
     self.fileName = fileName
     self._sndTable = pyo.SndTable(initchnls=self.channels)
     self._sndTable.setSound(self.fileName)  # mono file loaded to all chnls
     self._updateSnd()
     self.duration = self._sndTable.getDur()
     return True
Example #9
0
 def _setSndFromFile(self, fileName):
     # want mono sound file played to both speakers, not just left / 0
     self.fileName = fileName
     self._sndTable = pyo.SndTable(initchnls=self.channels)
     self.loops = self.requestedLoops #in case a tone with inf loops had been used before
     # mono file loaded to all chnls:
     self._sndTable.setSound(self.fileName,
                             start=self.startTime, stop=self.stopTime)
     self._updateSnd()
     self.duration = self._sndTable.getDur()
Example #10
0
 def _setSndFromFile(self, fileName):
     # want mono sound file played to both speakers, not just left / 0
     self.fileName = fileName
     self._sndTable = pyo.SndTable(initchnls=self.channels)
     # mono file loaded to all chnls:
     self._sndTable.setSound(self.fileName,
                             start=self.startTime,
                             stop=self.stopTime)
     self._updateSnd()
     self.duration = self._sndTable.getDur()
Example #11
0
 def __init__(self, sound='feu.wav', start=0, stop=None):
     self.sound = sound
     self.start = start
     self.stop = stop
     self.table = pyo.SndTable(path=self.sound,
                               chnl=0,
                               start=self.start,
                               stop=self.stop,
                               initchnls=0)
     self.dur = self.table.getDur()
     self.tableOG = pyo.SndTable(path=self.sound,
                                 chnl=0,
                                 start=0,
                                 stop=None,
                                 initchnls=0)
     self.durOG = self.tableOG.getDur()
     self.refreshRate = 3600
     self.OGTable = pyo.SndTable(path=self.sound, chnl=0, initchnls=0)
     self.OGDur = self.OGTable.getDur()
Example #12
0
 def playback3(self, file_path=imsend_sound_path):
     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=self.env)
     panner = pyo.Pan(g,
                      outs=2,
                      pan=random.random(),
                      spread=random.random()).out()
     time.sleep(self.env + 0.05)
     g.stop()
Example #13
0
 def _setSndFromFile(self, fileName):
     # want mono sound file played to both speakers, not just left / 0
     self.fileName = fileName
     self._sndTable = pyo.SndTable(initchnls=self.channels)
     self.loops = self.requestedLoops #in case a tone with inf loops had been used before
     # mono file loaded to all chnls:
     try:
         self._sndTable.setSound(self.fileName,
                             start=self.startTime, stop=self.stopTime)
     except:
         msg = 'Could not open sound file; not found or format not supported (%s)' % fileName
         logging.error(msg)
         raise TypeError(msg)
     self._updateSnd()
     self.duration = self._sndTable.getDur()
Example #14
0
 def _fromFile(self, fileName):
     #try finding the file
     self.fileName=None
     for filePath in ['', mediaLocation]:
         if path.isfile(path.join(filePath,fileName)):
             self.fileName=path.join(filePath,fileName)
         elif path.isfile(path.join(filePath,fileName+'.wav')):
             self.fileName=path.join(filePath,fileName+'.wav')
     if self.fileName is None:
         return False
     #load the file
     self._sndTable = pyo.SndTable(self.fileName)
     self._updateSnd()
     self.duration = self._sndTable.getDur()
     return True
Example #15
0
 def _fromFile(self, fileName):
     #try finding the file
     self.fileName = None
     for filePath in ['', mediaLocation]:
         if path.isfile(path.join(filePath, fileName)):
             self.fileName = path.join(filePath, fileName)
         elif path.isfile(path.join(filePath, fileName + '.wav')):
             self.fileName = path.join(filePath, fileName + '.wav')
     if self.fileName is None:
         return False
     # want mono sound file played to both speakers, not just left / 0
     self._sndTable = pyo.SndTable(initchnls=self.channels)
     self._sndTable.setSound(self.fileName)  # mono file loaded to all chnls
     self._updateSnd()
     self.duration = self._sndTable.getDur()
     return True
Example #16
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()
Example #17
0
    def __new__(cls, name, bases, dct):
        instance = super().__new__(cls, name, bases, dct)

        try:
            sample_path = instance._path
        except AttributeError:
            msg = "Class have to have the '_path' class attribute!"
            raise NotImplementedError(msg)

        tables_per_index = []
        for sf in natsort.natsorted(os.listdir(sample_path)):
            if sf[-3:] == "wav":
                # hard coded: the expected samples have to be stereo!
                tables = tuple(
                    pyo.SndTable(path="{}/{}".format(sample_path, sf),
                                 chnl=chnl) for chnl in range(2))
                tables_per_index.append(tables)

        instance.snd_tables = tuple(tables_per_index)

        return instance
Example #18
0
    def loadFiles(self):
        dir = os.getcwd()

        for path, dirs, files in os.walk(dir):
            # ignore directories whose name starts with '_'
            for d in dirs:
                if d.startswith('_'): dirs.remove(d)
            for f in files:
                if len(self.filenames) >= MIDI_MAX_NOTE:
                    break
                if os.path.splitext(f)[1].lower() in [
                        '.wav', '.aif', '.aiff', '.flac'
                ]:
                    print f, u"ajouté"
                    self.filenames.append(os.path.join(path, f))

        self.filenames.sort()
        for f in self.filenames:
            self.tables.append(pyo.SndTable(f))
            self.readers.append(
                pyo.TableRead(table=self.tables[-1],
                              freq=self.tables[-1].getRate()))
Example #19
0
 def refresh(self):
     self.dur = self.dur
     self.table = pyo.SndTable('blank.wav', stop=self.dur)
     self.input = pyo.Input()
     self.tabFill = pyo.TableFill(self.input, self.table)
Example #20
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']))
Example #21
0
import pyo
import numpy as np
from numpy.random import choice
import random

s = pyo.Server().boot()

table = pyo.SndTable('feu.wav')
dur = table.getDur()
read = pyo.TableRead(table, 1 / dur, 1).out()


def out(mul=1):
    vol = mul
    read.setMul(vol)
    return read


#pat = pyo.Pattern(out, .5, 0).play()

s.gui(locals())
Example #22
0
 def __init__(self, sound='01-181117_1724.wav'):
     self.sound = sound
     self.table = pyo.SndTable(path=self.sound, stop=5, chnl=0,
                               initchnls=0).normalize()
     self.read = pyo.TableRead(self.table, loop=0).play()