From cc2d75b8da270de6b1c2d96f0bc8ba1af080bcd8 Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 3 Mar 2010 21:25:08 +0100 Subject: [PATCH] Aggiunto script per convertire file in wav e qualche modifica. --- Filtering/dwt | 21 +++++++++++++++++---- Filtering/shell.sh | 7 +++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100755 Filtering/shell.sh diff --git a/Filtering/dwt b/Filtering/dwt index ee2cc7b..dcf2eba 100755 --- a/Filtering/dwt +++ b/Filtering/dwt @@ -2,9 +2,11 @@ # -*- coding: utf-8 -*- # -import Filtering, pylab +import Filtering +from pylab import show, plot from numpy import array, sqrt, memmap, roll from numpy.linalg import norm +import time from optparse import OptionParser @@ -18,6 +20,8 @@ class DWT(): def __init__(self, filename, action = 'show', filewrite = 'rebuilt.pcm', filterbank = 'haar', depth = 4): + startingTime = time.time () + # Scelgo la filterbank da utilizzare if filterbank == 'haar': filterBank = Filtering.HaarFilterBank @@ -34,17 +38,23 @@ class DWT(): samples = self.LoadSamples (filename) wavelets = filterBank.Split (samples) + Output ("Decomposed in %f seconds" % (time.time() - startingTime)) + # Mostro la decomposizione se l'utente l'ha chiesto if action == 'show': self.Show (wavelets) if action is 'rebuild': + startingTime = time.time () rebuilt = filterBank.Rebuild (wavelets) + Output ("Rebuilt in %f seconds" % (time.time() - startingTime)) Output ("||rebuilt - samples|| = %f" % norm(rebuilt - samples[0:len(rebuilt)])) self.WriteSamples(rebuilt, filewrite) + + def LoadSamples(self, filename = "sunny.pcm"): """ Load the samples from an audio file @@ -70,12 +80,15 @@ class DWT(): """ scale = 1 offset = -90000 + # We plot only the first 2000 samples, to avoid memory + # being flooded with our data :) + toPlot = 1000000 for samples in wavelets[0:-1]: - pylab.plot (range(0, scale * len(samples), scale), samples + offset) + plot (range(0, toPlot, scale), samples[0:toPlot / scale] + offset) offset += 30000 scale = 2*scale - pylab.plot (range(0, int(0.5*scale*len(wavelets[-1])), int(0.5 * scale)), wavelets[-1] + offset) - pylab.show () + plot ( range(0, toPlot, int(0.5 * scale)), wavelets[-1][:2 * toPlot /scale] + offset) + show () if __name__ == "__main__": diff --git a/Filtering/shell.sh b/Filtering/shell.sh new file mode 100755 index 0000000..f328fa1 --- /dev/null +++ b/Filtering/shell.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [[ "$1" == "convert" ]]; then + ffmpeg -i "$2" -acodec pcm_s16le -ac 1 "$3" +else + aplay -r 44100 -f s16_le "$1" +fi -- 2.1.4