Browse Source

forgot from previous comming of audioraw.py:

only do one block when we are called...

flac.py:
add the support for returning the results of one block or up to
n samples...  This should help prevent some of the coping that
goes w/ combining strings, though it may increase call overhead..

add usage...

[git-p4: depot-paths = "//depot/": change = 1424]
main
John-Mark Gurney 15 years ago
parent
commit
8ba923751c
1 changed files with 20 additions and 11 deletions
  1. +20
    -11
      flac.py

+ 20
- 11
flac.py View File

@@ -465,7 +465,7 @@ class FLACDec(object):
if self.flacdec is None: if self.flacdec is None:
return return


print 'delete called'
#print 'close called'
if not flaclib.FLAC__stream_decoder_finish(self.flacdec): if not flaclib.FLAC__stream_decoder_finish(self.flacdec):
md5invalid = True md5invalid = True
else: else:
@@ -513,7 +513,7 @@ class FLACDec(object):


def cb_metadata(self, metadata_p): def cb_metadata(self, metadata_p):
md = metadata_p[0] md = metadata_p[0]
print 'metadata:', `md`
#print 'metadata:', `md`
if md.type == FLAC__METADATA_TYPE_STREAMINFO: if md.type == FLAC__METADATA_TYPE_STREAMINFO:
si = md.data.stream_info si = md.data.stream_info
self._channels = si.channels self._channels = si.channels
@@ -522,15 +522,15 @@ class FLACDec(object):
self._totalsamples = si.total_samples self._totalsamples = si.total_samples
self._bytespersample = si.channels * \ self._bytespersample = si.channels * \
si.bits_per_sample / 8 si.bits_per_sample / 8
print `si`
#print `si`
elif md.type == FLAC__METADATA_TYPE_VORBIS_COMMENT: elif md.type == FLAC__METADATA_TYPE_VORBIS_COMMENT:
self.vorbis = md.data.vorbis_comment.asobj() 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: elif md.type == FLAC__METADATA_TYPE_CUESHEET:
self.cuesheet = md.data.cue_sheet.asobj() 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: else:
print 'unknown metatype:', md.type print 'unknown metatype:', md.type


@@ -573,7 +573,9 @@ class FLACDec(object):
self.read(tread) self.read(tread)
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: if self.flacdec is None:
raise ValueError('closed') raise ValueError('closed')


@@ -581,13 +583,13 @@ class FLACDec(object):
nsamp = min(nsamp, self.totalsamples - self.cursamp) nsamp = min(nsamp, self.totalsamples - self.cursamp)
nchan = self.channels nchan = self.channels
while nsamp: 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( flaclib.FLAC__stream_decoder_process_single(
self.flacdec) self.flacdec)
continue continue


cnt = min(nsamp, self.curcnt)
sampcnt = cnt * nchan
r.append(self.curdata[:sampcnt].tostring()) r.append(self.curdata[:sampcnt].tostring())


self.cursamp += cnt self.cursamp += cnt
@@ -595,6 +597,9 @@ class FLACDec(object):
self.curdata = self.curdata[sampcnt:] self.curdata = self.curdata[sampcnt:]
nsamp -= cnt nsamp -= cnt


if oneblk:
break

return ''.join(r) return ''.join(r)


def doprofile(d): def doprofile(d):
@@ -615,6 +620,10 @@ def doprofile(d):
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys


if len(sys.argv) == 1:
print 'Usage: %s <file>' % sys.argv[0]
sys.exit(1)

d = FLACDec(sys.argv[1]) d = FLACDec(sys.argv[1])
print 'total samples:', d.totalsamples print 'total samples:', d.totalsamples
print 'channels:', d.channels print 'channels:', d.channels


Loading…
Cancel
Save