def blit():
    gen = [
        "Series/fmnet",
        ["BlitOsc/blit", "ADSR/adsr", "Gain/gain", "SoundFileSink/dest2"]
    ]
    # Create network and intialize parameter mapping
    network = create(gen)
    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.8)
    # These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")
    network.linkControl("BlitOsc/blit/mrs_real/frequency",
                        "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl("mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("BlitOsc/blit/mrs_natural/type", 0)
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "BlitTestSaw.wav")
    notes = [midi2freq(i) for i in range(10, 100)]
    play_melody(network, notes=notes)
    network.updControl("BlitOsc/blit/mrs_natural/type", 1)
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "BlitTestSquare.wav")
    play_melody(network)
def waveguide():
    gen = [
        "Series/fmnet",
        [
            "ADSR/pitch", "WaveguideOsc/waveguide", "ADSR/adsr", "Gain/gain",
            "SoundFileSink/dest2"
        ]
    ]
    # Create network and intialize parameter mapping
    network = create(gen)
    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.6)
    # These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("ADSR/pitch/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/pitch/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("WaveguideOsc/waveguide/mrs_real/frequency",
                        "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl("mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "WaveguideTest.wav")
    play_melody(network)
    network.updControl("ADSR/pitch/mrs_bool/bypass",
                       MarControlPtr.from_bool(True))
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "WaveguideTestPitch.wav")
    play_melody(network)
def allpass():
    gen = [
        "Series/fmnet",
        [
            "APDelayOsc/apdelay", "ADSR/adsr", "Gain/gain",
            "SoundFileSink/dest2"
        ]
    ]
    # Create network and intialize parameter mapping
    network = create(gen)
    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("APDelayOsc/apdelay/mrs_bool/noteon",
                       MarControlPtr.from_bool(True))
    network.updControl("Gain/gain/mrs_real/gain", 0.8)
    # These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")
    network.linkControl("APDelayOsc/apdelay/mrs_real/frequency",
                        "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl("mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("APDelayOsc/apdelay/mrs_natural/type", 0)
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "APTestSaw.wav")
    play_melody(network)
def main():
    gen = ["Series/fmnet", ["APDelayOsc/apdelay","ADSR/adsr","Gain/gain","SoundFileSink/dest2"]]

# Create network and intialize parameter mapping 
    network = create(gen)

    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("APDelayOsc/apdelay/mrs_bool/noteon", MarControlPtr.from_bool(True))
    network.updControl("Gain/gain/mrs_real/gain", 0.8)

# These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")
    network.linkControl("APDelayOsc/apdelay/mrs_real/frequency", "mrs_real/frequency")

# Set the systems sample rate
    sample_rate = 44100.0
    network.updControl("mrs_real/israte", sample_rate)

# Set up Audio File
    network.updControl("APDelayOsc/apdelay/mrs_natural/type", 0)
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "APTestSaw.wav")

    notes = [midi2freq(i) for i in range(30,100)]
    play_melody(network, notes=notes)
Beispiel #5
0
def main(): 
    

    maxmin_spec = ["Series/mxm", 
              ["MaxMin/mxmin", 
               "Transposer/trs"]]
    
    spec = ["Series/plot", 
            ["SoundFileSource/src", 
             "Stereo2Mono/s2m",
             ["Fanout/measurements", 
             [
              "ZeroCrossings/zcrs",
              "Rms/rms",
              maxmin_spec
              ]]]]

    accum_spec = ["Accumulator/accum", 
                  [spec]]


    playlist_folder = "/Users/georgetzanetakis/data/sound/yogi_tunes/"
    print(playlist_folder)
    wav_fnames = [f for f in os.listdir(playlist_folder) if f.endswith(".wav")]

    wav_fnames = [playlist_folder + s for s in wav_fnames]

    print(wav_fnames)
    

#    wav_fnames = ["/Users/georgetzanetakis/data/sound/yogi_tunes/1 - The Player's Hands (Instrumental).wav", 
#                 "6_lion_heart.wav", 
#                  "10_alienist.wav"] 

    winSize = 44100
    plot_net = create(accum_spec)


    inSamples = plot_net.getControl("mrs_natural/inSamples")
    inSamples.setValue_natural(winSize)
    nTimes = plot_net.getControl("mrs_natural/nTimes")
    
    fname = plot_net.getControl("Series/plot/SoundFileSource/src/mrs_string/filename")


    figs = [] 
    for wav_fname in wav_fnames: 
        fname.setValue_string(wav_fname)
        fsize = plot_net.getControl("Series/plot/SoundFileSource/src/mrs_natural/size").to_natural()
        srate = plot_net.getControl("Series/plot/SoundFileSource/src/mrs_real/osrate").to_real()
        nTicks = int(fsize /winSize)
        print(("nTicks=", nTicks))
        nTimes.setValue_natural(nTicks)

        plot_net.tick() 
        mydata = control2array(plot_net, "mrs_realvec/processedData")    
        fig = bokeh_plot(mydata, wav_fname)
        figs.append(fig)
        
    show(column(*figs))
Beispiel #6
0
def make_input(filename_input):
    series = ["Series/input", ["SoundFileSource/src"]]
    this_net = marsyas_util.create(series)
    this_net.updControl(
        "SoundFileSource/src/mrs_string/filename",
        filename_input)
    return this_net
Beispiel #7
0
    def __init__(self, voices=8):
        self.sample_rate = 44100.0

        self.playing = deque()
        self.off = deque(
            [Osc(sample_rate=self.sample_rate) for _ in range(voices)])

        osc_bank = ["Fanout/bank", [osc.get_network() for osc in self.off]]
        net = [
            "Series/fmnet",
            [
                osc_bank, "Sum/sum", "Gain/ogain", "SVFilter/postmixfilter",
                "MidiInput/midi", "AudioSink/dest", "SoundFileSink/dest2"
            ]
        ]

        # Create network and intialize parameter mapping
        self.network = create(net)

        self.network.updControl("Gain/ogain/mrs_real/gain", 0.4)

        # Output settings
        self.network.updControl("mrs_real/israte", self.sample_rate)
        self.network.updControl("AudioSink/dest/mrs_bool/initAudio",
                                MarControlPtr.from_bool(True))
        self.network.updControl("SoundFileSink/dest2/mrs_string/filename",
                                "synthout.wav")

        # Midi settings
        self.network.updControl("MidiInput/midi/mrs_bool/initmidi",
                                MarControlPtr.from_bool(True))
        self.network.updControl("MidiInput/midi/mrs_natural/port", 0)
