def run(): channels = parse(sys.argv[1:]) freqs = set([freq for channel in channels for freq in channel['freqs']]) scheme['filter_duration'] = FILTER_DURATION filter_size = int(np.power(2, int(np.log2(scheme['sample_rate'] - 1)) + 1) * scheme['filter_duration']) scheme['filter_size'] = filter_size fir = Fir(filter_size) for channel in channels: channel['bands'] = [] if len(channel['freqs']) < 2: channel['freqs'] = [0, HIGHEST_FREQENCY] for lower, upper in pairwise(channel['freqs']): band = { 'lower': lower, 'upper': upper, 'range': '%s_%s' % (lower, upper), 'name': '%s_%s_%s' % (channel['name'], lower, upper), } if lower > 0 or upper != HIGHEST_FREQENCY: filename = fir_coeffs_filename('bandpass', scheme['sample_rate'], filter_size, lower, upper) band['file'] = scheme.path('coeffs', filename) fir.save(band['file'], fir.bandpass(upper, lower)) else: band['file'] = '' channel['bands'].append(band) channel['bands'].reverse() del channel['freqs'] scheme['channels'] = channels scheme.save()
def run(): # map output ports ports = dict(enumerate(scheme['send'], 1)) for band in scheme.get_bands(): selected_port = None while True: if selected_port: print 'using [%s]' % selected_port break current_value = band.get('jackport') print 'which jack port to use for channel [%s]? %s' % \ (band['name'], current_value and 'default is "%s"' % current_value or '') show_possible(ports) selected_port = select_port(ports, current_value) band['jackport'] = selected_port # map measure ports ports = dict(enumerate(scheme['receive'], 1)) show_possible(ports) for channel_name, current_value in scheme['measure'].items(): selected_port = None while True: if selected_port: print 'using [%s]' % selected_port break print 'which jack port to use for [%s]? %s' % \ (channel_name, current_value and 'current: "%s"' % current_value or '') show_possible(ports) selected_port = select_port(ports, current_value) scheme['measure'][channel_name] = selected_port scheme.save()
def compile(): config = BF_HEAD % { 'sampling_rate': scheme['sample_rate'], 'filter_length': '%s,%s' % (scheme['filter_size'] / PARTS_COUNT, PARTS_COUNT)} # coeffs coeffs = [ ((band['lower'], band['upper']), band['range'], band['file']) for channel in scheme['channels'] for band in channel['bands'] if band['file'] ] + [ (0, '%s_correction' % channel['name'], channel['correction']) for channel in scheme['channels'] if channel.get('correction') ] coeffs = sorted(set(coeffs)) config += """\n\n## COEFFS ##\n""" for order, coeff, file_path in coeffs: config += BF_COEFF % { 'name': coeff, 'file': file_path, } # inputs inputs = [channel['name'] for channel in scheme['channels']] + \ ['%s_correction' % channel['name'] for channel in scheme['channels'] if channel.get('correction')] config += BF_INPUT % { 'names': ', '.join(map(quote, inputs)), 'channels': '%s/%s' % (len(inputs), ', '.join(map(str, range(len(inputs))))), 'delays': ','.join('0' * len(inputs)), 'mutes': ','.join(['false'] * len(inputs)), } # outputs outputs = scheme.get_bands() config += BF_OUTPUT % { 'names': ', '.join([quote(band['name']) for band in outputs]), # 'ports': ', '.join([quote(band['jack_port']) for band in outputs]), 'channels': '%s/%s' % (len(outputs), ','.join(map(str, range(len(outputs))))), 'delays': ','.join([str(int(band.get('delay', 0))) for band in outputs]), 'mutes': ','.join(['false'] * len(outputs)), } # scheme for j, input in enumerate(scheme['channels']): input['brutenum'] = j for j, out in enumerate(outputs): out['brutenum'] = j scheme.save() # filters config += """\n\n## FILTERS ##\n""" for channel in scheme['channels']: for band in channel['bands']: if channel.get('correction'): from_filters_line = 'from_filters: "%s";' % ('%s_correction' % channel['name']) else: from_filters_line = '' config += BF_FILTER % { 'name': band['name'], 'input_line': 'inputs: "%s";' % channel['name'], 'from_filters_line': from_filters_line, 'output_line': 'outputs: "%s";' % band['name'], 'coeff': band['file'] and '"%s"' % band['range'] or '-1', } for channel in scheme['channels']: if channel.get('correction'): config += BF_FILTER % { 'name': '%s_correction' % channel['name'], 'input_line': 'inputs: "%s_correction";' % channel['name'], 'from_filters_line': '', 'output_line': 'to_filters: %s;' % \ ','.join(('"%s"' % b['name'] for b in channel['bands'])), 'coeff': '"%s_correction"' % channel['name'], } return config
check_call(cmd) check_call(['mv', '/tmp/trimmed_impulse_file.pcm', impulse_file]) if __name__ == '__main__': brute.stop() time.sleep(1) # сформировать конфигурацию brutefir без коррекции for channel in scheme.channels: if 'correction' in channel: del channel['correction'] scheme.save() time.sleep(1) bruteconf.configure() brute.start() time.sleep(1) plum = Plum() plum[(scheme['measure']['microphone'], 'jack.record-[0-9]+:in_1')] = True plum[('jack.play.sweep:out_1', 'jack.record-[0-9]+:in_2')] = True for channel in scheme['channels']: for ch in scheme.channels: