return frames, eod
def post_process(self):
-
melenergy = self.new_result(data_mode='value', time_mode='framewise')
-
- # Metadata
melenergy.parameters = dict(n_filters=self.n_filters,
n_coeffs=self.n_coeffs)
- # Set Data
melenergy.data_object.value = self.melenergy_results
-
self._results.add(melenergy)
return frames, eod
def post_process(self):
- # MFCC
mfcc = self.new_result(data_mode='value', time_mode='framewise')
-
mfcc.parameters = dict(n_filters=self.n_filters,
n_coeffs=self.n_coeffs)
-
mfcc.data_object.value = self.mfcc_results
self._results.add(mfcc)
return frames, eod
def post_process(self):
- # set Result
pitch = self.new_result(data_mode='value', time_mode='framewise')
# parameters : None # TODO check with Piem "default" and "freq" in
# setup
- # Set Data
pitch.data_object.value = self.pitches
-
self._results.add(pitch)
# Set metadata
res_specdesc.id_metadata.id += '.' + method
res_specdesc.id_metadata.name = ' ' + method
-
res_specdesc.data_object.value = self.specdesc_results[method]
self._results.add(res_specdesc)
onsets.data_object.label = numpy.ones(len(self.onsets))
onsets.data_object.time = self.onsets
-
onsets.label_metadata.label = {1: 'Onset'}
self._results.add(onsets)
def post_process(self):
dc_result = self.new_result(data_mode='value', time_mode='global')
-
- # Set Data
dc_result.data_object.value = numpy.round(
numpy.mean(100 * self.values), 3)
self._results.add(dc_result)
for samples in downsample_blocking(frames, self.input_stepsize):
#time = self.block_read * self.input_stepsize * 1. / self.samplerate()
self.values.append(np.abs(np.fft.rfft(samples, self.FFT_SIZE)))
-
return frames, eod
def post_process(self):
- # set Result
spectrogram = self.new_result(data_mode='value', time_mode='framewise')
-
- # parameters :
spectrogram.parameters = {'FFT_SIZE': self.FFT_SIZE}
-
- # Set Data
spectrogram.data_object.value = self.values
-
self._results.add(spectrogram)
def process(self, frames, eod=False):
for samples in downsample_blocking(frames, self.input_blocksize):
self.values.append(samples)
-
return frames, eod
def post_process(self):
- # set Result
waveform = self.new_result(data_mode='value', time_mode='framewise')
-
- # Set Data
waveform.data_object.value = np.asarray(self.values).flatten()
-
self._results.add(waveform)
from waveform_contour_black import *
from waveform_contour_white import *
from spectrogram import *
+from spectrogram_linear import *
super(Spectrogram, self).__init__(width, height, bg_color, color_scheme)
self.colors = default_color_schemes[color_scheme]['spectrogram']
self.pixels = []
-
- # generate the lookup which translates y-coordinate to fft-bin
self.y_to_bin = []
- f_min = float(self.lower_freq)
- f_max = float(self.higher_freq)
- y_min = math.log10(f_min)
- y_max = math.log10(f_max)
- for y in range(self.image_height):
- freq = math.pow(10.0, y_min + y / (self.image_height - 1.0) *(y_max - y_min))
- fft_bin = freq / 22050.0 * (self.fft_size/2 + 1)
- if fft_bin < self.fft_size/2:
- alpha = fft_bin - int(fft_bin)
- self.y_to_bin.append((int(fft_bin), alpha * 255))
@staticmethod
@interfacedoc
super(Spectrogram, self).setup(channels, samplerate, blocksize, totalframes)
self.image = Image.new("P", (self.image_height, self.image_width))
self.image.putpalette(interpolate_colors(self.colors, True))
+ self.set_scale()
+
+ def set_scale(self):
+ """generate the lookup which translates y-coordinate to fft-bin"""
+
+ f_min = float(self.lower_freq)
+ f_max = float(self.higher_freq)
+ y_min = math.log10(f_min)
+ y_max = math.log10(f_max)
+ for y in range(self.image_height):
+ freq = math.pow(10.0, y_min + y / (self.image_height - 1.0) *(y_max - y_min))
+ fft_bin = freq / f_max * (self.fft_size/2 + 1)
+ if fft_bin < self.fft_size/2:
+ alpha = fft_bin - int(fft_bin)
+ self.y_to_bin.append((int(fft_bin), alpha * 255))
def draw_spectrum(self, x, spectrum):
for (index, alpha) in self.y_to_bin:
--- /dev/null
+# -*- coding: utf-8 -*-
+#
+# Copyright (c) 2007-2010 Guillaume Pellerin <yomguy@parisson.com>
+# Copyright (c) 2010 Olivier Guilyardi <olivier@samalyse.com>
+
+# This file is part of TimeSide.
+
+# TimeSide is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+
+# TimeSide is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with TimeSide. If not, see <http://www.gnu.org/licenses/>.
+
+
+from timeside.core import implements, interfacedoc
+from timeside.api import IGrapher
+from timeside.grapher.core import *
+from timeside.grapher.spectrogram import Spectrogram
+
+
+class SpectrogramLinear(Spectrogram):
+ """ Builds a PIL image representing a spectrogram of the audio stream (level vs. frequency vs. time).
+ Adds pixels iteratively thanks to the adapter providing fixed size frame buffers."""
+
+ implements(IGrapher)
+
+ @interfacedoc
+ def __init__(self, width=1024, height=256, bg_color=(0,0,0), color_scheme='default'):
+ super(SpectrogramLinear, self).__init__(width, height, bg_color, color_scheme)
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return "spectrogram_linear"
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return "Spectrogram linear"
+
+ @interfacedoc
+ def setup(self, channels=None, samplerate=None, blocksize=None, totalframes=None):
+ super(SpectrogramLinear, self).setup(channels, samplerate, blocksize, totalframes)
+
+ def set_scale(self):
+ """generate the lookup which translates y-coordinate to fft-bin"""
+
+ f_min = float(self.lower_freq)
+ f_max = float(self.higher_freq)
+ y_min = f_min
+ y_max = f_max
+ for y in range(self.image_height):
+ freq = y_min + y / (self.image_height - 1.0) *(y_max - y_min)
+ fft_bin = freq / f_max * (self.fft_size/2 + 1)
+ if fft_bin < self.fft_size/2:
+ alpha = fft_bin - int(fft_bin)
+ self.y_to_bin.append((int(fft_bin), alpha * 255))
numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve
scipy.signal.lfilter
-
Examples
--------
# TODO: the window parameter could be the window itself if an array instead of a string
-
if x.ndim != 1:
raise ValueError, "smooth only accepts 1 dimension arrays."
-
if x.size < window_len:
raise ValueError, "Input vector needs to be bigger than window size."
-
if window_len < 3:
return x
-
if not window in ['flat', 'hanning', 'hamming', 'bartlett', 'blackman']:
raise ValueError, "Window is on of 'flat', 'hanning', 'hamming', 'bartlett', 'blackman'"
- s=numpy.r_[2*x[0]-x[window_len:1:-1], x, 2*x[-1]-x[-1:-window_len:-1]]
+ s = numpy.r_[2*x[0]-x[window_len:1:-1], x, 2*x[-1]-x[-1:-window_len:-1]]
if window == 'flat': #moving average
w = numpy.ones(window_len,'d')
def im_watermark(im, inputtext, font=None, color=None, opacity=.6, margin=(30,30)):
- """
- imprints a PIL image with the indicated text in lower-right corner
- """
+ """imprints a PIL image with the indicated text in lower-right corner"""
if im.mode != "RGBA":
im = im.convert("RGBA")
textlayer = Image.new("RGBA", im.size, (0,0,0,0))
def normalize(contour):
contour = contour-min(contour)
return contour/max(contour)
-
-