Ejemplo n.º 1
0
    def detect(self):
        sent = "Series {+ input_file = \"%s\"-> input: SoundFileSource { filename = /input_file inSamples = 2048}-> Windowing {size = 2048}-> Spectrum -> PowerSpectrum -> Transposer -> MaxArgMax ->Transposer -> selection: Selector {disable = 0}-> CsvSink { filename = \"wode.csv\" }+ done = (input/hasData == false)}" % self.filename
        file = open("wodefile.mrs", "w")
        file.write(sent)
        file.close()
        mng = marsyas.MarSystemManager()

        fnet = mng.create("Series", "featureNetwork")
        result = []
        system = marsyas.system_from_script_file("wodefile.mrs")
        get = system.getControl

        while get("SoundFileSource/input/mrs_bool/hasData").to_bool():
            system.tick()
            result.extend(
                get("Selector/selection/mrs_realvec/processedData").to_realvec(
                ))
            result[-1] *= 44100 / 2048
        sum = 0.0
        for i in range(0, len(result)):
            sum += result[i]
        avg = np.array(sum / len(result) / 1000)
        clfs = [SVC()]
        for clf in clfs:
            clf.fit(self.X, self.y)
            y_pred = clf.predict(avg)
            self.play(y_pred[0])
Ejemplo n.º 2
0
def detect_key(music_file):
    """
    Determines the predominant key of a given music file.

    * music_file: The filename of a music file which Marsyas can read.

    Returns one of ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
    """
    from collections import Counter
    keys = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]

    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file("marsystems/key-detection.mrs")
    # Define some variables
    system.updControl("mrs_string/file", marsyas.MarControlPtr.from_string(music_file))
    system.updControl("mrs_real/israte", 22050.0)
    system.updControl("mrs_real/osrate", 22050.0)

    system.updControl("mrs_natural/inSamples", 16384)
    system.updControl("mrs_natural/onSamples", 16384)

    result = []
    # Tick the system.
    while (system.getControl("SoundFileSource/input/mrs_bool/hasData").to_bool()):
        system.tick()
        result.append(system.getControl("mrs_string/key_name").to_string())

    counts = Counter(result).most_common();
    # print(counts)
    return counts[0][0]
Ejemplo n.º 3
0
def run_script(script_file, output_file, *input_files):
    """
    This function assists in running Marsyas scripts.
    """
    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file(script_file)
    # Define some variables
    for i, this_input in enumerate(input_files):
        system.updControl("SoundFileSource/input_{}/mrs_string/filename".format(i), marsyas.MarControlPtr.from_string(this_input))
    system.updControl("SoundFileSink/output/mrs_string/filename", marsyas.MarControlPtr.from_string(output_file))
    
    # Tick the system.
    while (system.getControl("SoundFileSource/input_0/mrs_bool/hasData").to_bool()):
        system.tick()
Ejemplo n.º 4
0
def key_detection(ingress):
    """
    Runs a key detection algorithm over the ingress realvec or list.
    """
    if type(ingress) != "list":
        list = list(ingress)
    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file(script_file)
    # Define some variables
    for i, this_input in enumerate(input_files):
        system.updControl("RealVecSource/input_{}/mrs_string/filename".format(i), marsyas.MarControlPtr.from_string(this_input))
    system.updControl("SoundFileSink/output/mrs_string/filename", marsyas.MarControlPtr.from_string(output_file))
    
    # Tick the system.
    while (system.getControl("RealVecSource/input_0/mrs_bool/hasData").to_bool()):
        system.tick()
Ejemplo n.º 5
0
def to_realvec(input_file):
    """
    Transforms an input file into a `marsyas.realvec` of data for further passing, also makes the track mono.
    """
    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file("marsystems/to_realvec.mrs")
    # Define some variables
    system.updControl("mrs_string/file", marsyas.MarControlPtr.from_string(input_file))
    # This is a dumb way of doing it but I can't figure out a better way.
    egress = marsyas.realvec()
    # Tick the system.
    while (not system.getControl("mrs_bool/done").to_bool()):
        system.tick()
        tick_data = system.getControl("mrs_realvec/processedData").to_realvec()
        egress.appendRealvec(tick_data)
    return egress
Ejemplo n.º 6
0
def to_realvec(input_file):
    """
    Transforms an input file into a `marsyas.realvec` of data for further passing, also makes the track mono.
    """
    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file("marsystems/to_realvec.mrs")
    # Define some variables
    system.updControl("mrs_string/file",
                      marsyas.MarControlPtr.from_string(input_file))
    # This is a dumb way of doing it but I can't figure out a better way.
    egress = marsyas.realvec()
    # Tick the system.
    while (not system.getControl("mrs_bool/done").to_bool()):
        system.tick()
        tick_data = system.getControl("mrs_realvec/processedData").to_realvec()
        egress.appendRealvec(tick_data)
    return egress
Ejemplo n.º 7
0
def run_script(script_file, output_file, *input_files):
    """
    This function assists in running Marsyas scripts.
    """
    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file(script_file)
    # Define some variables
    for i, this_input in enumerate(input_files):
        system.updControl(
            "SoundFileSource/input_{}/mrs_string/filename".format(i),
            marsyas.MarControlPtr.from_string(this_input))
    system.updControl("SoundFileSink/output/mrs_string/filename",
                      marsyas.MarControlPtr.from_string(output_file))

    # Tick the system.
    while (system.getControl(
            "SoundFileSource/input_0/mrs_bool/hasData").to_bool()):
        system.tick()
