Onyx logo

Previous topic

Audio

Next topic

onyx.audio.audiodata – Interfaces for getting audio data from files

This Page

onyx.audio.unshorten – Code for parsing the bitstream of a shorten encoded file.

This is a start on a reference for a replacement for Tony Robinson’s license-restricted code for unshortening shorten files. To date, it appears to be able to decode the bit-stream and generate the arrays of numbers involved, but it doesn’t yet implement the numerical work needed to reconstruct the signals. Once that is implemented, we could work with Erik de Castro Lopo of libsndfile to make a C version for use in libsndfile.

See shorten_x.c which appears in the sph2pipe package from LDC.

onyx.audio.unshorten.file_bit_gen(infile)

Return a generator that yields the bits, 0 or 1, from the contents of each byte of infile, from MSB to LSB.

>>> tuple(file_bit_gen(cStringIO.StringIO(' ab' + chr(255) + chr(1)))) # using chr() because Sphinx isn't happy with non-ascii chars
(0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1)
onyx.audio.unshorten.parse_shorten_bitstream(filename)
>>> module_dir, module_name = os.path.split(__file__)
>>> shorten_shn = os.path.join(module_dir, 'shorten.shn')
>>> import itertools
>>> with open(shorten_shn, 'rb') as infile:
...   h = infile.read(4)
...   v = ord(infile.read(1))
...   y = tuple(itertools.islice(file_bit_gen(infile), 32))
>>> h
'ajkg'
>>> v
2
>>> y
(1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1)
>>> parse_shorten_bitstream(shorten_shn)
ftype 3
nchan 1
blocksize 256
maxnlpc 0
nmean 4
nskip 0
count 146
onyx.audio.unshorten.ulong_get(bitstream)
onyx.audio.unshorten.uvar_get(bitstream, nbit)
onyx.audio.unshorten.var_get(bitstream, nbin)