コード例 #1
0
def panMove(snd0, snd1, fil, nch, mult):
    if snd0.isPlaying() == True:
        pass
    else:
        snd0.play()
        snd1.play()
        ff = float(1 / po.sndinfo(fil)[1] / 4)
        sin = po.Sine(freq=ff, phase=0)
        cos = po.Sine(freq=ff, phase=0.25)
        ini = np.random.randint(0, nch)
        step = np.random.randint(0, int(nch / 2) + 1)
        end = (ini + step) % nch
        snd0.out(ini, 0).setMul(mult * cos)
        snd1.out(end, 0).setMul(mult * sin)
        snd0.stop(wait=po.sndinfo(fil)[1])
        snd1.stop(wait=po.sndinfo(fil)[1])
コード例 #2
0
ファイル: SoundFilePanel.py プロジェクト: lucasParis/QLive
    def __init__(self, id, filename, loopmode=0, transpo=1, gain=0,
                 playing=0, directout=True, startpoint=0,
                 endpoint=-1, crossfade=5, channel=0):
        self.id = id
        self.filename = filename
        sndfolder = os.path.join(QLiveLib.getVar("projectFolder"), "sounds")        
        info = sndinfo(os.path.join(sndfolder, self.filename))
        if info is None:
            self.valid = False
            self.duration = -1
        else:
            self.valid = True
            self.duration = info[1]
        self.loopmode = loopmode
        self.transpo = transpo
        self.gain = gain
        self.playing = playing
        self.directout = directout
        self.startpoint = startpoint
        self.endpoint = self.duration
        self.crossfade = crossfade
        self.channel = channel
        
        self.playerRef = None

        self.currentCue = 0
        self.cues = {}
        self.saveCue()
コード例 #3
0
ファイル: transform_audio.py プロジェクト: bedoya-daniel/STIM
def filter_file(s, src, target, type, freq, q=1):
    """
	freq : float or PyoObject, optional
	Cutoff or center frequency of the filter. Defaults to 1000.
	q : float or PyoObject, optional
	Q of the filter, defined (for bandpass filters) as freq/bandwidth. Should be between 1 and 500. Defaults to 1.
	type : int, optional
	Filter type. Five possible values :
		0 : lowpass (default)
		1 : highpass
		2 : bandpass
		3 : bandstop
		4 : allpass

	example of use: 
		s  = Server(duplex=0, audio="offline")
		for file in glob.glob("*.wav"):
			filter_file(s, file, "filtered/"+file, type = 1, freq = 300, q = 1)
			s.shutdown()
	"""

    from pyo import sndinfo

    duration = sndinfo(src)[1]
    s.boot()
    s.recordOptions(dur=duration, filename=target, fileformat=0, sampletype=0)

    sf = SfPlayer(src, speed=1, loop=False)
    f = Biquad(sf, freq=freq, q=q, type=type).mix(2).out()  # highpass
    s.start()
    s.stop()
    s.shutdown()
コード例 #4
0
    def getSoundInfo(self, path):
        """
        Retrieves information of the sound and prints it to the console.
    
        return (number of channels, sampling rate, duration, 
                fraction of a table, length in samples, bitrate)
        """
        print '--------------------------------------'
        print path

        info = sndinfo(path)
        if info is not None:
            type = info[4]
            samprate = int(info[2])
            chnls = info[3]
            nsamps = info[0]
            dur = info[1]
            bitrate = INV_BIT_DEPTHS.get(info[5], -1)
            for i in range(24):
                size = math.pow(2, (i + 1))
                if size > nsamps:
                    break
            tableFrac = nsamps / size

            print "channels = %d" % chnls
            print "sampling rate = %s" % samprate
            print "number of samples = %s" % nsamps
            print "duration in sec. = %s" % dur
            print "bitrate = %s" % bitrate
            print "type = %s" % type

            return (chnls, samprate, dur, tableFrac, nsamps, bitrate, type)
        else:
            print "Unable to get sound infos..."
            return None
