# HG changeset patch # User hamel.phil # Date 1294344701 0 # Node ID 07dc1f7047f560d8fd49d99f7fa3faf6cbcda7a7 # Parent d129539a7cc2fde56a87720fe6797d974cf91637 Debug output for audio_example and added a write function for aimc_data diff -r d129539a7cc2 -r 07dc1f7047f5 swig/aimc_data_io.py --- a/swig/aimc_data_io.py Thu Jan 06 16:30:25 2011 +0000 +++ b/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)) + + diff -r d129539a7cc2 -r 07dc1f7047f5 swig/audio_example.py --- a/swig/audio_example.py Thu Jan 06 16:30:25 2011 +0000 +++ b/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()