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() mixer = ChannelsMixer() mixer.append_channel(formatter1.get_channel()) mixer.append_channel(formatter2.get_channel()) mixer.norm_length() self.assertEqual(mixer.get_channel(0).get_nframes(), mixer.get_channel(1).get_nframes()) newchannel = mixer.mix() self.assertEqual(newchannel.get_nframes(), mixer.get_channel(0).get_nframes()) self.assertEqual(newchannel.get_nframes(), mixer.get_channel(1).get_nframes())
def verify_channels(self): """ Check that the channels have the same parameters. Check framerate, sample width and number of frames. @return bool """ mixer = ChannelsMixer() f = 1./len(self.channels) for c in self.channels: mixer.append_channel(c,f) try: mixer.check_channels() except AudioDataError: return False return True
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
def normalize_channels( settings, p=None ): """ Normalize the length of channels of the settings. @param settings: a list of dictionaries with extracted information from a settings file. @param p is a progress dialog """ norm = ChannelsMixer() if p: p.update(0.25, "Load channels to normalize. ") for channel in settings: norm.append_channel( channel['channel'] ) if p: p.update(0.50, "Normalize length of each channel... ") norm.norm_length() if p: p.update(0.90, "Save normalized channels. ") for i,channel in enumerate(settings): channel['channel'] = norm.get_channel(i)
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 = audiodata.open(inputFile) idx = audio.extract_channel(0) mixer.append_channel(audio.get_channel(idx)) newchannel = mixer.mix() # Save the converted channel audio_out = AudioPCM() audio_out.append_channel( newchannel ) audiodata.save( args.o, audio_out ) # ----------------------------------------------------------------------------
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 = audiodata.open(inputFile) idx = audio.extract_channel(0) mixer.append_channel(audio.get_channel(idx)) print mixer.get_max() # ----------------------------------------------------------------------------