コード例 #5
0
        def __init__(self, index: int, frequency: float):
            closest_frequency = tools.find_closest_item(
                frequency, self.available_frequencies)
            second_closest_frequency = tools.find_closest_item(
                frequency,
                tuple(f for f in self.available_frequencies
                      if f != closest_frequency),
            )

            if (self.freq_used_counter[closest_frequency] <=
                    self.freq_used_counter[second_closest_frequency]):
                choosen_frequency = closest_frequency
            else:
                choosen_frequency = second_closest_frequency

            print(frequency, choosen_frequency)

            self.freq_used_counter.update({choosen_frequency: 1})
            self.choosen_sample = self.samples[choosen_frequency]
            self.pitch_factor = frequency / choosen_frequency
            self.frequency = frequency
            self.duration = pyo.sndinfo(self.choosen_sample)[1] + self.tail
            self.index = index
            self.bandwidth = 2
            self.original_amp = 0.7
            self.bp_amp = 0.0000009
            self.lp_freq = 11000
コード例 #6
0
        def __init__(self, index: int, frequency: float):
            if frequency < 300:
                frequency *= 2
            closest_frequency = tools.find_closest_item(
                frequency, self.available_frequencies)
            print(frequency, closest_frequency)
            second_closest_frequency = tools.find_closest_item(
                frequency,
                tuple(f for f in self.available_frequencies
                      if f != closest_frequency),
            )

            if (self.freq_used_counter[closest_frequency] <=
                    self.freq_used_counter[second_closest_frequency]):
                choosen_frequency = closest_frequency
            else:
                choosen_frequency = second_closest_frequency

            self.freq_used_counter.update({choosen_frequency: 1})

            self.choosen_sample = self.samples[choosen_frequency]
            self.pitch_factor = frequency / choosen_frequency
            print(self.pitch_factor)
            self.frequency = frequency
            self.duration = pyo.sndinfo(self.choosen_sample)[1] + self.tail
            self.index = index
コード例 #7
0
 def OnDropFiles(self, x, y, filenames):
     x, y = self.grid.CalcUnscrolledPosition(x, y)
     col = self.grid.XToCol(x)
     row = self.grid.YToRow(y)
     if row > -1 and col == ID_COL_FILENAME:
         filename = filenames[0]
         if sndinfo(filename) is not None:
             self.grid.copyToSoundsFolder(filename)
             self.grid.setSelRow(row)
             self.grid.loadSound(os.path.basename(filename))
コード例 #8
0
ファイル: SoundFilePanel.py プロジェクト: lucasParis/QLive
 def OnDropFiles(self, x, y, filenames):
     x, y = self.grid.CalcUnscrolledPosition(x, y)
     col = self.grid.XToCol(x)
     row = self.grid.YToRow(y)
     if row > -1 and col == ID_COL_FILENAME:
         filename = filenames[0]
         if sndinfo(filename) is not None:
             self.grid.copyToSoundsFolder(filename)
             self.grid.setSelRow(row)
             self.grid.loadSound(os.path.basename(filename))
コード例 #9
0
ファイル: resonators.py プロジェクト: levinericzimmermann/ot2
    def render(self):
        s = pyo.Server(audio="offline")
        s.boot()

        sndinfo = pyo.sndinfo(self.path)
        s.recordOptions(filename=self.complete_output_path, dur=sndinfo[1])

        source = pyo.SfPlayer(self.path)
        source_envelope = pyo.Expseg(list(
            zip(self.source_envelope.times, self.source_envelope.levels)),
                                     exp=5)
        waveguide_envelope = pyo.Expseg(
            list(
                zip(self.waveguide_envelope.times,
                    self.waveguide_envelope.levels)),
            exp=5,
        )
        filter_envelope = pyo.Expseg(
            list(zip(self.filter_envelope.times, self.filter_envelope.levels)),
            exp=5,
        )
        filter_q_envelope = pyo.Linseg(
            list(
                zip(self.filter_q_envelope.times,
                    self.filter_q_envelope.levels)))

        waveguide = pyo.Waveguide(
            source,
            freq=self.frequencies,
            minfreq=self.minfreq,
            mul=self.waveguide_mul,
            dur=self.waveguide_dur,
        )
        bandpass = pyo.Resonx(
            waveguide,
            self.frequencies,
            q=filter_q_envelope,
            stages=4,
            mul=self.bandpass_mul,
        )

        lfo = pyo.Sine(freq=self.pan_lfo_frequency, mul=0.5, add=0.5)
        bandpass_pan = pyo.Pan(bandpass, outs=2, pan=lfo)

        filter_q_envelope.play()
        filter_envelope.play()
        source_envelope.play()
        waveguide_envelope.play()

        (bandpass_pan * filter_envelope).out()
        (waveguide * waveguide_envelope).out()
        (source * source_envelope).out()

        s.start()
