--- /dev/null
+# -*- coding: utf-8 -*-
+"""
+Created on Tue Jul 16 13:04:49 2013
+
+@author: thomas
+"""
+from __future__ import division
+import timeside
+import matplotlib.pyplot as plt
+import numpy as np
+import sys
+
+if not sys.argv[-1]:
+ wav_file = 'toto.wav'
+else:
+ 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)
+print pipe
+pipe.run()
+
+print 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.frame_metadata.samplerate],
+ aspect='auto')
+
+res_pitch = aubio_pitch.results['aubio_pitch.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()
+++ /dev/null
-# -*- coding: utf-8 -*-
-"""
-Created on Tue Jul 16 13:04:49 2013
-
-@author: thomas
-"""
-from __future__ import division
-import timeside
-import matplotlib.pyplot as plt
-import numpy as np
-import sys
-
-if not '.wav' in sys.argv[-1]:
- wav_file = 'toto.wav'
-else:
- 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.frame_metadata.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()
all([numpy.array_equal(self[key], other[key])
for key in self.keys()]))
except AttributeError:
- # print self
- # print [self[key] == other[key] for key in self.keys()]
return (isinstance(other, self.__class__) and
all([bool(numpy.logical_and.reduce((self[key] == other[key]).ravel()))
for key in self.keys()]))
@staticmethod
def from_hdf5(h5group):
# Read Sub-Group
- result = AnalyzerResult.factory(
- data_mode=h5group.attrs['data_mode'],
- time_mode=h5group.attrs['time_mode'])
+ result = AnalyzerResult.factory(data_mode=h5group.attrs['data_mode'],
+ time_mode=h5group.attrs['time_mode'])
for subgroup_name, h5subgroup in h5group.items():
result[subgroup_name].from_hdf5(h5subgroup)
return result
analyzer_result)
#self.results += [analyzer_result]
- def to_xml(self, output_file = None):
+ def to_xml(self, output_file=None):
import xml.etree.ElementTree as ET
# TODO : cf. telemeta util
root.append(ET.fromstring(result.to_xml()))
xml_str = ET.tostring(root, encoding="utf-8", method="xml")
- if output_file: open(output_file, 'w').write(xml_str)
- else: return xml_str
+ if output_file:
+ open(output_file, 'w').write(xml_str)
+ else:
+ return xml_str
@staticmethod
def from_xml(xml_string):
return results
- def to_json(self, output_file = None):
+ def to_json(self, output_file=None):
#if data_list == None: data_list = self.results
import simplejson as json
raise TypeError(repr(obj) + " is not JSON serializable")
json_str = json.dumps([res.as_dict() for res in self.values()],
- default=NumpyArrayEncoder)
- if output_file: open(output_file, 'w').write(json_str)
- else: return json_str
+ default=NumpyArrayEncoder)
+ if output_file:
+ open(output_file, 'w').write(json_str)
+ else:
+ return json_str
@staticmethod
def from_json(json_str):
yaml.add_representer(numpy.ndarray, numpyArray_representer)
yaml_str = yaml.dump([res.as_dict() for res in self.values()])
- if output_file: open(output_file, 'w').write(yaml_str)
- else: return yaml_str
+ if output_file:
+ open(output_file, 'w').write(yaml_str)
+ else:
+ return yaml_str
@staticmethod
def from_yaml(yaml_str):
@property
def results(self):
-
return AnalyzerResultContainer(
[self.process_pipe.results[key] for key in self.process_pipe.results.keys()
if key.split('.')[0] == self.id()])
from datetime import datetime
result = AnalyzerResult.factory(data_mode=data_mode,
- time_mode=time_mode)
+ time_mode=time_mode)
# Automatically write known metadata
result.id_metadata.date = datetime.now().replace(
if __name__ == "__main__":
import doctest
- doctest.testmod()
+ doctest.testmod()
\ No newline at end of file
self.results = AnalyzerResultContainer()
def __or__(self, other):
- return ProcessPipe(self, other)
+ self |= other
+ return self
def __ior__(self, other):
if isinstance(other, Processor):