def to_pcm(self): """returns a PCMReader object containing the track's PCM data if an error occurs initializing a decoder, this should return a PCMReaderError with an appropriate error message""" from audiotools.decoders import TTADecoder from audiotools import PCMReaderError from audiotools.id3 import skip_id3v2_comment try: tta = open(self.filename, "rb") except IOError as msg: return PCMReaderError(error_message=str(msg), sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=self.bits_per_sample()) try: skip_id3v2_comment(tta) return TTADecoder(tta) except (IOError, ValueError) as msg: # This isn't likely unless the TTA file is modified # between when TrueAudio is instantiated # and to_pcm() is called. tta.close() return PCMReaderError(error_message=str(msg), sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=self.bits_per_sample())
def to_pcm(self): for (chunk_id, chunk_length, chunk_offset) in self.chunks(): if (chunk_id == 'SSND'): f = open(self.filename, 'rb') f.seek(chunk_offset, 0) alignment = self.SSND_ALIGN.parse_stream(f) #FIXME - handle different types of SSND alignment pcmreader = PCMReader(__capped_stream_reader__( f, chunk_length - self.SSND_ALIGN.sizeof()), sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=self.bits_per_sample(), signed=True, big_endian=True) if (self.channels() <= 2): return pcmreader elif (self.channels() in (3, 4, 6)): #FIXME - handle undefined channel mask standard_channel_mask = self.channel_mask() aiff_channel_mask = AIFFChannelMask(self.channel_mask()) return ReorderedPCMReader(pcmreader, [ aiff_channel_mask.channels().index(channel) for channel in standard_channel_mask.channels() ]) else: return pcmreader else: return PCMReaderError()
def to_pcm(self): #if mpg123 is available, use that for decoding if (BIN.can_execute(BIN["mpg123"])): sub = subprocess.Popen([BIN["mpg123"],"-qs",self.filename], stdout=subprocess.PIPE, stderr=file(os.devnull,"a")) return PCMReader(sub.stdout, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16, channel_mask=int(ChannelMask.from_channels(self.channels())), process=sub, big_endian=BIG_ENDIAN) else: #if not, use LAME for decoding if (self.filename.endswith("." + self.SUFFIX)): if (BIG_ENDIAN): endian = ['-x'] else: endian = [] sub = subprocess.Popen([BIN['lame']] + endian + \ ["--decode","-t","--quiet", self.filename,"-"], stdout=subprocess.PIPE) return PCMReader(sub.stdout, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16, channel_mask=int(ChannelMask.from_channels(self.channels())), process=sub) else: import tempfile from audiotools import TempWaveReader #copy our file to one that ends with .mp3 tempmp3 = tempfile.NamedTemporaryFile(suffix='.' + self.SUFFIX) f = open(self.filename,'rb') transfer_data(f.read,tempmp3.write) f.close() tempmp3.flush() #decode the mp3 file to a WAVE file wave = tempfile.NamedTemporaryFile(suffix='.wav') returnval = subprocess.call([BIN['lame'],"--decode","--quiet", tempmp3.name,wave.name]) tempmp3.close() if (returnval == 0): #return WAVE file as a stream wave.seek(0,0) return TempWaveReader(wave) else: return PCMReaderError(None, sample_rate=self.sample_rate(), channels=self.channels(), bits_per_sample=16)
def to_pcm(self): """returns a PCMReader object containing the track's PCM data""" from audiotools.decoders import VorbisDecoder try: return VorbisDecoder(self.filename) except ValueError as err: from audiotools import PCMReaderError return PCMReaderError(str(err), self.sample_rate(), self.channels(), int(self.channel_mask()), self.bits_per_sample())
def to_pcm(self): """returns a PCMReader object containing the track's PCM data""" try: return WaveReader(self.filename) except (IOError, ValueError) as err: from audiotools import PCMReaderError return PCMReaderError(error_message=str(err), sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=self.bits_per_sample())
def to_pcm(self): """Returns a PCMReader object containing the track's PCM data.""" from . import decoders try: return decoders.WavPackDecoder(self.filename) except (IOError, ValueError), msg: return PCMReaderError(error_message=str(msg), sample_rate=self.__samplerate__, channels=self.__channels__, channel_mask=int(self.channel_mask()), bits_per_sample=self.__bitspersample__)
def to_pcm(self): """returns a PCMReader object containing the track's PCM data""" from audiotools.decoders import ALACDecoder from audiotools import PCMReaderError try: return ALACDecoder(open(self.filename, "rb")) except (IOError, ValueError) as msg: return PCMReaderError(error_message=str(msg), sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=self.bits_per_sample())
def to_pcm(self): """Returns a PCMReader object containing the track's PCM data.""" for (chunk_id, chunk_length, chunk_offset) in self.chunks(): if (chunk_id == 'SSND'): f = open(self.filename, 'rb') f.seek(chunk_offset, 0) return AiffReader(f, self.sample_rate(), self.channels(), int(self.channel_mask()), self.bits_per_sample(), chunk_length) else: return PCMReaderError(u"no SSND chunk found", self.sample_rate(), self.channels(), int(self.channel_mask()), self.bits_per_sample)
def to_pcm(self): """returns a PCMReader object containing the track's PCM data""" from audiotools.decoders import WavPackDecoder from audiotools import PCMReaderError try: return WavPackDecoder(self.filename) except IOError as err: return PCMReaderError(error_message=str(err), sample_rate=self.__samplerate__, channels=self.__channels__, channel_mask=int(self.channel_mask()), bits_per_sample=self.__bitspersample__)
def to_pcm(self): """returns a PCMReader object containing the track's PCM data""" from audiotools import decoders from audiotools import PCMReaderError try: f = open(self.filename, "rb") except IOError as msg: return PCMReaderError(error_message=str(msg), sample_rate=self.__samplerate__, channels=self.__channels__, channel_mask=int(self.channel_mask()), bits_per_sample=self.__bitspersample__) try: return decoders.WavPackDecoder(f) except (IOError, ValueError) as msg: f.close() return PCMReaderError(error_message=str(msg), sample_rate=self.__samplerate__, channels=self.__channels__, channel_mask=int(self.channel_mask()), bits_per_sample=self.__bitspersample__)
def to_pcm(self): """returns a PCMReader object containing the track's PCM data""" from audiotools.decoders import SHNDecoder from audiotools import PCMReaderError try: return SHNDecoder(open(self.filename, "rb")) except (IOError, ValueError) as msg: # these may not be accurate if the Shorten file is broken # but if it is broken, there'll be no way to # cross-check the results anyway return PCMReaderError(error_message=str(msg), sample_rate=44100, channels=2, channel_mask=0x3, bits_per_sample=16)
def to_pcm(self): """returns a PCMReader object containing the track's PCM data if an error occurs initializing a decoder, this should return a PCMReaderError with an appropriate error message""" from audiotools.decoders import OpusDecoder try: return OpusDecoder(self.filename) except ValueError as err: from audiotools import PCMReaderError return PCMReaderError(error_message=str(err), sample_rate=self.sample_rate(), channels=self.channels(), channel_mask=int(self.channel_mask()), bits_per_sample=self.bits_per_sample())
def to_pcm(self): """Returns a PCMReader object containing the track's PCM data.""" try: sample_rate = self.sample_rate() channels = self.channels() channel_mask = int(self.channel_mask()) bits_per_sample = self.bits_per_sample() decoder = audiotools.decoders.SHNDecoder(self.filename) decoder.sample_rate = sample_rate decoder.channel_mask = channel_mask return decoder except (IOError, ValueError), msg: #these may not be accurate if the Shorten file is broken #but if it is broken, there'll be no way to #cross-check the results anyway return PCMReaderError(error_message=str(msg), sample_rate=44100, channels=2, channel_mask=0x3, bits_per_sample=16)