From 92c0630fad218be74f323e444c8b9846b9b487df Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 10 Oct 2013 18:48:52 +0200 Subject: [PATCH] add thomas' CMMR exemple, rewrite variables, BUG relative to last changes --- tests/api/exemplesCMMR.py | 64 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/api/exemplesCMMR.py diff --git a/tests/api/exemplesCMMR.py b/tests/api/exemplesCMMR.py new file mode 100644 index 0000000..c4a2def --- /dev/null +++ b/tests/api/exemplesCMMR.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +""" +Created on Tue Jul 16 13:04:49 2013 + +@author: thomas +""" +from __future__ import division +import timeside.decoder +import timeside.encoder +import timeside.grapher +import timeside.analyzer +import matplotlib.pyplot as plt +import numpy as np +import sys + +wav_file = sys.argv[-1] + +# normal +decoder = timeside.decoder.FileDecoder(wav_file, start=10, duration=15) +#e = timeside.encoder.VorbisEncoder('output.ogg', overwrite = True) +aubio_pitch = timeside.analyzer.AubioPitch() +aubio_temporal = timeside.analyzer.AubioTemporal() +specgram = timeside.analyzer.Spectrogram() +waveform = timeside.analyzer.Waveform() +#g = timeside.grapher.Spectrogram() +# +# +pipe = (decoder | aubio_pitch | aubio_temporal | specgram | waveform).run() + +pipe.results.keys() + +# Display Spectrogram + Aubio Pitch + Aubio Beat +plt.figure(1) + +spec_res = specgram.results['spectrogram_analyzer'] +N = spec_res.parameters['FFT_SIZE'] +plt.imshow(20 * np.log10(spec_res.data.T), + origin='lower', + extent=[spec_res.time[0], spec_res.time[-1], 0, + (N // 2 + 1) / N * spec_res.frameMetadata.samplerate], + aspect='auto') + +res_pitch = aubio_pitch.results['aubio_pitch'] +plt.plot(res_pitch.time, res_pitch.data) + + +res_beats = aubio_temporal.results['aubio_temporal.beat'] + +for time in res_beats.time: + plt.axvline(time, color='r') + +plt.title('Spectrogram + Aubio pitch + Aubio beat') +plt.grid() + +# Display waveform + Onsets +plt.figure(2) +res_wave = waveform.results['waveform_analyzer'] +plt.plot(res_wave.time, res_wave.data) +res_onsets = aubio_temporal.results['aubio_temporal.onset'] +for time in res_onsets.time: + plt.axvline(time, color='g') +plt.grid() +plt.title('Waveform + Aubio onset') +plt.show() -- 2.39.5