コード例 #10
0
ファイル: versemaker.py プロジェクト: levinericzimmermann/aml
    def __init__(self, sf_path_meta_track_pairs: dict):
        self.sf_path_meta_track_pairs = sf_path_meta_track_pairs
        durations = []
        channels_per_meta_track = {}
        for meta_track, sf_path_meta_track_pair in sf_path_meta_track_pairs.items(
        ):
            if meta_track != "keyboard":
                sf_path, _ = sf_path_meta_track_pair
                info = pyo.sndinfo("{}.wav".format(sf_path))
                duration, nchannels = info[1], info[3]
                durations.append(duration)
                channels_per_meta_track.update({meta_track: nchannels})

        self.duration = max(durations) + self.tail
コード例 #11
0
    def __init__(self,
                 id,
                 filename,
                 loopmode=0,
                 transpo=1,
                 gain=0,
                 playing=0,
                 directout=True,
                 startpoint=0,
                 endpoint=-1,
                 crossfade=5,
                 channel=0):
        interpTime = QLiveLib.getVar("globalInterpTime")
        self.id = id
        self.filename = filename
        sndfolder = os.path.join(QLiveLib.getVar("projectFolder"), "sounds")
        info = sndinfo(os.path.join(sndfolder, self.filename))
        if info is None:
            self.valid = False
            self.duration = -1
            self.sndchnls = -1
        else:
            self.valid = True
            self.duration = info[1]
            self.sndchnls = info[3]
        self.loopmode = loopmode
        self.transpo = transpo
        self.gain = gain
        self.playing = playing
        self.directout = directout
        self.startpoint = startpoint
        self.endpoint = self.duration
        self.crossfade = crossfade
        self.channel = channel
        self.transpox = interpTime
        self.gainx = interpTime
        self.transpoDict = None
        self.gainDict = None

        self.showInterp = 0

        self.playerRef = None
        self.transpoAutoWindow = None
        self.gainAutoWindow = None

        self.cues = {}
        self.copied = {}
        currentCue = QLiveLib.getVar("CuesPanel").getCurrentCue()
        self.addCue(0)
        self.addCue(currentCue)
コード例 #12
0
    def _essentia(path: str, params=None) -> float:
        """Using essentia to calculate the bpm of a given files.

        This function has been copied from the essentia examples here:
            https://essentia.upf.edu/essentia_python_examples.html
        """

        info = pyo.sndinfo(path)

        audio = es.MonoLoader(filename=path, sampleRate=info[2])()

        # Compute beat positions and BPM
        rhythm_extractor = es.RhythmExtractor2013(method="multifeature")
        bpm, beats, beats_confidence, _, beats_intervals = rhythm_extractor(
            audio)

        return bpm
コード例 #13
0
ファイル: radio_pyo.py プロジェクト: tiagovaz/radiopyo
def select_song(path=None):
    # call out to the newer helper function:
    song = get_random_song(path)
    # ices2 needs this
    logger.debug('Selected song: {0}'.format(song))
    song_duration = sndinfo(song)[1]
    now = datetime.datetime.now()
    # tag for update at now + song duration
    removal_date = now + datetime.timedelta(seconds=song_duration)
    song_stamp = '{0}({1}).stamp'.format(song, removal_date)
    open(song_stamp, 'a').close()
    # write music info to a txt which will be available in the web player
    song_info = get_song_info(os.path.splitext(song)[0] + '.py')
    f = open(os.path.join(RADIOPYO_PATH, CURRENT_SONG_INFO_FILE), 'w+')
    current_info = ('<h6>Now playing <em>{0}</em> by {1}</h6> ({2} sec)'
                    .format(song_info['TITLE'], song_info['ARTIST'],
                            song_info['DURATION']))
    f.write(current_info)
    f.close()
