]> git.parisson.com Git - telemeta.git/commitdiff
- Cleaned OctaveCoreVisualizer to avoid wrong subprocess calls
authoryomguy <>
Sun, 27 May 2007 19:18:22 +0000 (19:18 +0000)
committeryomguy <>
Sun, 27 May 2007 19:18:22 +0000 (19:18 +0000)
- Fix the maximum displayed length to 10s max for Octave visualizers (need to downsample !)

telemeta/visualization/octave/spectrogram2img.m
telemeta/visualization/octave/waveform2img.m
telemeta/visualization/octave_core.py
telemeta/visualization/spectrogram2.py
telemeta/visualization/waveform2.py

index 16abe06dc298ab8c1f31aee8375d0c1094a9c763..9294bae1099dab2fe655c3abd5c0939792d3e22d 100644 (file)
@@ -33,7 +33,7 @@ lim_x_length = 10; % (s)
 x = x(:,1);  % mono
 lim_x_samples = Fs.*lim_x_length;
 if length(x) > lim_x_samples;
- x = x(1:lim_x_samples)
+ x = x(1:lim_x_samples);
 end
 
 %fftn = 2^nextpow2(window); % next highest power of 2
@@ -50,8 +50,7 @@ S = flipud(20*log10(S));
 cmap = colormap(jet(ncmap));
 
 img = imagesc(t, f, S);
-%stdin(imagesc(t, f, S));
 saveimage(dest_image, img, 'ppm', cmap);
-%print([img_dir wav_file '.eps'], '-depsc');
 
-quit
+quit;
+
index 4b917123013da75591ddf24a624158fb392ff547..2562d4324a9756c475ccab4ab8f60b4dea4fc57a 100644 (file)
@@ -35,12 +35,14 @@ lx = length(x);
 lim_x_samples = Fs.*lim_x_length;
 
 if lx > lim_x_samples;
- x = x(1:lim_x_samples)
+ x = x(1:lim_x_samples);
 end
 
-t = [1:1:lx]./Fs;
+lx = length(x);
+t = [0:1:lx-1]./Fs;
 
 img = plot(t,x);
-print(dest_image, '-dpng')
+print(dest_image, '-dpng');
+
+quit;
 
-quit
index edff7b4fed7f71a2a5c5f236803e387fea3a0ddb..a56eb45a0e27eeab163167308d770626b0da6626 100644 (file)
@@ -18,10 +18,7 @@ class OctaveCoreVisualizer(Component):
         mFile_path = os.path.dirname(__file__) + '/octave/' + self.mFile
         mFile = open(mFile_path,'r')
         
-        while True:
-            line = mFile.readline()
-            if 'quit' in line:
-                break
+        for line in mFile.readlines():
             if '$OCTAVEPATH' in line:
                 line = line.replace('$OCTAVEPATH','"'+octave_path+'"')
             if '$WAVFILE' in line:
@@ -40,36 +37,26 @@ class OctaveCoreVisualizer(Component):
         
     def octave_to_png_stream(self, media_item):
 
-        self.pngFile = NamedTemporaryFile(suffix='.png')
-        self.ppmFile = NamedTemporaryFile(suffix='.'+self.dest_type)
+        self.ppmFile = NamedTemporaryFile(suffix='.'+self.trans_type)
         self.wavFile = self.get_wav_path(media_item)
-        #command = 'octave2.9 ' + self.mFile_tmp.name
-        command = 'octave2.9'
-                
-        proc = subprocess.Popen(command,
-                                shell = True,
-                                #bufsize = buffer_size,
-                                stdin = subprocess.PIPE,
-                                stdout = subprocess.PIPE,
-                                close_fds = True)
+        mFile_tmp = NamedTemporaryFile(suffix='.m')
+        mFile_name = mFile_tmp.name
+        mFile_tmp.close()
+        mFile_tmp = open(mFile_name,'w')
+        self.pngFile = NamedTemporaryFile(suffix='.png')
+        command = ['octave2.9', mFile_name]
 
         for line in self.get_mFile_line():
-            proc.stdin.write(line)
-
-        # Wait for ppm
-        status = os.stat(self.ppmFile.name).st_size
-        while True:
-            if status == os.stat(self.ppmFile.name).st_size and status != 0:
-                break
-            status = os.stat(self.ppmFile.name).st_size
-            #print status
-        time.sleep(1)
+            mFile_tmp.write(line)
+        mFile_tmp.close()
 
+        # Compute
+        proc = subprocess.Popen(command)               
+        proc.wait()
+        
         # Convert
         os.system('convert ' + self.ppmFile.name + ' -scale 300x300 ' + self.pngFile.name)
 
-        os.kill(proc.pid, signal.SIGKILL)
-
         # Stream
         while True  :
             buffer = self.pngFile.read(self.buffer_size)
@@ -79,3 +66,6 @@ class OctaveCoreVisualizer(Component):
 
         self.ppmFile.close()
         self.pngFile.close()
+        os.remove(mFile_name)
+        
+        
\ No newline at end of file
index 833091dd088d7d5ab364585cc899370b998348e2..09eca34c8260b33dac3f0d5aaa4bd9931fdb8e6d 100644 (file)
@@ -20,13 +20,13 @@ class SpectrogramVisualizer2(OctaveCoreVisualizer):
     def __init__(self):
         self.set_m_file('spectrogram2img.m')
         self.buffer_size = 0xFFFF
-        self.dest_type = 'ppm'
+        self.trans_type = 'ppm'
         
     def get_id(self):
         return "spectrogram2"
 
     def get_name(self):
-        return "Spectrogram2"
+        return "Spectrogram2 (< 10s)"
     
     def render(self, media_item, options=None):
         """Generator that streams the spectral view as a PNG image"""
index bcc848faae6ec98b73d71e7490bdd25e64d39054..a5e3b488d3e9181b0d49ca30205646eecb0602bd 100644 (file)
@@ -20,13 +20,13 @@ class WaveformVisualizer2(OctaveCoreVisualizer):
     def __init__(self):
         self.set_m_file('waveform2img.m')
         self.buffer_size = 0xFFFF
-        self.dest_type = 'png'
+        self.trans_type = 'png'
         
     def get_id(self):
         return "waveform2"
 
     def get_name(self):
-        return "Waveform2"
+        return "Waveform2 (< 10s)"
     
     def render(self, media_item, options=None):
         """Generator that streams the temporal view as a PNG image"""