from core import *
from waveform import *
from spectrogram import *
-from waveform_joydiv import *
-from waveform_awdio import *
+from waveform_contour_bk import *
+from waveform_contour_wh import *
+from waveform_simple import *
'waveform': [(173,173,173), (147,149,196), (77,80,138), (108,66,0)],
'spectrogram': [(0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100),
(224,224,44), (255,60,30), (255,255,255)]
- },
+ },
'awdio': {
'waveform': [(255,255,255), (255,255,255), (255,255,255), (255,255,255)],
'spectrogram': [(0, 0, 0), (58/4,68/4,65/4), (80/2,100/2,153/2), (90,180,100),
(224,224,44), (255,60,30), (255,255,255)]
- },
+ },
}
def draw_anti_aliased_pixels(self, x, y1, y2, color):
""" vertical anti-aliasing at y1 and y2 """
-
+
y_max = max(y1, y2)
y_max_int = int(y_max)
alpha = y_max - y_max_int
def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
-
+
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
class WaveformImageJoyContour(WaveformImage):
- def __init__(self, image_width, image_height, nframes, samplerate, fft_size, bg_color, color_scheme, ndiv=1, symetry=None):
- WaveformImage.__init__(self, image_width, image_height, nframes, samplerate, fft_size, bg_color, color_scheme)
+ def __init__(self, image_width, image_height, nframes, samplerate,
+ fft_size, bg_color, color_scheme, ndiv=1, symetry=None, color_offset=160):
+ WaveformImage.__init__(self, image_width, image_height, nframes, samplerate,
+ fft_size, bg_color, color_scheme)
self.contour = numpy.zeros(self.image_width)
self.centroids = numpy.zeros(self.image_width)
self.ndiv = ndiv
self.x = numpy.r_[0:self.image_width-1:1]
self.dx1 = self.x[1]-self.x[0]
self.symetry = symetry
+ self.color_offset = color_offset
def get_peaks_contour(self, x, peaks, spectral_centroid=None):
self.contour[x] = numpy.max(peaks)
height = int(self.image_height/2)
else:
height = self.image_height
-
+
# Multicurve rotating
for i in range(0,self.ndiv):
self.previous_x, self.previous_y = None, None
#bright_color = 255
bright_color = int(255*(1-float(i)/(self.ndiv*2)))
- bright_color = 255-bright_color+160
+ bright_color = 255-bright_color+self.color_offset
#line_color = self.color_lookup[int(self.centroids[j]*255.0)]
line_color = (bright_color,bright_color,bright_color)
curve = (height-1)*contour
#curve = contour*(height-2)/2+height/2
-
+
for x in self.x:
x = int(x)
y = curve[x]
def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
-
+
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
# middle line (0 for none)
self.pixel[x, self.image_height/2] = tuple(map(lambda p: p+a, self.pixel[x, self.image_height/2]))
#self.image = self.image.transpose(Image.FLIP_TOP_BOTTOM)
self.image.save(filename)
-
+
def release(self):
pass
-
+
class WaveformImageSimple(object):
""" Builds a PIL image representing a waveform of the audio stream.
Adds pixels iteratively thanks to the adapter providing fixed size frame buffers.
self.previous_x, self.previous_y = None, None
self.frame_cursor = 0
self.pixel_cursor = 0
-
+
def normalize(self, contour):
contour = contour-min(contour)
return contour/max(contour)
-
+
def peaks(self, samples):
""" Find the minimum and maximum peak of the samples.
Returns that pair in the order they were found.
return (min_value, max_value)
else:
return (max_value, min_value)
-
+
def draw_peaks(self, x, peaks):
""" draw 2 peaks at x using the spectral_centroid for color """
y1 = self.image_height * 0.5 - peaks[0] * (self.image_height - 4) * 0.5
y2 = self.image_height * 0.5 - peaks[1] * (self.image_height - 4) * 0.5
-
+
if self.previous_y and x < self.image_width-1:
if y1 < y2:
self.draw.line((x, 0, x, y1), self.line_color)
def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
-
+
def save(self, filename):
""" Apply last 2D transforms and write all pixels to the file. """
-
+
# middle line (0 for none)
a = 1
for x in range(self.image_width):
self.pixel[x, self.image_height/2] = tuple(map(lambda p: p+a, self.pixel[x, self.image_height/2]))
self.image.save(filename)
-
+
def release(self):
pass
-
+
class SpectrogramImage(object):
""" 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."""
(spectral_centroid, db_spectrum) = self.spectrum.process(samples, True)
self.draw_spectrum(self.pixel_cursor, db_spectrum)
self.pixel_cursor += 1
-
+
def watermark(self, text, color=None, opacity=.6, margin=(10,10)):
#self.image = im_watermark(self.image, text, color=color, opacity=opacity, margin=margin)
pass
def release(self):
pass
-
+
class Noise(object):
"""A class that mimics audiolab.sndfile but generates noise instead of reading
a wave file. Additionally it can be told to have a "broken" header and thus crashing
+++ /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 Processor, implements, interfacedoc, FixedSizeInputAdapter
-from timeside.api import IGrapher
-from timeside.grapher.core import *
-
-
-class WaveformAwdio(Processor):
- implements(IGrapher)
-
- FFT_SIZE = 0x400
-
- @interfacedoc
- def __init__(self, width=572, height=74, bg_color=None, color_scheme='awdio'):
- self.width = width
- self.height = height
- self.bg_color = bg_color
- self.color_scheme = color_scheme
-
- @staticmethod
- @interfacedoc
- def id():
- return "waveform_awdio"
-
- @staticmethod
- @interfacedoc
- def name():
- return "Waveform Awdio"
-
- @interfacedoc
- def set_colors(self, background, scheme):
- self.bg_color = background
- self.color_scheme = scheme
-
- @interfacedoc
- def setup(self, channels=None, samplerate=None, nframes=None):
- super(WaveformAwdio, self).setup(channels, samplerate, nframes)
- self.graph = WaveformImageSimple(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE,
- bg_color=self.bg_color, color_scheme=self.color_scheme)
-
- @interfacedoc
- def process(self, frames, eod=False):
- self.graph.process(frames, eod)
- return frames, eod
-
- @interfacedoc
- def render(self, output):
- if output:
- self.graph.save(output)
- return self.graph.image
-
- def watermark(self, text, font=None, color=(255, 255, 255), opacity=.6, margin=(5,5)):
- self.graph.watermark(text, color=color, opacity=opacity, margin=margin)
--- /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 Processor, implements, interfacedoc, FixedSizeInputAdapter
+from timeside.api import IGrapher
+from timeside.grapher.core import *
+
+
+class WaveformContourBlack(Processor):
+ implements(IGrapher)
+
+ FFT_SIZE = 0x400
+
+ @interfacedoc
+ def __init__(self, width=1024, height=256, bg_color=(0,0,0), color_scheme='default'):
+ self.width = width
+ self.height = height
+ self.bg_color = bg_color
+ self.color_scheme = color_scheme
+ self.graph = None
+ self.ndiv = 4
+ self.symetry = True
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return "waveform_contour_bk"
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return "Contour black"
+
+ @interfacedoc
+ def set_colors(self, background, scheme):
+ self.bg_color = background
+ self.color_scheme = scheme
+
+ @interfacedoc
+ def setup(self, channels=None, samplerate=None, nframes=None):
+ super(WaveformContourBlack, self).setup(channels, samplerate, nframes)
+ self.graph = WaveformImageJoyContour(self.width, self.height, self.nframes(),
+ self.samplerate(), self.FFT_SIZE,
+ bg_color=self.bg_color,
+ color_scheme=self.color_scheme,
+ ndiv=self.ndiv, symetry=self.symetry)
+
+ @interfacedoc
+ def process(self, frames, eod=False):
+ self.graph.process(frames, eod)
+ return frames, eod
+
+ @interfacedoc
+ def render(self, output):
+ if output:
+ self.graph.save(output)
+ return self.graph.image
+
+ def release(self):
+ self.graph.release()
+
+ def watermark(self, text, font=None, color=(255, 255, 255), opacity=.6, margin=(5,5)):
+ self.graph.watermark(text, color=color, opacity=opacity, margin=margin)
+++ /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 Processor, implements, interfacedoc, FixedSizeInputAdapter
-from timeside.api import IGrapher
-from timeside.grapher.core import *
-
-
-class WaveformJoyDiv(Processor):
- implements(IGrapher)
-
- FFT_SIZE = 0x400
-
- @interfacedoc
- def __init__(self, width=1024, height=256, bg_color=(0,0,0), color_scheme='default'):
- self.width = width
- self.height = height
- self.bg_color = bg_color
- self.color_scheme = color_scheme
- self.graph = None
- self.ndiv = 4
- self.symetry = True
-
- @staticmethod
- @interfacedoc
- def id():
- return "waveform_joydiv"
-
- @staticmethod
- @interfacedoc
- def name():
- return "Waveform JoyDiv"
-
- @interfacedoc
- def set_colors(self, background, scheme):
- self.bg_color = background
- self.color_scheme = scheme
-
- @interfacedoc
- def setup(self, channels=None, samplerate=None, nframes=None):
- super(WaveformJoyDiv, self).setup(channels, samplerate, nframes)
- self.graph = WaveformImageJoyContour(self.width, self.height, self.nframes(), self.samplerate(), self.FFT_SIZE,
- bg_color=self.bg_color, color_scheme=self.color_scheme, ndiv=self.ndiv, symetry=self.symetry)
-
- @interfacedoc
- def process(self, frames, eod=False):
- self.graph.process(frames, eod)
- return frames, eod
-
- @interfacedoc
- def render(self, output):
- if output:
- self.graph.save(output)
- return self.graph.image
-
- def release(self):
- self.graph.release()
-
- def watermark(self, text, font=None, color=(255, 255, 255), opacity=.6, margin=(5,5)):
- self.graph.watermark(text, color=color, opacity=opacity, margin=margin)
--- /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 Processor, implements, interfacedoc, FixedSizeInputAdapter
+from timeside.api import IGrapher
+from timeside.grapher.core import *
+
+
+class WaveformAwdio(Processor):
+ implements(IGrapher)
+
+ FFT_SIZE = 0x400
+
+ @interfacedoc
+ def __init__(self, width=572, height=74, bg_color=None, color_scheme='awdio'):
+ self.width = width
+ self.height = height
+ self.bg_color = bg_color
+ self.color_scheme = color_scheme
+
+ @staticmethod
+ @interfacedoc
+ def id():
+ return "waveform_simple"
+
+ @staticmethod
+ @interfacedoc
+ def name():
+ return "Waveform simple"
+
+ @interfacedoc
+ def set_colors(self, background, scheme):
+ self.bg_color = background
+ self.color_scheme = scheme
+
+ @interfacedoc
+ def setup(self, channels=None, samplerate=None, nframes=None):
+ super(WaveformAwdio, self).setup(channels, samplerate, nframes)
+ self.graph = WaveformImageSimple(self.width, self.height, self.nframes(),
+ self.samplerate(), self.FFT_SIZE,
+ bg_color=self.bg_color,
+ color_scheme=self.color_scheme)
+
+ @interfacedoc
+ def process(self, frames, eod=False):
+ self.graph.process(frames, eod)
+ return frames, eod
+
+ @interfacedoc
+ def render(self, output):
+ if output:
+ self.graph.save(output)
+ return self.graph.image
+
+ def watermark(self, text, font=None, color=(255, 255, 255), opacity=.6, margin=(5,5)):
+ self.graph.watermark(text, color=color, opacity=opacity, margin=margin)