History

python/scripts/aubiocut: use slice_source_at_stamps

Paul Brossier committed 12 years ago

Commit bc24e9c1 parent 88432a91 file · +3 −37Browse files

Showing the changes to python/scripts/aubiocut (1 of 1 file). Show all

Unified · Split

python/scripts/aubiocut+3−37
@@ -166,43 +166,9 @@ if __name__ == '__main__': · 165 unmodified lines
166 # cutting pass166 # cutting pass
167 if options.cut and nstamps > 0:167 if options.cut and nstamps > 0:
168 # generate output filenames168 # generate output filenames
169 import os169 from aubio.slicing import slice_source_at_stamps
170 source_base_name, source_ext = os.path.splitext(os.path.basename(source_file))170 slice_source_at_stamps(source_file, timestamps,
171 if options.output_directory != None:171 output_dir = options.output_directory)
172 if not os.path.isdir(options.output_directory):
173 os.makedirs(options.output_directory)
174 source_base_name = os.path.join(options.output_directory, source_base_name)
175 def new_sink_name(source_base_name, timestamp):
176 return source_base_name + '_%02.3f' % (timestamp) + '.wav'
177 # reopen source file
178 s = source(source_file, samplerate, hopsize)
179 if samplerate == 0: samplerate = s.get_samplerate()
180 # create first sink at 0
181 g = sink(new_sink_name(source_base_name, 0.), samplerate)
182 total_frames = 0
183 # get next region
184 next_stamp = int(timestamps.pop(0))
185 while True:
186 vec, read = s()
187 remaining = next_stamp - total_frames
188 if remaining <= read:
189 # write remaining samples from current region
190 g(vec[0:remaining], remaining)
191 # close this file
192 del g
193 # create a new file for the new region
194 g = sink(new_sink_name(source_base_name, next_stamp / float(samplerate)), samplerate)
195 # write the remaining samples in the new file
196 g(vec[remaining:read], read - remaining)
197 #print "new slice", total_frames_written, "+", remaining, "=", start_of_next_region
198 if len(timestamps):
199 next_stamp = int(timestamps.pop(0))
200 else:
201 next_stamp = 1e120
202 else:
203 g(vec[0:read], read)
204 total_frames += read
205 if read < hopsize: break
206 172
207 # print some info173 # print some info
208 duration = float (total_frames) / float(samplerate)174 duration = float (total_frames) / float(samplerate)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t