From: Guillaume Pellerin Date: Wed, 22 Oct 2014 15:19:25 +0000 (+0200) Subject: cleanup old sandbox X-Git-Tag: 0.6~4^2~2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=2f1dba67f51660507b61d3ef018b3e80112ee044;p=timeside.git cleanup old sandbox --- diff --git a/tests/sandbox/example_CMMR.py b/tests/sandbox/example_CMMR.py deleted file mode 100644 index 5ff4516..0000000 --- a/tests/sandbox/example_CMMR.py +++ /dev/null @@ -1,65 +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 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() diff --git a/tests/sandbox/examples.py b/tests/sandbox/examples.py deleted file mode 100644 index 2c69222..0000000 --- a/tests/sandbox/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/sandbox/exempleCMMR_vamp.py b/tests/sandbox/exempleCMMR_vamp.py deleted file mode 100644 index 0b779ed..0000000 --- a/tests/sandbox/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/sandbox/test_all.py b/tests/sandbox/test_all.py deleted file mode 100644 index b7df0ba..0000000 --- a/tests/sandbox/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/sandbox/test_all_graphers.py b/tests/sandbox/test_all_graphers.py deleted file mode 100644 index a62b855..0000000 --- a/tests/sandbox/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/sandbox/test_analyzer.py b/tests/sandbox/test_analyzer.py deleted file mode 100644 index ce3fa60..0000000 --- a/tests/sandbox/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/sandbox/test_analyzer3.py b/tests/sandbox/test_analyzer3.py deleted file mode 100644 index f029392..0000000 --- a/tests/sandbox/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/sandbox/test_analyzer4.py b/tests/sandbox/test_analyzer4.py deleted file mode 100644 index 440fc00..0000000 --- a/tests/sandbox/test_analyzer4.py +++ /dev/null @@ -1,31 +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 self.sub_pipe.results() - -test = TestAnalyzer(sys.argv[-1]) -test.process() -test.results() diff --git a/tests/sandbox/test_analyzer_stack.py b/tests/sandbox/test_analyzer_stack.py deleted file mode 100644 index 06ea0e8..0000000 --- a/tests/sandbox/test_analyzer_stack.py +++ /dev/null @@ -1,18 +0,0 @@ -# -*- coding: utf-8 -*- - -import timeside -import sys - -analyzers = [timeside.analyzer.Level(), - timeside.analyzer.AubioTemporal(),] - -source = sys.argv[-1] -print "Processing %s" % source -pipe = timeside.decoder.FileDecoder(source, stack=True) -print 'format: ', pipe.format() -for analyzer in analyzers: - pipe |= analyzer - -pipe.run() -print pipe.results - diff --git a/tests/sandbox/test_aubio_bpm.py b/tests/sandbox/test_aubio_bpm.py deleted file mode 100644 index 9c0e84a..0000000 --- a/tests/sandbox/test_aubio_bpm.py +++ /dev/null @@ -1,13 +0,0 @@ -# -*- 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 deleted file mode 100644 index 1a812eb..0000000 --- a/tests/sandbox/test_aubio_onsetrate.py +++ /dev/null @@ -1,10 +0,0 @@ -# -*- 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 deleted file mode 100644 index 17e604a..0000000 --- a/tests/sandbox/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/sandbox/test_enc_mp3.py b/tests/sandbox/test_enc_mp3.py deleted file mode 100644 index 2dea63c..0000000 --- a/tests/sandbox/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/sandbox/test_enc_mp3_by_block.py b/tests/sandbox/test_enc_mp3_by_block.py deleted file mode 100644 index eb90b72..0000000 --- a/tests/sandbox/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/sandbox/test_enc_ogg.py b/tests/sandbox/test_enc_ogg.py deleted file mode 100644 index b6be599..0000000 --- a/tests/sandbox/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/sandbox/test_enc_webm.py b/tests/sandbox/test_enc_webm.py deleted file mode 100644 index 321d386..0000000 --- a/tests/sandbox/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/sandbox/test_flac.py b/tests/sandbox/test_flac.py deleted file mode 100644 index ee590c4..0000000 --- a/tests/sandbox/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/sandbox/test_limsi_sad.py b/tests/sandbox/test_limsi_sad.py deleted file mode 100644 index 2c54070..0000000 --- a/tests/sandbox/test_limsi_sad.py +++ /dev/null @@ -1,8 +0,0 @@ -# -*- coding: utf-8 -*- - -import timeside - -decoder = timeside.decoder.FileDecoder('/home/momo/music_local/test/sweep.wav') -analyzer = timeside.analyzer.LimsiSad('etape') -(decoder | analyzer).run() -print analyzer.results() diff --git a/tests/sandbox/test_live.py b/tests/sandbox/test_live.py deleted file mode 100644 index 2a9e79e..0000000 --- a/tests/sandbox/test_live.py +++ /dev/null @@ -1,28 +0,0 @@ -# -*- coding: utf-8 -*- - -import timeside -import matplotlib.pyplot as plt -import numpy as np - - -d = timeside.decoder.LiveDecoder(num_buffers=256) -w = timeside.analyzer.Waveform() -s = timeside.analyzer.Spectrogram() -m = timeside.encoder.Mp3Encoder('/tmp/test_live.mp3', overwrite=True) -v = timeside.encoder.VorbisEncoder('/tmp/test_live.ogg', overwrite=True) - -(d | w | s | m | v).run() - -plt.figure(1) -plt.plot(w.results['waveform_analyzer'].time, w.results['waveform_analyzer'].data) - -plt.figure(2) -sr = s.results['spectrogram_analyzer'] -N = sr.parameters['FFT_SIZE'] -plt.imshow(20 * np.log10(sr.data.T), - origin='lower', - extent=[sr.time[0], sr.time[-1], 0, - (N // 2 + 1) / N * sr.frame_metadata.samplerate], - aspect='auto') - -plt.show() diff --git a/tests/sandbox/test_lolevel.py b/tests/sandbox/test_lolevel.py deleted file mode 100644 index 421ce95..0000000 --- a/tests/sandbox/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/sandbox/test_lolevel_streaming.py b/tests/sandbox/test_lolevel_streaming.py deleted file mode 100644 index e0f6e2b..0000000 --- a/tests/sandbox/test_lolevel_streaming.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import * -from timeside.decoder.file import FileDecoder -from timeside.encoder import Mp3Encoder - -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, overwrite=True) -encoder.setup(channels=channels, samplerate=samplerate, - blocksize=decoder.blocksize(), totalframes=decoder.totalframes()) -while True: - encoder.process(*decoder.process()) - if streaming: - f.write(encoder.chunk) - if encoder.eod: - break - -f.close() -print encoder.pipe - -import os -dest1_size = os.path.getsize(dest1) -dest2_size = os.path.getsize(dest2) - -print "sizes : %d , %d" % (dest1_size, dest2_size) - -assert os.path.getsize(dest1)==os.path.getsize(dest2) diff --git a/tests/sandbox/test_lolevel_streaming_mp3.py b/tests/sandbox/test_lolevel_streaming_mp3.py deleted file mode 100644 index 1039ad2..0000000 --- a/tests/sandbox/test_lolevel_streaming_mp3.py +++ /dev/null @@ -1,45 +0,0 @@ -# -*- coding: utf-8 -*- - -import os, sys, time - -from timeside.core import * -from timeside.decoder import * -from timeside.analyzer import * -from timeside.encoder import * -from timeside.api import * - - -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - source= os.path.join(os.path.dirname(__file__), "../samples/sweep.wav") - -streaming = True - -dest1 = "/tmp/test_filesink.mp3" -dest2 = "/tmp/test_appsink.mp3" -f = open(dest2,'w') - -decoder = FileDecoder(source) -decoder.setup() - -encoder = Mp3Encoder(dest1, streaming=streaming, overwrite=True) -encoder.setup(channels=decoder.channels(), samplerate=decoder.samplerate(), - blocksize=decoder.blocksize(), totalframes=decoder.totalframes()) - -print encoder.pipe - -while True: - encoder.process(*decoder.process()) - # time.sleep(0.1) - if streaming: - f.write(encoder.chunk) - if encoder.eod: - break - -decoder.release() -encoder.release() -f.close() - -os.system('ls -tl /tmp/test*') \ No newline at end of file diff --git a/tests/sandbox/test_lolevel_streaming_threaded.py b/tests/sandbox/test_lolevel_streaming_threaded.py deleted file mode 100644 index 1e19dab..0000000 --- a/tests/sandbox/test_lolevel_streaming_threaded.py +++ /dev/null @@ -1,50 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import * -from timeside.decoder.file import FileDecoder -from timeside.encoder import Mp3Encoder - -import sys -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - audio_file = '../samples/sweep.flac' - source = os.path.join(os.path.dirname(__file__), audio_file) - -#source = '/home/thomas/data/CNRSMH_E_1985_001_001_001_04.wav' -decoder = FileDecoder(source) - -print "Creating decoder with id=%s for: %s" % (decoder.id(), source) - -dest1 = "/tmp/test_filesink.mp3" -dest2 = "/tmp/test_appsink.mp3" -f = open(dest2, 'w') - - -streaming = True -encoder = Mp3Encoder(dest1, streaming=streaming, overwrite=True) - -pipe = (decoder | encoder) -print pipe -#pipe.run() - -for chunk in pipe.stream(): - f.write(chunk) -#while True: -# encoder.process(*decoder.process()) -# if streaming: -# f.write(encoder.chunk) -# if encoder.eod: -# break - -f.close() -#print encoder.pipe - -import os -dest1_size = os.path.getsize(dest1) -dest2_size = os.path.getsize(dest2) - -print "Filesink filesize: %d" % dest1_size -print "Appsink filesize: %d" % dest2_size -#assert os.path.getsize(dest1) == os.path.getsize(dest2) diff --git a/tests/sandbox/test_lolevel_streaming_threaded_ogg.py b/tests/sandbox/test_lolevel_streaming_threaded_ogg.py deleted file mode 100644 index 7b41879..0000000 --- a/tests/sandbox/test_lolevel_streaming_threaded_ogg.py +++ /dev/null @@ -1,54 +0,0 @@ -# -*- coding: utf-8 -*- - -from timeside.core import * -from timeside.decoder.file import FileDecoder -from timeside.encoder import Mp3Encoder, VorbisEncoder - -import sys -if len(sys.argv) > 1: - source = sys.argv[1] -else: - import os.path - audio_file = '../samples/sweep.flac' - source = os.path.join(os.path.dirname(__file__), audio_file) - -decoder = FileDecoder(audio_file) - -print "Creating decoder with id=%s for: %s" % (decoder.id(), audio_file) - -dest1 = "/tmp/test_filesink.ogg" -dest2 = "/tmp/test_appsink.ogg" -f = open(dest2, 'w') - - -streaming = True -encoder = VorbisEncoder(dest1, streaming=streaming, overwrite=True) - -pipe = (decoder | encoder) -print pipe -#pipe.run() - -for chunk in pipe.stream(): - f.write(chunk) -#while True: -# encoder.process(*decoder.process()) -# if streaming: -# f.write(encoder.chunk) -# if encoder.eod: -# break - -f.close() -#print encoder.pipe - -import os -dest1_size = os.path.getsize(dest1) -dest2_size = os.path.getsize(dest2) - -print "sizes : %d , %d" % (dest1_size, dest2_size) - -assert os.path.getsize(dest1) == os.path.getsize(dest2) - -# Sometime randomly freeze -# Appsink file is always 1 buffer longer than filesink -# TODO : Try to transcode with a pure gstreamer pipe to see the file length -# maybe appsink is fine but filesink not ? just to be checked diff --git a/tests/sandbox/test_lolevel_streaming_vorbis.py b/tests/sandbox/test_lolevel_streaming_vorbis.py deleted file mode 100644 index ecc3d3f..0000000 --- a/tests/sandbox/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/sandbox/test_mp3.py b/tests/sandbox/test_mp3.py deleted file mode 100644 index 5d5fe22..0000000 --- a/tests/sandbox/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/sandbox/test_mp3_2.py b/tests/sandbox/test_mp3_2.py deleted file mode 100644 index 5d5fe22..0000000 --- a/tests/sandbox/test_mp3_2.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/sandbox/test_mp3_3.py b/tests/sandbox/test_mp3_3.py deleted file mode 100644 index 13b7159..0000000 --- a/tests/sandbox/test_mp3_3.py +++ /dev/null @@ -1,22 +0,0 @@ -# -*- coding: utf-8 -*- - -import sys -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(sys.argv[-1]) - -encoder = timeside.encoder.Mp3Encoder('/tmp/output.mp3', overwrite=True) -encoder.set_metadata(metadata) - -(decoder | encoder).run() diff --git a/tests/sandbox/test_parent.py b/tests/sandbox/test_parent.py deleted file mode 100644 index 84df1fc..0000000 --- a/tests/sandbox/test_parent.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- 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() - -pipe = d | a -pipe.run() - -print pipe.results - -a.results.to_hdf5('../results/sweep_odf.hdf5') diff --git a/tests/sandbox/test_pipe.py b/tests/sandbox/test_pipe.py deleted file mode 100644 index 629b3e9..0000000 --- a/tests/sandbox/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/sandbox/test_results.py b/tests/sandbox/test_results.py deleted file mode 100644 index f489b38..0000000 --- a/tests/sandbox/test_results.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- 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 deleted file mode 100644 index a16874e..0000000 --- a/tests/sandbox/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/sandbox/test_spectrogram2.py b/tests/sandbox/test_spectrogram2.py deleted file mode 100644 index 762f5ac..0000000 --- a/tests/sandbox/test_spectrogram2.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- 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 deleted file mode 100644 index 19fcf9b..0000000 --- a/tests/sandbox/test_spectrogram3.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- 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 deleted file mode 100644 index 53818cd..0000000 --- a/tests/sandbox/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/sandbox/test_wav.py b/tests/sandbox/test_wav.py deleted file mode 100644 index 077a01e..0000000 --- a/tests/sandbox/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/sandbox/test_wav_resample.py b/tests/sandbox/test_wav_resample.py deleted file mode 100644 index e30f103..0000000 --- a/tests/sandbox/test_wav_resample.py +++ /dev/null @@ -1,12 +0,0 @@ -# -*- coding: utf-8 -*- - -import timeside -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_48000.wav") - -decoder = timeside.decoder.FileDecoder(source) -decoder.output_samplerate = 48000 -encoder = timeside.encoder.WavEncoder(dest) -(decoder | encoder).run() diff --git a/tests/sandbox/test_waveform.py b/tests/sandbox/test_waveform.py deleted file mode 100644 index a028df5..0000000 --- a/tests/sandbox/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/test_waveform3.py b/tests/sandbox/test_waveform3.py deleted file mode 100644 index 74603cb..0000000 --- a/tests/sandbox/test_waveform3.py +++ /dev/null @@ -1,26 +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 = '/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 deleted file mode 100644 index 41e7a82..0000000 --- a/tests/sandbox/test_waveform4.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- 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 deleted file mode 100644 index 6b343d1..0000000 --- a/tests/sandbox/test_waveform_centroid.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 = 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 deleted file mode 100644 index 7fde73c..0000000 --- a/tests/sandbox/test_waveform_contour.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 = 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 deleted file mode 100644 index ea95a4a..0000000 --- a/tests/sandbox/test_waveform_simple.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() - (decoder | waveform).run() - print 'frames per pixel = ', waveform.samples_per_pixel - print "render waveform to: %s" % image - waveform.render(image) diff --git a/timeside/effects/gain.py b/timeside/effects/gain.py new file mode 100644 index 0000000..2c69222 --- /dev/null +++ b/timeside/effects/gain.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