changeset 7:f90eba90a78f

fixed a bug where the event rectangles were not appearing anywhere; fixed a bug where a file would incorrectly be assigned half the sampling rate
author Emmanouil Theofanis Chourdakis <e.t.chourdakis@qmul.ac.uk>
date Tue, 03 Oct 2017 12:14:55 +0100
parents f5edaa5ca167
children 0f8d8ff0ece7
files requirements.txt simscene.py
diffstat 2 files changed, 13 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/requirements.txt	Mon Oct 02 19:21:31 2017 +0100
+++ b/requirements.txt	Tue Oct 03 12:14:55 2017 +0100
@@ -1,7 +1,6 @@
 argparse
 pandas
 numpy
-glob
 librosa
 matplotlib
 tabulate
--- a/simscene.py	Mon Oct 02 19:21:31 2017 +0100
+++ b/simscene.py	Tue Oct 03 12:14:55 2017 +0100
@@ -178,14 +178,15 @@
     scene_starting_times = []
     scene_ending_times = []
     
-    
     for n in range(len(events_df)):
         # Get label of track
         label = str(events_df['label'].loc[n])
         
         candidates = glob.glob('{}/event/{}*.wav'.format(input_path, events_df['sampleid'].loc[n]))
-        wav, SR = librosa.load(random.sample(candidates,1)[0])
-                
+        chosen_fname = random.sample(candidates,1)[0]
+        wav, sr = librosa.load(chosen_fname, sr=SR)
+        assert sr == SR, "Sample rate of individual tracks must be 44100Hz (Failed: `{}' with sample rate: {} )".format(chosen_fname, sr)
+                  
         # Apply a fader envelope
         fade_in_time = float(events_df['fade_in_time'].loc[n])
         fade_out_time = float(events_df['fade_out_time'].loc[n])
@@ -259,7 +260,7 @@
             plt.title('`{}\' waveform and spectrogram'.format(label))                
 
             visible_track = track_arr[int(start_times[0]*SR):int(end_times[-1]*SR)]
-            librosa.display.waveplot(visible_track)
+            librosa.display.waveplot(visible_track,sr=SR)
             F = librosa.stft(visible_track)
             Fdb = librosa.amplitude_to_db(F)
             plt.subplot(2,1,2)
@@ -269,7 +270,7 @@
             
         scene_starting_times.append((label, start_times))
         scene_ending_times.append((label, end_times))
-                
+
     if figure_verbosity > 0:
         plt.figure()
         plt.subplot(3,1,1)
@@ -280,17 +281,19 @@
         plt.subplot(3,1,2)
         librosa.display.specshow(Fdb, sr=SR, x_axis='time', y_axis='hz')
         ax = plt.subplot(3,1,3)
+        ax.set_xlim([0,scene_duration])
         
         for n in range(len(scene_starting_times)):
             label = scene_starting_times[n][0]
             start_times = scene_starting_times[n][1]
             end_times = scene_ending_times[n][1]
             for m in range(len(start_times)):
-                ax.add_patch(
-                    patches.Rectangle(
-                        (start_times[m], float(n)),
-                        end_times[m]-start_times[m], 0.2
-                    )
+                plt.text(
+                    start_times[m],
+                    0.1+n/float(len(scene_starting_times)),
+                    label,
+                    size=9,ha='center',va='center',
+                    bbox=dict(boxstyle='square', ec=(1., 0.5, 0.5), fc=(1., 1-n/float(len(scene_starting_times)), n/float(len(scene_starting_times)))),
                 )
         
         plt.savefig('{}/full-scene.{}'.format(output_path, image_format))