コード例 #14
0
ファイル: radio_pyo.py プロジェクト: yyywrz/radiopyo
def select_song(path=None):
    # call out to the newer helper function:
    song = get_random_song(path)
    # ices2 needs this
    logger.debug('Selected song: {0}'.format(song))
    song_duration = sndinfo(song)[1]
    now = datetime.datetime.now()
    # tag for update at now + song duration
    removal_date = now + datetime.timedelta(seconds=song_duration)
    song_stamp = '{0}({1}).stamp'.format(song, removal_date)
    open(song_stamp, 'a').close()
    # write music info to a txt which will be available in the web player
    song_info = get_song_info(os.path.splitext(song)[0] + '.py')
    f = open(os.path.join(RADIOPYO_PATH, CURRENT_SONG_INFO_FILE), 'w+')
    current_info = (
        '<h6>Now playing <em>{0}</em> by {1}</h6> ({2} sec)'.format(
            song_info['TITLE'], song_info['ARTIST'], song_info['DURATION']))
    f.write(current_info)
    f.close()
コード例 #15
0
        def __init__(self, index: int, frequency: float):
            if index in tuple(range(0, 5)):
                choosen_frequency = 527.13
                frequency *= 2

            elif index in tuple(range(5, 8)):
                choosen_frequency = 394.636

            elif index in tuple(range(8, 14)):
                choosen_frequency = 279.6

            else:
                raise NotImplementedError(index)

            self.choosen_sample = self.samples[choosen_frequency]
            self.pitch_factor = frequency / choosen_frequency
            print(self.pitch_factor)
            self.frequency = frequency
            self.duration = pyo.sndinfo(self.choosen_sample)[1] + self.tail
            self.index = index
コード例 #16
0
ファイル: SoundFilePanel.py プロジェクト: belangeo/qlive
    def __init__(self, id, filename, loopmode=0, transpo=1, gain=0,
                 playing=0, directout=True, startpoint=0,
                 endpoint=-1, crossfade=5, channel=0):
        interpTime = QLiveLib.getVar("globalInterpTime")
        self.id = id
        self.filename = filename
        sndfolder = os.path.join(QLiveLib.getVar("projectFolder"), "sounds")
        info = sndinfo(os.path.join(sndfolder, self.filename))
        if info is None:
            self.valid = False
            self.duration = -1
            self.sndchnls = -1
        else:
            self.valid = True
            self.duration = info[1]
            self.sndchnls = info[3]
        self.loopmode = loopmode
        self.transpo = transpo
        self.gain = gain
        self.playing = playing
        self.directout = directout
        self.startpoint = startpoint
        self.endpoint = self.duration
        self.crossfade = crossfade
        self.channel = channel
        self.transpox = interpTime
        self.gainx = interpTime
        self.transpoDict = None
        self.gainDict = None

        self.showInterp = 0

        self.playerRef = None
        self.transpoAutoWindow = None
        self.gainAutoWindow = None

        self.cues = {}
        self.copied = {}
        currentCue = QLiveLib.getVar("CuesPanel").getCurrentCue()
        self.addCue(0)
        self.addCue(currentCue)
コード例 #17
0
ファイル: overlap_player.py プロジェクト: ganwell/pyofocus
 def __init__(self, path, overlap=0.2, speed=1, mul=1, state=0, delay=None):
     self._path      = path
     self._mul       = mul
     self._speed     = speed
     self._overlap   = overlap
     self._time      = None
     self._pattern   = pyo.Pattern(self._control)
     self._infos     = pyo.sndinfo(path)
     self._duration  = self._infos[1]
     self._player0   = pyo.SfPlayer(path, speed=speed, mul=0.5, interp=3)
     self._player1   = pyo.SfPlayer(path, speed=speed, mul=0.5, interp=3)
     self._mix       = pyo.Mix(
         [self._player0, self._player1],
         voices=2,
         mul=mul
     )
     self._base_objs = self._mix.getBaseObjects()
     self._state     = state
     self.setOverlap(overlap)
     self._player0.stop()
     self._player1.stop()
     if delay is not None:
         self._pattern.time = delay
