diff --git a/flac.py b/flac.py index 9974992..05641aa 100644 --- a/flac.py +++ b/flac.py @@ -465,7 +465,7 @@ class FLACDec(object): if self.flacdec is None: return - print 'delete called' + #print 'close called' if not flaclib.FLAC__stream_decoder_finish(self.flacdec): md5invalid = True else: @@ -513,7 +513,7 @@ class FLACDec(object): def cb_metadata(self, metadata_p): md = metadata_p[0] - print 'metadata:', `md` + #print 'metadata:', `md` if md.type == FLAC__METADATA_TYPE_STREAMINFO: si = md.data.stream_info self._channels = si.channels @@ -522,15 +522,15 @@ class FLACDec(object): self._totalsamples = si.total_samples self._bytespersample = si.channels * \ si.bits_per_sample / 8 - print `si` + #print `si` elif md.type == FLAC__METADATA_TYPE_VORBIS_COMMENT: self.vorbis = md.data.vorbis_comment.asobj() - print 'vc:', `md.data.vorbis_comment` - print 'v:', `self.vorbis` + #print 'vc:', `md.data.vorbis_comment` + #print 'v:', `self.vorbis` elif md.type == FLAC__METADATA_TYPE_CUESHEET: self.cuesheet = md.data.cue_sheet.asobj() - print 'cs:', `md.data.cue_sheet` - print 'c:', `self.cuesheet` + #print 'cs:', `md.data.cue_sheet` + #print 'c:', `self.cuesheet` else: print 'unknown metatype:', md.type @@ -573,7 +573,9 @@ class FLACDec(object): self.read(tread) read -= tread - def read(self, nsamp=16*1024): + def read(self, nsamp=16*1024, oneblk=False): + '''If oneblk is True, we will only process data once.''' + if self.flacdec is None: raise ValueError('closed') @@ -581,13 +583,13 @@ class FLACDec(object): nsamp = min(nsamp, self.totalsamples - self.cursamp) nchan = self.channels while nsamp: - cnt = min(nsamp, self.curcnt) - sampcnt = cnt * nchan - if cnt == 0 and self.curcnt == 0: + if self.curcnt == 0: flaclib.FLAC__stream_decoder_process_single( self.flacdec) continue + cnt = min(nsamp, self.curcnt) + sampcnt = cnt * nchan r.append(self.curdata[:sampcnt].tostring()) self.cursamp += cnt @@ -595,6 +597,9 @@ class FLACDec(object): self.curdata = self.curdata[sampcnt:] nsamp -= cnt + if oneblk: + break + return ''.join(r) def doprofile(d): @@ -615,6 +620,10 @@ def doprofile(d): if __name__ == '__main__': import sys + if len(sys.argv) == 1: + print 'Usage: %s ' % sys.argv[0] + sys.exit(1) + d = FLACDec(sys.argv[1]) print 'total samples:', d.totalsamples print 'channels:', d.channels