コード例 #1
0
    def buildLinearOscillatorVisualizer(self):
        from musicvisualizer.pipeline.ir import PhaseVocPR, AudioRepr
        from musicvisualizer.pipeline.models.linear_oscillator import LinearOscillatorModel
        from musicvisualizer.pipeline.models.linear_oscillator_visualizer import LinearOscillatorVisualizer
        
        if self.verbose:
            print("Creating AIR")
        audio = AudioRepr(self.source_wav, self.input_fields)

        if self.verbose:
            print("Creating PIR")
        phvoc = PhaseVocPR(audio, self.input_fields)
        if self.verbose:
            print("Creating MIR")
        dataInFPS = phvoc.dataInFPS # XXX: This should be automatic
        linos = LinearOscillatorModel(
                phvoc,                         # Phase Vocoder
                input_fields     = self.input_fields,
                sampleRate       = 24,         # Visual sample rate
                dataInFPS        = dataInFPS,  # Data sample rate (to generate visual)
                number_of_points = 256,        # how many points in simulation?
                hook             = 821.0,
                vertical_hook    = .15,
                data_shape       = (256, ),
                damping          = 0.92)
        if self.verbose:
            print("Creating VIR")
        lovis = LinearOscillatorVisualizer(linos, mode = 'dots')
        return lovis
コード例 #2
0
def plot_spectrogram(filename, samplerate=0):
    points = 128
    win_s = 512  # fft window size
    hop_s = win_s // 2  # hop size
    fft_s = win_s // 2 + 1  # spectrum bins

    a = source(filename, samplerate, hop_s)  # source file

    if samplerate == 0:
        samplerate = a.samplerate
    pv = pvoc(win_s, hop_s)  # phase vocoder
    specgram = zeros([0, fft_s],
                     dtype=float_type)  # numpy array to store spectrogram

    # Set up LinearOscillatorModel
    def dataIn():
        while True:
            samples, read = a()  # read file
            specgram = pv(samples)  # grab complex vector
            if read < a.hop_size:
                break
            yield (specgram)

    dataInFPS = int(samplerate / hop_s)

    M = LinearOscillatorModel(
        sampleRate=24,  # Visual sample rate
        dataInFPS=dataInFPS,  # Data sample rate (to generate visual)
        number_of_points=points,  # how many points in simulation?
        hook=121.0,
        dataIn=dataIn,
        data_shape=(256, ),
        damping=0.95)

    frames = M.get_frames()
    clip = ImageSequenceClip(frames, fps=24)
    try:
        clip.write_videofile("output.mp4", fps=24, audio=filename)
    except:
        print("[!] ERROR: Couldn't Write Audio!")
        clip.write_videofile("output.mp4", fps=24)
コード例 #3
0
        while t < MAXT:
            t += 0.1

    def dataIn_empty():
        for i in range(1000):
            yield (0.0, 0.0)

    def dataIn_singlePulse():
        yield (points / 2, 20)
        for i in range(1000):
            yield (0.0, 0.0)

    M = LinearOscillatorModel(
        sampleRate=24,  # Visual sample rate
        dataInFPS=96,  # Data sample rate (to generate visual)
        number_of_points=points,  # how many points in simulation?
        hook=11.0,
        dataIn=None,
        damping=0.9999)

    I = iter(M)

    plt.ion()  # Interactive I/O

    for frame in I:
        ys = [p[0] for p in frame]
        vs = [p[1] for p in frame]
        xs = range(len(frame))
        # print("max(ys) = {}".format(max(ys)))
        # print("max(vs) = {}".format(max(vs)))
        ys = ys + [1.0, -1.0]
コード例 #4
0
 def this_should_raise():
     try:
         linosc = LinearOscillatorModel(pir, self.input_fields)
     except Exception as e:
         print(e)
         raise e
コード例 #5
0
 def test_constructor_type2(self):
     linosc = LinearOscillatorModel(self.phvoc, self.input_fields)
     self.assertIsInstance(linosc, ModelledRepr)
コード例 #6
0
def plot_spectrogram(filename, samplerate=0):
    points = 257
    win_s = 512  # fft window size
    hop_s = win_s // 2  # hop size
    fft_s = win_s // 2 + 1  # spectrum bins

    a = source(filename, samplerate, hop_s)  # source file

    if samplerate == 0:
        samplerate = a.samplerate
    pv = pvoc(win_s, hop_s)  # phase vocoder
    specgram = zeros([0, fft_s],
                     dtype=float_type)  # numpy array to store spectrogram

    while False:  # Set to true for interpreter
        s = input('>>> ').strip()
        if s.lower() in ('x', 'q', 'quit', 'exit', 'break'):
            break
        try:
            exec(s)
        except Exception as e:
            print(e)

    # Set up LinearOscillatorModel
    def dataIn():
        while True:
            samples, read = a()  # read file
            specgram = pv(samples)  # grab complex vector
            # while True:
            #     s = input('>>> ')
            #     if s.strip() == 'q':
            #         break
            #     try:
            #         exec(s)
            #     except Exception as e:
            #         print(e)
            if read < a.hop_size:
                break
            yield (specgram)

    dataInFPS = int(samplerate / hop_s)

    M = LinearOscillatorModel(
        sampleRate=24,  # Visual sample rate
        dataInFPS=dataInFPS,  # Data sample rate (to generate visual)
        number_of_points=points,  # how many points in simulation?
        hook=121.0,
        dataIn=dataIn,
        data_shape=(256, ),
        damping=0.95)

    I = iter(M)

    plt.ion()  # Interactive I/O

    for frame in I:
        ys = [p[0] for p in frame]
        xs = range(len(frame))
        # Set frame info (+/- 1) to keep view realtively fixed...
        ys = ys + [1.0, -1.0]
        # Set the extra points in ys to x = 0
        xs = list(xs) + [len(xs), len(xs)]
        plt.plot(xs, ys)
        plt.show()  # Update visuals
        plt.pause(0.01)  # Pause
        plt.cla()  # Clear