def aliasing():
    mod = ["Fanout/fo", ["ADSR/pitch", "ADSR/pwm"]]
    osc = ["Series/osc", [mod, "AliasingOsc/osc"]]
    gen = [
        "Series/fmnet", [osc, "ADSR/adsr", "Gain/gain", "SoundFileSink/dest2"]
    ]
    # Create network and intialize parameter mapping
    network = create(gen)
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl("mrs_real/israte", sample_rate)
    network.updControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_real/aTime", 0.7)
    network.updControl("Gain/gain/mrs_real/gain", 0.7)
    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.8)
    # These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")
    network.linkControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/noteon",
                        "mrs_bool/noteon")
    network.linkControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/noteoff",
                        "mrs_bool/noteoff")
    network.linkControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/noteon",
                        "mrs_bool/noteon")
    network.linkControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/noteoff",
                        "mrs_bool/noteoff")
    network.linkControl("Series/osc/AliasingOsc/osc/mrs_real/frequency",
                        "mrs_real/frequency")
    # PWM Example
    network.updControl("Series/osc/AliasingOsc/osc/mrs_natural/type", 1)
    network.updControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/bypass",
                       MarControlPtr.from_bool(True))
    network.updControl("Series/osc/AliasingOsc/osc/mrs_bool/cyclicin",
                       MarControlPtr.from_bool(True))
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "AliasingTestPWM.wav")
    play_melody(network)
    # Saw Wave example
    network.updControl("Series/osc/AliasingOsc/osc/mrs_natural/type", 0)
    network.updControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/bypass",
                       MarControlPtr.from_bool(False))
    network.updControl("Series/osc/AliasingOsc/osc/mrs_bool/cyclicin",
                       MarControlPtr.from_bool(False))
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "AliasingTestSaw.wav")
    play_melody(network)
    # Pitch modulation example
    network.updControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/bypass",
                       MarControlPtr.from_bool(True))
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "AliasingTestPitch.wav")
    play_melody(network)
    network.updControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/bypass",
                       MarControlPtr.from_bool(False))
    # Square Wave example
    network.updControl("Series/osc/AliasingOsc/osc/mrs_natural/type", 1)
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "AliasingTestSquare.wav")
    play_melody(network)
Beispiel #9
0
def make_output():
    series = ["Series/output", 
              ["RealvecGrainSource/real_src",
               "AudioSink/dest"]]
    this_net = marsyas_util.create(series)
    this_net.updControl("mrs_natural/inSamples", buffsize)
    this_net.updControl("mrs_real/israte", 44100.0)    
    return this_net
Beispiel #10
0
 def setup( self ):
     series = ["Series/input", [self.get_source(), detectors]]
     self.input_net = marsyas_util.create( series )
     # override
     self.post_network_setup()
     self.notempty = self.input_net.getControl(self.get_source() + "/mrs_bool/hasData")
     self.input_net_end_control = self.input_net.getControl(self.get_source() + "/mrs_realvec/processedData")
     self.metrics_control = self.input_net.getControl("mrs_realvec/processedData")
Beispiel #11
0
def main():

    maxmin_spec = ["Series/mxm", ["MaxMin/mxmin", "Transposer/trs"]]

    spec = [
        "Series/plot",
        [
            "SoundFileSource/src", "Stereo2Mono/s2m",
            [
                "Fanout/measurements",
                ["ZeroCrossings/zcrs", "Rms/rms", maxmin_spec]
            ]
        ]
    ]

    accum_spec = ["Accumulator/accum", [spec]]

    playlist_folder = "/Users/georgetzanetakis/data/sound/yogi_tunes/"
    print(playlist_folder)
    wav_fnames = [f for f in os.listdir(playlist_folder) if f.endswith(".wav")]

    wav_fnames = [playlist_folder + s for s in wav_fnames]

    print(wav_fnames)

    #    wav_fnames = ["/Users/georgetzanetakis/data/sound/yogi_tunes/1 - The Player's Hands (Instrumental).wav",
    #                 "6_lion_heart.wav",
    #                  "10_alienist.wav"]

    winSize = 44100
    plot_net = create(accum_spec)

    inSamples = plot_net.getControl("mrs_natural/inSamples")
    inSamples.setValue_natural(winSize)
    nTimes = plot_net.getControl("mrs_natural/nTimes")

    fname = plot_net.getControl(
        "Series/plot/SoundFileSource/src/mrs_string/filename")

    figs = []
    for wav_fname in wav_fnames:
        fname.setValue_string(wav_fname)
        fsize = plot_net.getControl(
            "Series/plot/SoundFileSource/src/mrs_natural/size").to_natural()
        srate = plot_net.getControl(
            "Series/plot/SoundFileSource/src/mrs_real/osrate").to_real()
        nTicks = int(fsize / winSize)
        print(("nTicks=", nTicks))
        nTimes.setValue_natural(nTicks)

        plot_net.tick()
        mydata = control2array(plot_net, "mrs_realvec/processedData")
        fig = bokeh_plot(mydata, wav_fname)
        figs.append(fig)

    show(column(*figs))
Beispiel #12
0
def make_output(filename_output):
    series = ["Series/output", ["RealvecSource/real_src",
        "SoundFileSink/dest"]]
    this_net = marsyas_util.create(series)
    this_net.updControl("mrs_natural/inSamples", 512)
    this_net.updControl("mrs_real/israte", 44100.0)
    this_net.updControl(
        "SoundFileSink/dest/mrs_string/filename",
        filename_output)
    return this_net
def make_output(filename_output):
    series = [
        "Series/output", ["RealvecSource/real_src", "SoundFileSink/dest"]
    ]
    this_net = marsyas_util.create(series)
    this_net.updControl("mrs_natural/inSamples", 512)
    this_net.updControl("mrs_real/israte", 44100.0)
    this_net.updControl("SoundFileSink/dest/mrs_string/filename",
                        filename_output)
    return this_net
def main():
    mod = ["Fanout/fo", ["ADSR/pitch",
                         "ADSR/pwm"]]
    osc = ["Series/osc",[mod, "AliasingOsc/osc"]]
    gen = ["Series/fmnet",[osc, "ADSR/adsr", "Gain/gain", "SoundFileSink/dest2"]]

# Create network and intialize parameter mapping 
    network = create(gen)
# Set the systems sample rate
    sample_rate = 44100.0
    network.updControl( "mrs_real/israte", sample_rate)

    network.updControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_real/aTime", 0.7)
    network.updControl("Gain/gain/mrs_real/gain", 0.7)

    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.8)

# These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("Series/osc/AliasingOsc/osc/mrs_real/frequency", "mrs_real/frequency")

# PWM Example
    network.updControl("Series/osc/AliasingOsc/osc/mrs_natural/type", 1)
    network.updControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/bypass", MarControlPtr.from_bool(True))
    network.updControl("Series/osc/AliasingOsc/osc/mrs_bool/cyclicin", MarControlPtr.from_bool(True))
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "AliasingTestPWM.wav")
    play_melody(network)

