def test_harmonic_synthesis_ifft(self): pd = SMSPeakDetection() pd.hop_size = hop_size frames = pd.find_peaks(self.audio) pt = SMSPartialTracking() pt.max_partials = max_partials frames = pt.find_partials(frames) synth = SMSSynthesis() synth.hop_size = hop_size synth.max_partials = max_partials synth.det_synthesis_type = SMSSynthesis.SMS_DET_IFFT synth_audio = synth.synth(frames) assert len(synth_audio) == len(self.audio) sms_audio, sampling_rate = simpl.read_wav( libsms_harmonic_synthesis_ifft_path ) assert len(synth_audio) == len(sms_audio) for i in range(len(synth_audio)): assert_almost_equals(synth_audio[i], sms_audio[i], float_precision)
def test_size_next_read(self): audio, sampling_rate = simpl.read_wav(audio_path) pd = SMSPeakDetection() pd.hop_size = hop_size pd.max_peaks = max_peaks sizes = self.test_data['size_next_read'] frames = pd.find_peaks(audio[0:num_samples]) for i, frame in enumerate(frames): assert sizes[i] == frame.size, (sizes[i], frame.size)
def test_residual_synthesis(self): res = SMSResidual() res.hop_size = hop_size simpl_residual = res.synth(self.audio) sms_residual, sampling_rate = simpl.read_wav( libsms_residual_synthesis_path ) assert len(simpl_residual) == len(sms_residual) for i in range(len(simpl_residual)): assert_almost_equals(simpl_residual[i], sms_residual[i], float_precision)
def test_peak_detection(self): audio, sampling_rate = simpl.read_wav(audio_path) pd = SMSPeakDetection() pd.hop_size = hop_size pd.max_peaks = max_peaks frames = pd.find_peaks(audio[0:num_samples]) sms_frames = self.test_data['peak_detection'] sms_frames = [f for f in sms_frames if f['status'] != 0] # assert len(sms_frames) == len(frames) for frame in frames: assert len(frame.peaks) <= max_peaks, len(frame.peaks) max_amp = max([p.amplitude for p in frame.peaks]) assert max_amp
import sys import numpy as np import scipy.io.wavfile as wav import simpl usage = 'Usage: python {0} '.format(__file__) + \ '<input wav file> <time scale factor> <output wav file>' if len(sys.argv) != 4: print usage sys.exit(1) audio, sampling_rate = simpl.read_wav(sys.argv[1]) time_scale_factor = float(sys.argv[2]) output_file = sys.argv[3] pd = simpl.LorisPeakDetection() peaks = pd.find_peaks(audio) pt = simpl.SMSPartialTracking() partials = pt.find_partials(peaks) synth = simpl.SndObjSynthesis() audio_out = np.array([]) step_size = 1.0 / time_scale_factor current_frame = 0 while current_frame < len(partials): i = int(current_frame) frame = synth.synth_frame(partials[i]) audio_out = np.hstack((audio_out, frame)) current_frame += step_size
def setup_class(cls): cls.audio = simpl.read_wav(audio_path)[0] cls.audio = cls.audio[len(cls.audio) / 2: (len(cls.audio) / 2) + num_samples]
def setup_class(cls): cls.audio = simpl.read_wav(audio_path)[0] cls.test_data = _load_libsms_test_data()
def setup_class(cls): cls.audio = simpl.read_wav(audio_path)[0] cls.audio = cls.audio[0:num_samples]
def setup_class(cls): cls.audio = simpl.read_wav(audio_path)[0]
import pysms import sndobj import simpl float_precision = 5 frame_size = 512 hop_size = 512 max_peaks = 10 max_partials = 10 num_frames = 30 num_samples = num_frames * hop_size audio_path = os.path.join( os.path.dirname(__file__), 'audio/flute.wav' ) audio, sampling_rate = simpl.read_wav(audio_path) def _pysms_analysis_params(sampling_rate): analysis_params = pysms.SMS_AnalParams() pysms.sms_initAnalParams(analysis_params) analysis_params.iSamplingRate = sampling_rate analysis_params.iFrameRate = sampling_rate / hop_size analysis_params.iWindowType = pysms.SMS_WIN_HAMMING analysis_params.fHighestFreq = 20000 analysis_params.iFormat = pysms.SMS_FORMAT_IHP analysis_params.nTracks = max_peaks analysis_params.peakParams.iMaxPeaks = max_peaks analysis_params.nGuides = max_peaks analysis_params.iMaxDelayFrames = 4 analysis_params.analDelay = 0
import sys import simpl import matplotlib.pyplot as plt usage = 'Usage: python {0} <wav file>'.format(__file__) if len(sys.argv) != 2: print usage sys.exit(1) audio = simpl.read_wav(sys.argv[1])[0] # take just a few frames audio = audio[len(audio) / 2:(len(audio) / 2) + 4096] # peak detection using the SndObj library pd = simpl.SndObjPeakDetection() pd.max_peaks = 20 frames = pd.find_peaks(audio) # plot peaks using matplotlib simpl.plot.plot_peaks(frames) plt.show()