changeset 450:913d13255f61

Debug output for audio_example and added a write function for aimc_data
author hamel.phil
date Thu, 06 Jan 2011 20:11:41 +0000
parents 91f3d4287ac2
children 63aaa0a08e74
files trunk/swig/aimc_data_io.py trunk/swig/audio_example.py
diffstat 2 files changed, 35 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/trunk/swig/aimc_data_io.py	Thu Jan 06 16:30:25 2011 +0000
+++ b/trunk/swig/aimc_data_io.py	Thu Jan 06 20:11:41 2011 +0000
@@ -39,4 +39,20 @@
     data = N.reshape(vec_data,(nFrames, nChannels, nSamples))
     return data, nFrames, period, nChannels, nSamples, sample_rate
 
-#TODO write_aimc_data(data, nFrames, period, nChannels, nSamples, sample_rate)
\ No newline at end of file
+def write_aimc_data(filename, data, sample_rate, period = 0.0):
+
+    nFrames, nChannels, nSamples = data.shape
+    
+    file = open(filename,'wb')
+    
+    file.write(pack('i',nFrames))
+    file.write(pack('f',period)) #Not correctly implemented yet
+    file.write(pack('i',nChannels))
+    file.write(pack('i',nSamples))
+    file.write(pack('f',sample_rate))
+    
+    vec_data = data.flatten()
+    for elem in vec_data:
+        file.write(pack('f',elem))
+
+    
--- a/trunk/swig/audio_example.py	Thu Jan 06 16:30:25 2011 +0000
+++ b/trunk/swig/audio_example.py	Thu Jan 06 20:11:41 2011 +0000
@@ -27,19 +27,25 @@
 
 if x.ndim <= 1:
 	x=reshape(x,(x.shape[0],1))
+sr = 1.*sr
 	
 nChannels = x.shape[1]
 
 nSamples = x.shape[0]
 buffer_length = 1024
-zero_pad = numpy.zeros((buffer_length-(nSamples%buffer_length),nChannels)).astype('float')
-print x.shape, zero_pad.shape
-x = numpy.vstack((x,zero_pad))
-print x.shape
+
+#Zero-padding
+#zero_pad = numpy.zeros((buffer_length-(nSamples%buffer_length),nChannels)).astype('float')
+#x = numpy.vstack((x,zero_pad))
+
+#OR
+
+#Drop last incomplete frame (this is what happens in the C++ code)
+nFrames = x.shape[0]/buffer_length
+x = x[:nFrames*buffer_length]
+
 assert(x.shape[0]%buffer_length == 0)
 
-nFrames = x.shape[0]/buffer_length
-print nFrames
 
 sig = aimc.SignalBank()
 sig.Initialize(nChannels,buffer_length,sr)
@@ -56,11 +62,8 @@
 global_params = aimc.Parameters()
 pzfc.Initialize(sig,global_params)
 
-
-##One chunk only
-#chunk=x[:buffer_length]
-
 output_list = []
+bank_list =[]
 
 for f in range(nFrames):
 	for i in range(nChannels):
@@ -68,6 +71,7 @@
 
 	pzfc.Process(sig)
 	output_bank = sai.GetOutputBank()
+	bank_list.append(output_bank)
 	n_channel = output_bank.channel_count()
 	sig_length = output_bank.buffer_length()
 	output_matrix = numpy.zeros((n_channel,sig_length))
@@ -75,6 +79,10 @@
 		output_matrix[i] = numpy.array(output_bank.get_signal(i))
 	output_list.append(output_matrix)
 
+print 'nFrames, nChannels, nSamples, sample_rate'
+print nFrames, n_channel, sig_length, sr
+
+
 if do_plot:
 	import pylab as P
 	P.figure()