Showing the changes to python (1 of 7 files). Show all
Unified · Split
| @@ -108,15 +108,10 @@ def audio_to_array(filename): · 107 unmodified lines | |||
| 108 | while (curpos < readsize): | 108 | while (curpos < readsize): |
| 109 | data.append(myvec.get(curpos,i)) | 109 | data.append(myvec.get(curpos,i)) |
| 110 | curpos+=1 | 110 | curpos+=1 |
| 111 | # FIXME again for the last frame | ||
| 112 | curpos = 0 | ||
| 113 | while (curpos < readsize): | ||
| 114 | data.append(myvec.get(curpos,i)) | ||
| 115 | curpos+=1 | ||
| 116 | time = arange(len(data))*framestep | 111 | time = arange(len(data))*framestep |
| 117 | return time,data | 112 | return time,data |
| 118 | 113 | ||
| 119 | def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None, task=audio_to_array): | 114 | def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None): |
| 120 | g = Gnuplot.Gnuplot(debug=1, persist=1) | 115 | g = Gnuplot.Gnuplot(debug=1, persist=1) |
| 121 | d = [] | 116 | d = [] |
| 122 | todraw = len(filenames) | 117 | todraw = len(filenames) |
| @@ -124,8 +119,7 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None, task=aud · 1 unmodified line | |||
| 124 | xsize = 1./todraw | 119 | xsize = 1./todraw |
| 125 | g.gnuplot('set multiplot;') | 120 | g.gnuplot('set multiplot;') |
| 126 | while (len(filenames)): | 121 | while (len(filenames)): |
| 127 | b,a = task(filenames.pop(0)) | 122 | d.append(plot_audio_make(filenames.pop(0))) |
| 128 | d.append(Gnuplot.Data(b,a)) | ||
| 129 | if not noaxis and todraw==1: | 123 | if not noaxis and todraw==1: |
| 130 | g.xlabel('Time (s)') | 124 | g.xlabel('Time (s)') |
| 131 | g.ylabel('Amplitude') | 125 | g.ylabel('Amplitude') |
| @@ -140,3 +134,12 @@ def plot_audio(filenames, fileout=None, start=0, end=None, noaxis=None, task=aud · 8 unmodified lines | |||
| 140 | if fileout != None: | 134 | if fileout != None: |
| 141 | g.hardcopy(fileout, enhanced=1, color=0) | 135 | g.hardcopy(fileout, enhanced=1, color=0) |
| 142 | 136 | ||
| 137 | def make_audio_plot(time,data,maxpoints=10000): | ||
| 138 | """ create gnuplot plot from an audio file """ | ||
| 139 | import numarray | ||
| 140 | length = len(time) | ||
| 141 | downsample = length/maxpoints | ||
| 142 | if downsample == 0: downsample = 1 | ||
| 143 | x = numarray.array(time).resize(length)[0:-1:downsample] | ||
| 144 | y = numarray.array(data).resize(length)[0:-1:downsample] | ||
| 145 | return Gnuplot.Data(x,y,with='lines') | ||