Showing the changes to python/aubio (1 of 1 file). Show all
Unified · Split
| @@ -23,7 +23,7 @@ __LICENSE__ = """\ · 22 unmodified lines | |||
| 23 | 23 | ||
| 24 | def audio_to_array(filename): | 24 | def audio_to_array(filename): |
| 25 | import aubio.aubioclass | 25 | import aubio.aubioclass |
| 26 | import numarray | 26 | from numpy import arange |
| 27 | hopsize = 2048 | 27 | hopsize = 2048 |
| 28 | filei = aubio.aubioclass.sndfile(filename) | 28 | filei = aubio.aubioclass.sndfile(filename) |
| 29 | framestep = 1/(filei.samplerate()+0.) | 29 | framestep = 1/(filei.samplerate()+0.) |
| @@ -39,7 +39,7 @@ def audio_to_array(filename): · 9 unmodified lines | |||
| 39 | while (curpos < readsize): | 39 | while (curpos < readsize): |
| 40 | data.append(myvec.get(curpos,i)) | 40 | data.append(myvec.get(curpos,i)) |
| 41 | curpos+=1 | 41 | curpos+=1 |
| 42 | time = numarray.arange(len(data))*framestep | 42 | time = arange(len(data))*framestep |
| 43 | return time,data | 43 | return time,data |
| 44 | 44 | ||
| 45 | def plot_audio(filenames, g, options): | 45 | def plot_audio(filenames, g, options): |
| @@ -143,29 +143,29 @@ def plot_spec(filename, g, options): · 97 unmodified lines | |||
| 143 | 143 | ||
| 144 | def downsample_audio(time,data,maxpoints=10000): | 144 | def downsample_audio(time,data,maxpoints=10000): |
| 145 | """ resample audio data to last only maxpoints """ | 145 | """ resample audio data to last only maxpoints """ |
| 146 | import numarray | 146 | from numpy import array, resize |
| 147 | length = len(time) | 147 | length = len(time) |
| 148 | downsample = length/maxpoints | 148 | downsample = length/maxpoints |
| 149 | if downsample == 0: downsample = 1 | 149 | if downsample == 0: downsample = 1 |
| 150 | x = numarray.array(time).resize(length)[0:-1:downsample] | 150 | x = resize(array(time),length)[0:-1:downsample] |
| 151 | y = numarray.array(data).resize(length)[0:-1:downsample] | 151 | y = resize(array(data),length)[0:-1:downsample] |
| 152 | return x,y | 152 | return x,y |
| 153 | 153 | ||
| 154 | def make_audio_plot(time,data,maxpoints=10000): | 154 | def make_audio_plot(time,data,maxpoints=10000): |
| 155 | """ create gnuplot plot from an audio file """ | 155 | """ create gnuplot plot from an audio file """ |
| 156 | import Gnuplot, Gnuplot.funcutils | 156 | import Gnuplot, Gnuplot.funcutils |
| 157 | x,y = downsample_audio(time,data,maxpoints=maxpoints) | 157 | x,y = downsample_audio(time,data,maxpoints=maxpoints) |
| 158 | return Gnuplot.Data(x,y,with='lines') | 158 | return Gnuplot.Data(x,y,with_='lines') |
| 159 | 159 | ||
| 160 | def make_audio_envelope(time,data,maxpoints=10000): | 160 | def make_audio_envelope(time,data,maxpoints=10000): |
| 161 | """ create gnuplot plot from an audio file """ | 161 | """ create gnuplot plot from an audio file """ |
| 162 | import numarray | 162 | from numpy import array |
| 163 | import Gnuplot, Gnuplot.funcutils | 163 | import Gnuplot, Gnuplot.funcutils |
| 164 | bufsize = 500 | 164 | bufsize = 500 |
| 165 | x = [i.mean() for i in numarray.array(time).resize(len(time)/bufsize,bufsize)] | 165 | x = [i.mean() for i in resize(array(time), (len(time)/bufsize,bufsize))] |
| 166 | y = [i.mean() for i in numarray.array(data).resize(len(time)/bufsize,bufsize)] | 166 | y = [i.mean() for i in resize(array(data), (len(time)/bufsize,bufsize))] |
| 167 | x,y = downsample_audio(x,y,maxpoints=maxpoints) | 167 | x,y = downsample_audio(x,y,maxpoints=maxpoints) |
| 168 | return Gnuplot.Data(x,y,with='lines') | 168 | return Gnuplot.Data(x,y,with_='lines') |
| 169 | 169 | ||
| 170 | def gnuplot_addargs(parser): | 170 | def gnuplot_addargs(parser): |
| 171 | """ add common gnuplot argument to OptParser object """ | 171 | """ add common gnuplot argument to OptParser object """ |