Esempio n. 1
0
    def _pyo_write(self, filepath):
        """
        TODO: document
        """

        # Getting data ready
        duration = self.data.meta["asf_note_duration"]
        pitches = np.repeat(self.data["asf_pitch"], 2)
        delays = np.repeat(self.data["asf_onsets"], 2)

        # Making sure we have a clean server
        if self.server.getIsBooted():
            self.server.shutdown()

        self.server.reinit(audio="offline")
        self.server.boot()
        self.server.recordOptions(dur=delays[-1] + duration, filename=filepath)

        env = pyo.Linseg(list=[(0, 0), (0.1, 1), (duration - 0.1, 1),
                               (duration - 0.05, 0.5), (duration - 0.005, 0)],
                         mul=[0.05 for i in range(len(pitches))
                              ]).play(delay=list(delays), dur=duration)
        sine = pyo.Sine(list(pitches), 0, env).out(delay=list(delays),
                                                   dur=duration)
        self.server.start()

        # Clean up
        self.server.shutdown()
        self.server.reinit(audio="portaudio")
Esempio n. 2
0
    def write(self, filepath):
        """
        Save data sonification to the given file. 
        Currently the only output option is a wav file.

        Parameters
        ----------
        filepath : str
            The path to the output file.
        """

        # Getting data ready
        duration = self.data.meta["asf_note_duration"]
        pitches = np.repeat(self.data["asf_pitch"], 2)
        delays = np.repeat(self.data["asf_onsets"], 2)

        # Making sure we have a clean server
        if self.server.getIsBooted():
            self.server.shutdown()

        self.server.reinit(audio="offline")
        self.server.boot()
        self.server.recordOptions(dur=delays[-1] + duration, filename=filepath)

        env = pyo.Linseg(list=[(0, 0), (0.1, 1), (duration - 0.1, 1),
                               (duration - 0.05, 0.5), (duration - 0.005, 0)],
                         mul=[self.gain for i in range(len(pitches))
                              ]).play(delay=list(delays), dur=duration)
        sine = pyo.Sine(list(pitches), 0, env).out(delay=list(delays),
                                                   dur=duration)
        self.server.start()

        # Clean up
        self.server.shutdown()
        self.server.reinit(audio="portaudio")
Esempio n. 3
0
    def _pyo_play(self):
        """
        TODO: document
        """

        # Making sure we have a clean server
        if self.server.getIsBooted():
            self.server.shutdown()

        self.server.boot()
        self.server.start()

        # Getting data ready
        duration = self.data.meta["asf_note_duration"]
        pitches = np.repeat(self.data["asf_pitch"], 2)
        delays = np.repeat(self.data["asf_onsets"], 2)

        # TODO: This doesn't seem like the best way to do this, but I don't know
        # how to make it better
        env = pyo.Linseg(list=[(0, 0), (0.01, 1), (duration - 0.1, 1),
                               (duration - 0.05, 0.5), (duration - 0.005, 0)],
                         mul=[.1 for i in range(len(pitches))
                              ]).play(delay=list(delays), dur=duration)

        self.streams = pyo.Sine(list(pitches), 0, env).out(delay=list(delays),
                                                           dur=duration)
Esempio n. 4
0
    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()