# Saw Wave example
    network.updControl("Series/osc/AliasingOsc/osc/mrs_natural/type", 0)
    network.updControl("Series/osc/Fanout/fo/ADSR/pwm/mrs_bool/bypass", MarControlPtr.from_bool(False))
    network.updControl("Series/osc/AliasingOsc/osc/mrs_bool/cyclicin", MarControlPtr.from_bool(False))
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "AliasingTestSaw.wav")
    play_melody(network)

# Pitch modulation example
    network.updControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/bypass", MarControlPtr.from_bool(True))
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "AliasingTestPitch.wav")
    play_melody(network)
    network.updControl("Series/osc/Fanout/fo/ADSR/pitch/mrs_bool/bypass", MarControlPtr.from_bool(False))

# Square Wave example
    network.updControl("Series/osc/AliasingOsc/osc/mrs_natural/type", 1)
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "AliasingTestSquare.wav")
    play_melody(network)
Beispiel #15
0
def main():
    N = 2**12
    fname = sys.argv[1] #Text file
    fname2 = sys.argv[2] #Wav file

    with open(fname, 'r') as f:
        file_data = np.array([line.split() for line in f if len(line.split()) == 3])

    time_data =  [(float(item[0]), float(item[1]), item[2])
                  for item in file_data[:,0:3]]
    print time_data[1]

    netspec = ["Series/net",
        ["SoundFileSource/src",
         "MixToMono/stm",
         #"Windowing/window",
         "ShiftOutput/shift",
         "Spectrum/spec",
         "PowerSpectrum/pspec",
         "Chroma/chroma",
         "Inject/inj", # add extra sample to hold label
         "WekaSink/wekout"
        ]]
    net = create(netspec)

    net.updControl("SoundFileSource/src/mrs_string/filename", fname2)
    #net.updControl("Windowing/window/mrs_natural/zeroPadding", N)
    net.updControl("ShiftOutput/shift/mrs_natural/Interpolation", N)
    #net.updControl("Windowing/window/mrs_natural/size", N)
    net.updControl("Chroma/chroma/mrs_natural/lowOctNum", 1)
    net.updControl("Chroma/chroma/mrs_natural/highOctNum", 5)

    notes = [
        'A', 'B', 'C', 'D', 'E', 'F', 'G',
        'A#', 'B#', 'C#', 'D#', 'E#', 'F#', 'G#',
        'Ab', 'Bb', 'Cb', 'Db', 'Eb', 'Fb', 'Gb',
    ]
    quals = ['maj', 'min', 'aug', 'dim', 'sus2', 'sus4']
    labels = [note + ':' + qual for note in notes for qual in quals]
    labels.extend(['X', 'N'])
    net.updControl("WekaSink/wekout/mrs_natural/nLabels", len(labels))
    net.updControl("WekaSink/wekout/mrs_string/labelNames", ','.join(labels))
    net.updControl("WekaSink/wekout/mrs_string/filename", fname2.split('.')[0] + '.arff')

    israte = net.getControl("mrs_real/israte").to_real()
    inSamples = net.getControl("mrs_natural/inSamples");

    for row in time_data:
        nsamples = get_num_samples(row[1], row[0], israte)
        inSamples.setValue_natural(nsamples)
        net.updControl("WekaSink/wekout/mrs_string/labelNames", row[2])
        net.tick()
Beispiel #16
0
def make_output(buffsize=1024):
    series = ["Series/output", 
              ["RealvecGrainSource/real_src",
               "AudioSink/dest"]]
    #           "SoundFileSink/dest"]]
    this_net = marsyas_util.create(series)
    this_net.updControl("mrs_natural/inSamples", buffsize)
    this_net.updControl("mrs_real/israte", 44100.0)
    #this_net.updControl(
    #    "SoundFileSink/dest/mrs_string/filename",
    #    "out.wav")
    #
    return this_net
Beispiel #17
0
def plucked():
    gen = ["Series/fmnet", ["Plucked/plucked","Gain/gain","SoundFileSink/dest2"]]
    # Create network and intialize parameter mapping 
    network = create(gen)
    network.updControl("Gain/gain/mrs_real/gain", 0.8)
    # These mapping are to make the system work with play melody
    network.linkControl("Plucked/plucked/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("Plucked/plucked/mrs_real/frequency", "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl( "mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "PluckedTest.wav")
    play_melody(network)
Beispiel #18
0
def make_net(expected_f0):
    spec = ["Series/series", [
          "SoundFileSource/src",
          "ShiftInput/si",
          "Windowing/window",
          "Spectrum/spec",
          "PowerSpectrum/ps",
          "RemoveObservations/ro",
          ["Fanout/fanout", [
            "HarmonicStrength/hsRel",
            "HarmonicStrength/hsAbs",
            "Centroid/centroid",
            "SpectralFlatnessAllBands/sfab",
          ]],
        ]]
    net = marsyas_util.create(spec)
    spect_cutoff = 0.34

    #net.updControl("mrs_natural/inSamples", 2048)
    #net.updControl("ShiftInput/si/mrs_natural/winSize", 4096)
    net.updControl("mrs_natural/inSamples", 4096)
    net.updControl("ShiftInput/si/mrs_natural/winSize", 8192)

    net.updControl("RemoveObservations/ro/mrs_real/highCutoff", spect_cutoff)

    net.updControl("Fanout/fanout/HarmonicStrength/hsRel/mrs_natural/harmonicsSize", 3)
    net.updControl("Fanout/fanout/HarmonicStrength/hsRel/mrs_real/harmonicsWidth",
        0.001)
    # magnitude / energy_rms
    net.updControl("Fanout/fanout/HarmonicStrength/hsRel/mrs_natural/type", 0)

    net.updControl("Fanout/fanout/HarmonicStrength/hsRel/mrs_real/base_frequency",
        float(expected_f0))
        #float(expected_f0)*spect_cutoff)
    net.updControl("Fanout/fanout/HarmonicStrength/hsRel/mrs_real/inharmonicity_B", 4e-5)

    net.updControl("Fanout/fanout/HarmonicStrength/hsAbs/mrs_natural/harmonicsSize", 3)
    net.updControl("Fanout/fanout/HarmonicStrength/hsAbs/mrs_real/harmonicsWidth",
        0.001)
    # log(magnitude)
    net.updControl("Fanout/fanout/HarmonicStrength/hsAbs/mrs_natural/type", 2)

    net.updControl("Fanout/fanout/HarmonicStrength/hsAbs/mrs_real/base_frequency",
        float(expected_f0))
        #float(expected_f0)*spect_cutoff)
    net.updControl("Fanout/fanout/HarmonicStrength/hsAbs/mrs_real/inharmonicity_B", 4e-5)

    notempty = net.getControl("SoundFileSource/src/mrs_bool/hasData")
    return net, notempty
Beispiel #19
0
def main():

# Set up Midi Stuff
    init()
    poll = Input.poll
    read = Input.read
    midi = Input(0)

# The Maysyas stuff
    gen = ["Series/fmnet", ["APDelayOsc/waveguide","ADSR/adsr","Gain/gain","AudioSink/dest"]]
    network = create(gen)

# Set the systems sample rate
    sample_rate = 44100.0
    network.updControl( "mrs_real/israte", sample_rate)

    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.6)
    network.updControl("APDelayOsc/waveguide/mrs_natural/type", 1)

# These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("APDelayOsc/waveguide/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("APDelayOsc/waveguide/mrs_real/frequency", "mrs_real/frequency")
    network.updControl("AudioSink/dest/mrs_bool/initAudio", MarControlPtr.from_bool(True))


    lastnote = 0
    while(True):
        if poll(midi):
            # format [[[128,  49 , 127,   0], 19633]]
            #           cc#| note| vel| n/a
            msg = read(midi, 1)
            note = msg[0][0][1]
            velocity = msg[0][0][2]
            noteon = msg[0][0][0]
            print(msg)
            if noteon == 145 or noteon == 144:
                network.updControl("mrs_real/frequency", midi2freq(note))
                network.updControl("Gain/gain/mrs_real/gain", velo2float(velocity))
                network.updControl("mrs_bool/noteon", MarControlPtr.from_bool(True))
                lastnote = note
            elif noteon == 128 or noteon == 129 and lastnote == note:
                network.updControl("mrs_bool/noteoff", MarControlPtr.from_bool(True))
                network.updControl("mrs_bool/noteon", MarControlPtr.from_bool(False))
        network.tick()
Beispiel #20
0
def additive():
    gen = ["Series/fmnet", ["AdditiveOsc/additve","ADSR/adsr","Gain/gain","SoundFileSink/dest2"]]
    # Create network and intialize parameter mapping 
    network = create(gen)
    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.8)
    # These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")
    network.linkControl("AdditiveOsc/additve/mrs_real/frequency", "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl( "mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "AdditiveTestSaw.wav")
    play_melody(network)
