def __populate_metadata__(self): #set up some default values self.__bits_per_sample__ = 16 self.__channels__ = 2 self.__channel_mask__ = 0x3 self.__sample_rate__ = 44100 self.__total_frames__ = 0 self.__blocks__ = [] self.__format__ = None #grab a few pieces of technical metadata from the Shorten file itself #which requires a dry-run through the decoder try: decoder = audiotools.decoders.SHNDecoder(self.filename) try: self.__bits_per_sample__ = decoder.bits_per_sample self.__channels__ = decoder.channels (self.__total_frames__, self.__blocks__) = decoder.metadata() finally: decoder.close() try: self.__channel_mask__ = ChannelMask.from_channels( self.__channels__) except ValueError: self.__channel_mask__ = 0 except (ValueError, IOError): #if we hit an error in SHNDecoder while reading #technical metadata, the default values will have to do return #the remainder requires parsing the file's VERBATIM blocks #which may contain Wave, AIFF or Sun AU info if (self.__blocks__[0] is not None): header = cStringIO.StringIO(self.__blocks__[0]) for format in WaveAudio, AiffAudio: header.seek(0, 0) if (format.is_type(header)): self.__format__ = format break if (self.__format__ is WaveAudio): for (chunk_id, chunk_data) in self.__wave_chunks__(): if (chunk_id == 'fmt '): fmt_chunk = WaveAudio.FMT_CHUNK.parse(chunk_data) self.__sample_rate__ = fmt_chunk.sample_rate if (fmt_chunk.compression == 0xFFFE): self.__channel_mask__ = \ WaveAudio.fmt_chunk_to_channel_mask( fmt_chunk.channel_mask) elif (self.__format__ is AiffAudio): for (chunk_id, chunk_data) in self.__aiff_chunks__(): if (chunk_id == 'COMM'): comm_chunk = AiffAudio.COMM_CHUNK.parse(chunk_data) self.__sample_rate__ = comm_chunk.sample_rate
def __populate_metadata__(self): # Alteration for BootTunes: # Since the vast majority of files will match the defaults, and because this method crashes # Windows 7 and locks up Mac, just go with the defaults. self.__bits_per_sample__ = 16 self.__channels__ = 2 self.__channel_mask__ = 0x3 self.__sample_rate__ = 44100 self.__total_frames__ = 0 self.__blocks__ = [] self.__format__ = None return #grab a few pieces of technical metadata from the Shorten file itself #which requires a dry-run through the decoder decoder = audiotools.decoders.SHNDecoder(self.filename) self.__bits_per_sample__ = decoder.bits_per_sample self.__channels__ = decoder.channels (self.__total_frames__, self.__blocks__) = decoder.metadata() decoder.close() #set up some default values self.__sample_rate__ = 44100 try: self.__channel_mask__ = ChannelMask.from_channels(self.__channels__) except ValueError: self.__channel_mask__ = 0 self.__format__ = None #the remainder requires parsing the file's VERBATIM blocks #which may contain Wave, AIFF or Sun AU info if (self.__blocks__[0] is not None): header = cStringIO.StringIO(self.__blocks__[0]) for format in WaveAudio,AiffAudio: header.seek(0,0) if (format.is_type(header)): self.__format__ = format break if (self.__format__ is WaveAudio): for (chunk_id,chunk_data) in self.__wave_chunks__(): if (chunk_id == 'fmt '): fmt_chunk = WaveAudio.FMT_CHUNK.parse(chunk_data) self.__sample_rate__ = fmt_chunk.sample_rate if (fmt_chunk.compression == 0xFFFE): self.__channel_mask__ = WaveAudio.fmt_chunk_to_channel_mask(fmt_chunk.channel_mask) elif (self.__format__ is AiffAudio): for (chunk_id,chunk_data) in self.__aiff_chunks__(): if (chunk_id == 'COMM'): comm_chunk = AiffAudio.COMM_CHUNK.parse(chunk_data) self.__sample_rate__ = comm_chunk.sample_rate