def set_format(self, sample_rate, channels, channel_mask, bits_per_sample): """sets the output stream to the given format if the stream hasn't been initialized, this method initializes it if the stream has been initialized to a different format, this method closes and reopens the stream to the new format if the stream has been initialized to the same format, this method does nothing""" if (self.__coreaudio__ is None): # output hasn't been initialized from audiotools.output import CoreAudio AudioOutput.set_format(self, sample_rate, channels, channel_mask, bits_per_sample) self.__coreaudio__ = CoreAudio(sample_rate, channels, channel_mask, bits_per_sample) elif (not self.compatible(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)): # output has been initialized in a different format self.close() self.set_format(sample_rate=sample_rate, channels=channels, channel_mask=channel_mask, bits_per_sample=bits_per_sample)