def plucked():
    gen = [
        "Series/fmnet",
        ["Plucked/plucked", "Gain/gain", "SoundFileSink/dest2"]
    ]
    # Create network and intialize parameter mapping
    network = create(gen)
    network.updControl("Gain/gain/mrs_real/gain", 0.8)
    # These mapping are to make the system work with play melody
    network.linkControl("Plucked/plucked/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("Plucked/plucked/mrs_real/frequency",
                        "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl("mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("SoundFileSink/dest2/mrs_string/filename",
                       "PluckedTest.wav")
    play_melody(network)
Beispiel #22
0
    def __init__(self, voices=8):
        sample_rate = 44100.0

        self.playing = deque()
        self.off = deque([Osc(sample_rate=sample_rate) for _ in range(voices)])

        osc_bank = ["Fanout/bank", [osc.get_network() for osc in self.off]]
        net = ["Series/fmnet", [osc_bank,"Sum/sum","MidiInput/midi","AudioSink/dest","SoundFileSink/dest2"]]

        # Create network and intialize parameter mapping 
        self.network = create(net)

        # Output settings
        self.network.updControl("mrs_real/israte", sample_rate)
        self.network.updControl("AudioSink/dest/mrs_bool/initAudio", MarControlPtr.from_bool(True))
        self.network.updControl("SoundFileSink/dest2/mrs_string/filename", "synthout.wav")

        # Midi settings
        self.network.updControl("MidiInput/midi/mrs_bool/initmidi", MarControlPtr.from_bool(True))
        self.network.updControl("MidiInput/midi/mrs_natural/port", 0)
Beispiel #23
0
    def __init__(self):
        """
        Sets up the marsystem, and then calls the functions to initialize
        the audio IO, and to re-map the controls

        """
        # Set up fm network
        osc1 = ["Series/osc1", ["FM/fm1", "ADSR/env1", "Gain/gain1"]]
        osc2 = ["Series/osc2", ["FM/fm2", "ADSR/env2", "Gain/gain2"]]
        fms = ["Fanout/mix", [osc1, osc2]]
        gen = ["Series/fmnet", [fms, "Sum/sum", "SoundFileSink/dest2"]]

        # Create network and intialize parameter mapping
        self.network = create(gen)
        self._init_fm()
        self._init_audio()

        # Used to calculate time based off of buffer size and rate
        self.bufferSize = self.network.getControl("mrs_natural/inSamples").to_natural()
        self.srate = self.network.getControl("mrs_real/osrate").to_real()
        self.tstep = self.bufferSize * 1.0 / self.srate
Beispiel #24
0
def waveguide():
    gen = ["Series/fmnet", ["ADSR/pitch","WaveguideOsc/waveguide","ADSR/adsr","Gain/gain","SoundFileSink/dest2"]]
    # Create network and intialize parameter mapping 
    network = create(gen)
    network.updControl("ADSR/adsr/mrs_real/aTime", 0.1)
    network.updControl("Gain/gain/mrs_real/gain", 0.6)
    # These mapping are to make the system work with play melody
    network.linkControl("ADSR/adsr/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/adsr/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("ADSR/pitch/mrs_bool/noteon", "mrs_bool/noteon")
    network.linkControl("ADSR/pitch/mrs_bool/noteoff", "mrs_bool/noteoff")

    network.linkControl("WaveguideOsc/waveguide/mrs_real/frequency", "mrs_real/frequency")
    # Set the systems sample rate
    sample_rate = 44100.0
    network.updControl( "mrs_real/israte", sample_rate)
    # Set up Audio File
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "WaveguideTest.wav")
    play_melody(network)
    network.updControl("ADSR/pitch/mrs_bool/bypass", MarControlPtr.from_bool(True))
    network.updControl("SoundFileSink/dest2/mrs_string/filename", "WaveguideTestPitch.wav")
    play_melody(network)
Beispiel #25
0
# Creating a sine wave with the same frequency as the input file.

from matplotlib import pyplot as plt
import sys
import marsyas
import marsyas_util

# Create top-level patch
centList = [
    "Series/extract_network",
    ["SoundFileSource/src", "Windowing/win", "Spectrum/spec", "PowerSpectrum/pspec", "Centroid/centr"],
]
sineList = ["Series/sinnet", ["SineSource/src1", "Gain/gain"]]

net1 = marsyas_util.create(centList)
net2 = marsyas_util.create(
    [
        "Series/sound",
        [["Fanout/snd", [sineList, "SoundFileSource/src2"]], ["Fanout/sinks", ["SoundFileSink/sfs", "AudioSink/as"]]],
    ]
)

filename = sys.argv[1]
fname1 = net1.getControl("SoundFileSource/src/mrs_string/filename")
fname1.setValue_string(filename)

fname2 = net2.getControl("Fanout/snd/SoundFileSource/src2/mrs_string/filename")
fname2.setValue_string(filename)

net1.linkControl("mrs_bool/hasData", "SoundFileSource/src/mrs_bool/hasData")
#!/usr/bin/env python

# A bouncing ball sound
from visual import *
import marsyas
import marsyas_util

# This is a MarSystem that should output the sound of a bouncing ball.
# It will work iteractivelly

# Network:
# sine oscillator => gain => output
spec = ["Series/net", ["SineSource/src1", "Gain/gain", "AudioSink/dest"]]
net = marsyas_util.create(spec)

fs = 44100.0
insamples = 256
net.updControl("mrs_real/israte", fs)
net.updControl("mrs_natural/inSamples", 256)
net.updControl("SineSource/src1/mrs_real/frequency",
               marsyas.MarControlPtr.from_real(440.0))
net.updControl("Gain/gain/mrs_real/gain", marsyas.MarControlPtr.from_real(0.0))
net.updControl("AudioSink/dest/mrs_bool/initAudio",
               marsyas.MarControlPtr.from_bool(True))

# The bouncing ball algorithm works like this:
#
# The ball is dropped from a certain height H, and falls to the ground by the laws of physics (considering a given g)
# Then, the gain is set to some alpha value, proportional to the ball's hitting speed, and fades exponentially
# In each hit, the bouncing speed is a factor of the collision speed
# If the collision speed is too small, the ball stops.
Beispiel #27
0
def process_collection(wav_fnames):
    spec = ["Series/plot", 
            ["SoundFileSource/src",
             ["Fanout/fan",
              [
                   ["Series/hist",
                   [
                       "Histogram/histo",
                       "Transposer/trsp",
                       "TextureStats/tstats1"
                       ]]
                   ,
                  ["Series/dlt",
                  [
                       "Spectrum/spk",
                       "PowerSpectrum/pspk",
                       "STFT_features", 
                       "TextureStats/tstats2"
                  ]]
                  ]]
             ,
             "Transposer/trs"
            ]]
   
    winSize = 4096
    plot_net = create(spec)
#    print(plot_net.toString())
    ratios = [] 
    
    inSamples = plot_net.getControl("mrs_natural/inSamples")
    inSamples.setValue_natural(winSize)
    fname = plot_net.getControl("SoundFileSource/src/mrs_string/filename")
    normalize = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_bool/normalize")
    # deltaStd = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_real/deltaStd")
    memSize1 = plot_net.getControl("Fanout/fan/Series/hist/TextureStats/tstats1/mrs_natural/memSize")
    memSize2 = plot_net.getControl("Fanout/fan/Series/dlt/TextureStats/tstats2/mrs_natural/memSize")
#    normalize1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/normalize")


    memSize1.setValue_natural(50);
    memSize2.setValue_natural(50);
    reset = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_bool/reset")
#    reset1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/reset")        
    figs = []
    ratio = 0.0
    avg_ratio = 0.0
    num_glitch = 0
    numFiles = 0
    seconds2process = 15.0
    samples2process = seconds2process * 48000
    iterations2process = int(samples2process * 1.0 / winSize)
    

    aggregate_deltas = [] 
    for wav_fname in wav_fnames:
#        print(str(numFiles) + ' - ' +  wav_fname);
        fname.setValue_string(wav_fname)
        reset.setValue_bool(True)
#        reset1.setValue_bool(True)
        nTicks = 0
        deltas = []        
        for i in range(0, iterations2process): 
            # while plot_net.getControl("SoundFileSource/src/mrs_bool/hasData").to_bool():
        
            plot_net.tick()
            # print("DELTA", deltaStd.to_real())
            # deltas.append(deltaStd.to_real())
            nTicks = nTicks + 1
        normalize.setValue_bool(True)
        # normalize1.setValue_bool(True)
        # extra tick to normalize 
        plot_net.tick()
        mydata = control2array(plot_net, "mrs_realvec/processedData")
        (fig, ratio, histo) = histo_plot(mydata, wav_fname)
        ratios.append(histo)
        figs.append(fig)
        numFiles = numFiles + 1;
        avg_ratio = avg_ratio + abs(1.0-ratio)
        #if (abs(1.0-ratio) > 0.2):
        #    num_glitch = num_glitch+1
        if (scipy.stats.kurtosis(deltas) < 2): 
            num_glitch = num_glitch+1
        
        aggregate_deltas.append(scipy.stats.kurtosis(deltas))
        
        
        
    avg_ratio = avg_ratio / numFiles
    print("----------------------")
    # print("AVERAGE AGGREGATE = ", np.mean(aggregate_deltas), np.std(aggregate_deltas))
    print(("AVERAGE RATIO=" , avg_ratio))
    print(("NUM GLITCH = ", num_glitch, numFiles))
    print(("GLITCH PERCENTAGE=", int(100 * (num_glitch * 1.0/len(wav_fnames)))))

#     print("AVG DELTA = ",  np.mean(deltas)) 
#    print("STD DELTA = ", np.std(deltas))
#    show(gridplot(*figs, ncols=2))
    return (ratios, wav_fnames)
def make_input(filename_input):
    series = ["Series/input", ["SoundFileSource/src"]]
    this_net = marsyas_util.create(series)
    this_net.updControl("SoundFileSource/src/mrs_string/filename",
                        filename_input)
    return this_net
Beispiel #29
0
def main():
    N = 2**12
    fname = sys.argv[1]  #Text file
    fname2 = sys.argv[2]  #Wav file

    with open(fname, 'r') as f:
        file_data = np.array(
            [line.split() for line in f if len(line.split()) == 3])

    time_data = [(float(item[0]), float(item[1]), item[2])
                 for item in file_data[:, 0:3]]
    print time_data[1]

    netspec = [
        "Series/net",
        [
            "SoundFileSource/src",
            "MixToMono/stm",
            #"Windowing/window",
            "ShiftOutput/shift",
            "Spectrum/spec",
            "PowerSpectrum/pspec",
            "Chroma/chroma",
            "Inject/inj",  # add extra sample to hold label
            "WekaSink/wekout"
        ]
    ]
    net = create(netspec)

    net.updControl("SoundFileSource/src/mrs_string/filename", fname2)
    #net.updControl("Windowing/window/mrs_natural/zeroPadding", N)
    net.updControl("ShiftOutput/shift/mrs_natural/Interpolation", N)
    #net.updControl("Windowing/window/mrs_natural/size", N)
    net.updControl("Chroma/chroma/mrs_natural/lowOctNum", 1)
    net.updControl("Chroma/chroma/mrs_natural/highOctNum", 5)

    notes = [
        'A',
        'B',
        'C',
        'D',
        'E',
        'F',
        'G',
        'A#',
        'B#',
        'C#',
        'D#',
        'E#',
        'F#',
        'G#',
        'Ab',
        'Bb',
        'Cb',
        'Db',
        'Eb',
        'Fb',
        'Gb',
    ]
    quals = ['maj', 'min', 'aug', 'dim', 'sus2', 'sus4']
    labels = [note + ':' + qual for note in notes for qual in quals]
    labels.extend(['X', 'N'])
    net.updControl("WekaSink/wekout/mrs_natural/nLabels", len(labels))
    net.updControl("WekaSink/wekout/mrs_string/labelNames", ','.join(labels))
    net.updControl("WekaSink/wekout/mrs_string/filename",
                   fname2.split('.')[0] + '.arff')

    israte = net.getControl("mrs_real/israte").to_real()
    inSamples = net.getControl("mrs_natural/inSamples")

    for row in time_data:
        nsamples = get_num_samples(row[1], row[0], israte)
        inSamples.setValue_natural(nsamples)
        net.updControl("WekaSink/wekout/mrs_string/labelNames", row[2])
        net.tick()
Beispiel #30
0
# The Product MarSystem combines all rows of a frame using multiplication. It also has a 'mask' control that
# allows us to have an 'external' fixed array of coefficients for multiplication.
# This what the filtering process will do: we will get a Spectrum, use Product to change the values of the DFT bins
# and then calculate the InvSpectrum.
#
# Unfortunately, Product works column-wise over a frame, while our multiplication should be row-wise to comply with the Spectrum
# output. To solve it, we use the Transpose MarSystem.
#
# Last, all we need to do is implement the OLA process, which is already done by the OverlapAdd MarSystem.
#
# So, we have this system:

fir_filtering = ["Series/fir", ["SoundFileSource/src", "ShiftInput/sft", "Windowing/win", "Spectrum/spk", "Transposer/tp1", "Product/prod", "Transposer/tp2", "InvSpectrum/ispk", "OverlapAdd/ola", "AudioSink/asnk"]]

# The following lines should be really self-explanatory
net = marsyas_util.create(fir_filtering)
snet = marsyas_util.mar_refs(fir_filtering)

net.updControl("mrs_natural/inSamples", 1024)
net.updControl(snet["sft"]+"/mrs_natural/winSize", 2048)
net.updControl(snet["win"]+"/mrs_string/type", "Hanning" )
net.updControl(snet['src']+"/mrs_string/filename", "input.wav")
net.updControl(snet['asnk']+"/mrs_bool/initAudio", marsyas.MarControlPtr.from_bool(True))

# ... but these lines here are new.
# We will operate the product and enable the use of a fixed mask:
net.updControl(snet['prod']+"/mrs_bool/use_mask", marsyas.MarControlPtr.from_bool(True))

# Now, we will define the shape of our FIR filter in the frequency domain.
# This is a low-pass filter.
vec = marsyas.realvec(2048+2)
Beispiel #31
0
#!/usr/bin/env python
import sys
import numpy
import math
from marsyas import * 
import marsyas
import marsyas_util
import random

mars = MarSystemManager()
buffsize=512
series = ["Series/output", ["RealvecGrainSource/real_src", "AudioSink/dest"]]
print "Make Network"
this_net = marsyas_util.create(series)
print "Set InSamples"
this_net.updControl("mrs_natural/inSamples", buffsize)
print "Set Rate"
this_net.updControl("mrs_real/israte", 44100.0)
print "Make grains"
grain1 = marsyas.realvec(buffsize)
grain2 = marsyas.realvec(buffsize)
grain3 = marsyas.realvec(buffsize)
grain4 = marsyas.realvec(3*buffsize)
for i in range(0, buffsize):
    grain1[i] = math.sin(i*440/buffsize)
    grain2[i] = random.uniform(-1,1)
    grain3[i] = math.sin(math.tan(math.sin(math.tan(i/40))))

for i in range(0, buffsize*3):
    grain4[i] = math.sin(math.tan(i/100))
Beispiel #32
0
 def _new_osc(self):
     osc = create(self.spec(Osc._num_of_oscs))
     Osc._num_of_oscs = Osc._num_of_oscs + 1
     return osc
Beispiel #33
0
from matplotlib import pyplot as plt
import sys
import marsyas
import marsyas_util

# Create top-level patch
net = marsyas_util.create(
    
        ["Series/extract_network",["SoundFileSource/src"
        ,"Windowing/win","Spectrum/spec","PowerSpectrum/pspec","Centroid/centr"
    ]])

filename = sys.argv[1]
fname = net.getControl("SoundFileSource/src/mrs_string/filename")
fname.setValue_string(filename)
net.linkControl("mrs_bool/hasData",
    "SoundFileSource/src/mrs_bool/hasData")
net.linkControl("mrs_string/filename",
    "SoundFileSource/src/mrs_string/filename")

x= net.getControl("mrs_realvec/processedData")
centroid =[]
while net.getControl("SoundFileSource/src/mrs_bool/hasData").to_bool():
    net.tick() # update time
    y = x.to_realvec()
    centroid.append(y[0])
plt.plot(centroid)
plt.show()
Beispiel #34
0
  parser = argparse.ArgumentParser(description='Quickly plot beautiful spectrograms for your audio files.')
  parser.add_argument('--fname', dest='Filename', type=str, default='test.wav', help='Filename from where data will be extracted')
  parser.add_argument('--flen', dest='Window_len', type=int, default=2048, help='Length (samples) of the window for analysis')
  parser.add_argument('--fstep', dest='Window_step', type=int, default=1024, help='Step (samples) of the sliding window used for analysis')
  parser.add_argument('--minfreq', dest='Min_freq', type=float, default=110, help='Minimum frequency (Hz) show in the spectrogram')
  parser.add_argument('--maxfreq', dest='Max_freq', type=float, default=8000, help='Maximum frequency (Hz) show in the spectrogram')
  parser.add_argument('--maxtime', dest='Max_time', type=float, default=9000, help='Maximum time (s) show in the spectrogram')
  parser.add_argument('--zeropad', dest='Zero_padding', type=float, default=1, help='Zero padding factor (the DFT is calculated after zero-padding the input to this times the input length - use 1 for standard DFT)')
  parser.add_argument('--width', dest='Width', type=int, default=450, help='Width of the plot')
  parser.add_argument('--height', dest='Height', type=int, default=200, help='Height of the plot')
  parser.add_argument('--window', dest='Window', type=str, default='Hamming', help='Shape of the window that will be used to calculate the spectrogram')
  args = parser.parse_args()

  # Create our Marsyas network for audio analysis
  spec_analyzer = ["Series/analysis", ["SoundFileSource/src",  "Sum/summation", "Gain/gain", "ShiftInput/sft", "Windowing/win","Spectrum/spk","PowerSpectrum/pspk", "Memory/mem"]]
  net = marsyas_util.create(spec_analyzer)
  snet = marsyas_util.mar_refs(spec_analyzer)

  # Configure the network
  net.updControl(snet["src"]+"/mrs_string/filename", args.Filename)
  nSamples = net.getControl(snet["src"]+"/mrs_natural/size").to_natural()
  fs = net.getControl(snet["src"]+"/mrs_real/osrate").to_real()
  dur = nSamples/fs
  print "Opened ", args.Filename
  print "It has ", nSamples, " samples at ", fs, " samples/second to a total of ", dur," seconds"
  memFs = fs/args.Window_step # Sampling rate of the memory buffer
  dur = min(dur, args.Max_time)
  memSize = int(dur*memFs)
  net.updControl("mrs_natural/inSamples", args.Window_step);
  net.updControl(snet["gain"]+"/mrs_real/gain", args.Window_len*1.0); # This will un-normalize the DFT
  net.updControl(snet["sft"]+"/mrs_natural/winSize", args.Window_len);
Beispiel #35
0
from visual import *
import math
import argparse
import marsyas
import marsyas_util


if __name__ == "__main__":
	notenames = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']
	pitch=440.0
	parser = argparse.ArgumentParser(description='Instrument tunning software built using Marsyas')
	args = parser.parse_args()
	
	# Defining the marsyas network
	spec = ["Series/system", ["AudioSource/src", "AubioYin/pitcher", "Memory/m", "Mean/mean"]];
	net = marsyas_util.create(spec)

	# Configuring the network
	gain = 1.0
	sropt = 44100.0;
	copt = 1;
	window_size = 2048;
	net.updControl("Memory/m/mrs_natural/memSize", 2)
	net.updControl("mrs_natural/inSamples", window_size);
	net.updControl("mrs_real/israte", sropt);
	net.updControl("AudioSource/src/mrs_natural/nChannels", copt);
	net.updControl("AudioSource/src/mrs_real/gain", gain);
	net.updControl("AudioSource/src/mrs_bool/initAudio", marsyas.MarControlPtr.from_bool(True));

	# Start visualization
	allowed_delta = 0.05
import marsyas
import marsyas_util

try:
    mf_filename = sys.argv[1]
    arff_filename = mf_filename.replace(".mf", ".arff")
    mpl_filename = mf_filename.replace(".mpl", ".arff")
except:
    print "Usage: py-bextract.py filename.mf"
    sys.exit(1)

# Create top-level patch
net = marsyas_util.create(
    ["Series/extract_network",
        ["SoundFileSource/src",
         "TimbreFeatures/featExtractor",
         "TextureStats/tStats",
         "Annotator/annotator",
         "WekaSink/wsink",
    ]])

# link the controls to coordinate things
net.linkControl("mrs_string/filename",
    "SoundFileSource/src/mrs_string/filename")
net.linkControl("mrs_bool/hasData",
    "SoundFileSource/src/mrs_bool/hasData")
net.linkControl("WekaSink/wsink/mrs_string/currentlyPlaying",
    "SoundFileSource/src/mrs_string/currentlyPlaying")
net.linkControl("Annotator/annotator/mrs_real/label",
    "SoundFileSource/src/mrs_real/currentLabel")
net.linkControl("SoundFileSource/src/mrs_natural/nLabels",
    "WekaSink/wsink/mrs_natural/nLabels")
Beispiel #37
0
from matplotlib import pyplot as plt
import sys
import marsyas
import marsyas_util
import string
# Create top-level patch
net = marsyas_util.create(
    
        ["Series/extract_network",["SoundFileSource/src", ['Fanout/fea', ['ZeroCrossings/zcrs',
        ['Series/ctr',["Windowing/win","Spectrum/spec","PowerSpectrum/pspec","Centroid/centr"
    ]]]],"Annotator/annotator",
         "WekaSink/wsink"]])
filename = sys.argv[1]
fname = net.getControl("SoundFileSource/src/mrs_string/filename")
fname.setValue_string(filename)
net.linkControl("mrs_bool/hasData",
    "SoundFileSource/src/mrs_bool/hasData")
net.linkControl("mrs_string/filename",
    "SoundFileSource/src/mrs_string/filename")
#net.linkControl("Annotator/annotator/mrs_real/label",
#    "SoundFileSource/src/mrs_real/currentLabel")
net.linkControl("SoundFileSource/src/mrs_natural/nLabels",
    "WekaSink/wsink/mrs_natural/nLabels")
net.linkControl("WekaSink/wsink/mrs_string/currentlyPlaying",
    "SoundFileSource/src/mrs_string/currentlyPlaying")
net.updControl("WekaSink/wsink/mrs_string/filename",
    marsyas.MarControlPtr.from_string('Q5.arff'))

net.updControl("Annotator/annotator/mrs_bool/labelInFront", marsyas.MarControlPtr.from_bool(True))

net.updControl("WekaSink/wsink/mrs_string/labelNames", "Classical, Disco")
def process_collection(wav_fnames):
    spec = [
        "Series/plot",
        [
            "SoundFileSource/src",
            [
                "Fanout/fan",
                [[
                    "Series/hist",
                    [
                        "Histogram/histo", "Transposer/trsp",
                        "TextureStats/tstats1"
                    ]
                ],
                 [
                     "Series/dlt",
                     [
                         "Spectrum/spk", "PowerSpectrum/pspk", "STFT_features",
                         "TextureStats/tstats2"
                     ]
                 ]]
            ], "Transposer/trs"
        ]
    ]

    winSize = 4096
    plot_net = create(spec)
    #    print(plot_net.toString())
    ratios = []

    inSamples = plot_net.getControl("mrs_natural/inSamples")
    inSamples.setValue_natural(winSize)
    fname = plot_net.getControl("SoundFileSource/src/mrs_string/filename")
    normalize = plot_net.getControl(
        "Fanout/fan/Series/hist/Histogram/histo/mrs_bool/normalize")
    # deltaStd = plot_net.getControl("Fanout/fan/Series/hist/Histogram/histo/mrs_real/deltaStd")
    memSize1 = plot_net.getControl(
        "Fanout/fan/Series/hist/TextureStats/tstats1/mrs_natural/memSize")
    memSize2 = plot_net.getControl(
        "Fanout/fan/Series/dlt/TextureStats/tstats2/mrs_natural/memSize")
    #    normalize1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/normalize")

    memSize1.setValue_natural(50)
    memSize2.setValue_natural(50)
    reset = plot_net.getControl(
        "Fanout/fan/Series/hist/Histogram/histo/mrs_bool/reset")
    #    reset1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/reset")
    figs = []
    ratio = 0.0
    avg_ratio = 0.0
    num_glitch = 0
    numFiles = 0
    seconds2process = 15.0
    samples2process = seconds2process * 48000
    iterations2process = int(samples2process * 1.0 / winSize)

    aggregate_deltas = []
    for wav_fname in wav_fnames:
        #        print(str(numFiles) + ' - ' +  wav_fname);
        fname.setValue_string(wav_fname)
        reset.setValue_bool(True)
        #        reset1.setValue_bool(True)
        nTicks = 0
        deltas = []
        for i in range(0, iterations2process):
            # while plot_net.getControl("SoundFileSource/src/mrs_bool/hasData").to_bool():

            plot_net.tick()
            # print("DELTA", deltaStd.to_real())
            # deltas.append(deltaStd.to_real())
            nTicks = nTicks + 1
        normalize.setValue_bool(True)
        # normalize1.setValue_bool(True)
        # extra tick to normalize
        plot_net.tick()
        mydata = control2array(plot_net, "mrs_realvec/processedData")
        (fig, ratio, histo) = histo_plot(mydata, wav_fname)
        ratios.append(histo)
        figs.append(fig)
        numFiles = numFiles + 1
        avg_ratio = avg_ratio + abs(1.0 - ratio)
        #if (abs(1.0-ratio) > 0.2):
        #    num_glitch = num_glitch+1
        if (scipy.stats.kurtosis(deltas) < 2):
            num_glitch = num_glitch + 1

        aggregate_deltas.append(scipy.stats.kurtosis(deltas))

    avg_ratio = avg_ratio / numFiles
    print("----------------------")
    # print("AVERAGE AGGREGATE = ", np.mean(aggregate_deltas), np.std(aggregate_deltas))
    print(("AVERAGE RATIO=", avg_ratio))
    print(("NUM GLITCH = ", num_glitch, numFiles))
    print(("GLITCH PERCENTAGE=",
           int(100 * (num_glitch * 1.0 / len(wav_fnames)))))

    #     print("AVG DELTA = ",  np.mean(deltas))
    #    print("STD DELTA = ", np.std(deltas))
    #    show(gridplot(*figs, ncols=2))
    return (ratios, wav_fnames)
#
# Last, all we need to do is implement the OLA process, which is already done by the OverlapAdd MarSystem.
#
# So, we have this system:

fir_filtering = [
    "Series/fir",
    [
        "SoundFileSource/src", "ShiftInput/sft", "Windowing/win",
        "Spectrum/spk", "Transposer/tp1", "Product/prod", "Transposer/tp2",
        "InvSpectrum/ispk", "OverlapAdd/ola", "AudioSink/asnk"
    ]
]

# The following lines should be really self-explanatory
net = marsyas_util.create(fir_filtering)
snet = marsyas_util.mar_refs(fir_filtering)

net.updControl("mrs_natural/inSamples", 1024)
net.updControl(snet["sft"] + "/mrs_natural/winSize", 2048)
net.updControl(snet["win"] + "/mrs_string/type", "Hanning")
net.updControl(snet['src'] + "/mrs_string/filename", "input.wav")
net.updControl(snet['asnk'] + "/mrs_bool/initAudio",
               marsyas.MarControlPtr.from_bool(True))

# ... but these lines here are new.
# We will operate the product and enable the use of a fixed mask:
net.updControl(snet['prod'] + "/mrs_bool/use_mask",
               marsyas.MarControlPtr.from_bool(True))

# Now, we will define the shape of our FIR filter in the frequency domain.
Beispiel #40
0
 def _new_osc(self):
     osc = create(self.spec(Osc._num_of_oscs))
     Osc._num_of_oscs = Osc._num_of_oscs + 1
     return osc
Beispiel #41
0
def process_collection(wav_fnames):
    spec = [
        "Series/plot",
        [
            "SoundFileSource/src",
            [
                "Fanout/fan",
                [
                    [
                        "Series/hist",
                        [
                            "Histogram/histo", "Transposer/trsp",
                            "TextureStats/tstats1"
                            # "Mean/mean1"
                        ]
                    ],
                    [
                        "Series/dlt",
                        [
                            "Spectrum/spk", "PowerSpectrum/pspk", "MFCC/mfcc",
                            "TextureStats/tstats2"
                            #"Memory/mem2",
                            #"Mean/mean2"
                        ]
                    ]
                ]
            ],
            "Transposer/trs"
        ]
    ]

    winSize = 512
    plot_net = create(spec)
    #    print(plot_net.toString())
    ratios = []

    inSamples = plot_net.getControl("mrs_natural/inSamples")
    inSamples.setValue_natural(winSize)
    fname = plot_net.getControl("SoundFileSource/src/mrs_string/filename")
    normalize = plot_net.getControl(
        "Fanout/fan/Series/hist/Histogram/histo/mrs_bool/normalize")
    memSize1 = plot_net.getControl(
        "Fanout/fan/Series/hist/TextureStats/tstats1/mrs_natural/memSize")
    memSize2 = plot_net.getControl(
        "Fanout/fan/Series/dlt/TextureStats/tstats2/mrs_natural/memSize")
    #    normalize1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/normalize")

    memSize1.setValue_natural(200)
    memSize2.setValue_natural(200)
    reset = plot_net.getControl(
        "Fanout/fan/Series/hist/Histogram/histo/mrs_bool/reset")
    #    reset1 = plot_net.getControl("Fanout/fan/Series/dlt/Histogram/histo1/mrs_bool/reset")
    figs = []
    ratio = 0.0
    avg_ratio = 0.0
    num_glitch = 0
    numFiles = 0
    seconds2process = 15.0
    samples2process = seconds2process * 8000
    iterations2process = int(samples2process * 1.0 / winSize)

    for wav_fname in wav_fnames:
        print(str(numFiles) + ' - ' + wav_fname)
        fname.setValue_string(wav_fname)
        reset.setValue_bool(True)
        #        reset1.setValue_bool(True)

        nTicks = 0
        for i in range(0, iterations2process):
            # while plot_net.getControl("SoundFileSource/src/mrs_bool/hasData").to_bool():

            plot_net.tick()
            nTicks = nTicks + 1
        normalize.setValue_bool(True)
        # normalize1.setValue_bool(True)
        # extra tick to normalize
        plot_net.tick()

        mydata = control2array(plot_net, "mrs_realvec/processedData")
        (fig, ratio, histo) = histo_plot(mydata, wav_fname)
        ratios.append(histo)
        #ratios.append(np.array([ratio, ratio]))
        figs.append(fig)
        numFiles = numFiles + 1


#        avg_ratio = avg_ratio + abs(1.0-ratio)
#        if (abs(1.0-ratio) > 0.2):
#           num_glitch = num_glitch+1

#    avg_ratio = avg_ratio / numFiles
#    print(("AVERAGE RATIO=" , avg_ratio))
#    print(("GLITCH PERCENTAGE=", int(100 * (num_glitch * 1.0/len(wav_fnames)))))
#    show(gridplot(*figs, ncols=2))
    return (ratios, wav_fnames)