def test_Mix(self): self._sample_1.extract_channel(0) self._sample_2.extract_channel(0) formatter1 = ChannelFormatter(self._sample_1.get_channel(0)) formatter1.set_framerate(16000) formatter1.set_sampwidth(2) formatter1.convert() formatter2 = ChannelFormatter(self._sample_2.get_channel(0)) formatter2.set_framerate(16000) formatter2.set_sampwidth(2) formatter2.convert() equalizer = ChannelsEqualizer() equalizer.append_channel(formatter1.channel) equalizer.append_channel(formatter2.channel) equalizer.equalize() mixer = ChannelsMixer() mixer.append_channel(equalizer.get_channel(0)) mixer.append_channel(equalizer.get_channel(1)) newchannel = mixer.mix() self.assertEqual(newchannel.get_nframes(), equalizer.get_channel(0).get_nframes()) self.assertEqual(newchannel.get_nframes(), equalizer.get_channel(1).get_nframes())
def mix_channels( settings, p=None ): """ Mix channels of the settings. @param settings: a list of dictionaries with extracted information from a settings file. @param p is a progress dialog """ #variables for displaying total = len(settings) mixerleft = ChannelsMixer() mixerright = ChannelsMixer() for i,channel in enumerate(settings): if p: p.update(float(i)/total, "Formatting channel " + str(i+1) + " of " + str(total)) coeffLeft = 50. coeffRight = 50. if channel['panoramic'] < 0: coeffLeft = float( 100 - channel['panoramic'] )/2 coeffRight = float( 100 - coeffLeft ) - channel['factor'] * channel['panoramic'] elif channel['panoramic'] > 0: coeffRight = float( 100 + channel['panoramic'] )/2 coeffLeft = float( 100 - coeffRight ) + channel['factor'] * channel['panoramic'] mixerleft.append_channel( channel['channel'], coeffLeft/100. * (channel['volume'])/100.) mixerright.append_channel(channel['channel'], coeffRight/100. * (channel['volume'])/100.) return mixerleft,mixerright
parser.add_argument("-w", metavar="file", nargs='+', required=True, help='Audio Input file name') parser.add_argument("-o", metavar="file", required=True, help='Audio Output file name') # ---------------------------------------------------------------------------- if len(sys.argv) <= 1: sys.argv.append('-h') args = parser.parse_args() # ---------------------------------------------------------------------------- mixer = ChannelsMixer() for inputFile in args.w: audio = signals.open(inputFile) for i in xrange(audio.get_nchannels()): idx = audio.extract_channel(i) audio.rewind() mixer.append_channel(audio.get_channel(idx)) newchannel = mixer.mix() # Save the converted channel audio_out = Audio() audio_out.append_channel( newchannel ) signals.save( args.o, audio_out )
import signals from signals.channelsmixer import ChannelsMixer from signals.audio import Audio sys.path.remove(SRC) parser = ArgumentParser(usage="%s -w input files" % os.path.basename(PROGRAM), description="A script to get the maximum value of a mix between mono audio files") parser.add_argument("-w", metavar="file", nargs='+', required=True, help='Audio Input file names') # ---------------------------------------------------------------------------- if len(sys.argv) <= 1: sys.argv.append('-h') args = parser.parse_args() # ---------------------------------------------------------------------------- mixer = ChannelsMixer() for inputFile in args.w: audio = signals.open(inputFile) idx = audio.extract_channel(0) mixer.append_channel(audio.get_channel(idx)) print mixer.get_max() # ----------------------------------------------------------------------------