--- /dev/null
+# -*- 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
+
--- /dev/null
+# -*- 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()
+++ /dev/null
-# -*- 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
--- /dev/null
+# -*- 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
--- /dev/null
+# -*- 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()
from timeside.tools import *
from gst import _gst as gst
+import threading
+
+
+class MainloopThread(threading.Thread):
+
+ def __init__(self, mainloop):
+ threading.Thread.__init__(self)
+ self.mainloop = mainloop
+
+ def run(self):
+ self.mainloop.run()
class GstEncoder(Processor):
if not self.filename and not self.streaming:
raise Exception('Must give an output')
- import threading
self.end_cond = threading.Condition(threading.Lock())
-
self.eod = False
self.metadata = None
self.num_samples = 0
self.bus.add_signal_watch()
self.bus.connect("message", self._on_message_cb)
- import threading
- class MainloopThread(threading.Thread):
- def __init__(self, mainloop):
- threading.Thread.__init__(self)
- self.mainloop = mainloop
-
- def run(self):
- self.mainloop.run()
self.mainloop = gobject.MainLoop()
self.mainloopthread = MainloopThread(self.mainloop)
self.mainloopthread.start()
self.end_cond.notify()
self.end_cond.release()
+ @interfacedoc
+ def set_metadata(self, metadata):
+ self.metadata = metadata
+
@interfacedoc
def process(self, frames, eod=False):
self.eod = eod
self.num_samples += frames.shape[0]
else:
self.num_samples += self.blocksize()
- buf = numpy_array_to_gst_buffer(frames, frames.shape[0],self.num_samples, self.samplerate())
+ buf = numpy_array_to_gst_buffer(frames, frames.shape[0], self.num_samples, self.samplerate())
self.src.emit('push-buffer', buf)
if self.eod:
self.src.emit('end-of-stream')
# Run doctest from __main__ and unittest from test_analyzer_preprocessors
from tests import test_encoding, test_transcoding
from tests.unit_timeside import run_test_module
- run_test_module([test_encoding, test_transcoding])
\ No newline at end of file
+ run_test_module([test_encoding, test_transcoding])
from timeside.api import IEncoder
from timeside.tools import *
-import mutagen
class Mp3Encoder(GstEncoder):
""" gstreamer-based mp3 encoder """
def mime_type():
return "audio/mpeg"
- @interfacedoc
- def set_metadata(self, metadata):
- self.metadata = metadata
-
def write_metadata(self):
"""Write all ID3v2.4 tags to file from self.metadata"""
+ import mutagen
from mutagen import id3
+
id3 = id3.ID3(self.filename)
for tag in self.metadata.keys():
value = self.metadata[tag]
id3.save()
except:
raise IOError('EncoderError: cannot write tags')
-
-
gobject.threads_init()
-def numpy_array_to_gst_buffer(frames, CHUNK_SIZE, num_samples, SAMPLE_RATE):
+def numpy_array_to_gst_buffer(frames, chunk_size, num_samples, sample_rate):
from gst import Buffer
""" gstreamer buffer to numpy array conversion """
buf = Buffer(getbuffer(frames.astype("float32")))
#Set its timestamp and duration
- buf.timestamp = gst.util_uint64_scale(num_samples, gst.SECOND, SAMPLE_RATE)
- buf.duration = gst.util_uint64_scale(CHUNK_SIZE, gst.SECOND, SAMPLE_RATE)
-
+ buf.timestamp = gst.util_uint64_scale(num_samples, gst.SECOND, sample_rate)
+ buf.duration = gst.util_uint64_scale(chunk_size, gst.SECOND, sample_rate)
return buf