コード例 #18
0
ファイル: radio.py プロジェクト: levinericzimmermann/pbIII
    def __init__(
        self,
        voice: old.Melody,
        new_sample_positions: tuple,
        sample_per_change: tuple,
        make_envelope: bool,
        average_volume: float,
        min_volume: float,
        max_volume: float,
        duration: float,
        tempo_factor: float,
        shadow_time: float,
        crossfade_duration: float = 0.25,
        anticipation_time: float = 0,
        overlaying_time: float = 0,
        attack_duration: infit.InfIt = infit.Value(0.5),
        release_duration: infit.InfIt = infit.Value(0.5),
        random_seed: int = 100,
    ) -> None:

        assert max_volume > min_volume
        assert min_volume > average_volume

        if not isinstance(attack_duration, infit.InfIt):
            attack_duration = infit.Value(attack_duration)

        if not isinstance(release_duration, infit.InfIt):
            release_duration = infit.Value(release_duration)

        import random as random_module

        random_module.seed(random_seed)

        self.__random_module = random_module

        voice.delay = rhy.Compound(voice.delay).stretch(tempo_factor)
        voice.dur = rhy.Compound(voice.dur).stretch(tempo_factor)

        self.__sndinfo_per_sample = {
            sample: pyo.sndinfo(sample) for sample in set(sample_per_change)
        }
        self.__n_channels_per_sample = {
            sample: self.__sndinfo_per_sample[sample][3]
            for sample in self.__sndinfo_per_sample
        }
        self.__duration_per_sample = {
            sample: self.__sndinfo_per_sample[sample][1]
            for sample in self.__sndinfo_per_sample
        }
        self.__new_sample_positions = new_sample_positions
        self.__sample_per_change = sample_per_change
        self.__duration = duration
        self.__envelope = self.mk_envelope(
            voice,
            shadow_time,
            duration,
            average_volume,
            min_volume,
            max_volume,
            make_envelope,
            anticipation_time,
            overlaying_time,
        )
        self.__anticipation_time = anticipation_time
        self.__overlaying_time = overlaying_time
        self.__tempo_factor = tempo_factor
        self.__attack_duration = attack_duration
        self.__release_duration = release_duration
        self.__crossfade_duration = crossfade_duration
        self.__halved_crossfade_duration = crossfade_duration * 0.5
コード例 #19
0
"""
import os
import pyo
import random
s = pyo.Server(duplex=0, audio="offline").boot()

# input sound
sndpath = "./test.aif"
# output folder
recpath = os.path.join("./rendered")
if not os.path.isdir(recpath):
    os.mkdir(recpath)

# output file duration
NUM = 10
orig_dur = pyo.sndinfo(sndpath)[1]
dur = pyo.sndinfo(sndpath)[1] * NUM

s.recordOptions(dur=dur, filename=os.path.join(recpath, "pyo_test.wav"), fileformat=0, sampletype=0)

    ############################
# Start an oscillator with a frequency of 250 Hz
#syn = pyo.SineLoop(freq=[250,251], feedback=.07, mul=.2).out()
#def callback(arg):
#    # Change the oscillator's frequency to 300 Hz after 2 seconds
#    syn.freq = arg
#a = pyo.CallAfter(callback, 2, [300,301])



コード例 #20
0
import pyo
import time

path = "example.wav"
frames, duration, sampRate, channels, fileFormat, sampType = pyo.sndinfo(path)

server = pyo.Server()
server.boot()
print("booted server")
server.start()

sound = pyo.SfPlayer(path).out()
soundHigh = pyo.FreqShift(sound, shift = 10)
soundLow = pyo.FreqShift(sound, shift = -10)
soundQuiet = sound * .6
soundLoud = sound / .6
rec = pyo.Record(sound, "test.wav")
recHigh = pyo.Record(soundHigh, "example_high.wav")
recLow = pyo.Record(soundLow, "example_low.wav")
recQuiet = pyo.Record(soundQuiet, "example_quiet.wav")
recLoud = pyo.Record(soundLoud, "example_loud.wav")
print("start recording...")
time.sleep(duration)
print("stop recording.")
rec.stop()
recHigh.stop()
recLow.stop()
recQuiet.stop()
recLoud.stop()