def testReduceChannels(self): n_in = 7 n_out = 2 n_samples = 10 data_in = np.arange(n_in * n_samples) buf = AudioBuffer(n_samples, n_in) data_out = buf.reduce_channels(data_in, n_in, n_out) correct = [x for x in range(n_in * n_samples) if x % n_in == 0 or (x - 1) % n_in == 0] self.assertListFloatEqual(correct, data_out)
def testReduceChannels(self): n_in = 7 n_out = 2 n_samples = 10 data_in = np.arange(n_in * n_samples) buf = AudioBuffer(n_samples, n_in) data_out = buf.reduce_channels(data_in, n_in, n_out) correct = [ x for x in range(n_in * n_samples) if x % n_in == 0 or (x - 1) % n_in == 0 ] self.assertListFloatEqual(correct, data_out)
data = in_buf.read_samples(WINDOW_LENGTH) # Perform an stft stft.performStft(data) # Process dfts from windowed segments of input dfts = stft.getDFTs() process_dfts(dfts) if DO_PLOT: # Must update here because dfts are altered upon calling ISTFT since # the dft is performed in place fft = to_full_fft(dfts[0][0][0], dfts[0][1][0]) # Get the istft of the processed data new_data = stft.performIStft() # Alter data so it can be written out if NUM_CHANNELS_IN != NUM_CHANNELS_OUT: new_data = out_buf.reduce_channels(new_data, NUM_CHANNELS_IN, NUM_CHANNELS_OUT) if out_buf.get_available_write() >= WINDOW_LENGTH: out_buf.write_samples(new_data) # Take care of plotting if DO_PLOT: # Time plot if NUM_CHANNELS_OUT != 1: plot_data = out_buf.reduce_channels( new_data, NUM_CHANNELS_OUT, 1) else: plot_data = new_data time_plot.set_ydata(plot_data) # Frequency plot freq_plot.set_ydata(np.abs(fft[:cutoff_ind])) # Update plot
# Get data from the circular buffer data = in_buf.read_samples(WINDOW_LENGTH) # Perform an stft stft.performStft(data) # Process dfts from windowed segments of input dfts = stft.getDFTs() process_dfts(dfts) if DO_PLOT: # Must update here because dfts are altered upon calling ISTFT since # the dft is performed in place fft = to_full_fft(dfts[0][0][0], dfts[0][1][0]) # Get the istft of the processed data new_data = stft.performIStft() # Alter data so it can be written out if NUM_CHANNELS_IN != NUM_CHANNELS_OUT: new_data = out_buf.reduce_channels(new_data, NUM_CHANNELS_IN, NUM_CHANNELS_OUT) if out_buf.get_available_write() >= WINDOW_LENGTH: out_buf.write_samples(new_data) # Take care of plotting if DO_PLOT: # Time plot if NUM_CHANNELS_OUT != 1: plot_data = out_buf.reduce_channels(new_data, NUM_CHANNELS_OUT, 1) else: plot_data = new_data time_plot.set_ydata(plot_data) # Frequency plot freq_plot.set_ydata(np.abs(fft[:cutoff_ind])) # Update plot fig.canvas.draw() #time.sleep(.001)