# 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.
# 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) for i in xrange (len(vec)/2):
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); net.updControl(snet["win"]+"/mrs_natural/zeroPadding",args.Window_len * (args.Zero_padding-1));