Ejemplo n.º 8
0
def key_detection(ingress):
    """
    Runs a key detection algorithm over the ingress realvec or list.
    """
    if type(ingress) != "list":
        list = list(ingress)
    # Build the system.
    msm = marsyas.MarSystemManager()
    system = marsyas.system_from_script_file(script_file)
    # Define some variables
    for i, this_input in enumerate(input_files):
        system.updControl(
            "RealVecSource/input_{}/mrs_string/filename".format(i),
            marsyas.MarControlPtr.from_string(this_input))
    system.updControl("SoundFileSink/output/mrs_string/filename",
                      marsyas.MarControlPtr.from_string(output_file))

    # Tick the system.
    while (system.getControl(
            "RealVecSource/input_0/mrs_bool/hasData").to_bool()):
        system.tick()
Ejemplo n.º 9
0
import marsyas 
import json 


net = marsyas.system_from_script_file("test.mrs")
print net.toStringShort()


net = marsyas.system_from_script(""" 

     Network : Series
     {
        -> input: NoiseSource
        -> amp: Gain
        -> output: AudioSink
     }
""")
print net.toStringShort()


Ejemplo n.º 10
0
def time_shift(**args):

	options = deepcopy(default_options)

	for arg in args:
		options[arg] = args[arg]

	outfile = options['outfile']


	mng = marsyas.MarSystemManager()
	pvseries = marsyas.system_from_script_file("./marsystems/time-shift.mrs")

	pvseries.updControl("mrs_string/file", options['music_file'])
	pvseries.updControl("mrs_string/outfile", outfile)


	pvseries.updControl("mrs_real/israte", 44100.0)
	pvseries.updControl("mrs_real/osrate", 44100.0)
	pvseries.updControl("mrs_natural/inSamples", options['D'])
	pvseries.updControl("mrs_natural/onSamples", options['I'])



	pvseries.updControl("SoundFileSource/src/mrs_natural/onSamples", options['D'])
	pvseries.updControl("mrs_natural/inObservations", 1)



	pvseries.updControl("ShiftInput/si/mrs_natural/winSize", options['Nw'])

	pvseries.updControl("PvFold/fo/mrs_natural/FFTSize", options['N'])

	pvseries.updControl("PvConvert/conv/mrs_natural/Decimation", options['D'])
	pvseries.updControl("PvConvert/conv/mrs_natural/Sinusoids", options['sopt'])
	pvseries.updControl("PvConvert/conv/mrs_string/mode", options['convertmode_'])

	pvseries.updControl("mrs_natural/onStabilizingDelay", 63)

	pvseries.updControl("SoundFileSource/src/mrs_natural/onObservations", 2)
	pvseries.updControl("SoundFileSource/src/mrs_natural/inSamples", options['D'])
	pvseries.updControl("SoundFileSource/src/mrs_natural/onSamples", options['D'])

	pvseries.updControl("ShiftInput/si/mrs_natural/onSamples", options['Nw'])
	pvseries.updControl("ShiftInput/si/mrs_real/israte", 44100.0)
	pvseries.updControl("ShiftInput/si/mrs_real/osrate", 44100.0)

	pvseries.updControl("ShiftInput/si/mrs_natural/onObservations", 1)

	pvseries.updControl("PvConvert/conv/mrs_natural/inSamples", 1)
	pvseries.updControl("PvConvert/conv/mrs_natural/onSamples", 1)
	pvseries.updControl("PvConvert/conv/mrs_real/osrate", 44100.0)


	pvseries.updControl("PvUnconvert/uconv/mrs_natural/inObservations", options['Nw'])
	pvseries.updControl("PvUnconvert/uconv/mrs_natural/onObservations", options['Nw'])
	pvseries.updControl("PvUnconvert/uconv/mrs_natural/Interpolation", options['I'])
	pvseries.updControl("PvUnconvert/uconv/mrs_natural/Decimation", options['D'])

	pvseries.updControl("PvUnconvert/uconv/mrs_string/mode",options['unconvertmode_'])

	pvseries.updControl("InvSpectrum/ispectrum/mrs_natural/onObservations", 1)
	pvseries.updControl("InvSpectrum/ispectrum/mrs_natural/onSamples", options['N'])

	pvseries.updControl("PvOverlapadd/pover/mrs_natural/FFTSize", options['N'])
	pvseries.updControl("PvOverlapadd/pover/mrs_natural/winSize", options['Nw'])
	pvseries.updControl("PvOverlapadd/pover/mrs_natural/Interpolation", options['I'])
	pvseries.updControl("PvOverlapadd/pover/mrs_natural/Decimation", options['D'])

	pvseries.updControl("ShiftOutput/so/mrs_natural/Interpolation", options['I'])

	pvseries.linkControl("PvConvert/conv/mrs_realvec/phases", "PvUnconvert/uconv/mrs_realvec/analysisphases")
	pvseries.linkControl("PvUnconvert/uconv/mrs_realvec/regions", "PvConvert/conv/mrs_realvec/regions")

	pvseries.updControl("SoundFileSink/last/mrs_natural/bitrate", 320)

	

	ticks = 0

	notempty = pvseries.getControl("SoundFileSource/src/mrs_bool/hasData")

	while (notempty.to_bool()):
		if(ticks == 0):
			pvseries.updControl("PvUnconvert/uconv/mrs_bool/phaselock", marsyas.MarControlPtr.from_bool(True))

		pvseries.tick()
		ticks = ticks + 1
		#print ticks*(options['D']/44100.0)

	return outfile
Ejemplo n.º 11
0
import marsyas
import json

net = marsyas.system_from_script_file("test.mrs")
print net.toStringShort()

net = marsyas.system_from_script(""" 

     Network : Series
     {
        -> input: NoiseSource
        -> amp: Gain
        -> output: AudioSink
     }
""")
print net.toStringShort()