From: Guillaume Pellerin Date: Thu, 31 Oct 2013 21:51:58 +0000 (+0100) Subject: tests/api to test/sandbox, add various tests in sandbox X-Git-Tag: 0.5.1-0~7 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=770add82a8492d585b979de576241159503c017b;p=timeside.git tests/api to test/sandbox, add various tests in sandbox --- diff --git a/tests/api/__init__.py b/tests/api/__init__.py deleted file mode 100644 index 40a96af..0000000 --- a/tests/api/__init__.py +++ /dev/null @@ -1 +0,0 @@ -# -*- coding: utf-8 -*- diff --git a/tests/api/examples.py b/tests/api/examples.py deleted file mode 100644 index 2c69222..0000000 --- a/tests/api/examples.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter -from timeside.api import * -import numpy - - -class Gain(Processor): - implements(IEffect) - - @interfacedoc - def __init__(self, gain=1.0): - self.gain = gain - - @staticmethod - @interfacedoc - def id(): - return "test_gain" - - @staticmethod - @interfacedoc - def name(): - return "Gain test effect" - - def process(self, frames, eod=False): - return numpy.multiply(frames, self.gain), eod diff --git a/tests/api/exempleCMMR_vamp.py b/tests/api/exempleCMMR_vamp.py deleted file mode 100644 index 7f5864f..0000000 --- a/tests/api/exempleCMMR_vamp.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Fri Oct 11 13:22:37 2013 - -@author: thomas -""" - -from __future__ import division -import timeside -import matplotlib.pyplot as plt -import numpy as np -import sys - -#wav_file = sys.argv[-1] -wav_file = '/home/thomas/code/timeside/TimeSide/tests/samples/sweep.wav' - -# normal -d = timeside.decoder.FileDecoder(wav_file) - -specgram = timeside.analyzer.Spectrogram() -waveform = timeside.analyzer.Waveform() - -# Get available Vamp plugins list -from timeside.analyzer.vamp_plugin import VampSimpleHost -plugins_list = VampSimpleHost.get_plugins_list() - -# Display avalaible plugins -print 'index \t soname \t \t identifier \t output ' -print '------ \t \t ---------- \t ------ ' -for index, line in zip(xrange(len(plugins_list)),plugins_list): - print '%d : %s \t %s \t %s' % (index,line[0],line[1],line[2]) - -# Let's choose #7 -my_plugin = plugins_list[7] -print my_plugin - -# -# Vamp plugin Analyzer -#vamp = timeside.analyzer.VampSimpleHost([my_plugin]) -vamp = timeside.analyzer.VampSimpleHost() - -# -myPipe = (d | vamp | specgram | waveform).run() - -# Get spectrogram result and plot the spectrogram -spec_res = specgram.results['spectrogram_analyzer'] -N = spec_res.parameters['FFT_SIZE'] -max_freq = (N // 2 + 1) / N * spec_res.frame_metadata.samplerate - - - -# Get the vamp plugin result and plot it -for key in vamp.results.keys(): - print vamp.results[key].data - -res_vamp = vamp.results['vamp_simple_host.percussiononsets.detectionfunction'] - -plt.figure(1) - -plt.subplot(2,1,1) -plt.plot(res_vamp.time, res_vamp.data) -plt.xlabel('time in s') -plt.grid -plt.title(res_vamp.name) - -plt.subplot(2,1,2) -plt.imshow(20 * np.log10(spec_res.data.T + 1e-6), - origin='lower', - extent=[spec_res.time[0], spec_res.time[-1], 0, - max_freq], - aspect='auto') - -data = (res_vamp.data - res_vamp.data.mean()).clip(0) -plt.plot(res_vamp.time, abs(data / data.max() * max_freq)) - - -plt.xlabel('time in s') -plt.show() \ No newline at end of file diff --git a/tests/api/exemplesCMMR.py b/tests/api/exemplesCMMR.py deleted file mode 100644 index 603ac9a..0000000 --- a/tests/api/exemplesCMMR.py +++ /dev/null @@ -1,63 +0,0 @@ -# -*- 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() diff --git a/tests/api/test_all.py b/tests/api/test_all.py deleted file mode 100644 index b7df0ba..0000000 --- a/tests/api/test_all.py +++ /dev/null @@ -1,46 +0,0 @@ -# -*- coding: utf-8 -*- - -import os, sys -import timeside - -path = sys.argv[-1] -filename = path.split(os.sep)[-1] -result_dir = '../results/' - -if not os.path.exists(result_dir): - os.makedirs(result_dir) - -decoder = timeside.decoder.FileDecoder(path) -graphers = timeside.core.processors(timeside.api.IGrapher) -encoders = timeside.core.processors(timeside.api.IEncoder) -analyzers = timeside.core.processors(timeside.api.IAnalyzer) - -grapher_list = [] -analyzer_list = [] -encoder_list = [] - -pipe = decoder - -for grapher in graphers: - proc = grapher() - grapher_list.append(proc) - pipe = pipe | proc - -for analyzer in analyzers: - proc = analyzer() - analyzer_list.append(proc) - pipe = pipe | proc - -for encoder in encoders: - path = result_dir + os.sep + filename + '.' + encoder.file_extension() - proc = encoder(path, overwrite=True) - encoder_list.append(proc) - pipe = pipe | proc - -print pipe -pipe.run() - -for grapher in grapher_list: - image = result_dir + os.sep + filename + '-' + grapher.id() + '.png' - grapher.render(image) - diff --git a/tests/api/test_all_graphers.py b/tests/api/test_all_graphers.py deleted file mode 100644 index a62b855..0000000 --- a/tests/api/test_all_graphers.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- - -import os, sys -import timeside - -audio_file = sys.argv[-1] -audio_filename = audio_file.split(os.sep)[-1] -img_dir = '../results/img' - -if not os.path.exists(img_dir): - os.makedirs(img_dir) - -decoder = timeside.decoder.FileDecoder(audio_file) -graphers = timeside.core.processors(timeside.api.IGrapher) -pipe = decoder -proc_list = [] - -for grapher in graphers: - proc = grapher() - proc_list.append(proc) - print proc.id() - pipe = pipe | proc - -pipe.run() - -for grapher in proc_list: - image = img_dir + os.sep + audio_filename + '-' + grapher.id() + '.png' - grapher.render(image) diff --git a/tests/api/test_analyzer.py b/tests/api/test_analyzer.py deleted file mode 100644 index ce3fa60..0000000 --- a/tests/api/test_analyzer.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- - -import timeside -from sys import stdout -import os.path -import numpy - -class TestAnalyzer: - - graphers = timeside.get_processors(timeside.api.IGrapher) - decoders = timeside.get_processors(timeside.api.IDecoder) - encoders= timeside.get_processors(timeside.api.IEncoder) - analyzers = timeside.get_processors(timeside.api.IAnalyzer) - - def __init__(self, path): - self.source = os.path.join(os.path.dirname(__file__), path) - print "Processing %s" % self.source - self.decoder = timeside.decoder.FileDecoder(self.source) - print 'format: ', self.decoder.format() - self.pipe = self.decoder - self.analyzers_sub_pipe = [] - - def process(self): - for analyzer in self.analyzers: - sub_pipe = analyzer() - self.analyzers_sub_pipe.append(sub_pipe) - self.pipe = self.pipe | sub_pipe - self.pipe.run() - - def results(self): - results = [] - for analyzer in self.analyzers_sub_pipe: - if hasattr(analyzer, 'results'): - results.append(analyzer.results()) - else: - value = analyzer.result() - results.append([{'name':analyzer.name(), - 'id':analyzer.id(), - 'unit':analyzer.unit(), - 'value':str(value)}]) - print results - - -test = TestAnalyzer('../samples/guitar.wav') -#test = TestAnalyzer('/home/momo/music/wav/Cellar/Cellar-FinallyMix_01.wav') -test.process() -test.results() - diff --git a/tests/api/test_analyzer3.py b/tests/api/test_analyzer3.py deleted file mode 100644 index f029392..0000000 --- a/tests/api/test_analyzer3.py +++ /dev/null @@ -1,34 +0,0 @@ -# -*- coding: utf-8 -*- - -import timeside -import sys -import os.path -import numpy -import time - - -class TestAnalyzer: - - analyzer = timeside.analyzer.Level() - - def __init__(self, path): - self.source = path - print "Processing %s" % self.source - self.decoder = timeside.decoder.FileDecoder(self.source) - print 'format: ', self.decoder.format() - self.pipe = self.decoder - self.sub_pipe = self.analyzer - - def process(self): - self.pipe = self.pipe | self.sub_pipe - self.pipe.run() - - def results(self): - print {'name':self.analyzer.name(), - 'id':self.analyzer.id(), - 'unit':self.analyzer.unit(), - 'value':str(self.analyzer.value)} - -test = TestAnalyzer(sys.argv[-1]) -test.process() -test.results() diff --git a/tests/api/test_enc_flac.py b/tests/api/test_enc_flac.py deleted file mode 100644 index 17e604a..0000000 --- a/tests/api/test_enc_flac.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path -import sys - -source = sys.argv[-1] -dest = source+'.flac' - -decoder = FileDecoder(source) -encoder = FlacEncoder(dest, overwrite=True) - -(decoder | encoder).run() diff --git a/tests/api/test_enc_mp3.py b/tests/api/test_enc_mp3.py deleted file mode 100644 index 2dea63c..0000000 --- a/tests/api/test_enc_mp3.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path -import sys - -if len(sys.argv) < 2: - print 'usage:', sys.argv[0], '' - sys.exit(1) - -source = sys.argv[-1] -dest = source+'.mp3' - -print 'converting', source, 'to', dest - -decoder = FileDecoder(source) -encoder = Mp3Encoder(dest, overwrite=True) - -(decoder | encoder).run() - -metadata = {'TIT2': 'title', #title2 - 'TCOM': 'composer', #composer - 'TPE1': 'lead creator', #lead - 'UFID': 'identifier', #Unique ID... - 'TALB': 'album', #album - 'TCON': 'genre', #genre - 'TDRC': '2011', #year -# 'COMM': 'blabla', #comment - } - -encoder.set_metadata(metadata) -encoder.write_metadata() diff --git a/tests/api/test_enc_mp3_by_block.py b/tests/api/test_enc_mp3_by_block.py deleted file mode 100644 index eb90b72..0000000 --- a/tests/api/test_enc_mp3_by_block.py +++ /dev/null @@ -1,33 +0,0 @@ -from numpy import vstack, zeros - -from timeside.decoder import * -from timeside.encoder import * - -import sys, os.path - -def transcode(source, target): - decoder = FileDecoder(source) - decoder.setup() - - channels = decoder.channels() - samplerate = decoder.samplerate() - - print channels, samplerate - - encoder = Mp3Encoder(target) - encoder.setup(channels = channels, samplerate = samplerate) - - totalframes = 0 - while True: - frames, eod = decoder.process() - encoder.process(frames, eod) - totalframes += frames.shape[0] - if eod or encoder.eod: - break - -if __name__ == '__main__': - - if len(sys.argv) < 3: - print 'needs 2 args' - sys.exit(1) - transcode(sys.argv[1], sys.argv[2]) diff --git a/tests/api/test_enc_ogg.py b/tests/api/test_enc_ogg.py deleted file mode 100644 index b6be599..0000000 --- a/tests/api/test_enc_ogg.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path -import sys - -if len(sys.argv) < 2: - print 'usage:', sys.argv[0], '' - sys.exit(1) - -source = sys.argv[-1] -dest = source+'.ogg' - -print 'converting', source, 'to', dest - -decoder = FileDecoder(source) -encoder = VorbisEncoder(dest, overwrite=True) - -(decoder | encoder).run() diff --git a/tests/api/test_enc_webm.py b/tests/api/test_enc_webm.py deleted file mode 100644 index 321d386..0000000 --- a/tests/api/test_enc_webm.py +++ /dev/null @@ -1,14 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path -import sys - -source = sys.argv[-1] -dest = source+'.webm' - -decoder = FileDecoder(source) -encoder = WebMEncoder(dest) - -(decoder | encoder).run() diff --git a/tests/api/test_flac.py b/tests/api/test_flac.py deleted file mode 100644 index ee590c4..0000000 --- a/tests/api/test_flac.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path - -source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") -dest = os.path.join(os.path.dirname(__file__), "../results/sweep_wav.flac") - -decoder = FileDecoder(source) -encoder = FlacEncoder(dest) - -(decoder | encoder).run() diff --git a/tests/api/test_lolevel.py b/tests/api/test_lolevel.py deleted file mode 100644 index 421ce95..0000000 --- a/tests/api/test_lolevel.py +++ /dev/null @@ -1,61 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.tests.api.examples import Gain -from timeside.core import * -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * -from timeside.api import * - -import sys -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - source= os.path.join (os.path.dirname(__file__), "../samples/guitar.wav") - -Decoder = FileDecoder -print "Creating decoder with id=%s for: %s" % (Decoder.id(), source) -decoder = Decoder(source) -analyzer = MaxLevel() -decoder.setup() -nchannels = decoder.channels() -samplerate = decoder.samplerate() -nframes = decoder.nframes() -analyzer.setup(nchannels, samplerate) - -print "Stats: duration=%f, nframes=%d, nchannels=%d, samplerate=%d, resolution=%d" % ( - nframes / float(samplerate), nframes, nchannels, samplerate, decoder.resolution()) - -while True: - frames, eod = decoder.process() - analyzer.process(frames, eod) - if eod: - break - -max_level = analyzer.result() -print "Max level: %f" % max_level - -destination = "../results/guitar_normalized.wav" -Encoder = WavEncoder -print "Creating encoder with id=%s for: %s" % (Encoder.id(), destination) -encoder = Encoder(destination) - -gain = 1 -if max_level > 0: - gain = 0.9 / max_level - -effect = Gain(gain) - -decoder.setup() -effect.setup(decoder.channels(), decoder.samplerate()) -encoder.setup(effect.channels(), effect.samplerate()) - -print "Applying effect id=%s with gain=%f" % (effect.id(), gain) - -while True: - frames, eod = decoder.process() - encoder.process(*effect.process(frames, eod)) - if eod: - break - diff --git a/tests/api/test_lolevel_streaming.py b/tests/api/test_lolevel_streaming.py deleted file mode 100644 index e394f0c..0000000 --- a/tests/api/test_lolevel_streaming.py +++ /dev/null @@ -1,40 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import * -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * -from timeside.api import * - -import sys -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - source= os.path.join (os.path.dirname(__file__), "../samples/sweep.flac") - -decoder = FileDecoder(source) -print "Creating decoder with id=%s for: %s" % (decoder.id(), source) -decoder.setup() -channels = decoder.channels() -print 'channels :', channels -samplerate = decoder.samplerate() -nframes = decoder.nframes() - -dest1 = "/tmp/test_filesink.mp3" -dest2 = "/tmp/test_appsink.mp3" -f = open(dest2,'w') - -streaming=True -encoder = Mp3Encoder(dest1, streaming=True) -encoder.setup(channels=channels, samplerate=samplerate) - -while True: - encoder.process(*decoder.process()) - if streaming: - f.write(encoder.chunk) - if encoder.eod : - break - -f.close() -print encoder.pipe diff --git a/tests/api/test_lolevel_streaming_bad.py b/tests/api/test_lolevel_streaming_bad.py deleted file mode 100644 index e414ead..0000000 --- a/tests/api/test_lolevel_streaming_bad.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import * -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * -from timeside.api import * - -import sys -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - source= os.path.join (os.path.dirname(__file__), "../samples/sweep.wav") - -decoder = FileDecoder(source) -print "Creating decoder with id=%s for: %s" % (decoder.id(), source) -decoder.setup() -channels = decoder.channels() -print 'channels :', channels -samplerate = decoder.samplerate() -nframes = decoder.nframes() - -dest1 = "/tmp/test_filesink.mp3" -dest2 = "/tmp/test_appsink.mp3" -f = open(dest2,'w') - -streaming=True -encoder = Mp3Encoder(dest1, streaming=True) -encoder.setup(channels=channels, samplerate=samplerate) - -print encoder.pipe - -while True: - encoder.process(*decoder.process()) - if streaming: - f.write(encoder.chunk) - if encoder.eod : - break - -f.close() -print encoder.pipe diff --git a/tests/api/test_lolevel_streaming_vorbis.py b/tests/api/test_lolevel_streaming_vorbis.py deleted file mode 100644 index ecc3d3f..0000000 --- a/tests/api/test_lolevel_streaming_vorbis.py +++ /dev/null @@ -1,42 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import * -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * -from timeside.api import * - -import sys -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - source= os.path.join (os.path.dirname(__file__), "../samples/sweep.flac") - -decoder = FileDecoder(source) -print "Creating decoder with id=%s for: %s" % (decoder.id(), source) -decoder.setup() -channels = decoder.channels() -print 'channels :', channels -samplerate = decoder.samplerate() -nframes = decoder.nframes() - -dest1 = "/tmp/test_filesink.ogg" -dest2 = "/tmp/test_appsink.ogg" -f = open(dest2,'w') - -streaming=True -encoder = VorbisEncoder(dest1, streaming=True) -encoder.setup(channels=channels, samplerate=samplerate) - -print encoder.pipe - -while True: - encoder.process(*decoder.process()) - if streaming: - f.write(encoder.chunk) - if encoder.eod : - break - -f.close() -print encoder.pipe diff --git a/tests/api/test_mp3.py b/tests/api/test_mp3.py deleted file mode 100644 index 5d5fe22..0000000 --- a/tests/api/test_mp3.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path - -source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") -dest = os.path.join(os.path.dirname(__file__), "/tmp/sweep_wav.mp3") - -decoder = FileDecoder(source) -encoder = Mp3Encoder(dest) - -(decoder | encoder).run() - -metadata = {'TIT2': 'title', #title2 - 'TCOM': 'composer', #composer - 'TPE1': 'lead creator', #lead - 'UFID': 'identifier', #Unique ID... - 'TALB': 'album', #album - 'TCON': 'genre', #genre - 'TDRC': '2011', #year -# 'COMM': 'blabla', #comment - } - -encoder.set_metadata(metadata) -encoder.write_metadata() - diff --git a/tests/api/test_pipe.py b/tests/api/test_pipe.py deleted file mode 100644 index 629b3e9..0000000 --- a/tests/api/test_pipe.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.tests.api.examples import Gain -from timeside.core import * -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * -from timeside.api import * -from sys import stdout -import os.path -import numpy - -source = os.path.join(os.path.dirname(__file__), "../samples/guitar.wav") - -print "Normalizing %s" % source -decoder = FileDecoder(source) -maxlevel = MaxLevel() -duration = Duration() - -(decoder | maxlevel | duration).run() - -gain = 1 -if maxlevel.result() < 0: - gain = 0.9 / numpy.exp(maxlevel.result()/20) - -print "input maxlevel: %f" % maxlevel.result() -print "gain: %f" % gain -print "duration: %f %s" % (duration.result(), duration.unit()) - -gain = Gain(gain) -encoder = WavEncoder("../results/guitar_normalized.wav") - -subpipe = gain | maxlevel - -(decoder | subpipe | encoder).run() - -print "output maxlevel: %f" % maxlevel.result() - - diff --git a/tests/api/test_spectrogram.py b/tests/api/test_spectrogram.py deleted file mode 100644 index a16874e..0000000 --- a/tests/api/test_spectrogram.py +++ /dev/null @@ -1,32 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -from timeside.core import * -from timeside.api import * -from timeside.decoder import * -from timeside.grapher import * - -sample_dir = '../samples' -img_dir = '../results/img' -if not os.path.exists(img_dir): - os.mkdir(img_dir) - -test_dict = {'sweep.wav': 'spec_wav.png', - 'sweep.flac': 'spec_flac.png', - 'sweep.ogg': 'spec_ogg.png', - 'sweep.mp3': 'spec_mp3.png', - } - -for source, image in test_dict.iteritems(): - audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) - image = img_dir + os.sep + image - print 'Test : decoder(%s) | waveform (%s)' % (source, image) - decoder = FileDecoder(audio) - spectrogram = Spectrogram() - (decoder | spectrogram).run() - print 'frames per pixel = ', spectrogram.samples_per_pixel - print "render spectrogram to: %s" % image - spectrogram.render(image) - - - diff --git a/tests/api/test_vorbis.py b/tests/api/test_vorbis.py deleted file mode 100644 index 53818cd..0000000 --- a/tests/api/test_vorbis.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.encoder import * -import os.path - -source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") -dest = os.path.join(os.path.dirname(__file__), "../results/sweep_wav.ogg") - -decoder = FileDecoder(source) -encoder = VorbisEncoder(dest) - -(decoder | encoder).run() diff --git a/tests/api/test_wav.py b/tests/api/test_wav.py deleted file mode 100644 index 077a01e..0000000 --- a/tests/api/test_wav.py +++ /dev/null @@ -1,15 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * - -import os.path -source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") -dest = os.path.join(os.path.dirname(__file__), "../results/sweep_wav.wav") - -decoder = FileDecoder(source) -encoder = WavEncoder(dest) - -(decoder | encoder).run() - diff --git a/tests/api/test_waveform.py b/tests/api/test_waveform.py deleted file mode 100644 index a028df5..0000000 --- a/tests/api/test_waveform.py +++ /dev/null @@ -1,29 +0,0 @@ -# -*- coding: utf-8 -*- - -import os -from timeside.core import * -from timeside.api import * -from timeside.decoder import * -from timeside.grapher import * - -sample_dir = '../samples' -img_dir = '../results/img' -if not os.path.exists(img_dir): - os.makedirs(img_dir) - -test_dict = {'sweep.wav': 'waveform_wav.png', - 'sweep.flac': 'waveform_flac.png', - 'sweep.ogg': 'waveform_ogg.png', - 'sweep.mp3': 'waveform_mp3.png', - } - -for source, image in test_dict.iteritems(): - audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) - image = img_dir + os.sep + image - print 'Test : decoder(%s) | waveform (%s)' % (source, image) - decoder = FileDecoder(audio) - waveform = Waveform(width=1024, height=256, bg_color=(255,255,255), color_scheme='default') - (decoder | waveform).run() - print 'frames per pixel = ', waveform.samples_per_pixel - print "render waveform to: %s" % image - waveform.render(image) diff --git a/tests/sandbox/__init__.py b/tests/sandbox/__init__.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/tests/sandbox/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/tests/sandbox/examples.py b/tests/sandbox/examples.py new file mode 100644 index 0000000..2c69222 --- /dev/null +++ b/tests/sandbox/examples.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from timeside.core import Processor, implements, interfacedoc, FixedSizeInputAdapter +from timeside.api import * +import numpy + + +class Gain(Processor): + implements(IEffect) + + @interfacedoc + def __init__(self, gain=1.0): + self.gain = gain + + @staticmethod + @interfacedoc + def id(): + return "test_gain" + + @staticmethod + @interfacedoc + def name(): + return "Gain test effect" + + def process(self, frames, eod=False): + return numpy.multiply(frames, self.gain), eod diff --git a/tests/sandbox/exempleCMMR_vamp.py b/tests/sandbox/exempleCMMR_vamp.py new file mode 100644 index 0000000..7f5864f --- /dev/null +++ b/tests/sandbox/exempleCMMR_vamp.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +""" +Created on Fri Oct 11 13:22:37 2013 + +@author: thomas +""" + +from __future__ import division +import timeside +import matplotlib.pyplot as plt +import numpy as np +import sys + +#wav_file = sys.argv[-1] +wav_file = '/home/thomas/code/timeside/TimeSide/tests/samples/sweep.wav' + +# normal +d = timeside.decoder.FileDecoder(wav_file) + +specgram = timeside.analyzer.Spectrogram() +waveform = timeside.analyzer.Waveform() + +# Get available Vamp plugins list +from timeside.analyzer.vamp_plugin import VampSimpleHost +plugins_list = VampSimpleHost.get_plugins_list() + +# Display avalaible plugins +print 'index \t soname \t \t identifier \t output ' +print '------ \t \t ---------- \t ------ ' +for index, line in zip(xrange(len(plugins_list)),plugins_list): + print '%d : %s \t %s \t %s' % (index,line[0],line[1],line[2]) + +# Let's choose #7 +my_plugin = plugins_list[7] +print my_plugin + +# +# Vamp plugin Analyzer +#vamp = timeside.analyzer.VampSimpleHost([my_plugin]) +vamp = timeside.analyzer.VampSimpleHost() + +# +myPipe = (d | vamp | specgram | waveform).run() + +# Get spectrogram result and plot the spectrogram +spec_res = specgram.results['spectrogram_analyzer'] +N = spec_res.parameters['FFT_SIZE'] +max_freq = (N // 2 + 1) / N * spec_res.frame_metadata.samplerate + + + +# Get the vamp plugin result and plot it +for key in vamp.results.keys(): + print vamp.results[key].data + +res_vamp = vamp.results['vamp_simple_host.percussiononsets.detectionfunction'] + +plt.figure(1) + +plt.subplot(2,1,1) +plt.plot(res_vamp.time, res_vamp.data) +plt.xlabel('time in s') +plt.grid +plt.title(res_vamp.name) + +plt.subplot(2,1,2) +plt.imshow(20 * np.log10(spec_res.data.T + 1e-6), + origin='lower', + extent=[spec_res.time[0], spec_res.time[-1], 0, + max_freq], + aspect='auto') + +data = (res_vamp.data - res_vamp.data.mean()).clip(0) +plt.plot(res_vamp.time, abs(data / data.max() * max_freq)) + + +plt.xlabel('time in s') +plt.show() \ No newline at end of file diff --git a/tests/sandbox/exemplesCMMR.py b/tests/sandbox/exemplesCMMR.py new file mode 100644 index 0000000..603ac9a --- /dev/null +++ b/tests/sandbox/exemplesCMMR.py @@ -0,0 +1,63 @@ +# -*- 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() diff --git a/tests/sandbox/test_all.py b/tests/sandbox/test_all.py new file mode 100644 index 0000000..b7df0ba --- /dev/null +++ b/tests/sandbox/test_all.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +import os, sys +import timeside + +path = sys.argv[-1] +filename = path.split(os.sep)[-1] +result_dir = '../results/' + +if not os.path.exists(result_dir): + os.makedirs(result_dir) + +decoder = timeside.decoder.FileDecoder(path) +graphers = timeside.core.processors(timeside.api.IGrapher) +encoders = timeside.core.processors(timeside.api.IEncoder) +analyzers = timeside.core.processors(timeside.api.IAnalyzer) + +grapher_list = [] +analyzer_list = [] +encoder_list = [] + +pipe = decoder + +for grapher in graphers: + proc = grapher() + grapher_list.append(proc) + pipe = pipe | proc + +for analyzer in analyzers: + proc = analyzer() + analyzer_list.append(proc) + pipe = pipe | proc + +for encoder in encoders: + path = result_dir + os.sep + filename + '.' + encoder.file_extension() + proc = encoder(path, overwrite=True) + encoder_list.append(proc) + pipe = pipe | proc + +print pipe +pipe.run() + +for grapher in grapher_list: + image = result_dir + os.sep + filename + '-' + grapher.id() + '.png' + grapher.render(image) + diff --git a/tests/sandbox/test_all_graphers.py b/tests/sandbox/test_all_graphers.py new file mode 100644 index 0000000..a62b855 --- /dev/null +++ b/tests/sandbox/test_all_graphers.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +import os, sys +import timeside + +audio_file = sys.argv[-1] +audio_filename = audio_file.split(os.sep)[-1] +img_dir = '../results/img' + +if not os.path.exists(img_dir): + os.makedirs(img_dir) + +decoder = timeside.decoder.FileDecoder(audio_file) +graphers = timeside.core.processors(timeside.api.IGrapher) +pipe = decoder +proc_list = [] + +for grapher in graphers: + proc = grapher() + proc_list.append(proc) + print proc.id() + pipe = pipe | proc + +pipe.run() + +for grapher in proc_list: + image = img_dir + os.sep + audio_filename + '-' + grapher.id() + '.png' + grapher.render(image) diff --git a/tests/sandbox/test_analyzer.py b/tests/sandbox/test_analyzer.py new file mode 100644 index 0000000..ce3fa60 --- /dev/null +++ b/tests/sandbox/test_analyzer.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- + +import timeside +from sys import stdout +import os.path +import numpy + +class TestAnalyzer: + + graphers = timeside.get_processors(timeside.api.IGrapher) + decoders = timeside.get_processors(timeside.api.IDecoder) + encoders= timeside.get_processors(timeside.api.IEncoder) + analyzers = timeside.get_processors(timeside.api.IAnalyzer) + + def __init__(self, path): + self.source = os.path.join(os.path.dirname(__file__), path) + print "Processing %s" % self.source + self.decoder = timeside.decoder.FileDecoder(self.source) + print 'format: ', self.decoder.format() + self.pipe = self.decoder + self.analyzers_sub_pipe = [] + + def process(self): + for analyzer in self.analyzers: + sub_pipe = analyzer() + self.analyzers_sub_pipe.append(sub_pipe) + self.pipe = self.pipe | sub_pipe + self.pipe.run() + + def results(self): + results = [] + for analyzer in self.analyzers_sub_pipe: + if hasattr(analyzer, 'results'): + results.append(analyzer.results()) + else: + value = analyzer.result() + results.append([{'name':analyzer.name(), + 'id':analyzer.id(), + 'unit':analyzer.unit(), + 'value':str(value)}]) + print results + + +test = TestAnalyzer('../samples/guitar.wav') +#test = TestAnalyzer('/home/momo/music/wav/Cellar/Cellar-FinallyMix_01.wav') +test.process() +test.results() + diff --git a/tests/sandbox/test_analyzer3.py b/tests/sandbox/test_analyzer3.py new file mode 100644 index 0000000..f029392 --- /dev/null +++ b/tests/sandbox/test_analyzer3.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +import timeside +import sys +import os.path +import numpy +import time + + +class TestAnalyzer: + + analyzer = timeside.analyzer.Level() + + def __init__(self, path): + self.source = path + print "Processing %s" % self.source + self.decoder = timeside.decoder.FileDecoder(self.source) + print 'format: ', self.decoder.format() + self.pipe = self.decoder + self.sub_pipe = self.analyzer + + def process(self): + self.pipe = self.pipe | self.sub_pipe + self.pipe.run() + + def results(self): + print {'name':self.analyzer.name(), + 'id':self.analyzer.id(), + 'unit':self.analyzer.unit(), + 'value':str(self.analyzer.value)} + +test = TestAnalyzer(sys.argv[-1]) +test.process() +test.results() diff --git a/tests/sandbox/test_analyzer4.py b/tests/sandbox/test_analyzer4.py new file mode 100644 index 0000000..440fc00 --- /dev/null +++ b/tests/sandbox/test_analyzer4.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +import timeside +import sys +import os.path +import numpy +import time + + +class TestAnalyzer: + + analyzer = timeside.analyzer.Level() + + def __init__(self, path): + self.source = path + print "Processing %s" % self.source + self.decoder = timeside.decoder.FileDecoder(self.source) + print 'format: ', self.decoder.format() + self.pipe = self.decoder + self.sub_pipe = self.analyzer + + def process(self): + self.pipe = self.pipe | self.sub_pipe + self.pipe.run() + + def results(self): + print self.sub_pipe.results() + +test = TestAnalyzer(sys.argv[-1]) +test.process() +test.results() diff --git a/tests/sandbox/test_aubio_bpm.py b/tests/sandbox/test_aubio_bpm.py new file mode 100644 index 0000000..9c0e84a --- /dev/null +++ b/tests/sandbox/test_aubio_bpm.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +import sys +sys.path.append('/home/momo/dev/aubio/interfaces/python/build/lib.linux-x86_64-2.6/') + +import timeside + +decoder = timeside.decoder.FileDecoder('/home/momo/music_local/Kavinsky - Nightcall EP/01 Nightcall (Feat. Lovefoxxx).mp3') +analyzer = timeside.analyzer.AubioBPM() +(decoder | analyzer).run() +print analyzer.result() + + diff --git a/tests/sandbox/test_aubio_onsetrate.py b/tests/sandbox/test_aubio_onsetrate.py new file mode 100644 index 0000000..1a812eb --- /dev/null +++ b/tests/sandbox/test_aubio_onsetrate.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +import timeside + +decoder = timeside.decoder.FileDecoder('/home/momo/music_local/Kavinsky - Nightcall EP/01 Nightcall (Feat. Lovefoxxx).mp3') +analyzer = timeside.analyzer.AubioOnsetRate() +(decoder | analyzer).run() +print analyzer.result() + + diff --git a/tests/sandbox/test_enc_flac.py b/tests/sandbox/test_enc_flac.py new file mode 100644 index 0000000..17e604a --- /dev/null +++ b/tests/sandbox/test_enc_flac.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path +import sys + +source = sys.argv[-1] +dest = source+'.flac' + +decoder = FileDecoder(source) +encoder = FlacEncoder(dest, overwrite=True) + +(decoder | encoder).run() diff --git a/tests/sandbox/test_enc_mp3.py b/tests/sandbox/test_enc_mp3.py new file mode 100644 index 0000000..2dea63c --- /dev/null +++ b/tests/sandbox/test_enc_mp3.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path +import sys + +if len(sys.argv) < 2: + print 'usage:', sys.argv[0], '' + sys.exit(1) + +source = sys.argv[-1] +dest = source+'.mp3' + +print 'converting', source, 'to', dest + +decoder = FileDecoder(source) +encoder = Mp3Encoder(dest, overwrite=True) + +(decoder | encoder).run() + +metadata = {'TIT2': 'title', #title2 + 'TCOM': 'composer', #composer + 'TPE1': 'lead creator', #lead + 'UFID': 'identifier', #Unique ID... + 'TALB': 'album', #album + 'TCON': 'genre', #genre + 'TDRC': '2011', #year +# 'COMM': 'blabla', #comment + } + +encoder.set_metadata(metadata) +encoder.write_metadata() diff --git a/tests/sandbox/test_enc_mp3_by_block.py b/tests/sandbox/test_enc_mp3_by_block.py new file mode 100644 index 0000000..eb90b72 --- /dev/null +++ b/tests/sandbox/test_enc_mp3_by_block.py @@ -0,0 +1,33 @@ +from numpy import vstack, zeros + +from timeside.decoder import * +from timeside.encoder import * + +import sys, os.path + +def transcode(source, target): + decoder = FileDecoder(source) + decoder.setup() + + channels = decoder.channels() + samplerate = decoder.samplerate() + + print channels, samplerate + + encoder = Mp3Encoder(target) + encoder.setup(channels = channels, samplerate = samplerate) + + totalframes = 0 + while True: + frames, eod = decoder.process() + encoder.process(frames, eod) + totalframes += frames.shape[0] + if eod or encoder.eod: + break + +if __name__ == '__main__': + + if len(sys.argv) < 3: + print 'needs 2 args' + sys.exit(1) + transcode(sys.argv[1], sys.argv[2]) diff --git a/tests/sandbox/test_enc_ogg.py b/tests/sandbox/test_enc_ogg.py new file mode 100644 index 0000000..b6be599 --- /dev/null +++ b/tests/sandbox/test_enc_ogg.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path +import sys + +if len(sys.argv) < 2: + print 'usage:', sys.argv[0], '' + sys.exit(1) + +source = sys.argv[-1] +dest = source+'.ogg' + +print 'converting', source, 'to', dest + +decoder = FileDecoder(source) +encoder = VorbisEncoder(dest, overwrite=True) + +(decoder | encoder).run() diff --git a/tests/sandbox/test_enc_webm.py b/tests/sandbox/test_enc_webm.py new file mode 100644 index 0000000..321d386 --- /dev/null +++ b/tests/sandbox/test_enc_webm.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path +import sys + +source = sys.argv[-1] +dest = source+'.webm' + +decoder = FileDecoder(source) +encoder = WebMEncoder(dest) + +(decoder | encoder).run() diff --git a/tests/sandbox/test_flac.py b/tests/sandbox/test_flac.py new file mode 100644 index 0000000..ee590c4 --- /dev/null +++ b/tests/sandbox/test_flac.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path + +source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") +dest = os.path.join(os.path.dirname(__file__), "../results/sweep_wav.flac") + +decoder = FileDecoder(source) +encoder = FlacEncoder(dest) + +(decoder | encoder).run() diff --git a/tests/sandbox/test_lolevel.py b/tests/sandbox/test_lolevel.py new file mode 100644 index 0000000..421ce95 --- /dev/null +++ b/tests/sandbox/test_lolevel.py @@ -0,0 +1,61 @@ +# -*- coding: utf-8 -*- + +from timeside.tests.api.examples import Gain +from timeside.core import * +from timeside.decoder import * +from timeside.analyzer import * +from timeside.encoder import * +from timeside.api import * + +import sys +if len(sys.argv) > 1: + source = sys.argv[1] +else: + import os.path + source= os.path.join (os.path.dirname(__file__), "../samples/guitar.wav") + +Decoder = FileDecoder +print "Creating decoder with id=%s for: %s" % (Decoder.id(), source) +decoder = Decoder(source) +analyzer = MaxLevel() +decoder.setup() +nchannels = decoder.channels() +samplerate = decoder.samplerate() +nframes = decoder.nframes() +analyzer.setup(nchannels, samplerate) + +print "Stats: duration=%f, nframes=%d, nchannels=%d, samplerate=%d, resolution=%d" % ( + nframes / float(samplerate), nframes, nchannels, samplerate, decoder.resolution()) + +while True: + frames, eod = decoder.process() + analyzer.process(frames, eod) + if eod: + break + +max_level = analyzer.result() +print "Max level: %f" % max_level + +destination = "../results/guitar_normalized.wav" +Encoder = WavEncoder +print "Creating encoder with id=%s for: %s" % (Encoder.id(), destination) +encoder = Encoder(destination) + +gain = 1 +if max_level > 0: + gain = 0.9 / max_level + +effect = Gain(gain) + +decoder.setup() +effect.setup(decoder.channels(), decoder.samplerate()) +encoder.setup(effect.channels(), effect.samplerate()) + +print "Applying effect id=%s with gain=%f" % (effect.id(), gain) + +while True: + frames, eod = decoder.process() + encoder.process(*effect.process(frames, eod)) + if eod: + break + diff --git a/tests/sandbox/test_lolevel_streaming.py b/tests/sandbox/test_lolevel_streaming.py new file mode 100644 index 0000000..e394f0c --- /dev/null +++ b/tests/sandbox/test_lolevel_streaming.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- + +from timeside.core import * +from timeside.decoder import * +from timeside.analyzer import * +from timeside.encoder import * +from timeside.api import * + +import sys +if len(sys.argv) > 1: + source = sys.argv[1] +else: + import os.path + source= os.path.join (os.path.dirname(__file__), "../samples/sweep.flac") + +decoder = FileDecoder(source) +print "Creating decoder with id=%s for: %s" % (decoder.id(), source) +decoder.setup() +channels = decoder.channels() +print 'channels :', channels +samplerate = decoder.samplerate() +nframes = decoder.nframes() + +dest1 = "/tmp/test_filesink.mp3" +dest2 = "/tmp/test_appsink.mp3" +f = open(dest2,'w') + +streaming=True +encoder = Mp3Encoder(dest1, streaming=True) +encoder.setup(channels=channels, samplerate=samplerate) + +while True: + encoder.process(*decoder.process()) + if streaming: + f.write(encoder.chunk) + if encoder.eod : + break + +f.close() +print encoder.pipe diff --git a/tests/sandbox/test_lolevel_streaming_bad.py b/tests/sandbox/test_lolevel_streaming_bad.py new file mode 100644 index 0000000..e414ead --- /dev/null +++ b/tests/sandbox/test_lolevel_streaming_bad.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- + +from timeside.core import * +from timeside.decoder import * +from timeside.analyzer import * +from timeside.encoder import * +from timeside.api import * + +import sys +if len(sys.argv) > 1: + source = sys.argv[1] +else: + import os.path + source= os.path.join (os.path.dirname(__file__), "../samples/sweep.wav") + +decoder = FileDecoder(source) +print "Creating decoder with id=%s for: %s" % (decoder.id(), source) +decoder.setup() +channels = decoder.channels() +print 'channels :', channels +samplerate = decoder.samplerate() +nframes = decoder.nframes() + +dest1 = "/tmp/test_filesink.mp3" +dest2 = "/tmp/test_appsink.mp3" +f = open(dest2,'w') + +streaming=True +encoder = Mp3Encoder(dest1, streaming=True) +encoder.setup(channels=channels, samplerate=samplerate) + +print encoder.pipe + +while True: + encoder.process(*decoder.process()) + if streaming: + f.write(encoder.chunk) + if encoder.eod : + break + +f.close() +print encoder.pipe diff --git a/tests/sandbox/test_lolevel_streaming_vorbis.py b/tests/sandbox/test_lolevel_streaming_vorbis.py new file mode 100644 index 0000000..ecc3d3f --- /dev/null +++ b/tests/sandbox/test_lolevel_streaming_vorbis.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- + +from timeside.core import * +from timeside.decoder import * +from timeside.analyzer import * +from timeside.encoder import * +from timeside.api import * + +import sys +if len(sys.argv) > 1: + source = sys.argv[1] +else: + import os.path + source= os.path.join (os.path.dirname(__file__), "../samples/sweep.flac") + +decoder = FileDecoder(source) +print "Creating decoder with id=%s for: %s" % (decoder.id(), source) +decoder.setup() +channels = decoder.channels() +print 'channels :', channels +samplerate = decoder.samplerate() +nframes = decoder.nframes() + +dest1 = "/tmp/test_filesink.ogg" +dest2 = "/tmp/test_appsink.ogg" +f = open(dest2,'w') + +streaming=True +encoder = VorbisEncoder(dest1, streaming=True) +encoder.setup(channels=channels, samplerate=samplerate) + +print encoder.pipe + +while True: + encoder.process(*decoder.process()) + if streaming: + f.write(encoder.chunk) + if encoder.eod : + break + +f.close() +print encoder.pipe diff --git a/tests/sandbox/test_mp3.py b/tests/sandbox/test_mp3.py new file mode 100644 index 0000000..5d5fe22 --- /dev/null +++ b/tests/sandbox/test_mp3.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path + +source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") +dest = os.path.join(os.path.dirname(__file__), "/tmp/sweep_wav.mp3") + +decoder = FileDecoder(source) +encoder = Mp3Encoder(dest) + +(decoder | encoder).run() + +metadata = {'TIT2': 'title', #title2 + 'TCOM': 'composer', #composer + 'TPE1': 'lead creator', #lead + 'UFID': 'identifier', #Unique ID... + 'TALB': 'album', #album + 'TCON': 'genre', #genre + 'TDRC': '2011', #year +# 'COMM': 'blabla', #comment + } + +encoder.set_metadata(metadata) +encoder.write_metadata() + diff --git a/tests/sandbox/test_mp3_2.py b/tests/sandbox/test_mp3_2.py new file mode 100644 index 0000000..5d5fe22 --- /dev/null +++ b/tests/sandbox/test_mp3_2.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path + +source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") +dest = os.path.join(os.path.dirname(__file__), "/tmp/sweep_wav.mp3") + +decoder = FileDecoder(source) +encoder = Mp3Encoder(dest) + +(decoder | encoder).run() + +metadata = {'TIT2': 'title', #title2 + 'TCOM': 'composer', #composer + 'TPE1': 'lead creator', #lead + 'UFID': 'identifier', #Unique ID... + 'TALB': 'album', #album + 'TCON': 'genre', #genre + 'TDRC': '2011', #year +# 'COMM': 'blabla', #comment + } + +encoder.set_metadata(metadata) +encoder.write_metadata() + diff --git a/tests/sandbox/test_mp3_3.py b/tests/sandbox/test_mp3_3.py new file mode 100644 index 0000000..2d74b37 --- /dev/null +++ b/tests/sandbox/test_mp3_3.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +import time +import timeside + +metadata = {'TIT2': 'title', #title2 + 'TCOM': 'composer', #composer + 'TPE1': 'lead creator', #lead + 'UFID': 'identifier', #Unique ID... + 'TALB': 'album', #album + 'TCON': 'genre', #genre + 'TDRC': '2011', #year +# 'COMM': 'blabla', #comment + } + +decoder = timeside.decoder.FileDecoder('/home/momo/dev/telemeta/sandboxes/sandbox_lam/media/items/2012/09/26/LAM_ETUD_01_01_004.wav') + +encoder = timeside.encoder.Mp3Encoder('/tmp/output.mp3') +encoder.set_metadata(metadata) + +(decoder | encoder).run() + diff --git a/tests/sandbox/test_parent.py b/tests/sandbox/test_parent.py new file mode 100644 index 0000000..4852464 --- /dev/null +++ b/tests/sandbox/test_parent.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +import timeside +import os.path + +source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") + +d = timeside.decoder.FileDecoder(source) +a = timeside.analyzer.OnsetDetectionFunction() + +(d | a).run() + +print a.results \ No newline at end of file diff --git a/tests/sandbox/test_pipe.py b/tests/sandbox/test_pipe.py new file mode 100644 index 0000000..629b3e9 --- /dev/null +++ b/tests/sandbox/test_pipe.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +from timeside.tests.api.examples import Gain +from timeside.core import * +from timeside.decoder import * +from timeside.analyzer import * +from timeside.encoder import * +from timeside.api import * +from sys import stdout +import os.path +import numpy + +source = os.path.join(os.path.dirname(__file__), "../samples/guitar.wav") + +print "Normalizing %s" % source +decoder = FileDecoder(source) +maxlevel = MaxLevel() +duration = Duration() + +(decoder | maxlevel | duration).run() + +gain = 1 +if maxlevel.result() < 0: + gain = 0.9 / numpy.exp(maxlevel.result()/20) + +print "input maxlevel: %f" % maxlevel.result() +print "gain: %f" % gain +print "duration: %f %s" % (duration.result(), duration.unit()) + +gain = Gain(gain) +encoder = WavEncoder("../results/guitar_normalized.wav") + +subpipe = gain | maxlevel + +(decoder | subpipe | encoder).run() + +print "output maxlevel: %f" % maxlevel.result() + + diff --git a/tests/sandbox/test_results.py b/tests/sandbox/test_results.py new file mode 100644 index 0000000..f489b38 --- /dev/null +++ b/tests/sandbox/test_results.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +import timeside.decoder +import timeside.analyzer + + +decoder = timeside.decoder.FileDecoder('/home/momo/dev/timeside/timeside/tests/samples/sweep.wav') +analyzer = timeside.analyzer.AubioMelEnergy() +(decoder | analyzer).run() + +print len(analyzer.results()) +print len(analyzer.results()) +print len(analyzer.results()) + + + diff --git a/tests/sandbox/test_spectrogram.py b/tests/sandbox/test_spectrogram.py new file mode 100644 index 0000000..a16874e --- /dev/null +++ b/tests/sandbox/test_spectrogram.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '../samples' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.mkdir(img_dir) + +test_dict = {'sweep.wav': 'spec_wav.png', + 'sweep.flac': 'spec_flac.png', + 'sweep.ogg': 'spec_ogg.png', + 'sweep.mp3': 'spec_mp3.png', + } + +for source, image in test_dict.iteritems(): + audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) + image = img_dir + os.sep + image + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + spectrogram = Spectrogram() + (decoder | spectrogram).run() + print 'frames per pixel = ', spectrogram.samples_per_pixel + print "render spectrogram to: %s" % image + spectrogram.render(image) + + + diff --git a/tests/sandbox/test_spectrogram2.py b/tests/sandbox/test_spectrogram2.py new file mode 100644 index 0000000..762f5ac --- /dev/null +++ b/tests/sandbox/test_spectrogram2.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '../samples' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.mkdir(img_dir) + +test_dict = {'sweep.wav': 'spec_wav.png',} + +for source, image in test_dict.iteritems(): + audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) + image = img_dir + os.sep + image + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + spectrogram = SpectrogramLinear() + (decoder | spectrogram).run() + print 'frames per pixel = ', spectrogram.samples_per_pixel + print "render spectrogram to: %s" % image + spectrogram.render(image) + + + diff --git a/tests/sandbox/test_spectrogram3.py b/tests/sandbox/test_spectrogram3.py new file mode 100644 index 0000000..19fcf9b --- /dev/null +++ b/tests/sandbox/test_spectrogram3.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +import os +import timeside + +audio_dir = '/home/momo/music_local/test/aboul/wav/' +audio_file = 'aboul.wav' +audio_path = audio_dir + audio_file +img_dir = '../results/img' + +if not os.path.exists(img_dir): + os.makedirs(img_dir) + +decoder = timeside.decoder.FileDecoder(audio_path) +analyzers = timeside.core.processors(timeside.api.IAnalyzer) +pipe = decoder + +for analyzer in analyzers: + subpipe = analyzer() + analyzers_sub.append(subpipe) + pipe = pipe | subpipe + +image = img_dir + os.sep + source + '.png' +print 'Test : decoder(%s) | waveform (%s)' % (source, image) + +spectrogram = SpectrogramLinear(width=10240, height=512, bg_color=(0,0,0), color_scheme='default') +(decoder | spectrogram).run() +print 'frames per pixel = ', spectrogram.samples_per_pixel +print "render spectrogram to: %s" % image +spectrogram.render(image) + diff --git a/tests/sandbox/test_vorbis.py b/tests/sandbox/test_vorbis.py new file mode 100644 index 0000000..53818cd --- /dev/null +++ b/tests/sandbox/test_vorbis.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.encoder import * +import os.path + +source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") +dest = os.path.join(os.path.dirname(__file__), "../results/sweep_wav.ogg") + +decoder = FileDecoder(source) +encoder = VorbisEncoder(dest) + +(decoder | encoder).run() diff --git a/tests/sandbox/test_wav.py b/tests/sandbox/test_wav.py new file mode 100644 index 0000000..077a01e --- /dev/null +++ b/tests/sandbox/test_wav.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- + +from timeside.decoder import * +from timeside.analyzer import * +from timeside.encoder import * + +import os.path +source = os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") +dest = os.path.join(os.path.dirname(__file__), "../results/sweep_wav.wav") + +decoder = FileDecoder(source) +encoder = WavEncoder(dest) + +(decoder | encoder).run() + diff --git a/tests/sandbox/test_waveform.py b/tests/sandbox/test_waveform.py new file mode 100644 index 0000000..a028df5 --- /dev/null +++ b/tests/sandbox/test_waveform.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '../samples' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.makedirs(img_dir) + +test_dict = {'sweep.wav': 'waveform_wav.png', + 'sweep.flac': 'waveform_flac.png', + 'sweep.ogg': 'waveform_ogg.png', + 'sweep.mp3': 'waveform_mp3.png', + } + +for source, image in test_dict.iteritems(): + audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) + image = img_dir + os.sep + image + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + waveform = Waveform(width=1024, height=256, bg_color=(255,255,255), color_scheme='default') + (decoder | waveform).run() + print 'frames per pixel = ', waveform.samples_per_pixel + print "render waveform to: %s" % image + waveform.render(image) diff --git a/tests/sandbox/test_waveform3.py b/tests/sandbox/test_waveform3.py new file mode 100644 index 0000000..74603cb --- /dev/null +++ b/tests/sandbox/test_waveform3.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '/home/momo/music_local/Isabelle Aboulker/Mon imagier des instruments/wav/' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.mkdir(img_dir) + +for source in os.listdir(sample_dir): + audio = sample_dir + os.sep + source + image = img_dir + os.sep + source + '.png' + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + waveform = Waveform(width=1024, height=256, bg_color=(0,0,0), color_scheme='default') + (decoder | waveform).run() + print 'frames per pixel = ', waveform.graph.samples_per_pixel + print "render waveform to: %s" % image + waveform.render(image) + + + diff --git a/tests/sandbox/test_waveform4.py b/tests/sandbox/test_waveform4.py new file mode 100644 index 0000000..41e7a82 --- /dev/null +++ b/tests/sandbox/test_waveform4.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample = '/home/momo/music_local/Isabelle Aboulker/Mon imagier des instruments/16 - Isabelle Aboulker - 16 instru.flac' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.mkdir(img_dir) + +audio = sample +image = img_dir + os.sep + 'toto.png' +decoder = FileDecoder(audio) +waveform = Waveform(width=1211, height=170, bg_color=(0,0,0), color_scheme='default') +(decoder | waveform).run() +print 'frames per pixel = ', waveform.graph.samples_per_pixel +print "render waveform to: %s" % image +waveform.render(image) + + + diff --git a/tests/sandbox/test_waveform_centroid.py b/tests/sandbox/test_waveform_centroid.py new file mode 100644 index 0000000..6b343d1 --- /dev/null +++ b/tests/sandbox/test_waveform_centroid.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '../samples' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.makedirs(img_dir) + +test_dict = {'sweep.wav': 'waveform_wav.png', + 'sweep.flac': 'waveform_flac.png', + 'sweep.ogg': 'waveform_ogg.png', + 'sweep.mp3': 'waveform_mp3.png', + } + +for source, image in test_dict.iteritems(): + audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) + image = img_dir + os.sep + image + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + waveform = WaveformCentroid(width=1024, height=256, bg_color=(0,0,0), color_scheme='default') + (decoder | waveform).run() + print 'frames per pixel = ', waveform.samples_per_pixel + print "render waveform to: %s" % image + waveform.render(image) diff --git a/tests/sandbox/test_waveform_contour.py b/tests/sandbox/test_waveform_contour.py new file mode 100644 index 0000000..7fde73c --- /dev/null +++ b/tests/sandbox/test_waveform_contour.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '../samples' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.makedirs(img_dir) + +test_dict = {'sweep.wav': 'waveform_wav.png', + 'sweep.flac': 'waveform_flac.png', + 'sweep.ogg': 'waveform_ogg.png', + 'sweep.mp3': 'waveform_mp3.png', + } + +for source, image in test_dict.iteritems(): + audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) + image = img_dir + os.sep + image + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + waveform = WaveformContourBlack() + (decoder | waveform).run() + print 'frames per pixel = ', waveform.samples_per_pixel + print "render waveform to: %s" % image + waveform.render(image) diff --git a/tests/sandbox/test_waveform_simple.py b/tests/sandbox/test_waveform_simple.py new file mode 100644 index 0000000..ea95a4a --- /dev/null +++ b/tests/sandbox/test_waveform_simple.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- + +import os +from timeside.core import * +from timeside.api import * +from timeside.decoder import * +from timeside.grapher import * + +sample_dir = '../samples' +img_dir = '../results/img' +if not os.path.exists(img_dir): + os.makedirs(img_dir) + +test_dict = {'sweep.wav': 'waveform_wav.png', + 'sweep.flac': 'waveform_flac.png', + 'sweep.ogg': 'waveform_ogg.png', + 'sweep.mp3': 'waveform_mp3.png', + } + +for source, image in test_dict.iteritems(): + audio = os.path.join(os.path.dirname(__file__), sample_dir + os.sep + source) + image = img_dir + os.sep + image + print 'Test : decoder(%s) | waveform (%s)' % (source, image) + decoder = FileDecoder(audio) + waveform = Waveform() + (decoder | waveform).run() + print 'frames per pixel = ', waveform.samples_per_pixel + print "render waveform to: %s" % image + waveform.render(image)