From c1f45d24dbd8adeb49b1ae13d0b4ef79a9125fb7 Mon Sep 17 00:00:00 2001 From: yomguy <> Date: Sun, 27 May 2007 21:53:20 +0000 Subject: [PATCH] - Added main tags to streamed mp3. Closes: #9 - Made Octave quiet - Downsampling data for waveform2 - Cleanup --- telemeta/export/core.py | 2 +- telemeta/export/flac.py | 5 +-- telemeta/export/mp3.py | 47 ++++++++++---------- telemeta/export/ogg.py | 6 +-- telemeta/visualization/octave/waveform2img.m | 23 +++++++--- telemeta/visualization/octave_core.py | 6 +-- 6 files changed, 47 insertions(+), 42 deletions(-) diff --git a/telemeta/export/core.py b/telemeta/export/core.py index 9fd7658e..3abbfd80 100644 --- a/telemeta/export/core.py +++ b/telemeta/export/core.py @@ -260,7 +260,7 @@ def clean_word(word) : word = re.sub("^[^\w]+","",word) #trim the beginning _ #word = string.replace(word,' ','_') #word = string.capitalize(word) - dict = '&[];"*' + dict = '&[];"*:,' for letter in dict: word = string.replace(word,letter,'_') return word diff --git a/telemeta/export/flac.py b/telemeta/export/flac.py index 3e96d1a5..acffa56d 100644 --- a/telemeta/export/flac.py +++ b/telemeta/export/flac.py @@ -119,9 +119,8 @@ class FlacExporter(ExporterCore): # Processing (streaming + cache writing) stream = self.core_process(self.command, self.buffer_size, self.dest) - for chunk in stream: - yield chunk - + return stream + # Post-proccessing self.post_process(self.item_id, self.source, diff --git a/telemeta/export/mp3.py b/telemeta/export/mp3.py index 21401b4f..72477415 100644 --- a/telemeta/export/mp3.py +++ b/telemeta/export/mp3.py @@ -45,7 +45,7 @@ class Mp3Exporter(ExporterCore): } self.dub2args_dict = {'title': 'tt', #title2 'creator': 'ta', #composer - 'identifier': 'tl', #album + 'relation': 'tl', #album #'type': 'tg', #genre 'publisher': 'tc', #comment 'date': 'ty', #year @@ -99,29 +99,29 @@ class Mp3Exporter(ExporterCore): def get_args(self, metadata, options=None): """Get process options and return arguments for the encoder""" - args = '' + args = [] if not options is None: self.options = options - - if 'verbose' in self.options and self.options['verbose'] != '0': - args = args - else: - args= args + '-S ' - + if not ( 'verbose' in self.options and self.options['verbose'] != '0' ): + args.append('-S') if 'mp3_bitrate' in self.options: - args = args+'-b '+self.options['mp3_bitrate'] + args.append('-b ' + self.options['mp3_bitrate']) else: - args = args+'-b '+self.bitrate_default + args.append('-b '+self.bitrate_default) #Copyrights, etc.. - args = args + ' -c -o ' + args.append('-c -o') else: - args = args + ' -S -c -o ' + args.append('-S -c -o') - #for tag in self.metadata.keys(): - #if tag in self.dub2args_dict.keys(): - #arg = self.dub2args_dict[tag] - #value = clean_word(self.metadata[tag]) - #args = args.append(' --' + arg + ' "' +value +'" ' + for tag in self.metadata.keys(): + print tag + if tag in self.dub2args_dict.keys(): + arg = self.dub2args_dict[tag] + print arg + value = clean_word(self.metadata[tag]) + print value + args.append('--' + arg) + args.append('"' + value + '"') return args @@ -131,9 +131,10 @@ class Mp3Exporter(ExporterCore): self.metadata = metadata self.args = self.get_args(self.metadata,options) self.ext = self.get_file_extension() - self.command = 'sox "'+self.source+'" -q -w -r 44100 -t wav -c2 - '+ \ - '| lame '+self.args+' --tc "default" - ' - + self.args = ' '.join(self.args) + self.command = 'sox "%s" -q -w -r 44100 -t wav -c2 - | lame %s -' \ + % (self.source,self.args) + # Pre-proccessing self.dest = self.pre_process(self.item_id, self.source, @@ -143,11 +144,9 @@ class Mp3Exporter(ExporterCore): self.options) # Processing (streaming + cache writing) - # FIXME return stream stream = self.core_process(self.command,self.buffer_size,self.dest) - for chunk in stream: - yield chunk - + return stream + # Post-proccessing self.post_process(self.item_id, self.source, diff --git a/telemeta/export/ogg.py b/telemeta/export/ogg.py index f473a1f0..6930b368 100644 --- a/telemeta/export/ogg.py +++ b/telemeta/export/ogg.py @@ -115,11 +115,9 @@ class OggExporter(ExporterCore): # Processing (streaming + cache writing) stream = self.core_process(self.command,self.buffer_size,self.dest) - for chunk in stream: - yield chunk - + return stream + # Post-proccessing - self.post_process(self.item_id, self.source, self.metadata, diff --git a/telemeta/visualization/octave/waveform2img.m b/telemeta/visualization/octave/waveform2img.m index 2562d432..4edeb2f4 100644 --- a/telemeta/visualization/octave/waveform2img.m +++ b/telemeta/visualization/octave/waveform2img.m @@ -27,21 +27,30 @@ step = 6; % spectral slice period (ms) % step_length = fix(5*Fs/1000); window = 30; % filter window (ms) % window = fix(40*Fs/1000); -lim_x_length = 10; % (s) +time_limit = 300; % length limit of the displayed sample (s) +% Downsampling factor +D = 100; +% Read audio data [x, Fs] = wavread(wav_file); x = x(:,1); % mono lx = length(x); -lim_x_samples = Fs.*lim_x_length; -if lx > lim_x_samples; - x = x(1:lim_x_samples); +% LIMITING time +lx_lim = Fs.*time_limit; +if lx > lx_lim; + x = x(1:lx_lim); end +N = length(x); -lx = length(x); -t = [0:1:lx-1]./Fs; +% Downsampling by D +t = 1:1:lx; +t = (t-1)./Fs; +x2(1:ceil(N/D)) = x(1:D:N); +t2(1:ceil(N/D)) = t(1:D:N); +%x(ceil(N/D)+1:N) = zeros(1,N-ceil(N/D)); -img = plot(t,x); +img = plot(t2,x2); print(dest_image, '-dpng'); quit; diff --git a/telemeta/visualization/octave_core.py b/telemeta/visualization/octave_core.py index 01ea89dd..726851fa 100644 --- a/telemeta/visualization/octave_core.py +++ b/telemeta/visualization/octave_core.py @@ -51,12 +51,12 @@ class OctaveCoreVisualizer(Component): mFile_tmp.close() # Compute - proc = subprocess.Popen(command) + proc = subprocess.Popen(command, stdout = subprocess.PIPE) proc.wait() # Convert - os.system('convert ' + self.ppmFile.name + ' -scale x250 ' + self.pngFile.name) - # + os.system('convert ' + self.ppmFile.name + \ + ' -scale x250 ' + self.pngFile.name) # Stream while True : -- 2.39.5