read clm chunk from wav file using python wavfile

Viewed 86

i am using the enhanced wavfile.py library, and i want to use it to read serum-style wavetables. i know that these files use a 'clm' block to store cue points, but i am having trouble with reading these using the library

right now i'm just trying to read the file (i'll do something with it later); here is my code:

import wavfile as wf

wf.read('wavetable.wav')

when i run the script, i get this error:

[my dir]/wavfile.py:223: WavFileWarning: Chunk b'clm ' skipped
  warnings.warn("Chunk " + str(chunk_id) + " skipped", WavFileWarning)
[my dir]/wavfile.py:223: WavFileWarning: Chunk b'' skipped
  warnings.warn("Chunk " + str(chunk_id) + " skipped", WavFileWarning)
Traceback (most recent call last):
  File "[my dir]/./test.py", line 5, in <module>
    wf.read('wavetable.wav')
  File "[my dir]/wavfile.py", line 228, in read
    _skip_unknown_chunk(fid)
  File "[my dir]/wavfile.py", line 112, in _skip_unknown_chunk
    size = struct.unpack('<i', data)[0]
struct.error: unpack requires a buffer of 4 bytes

is it even possible to do this using the library? if not, how could i modify the library to make this work?

bear with me, i'm new to working with files and python in general

UPDATE:

here's the output after i add madison courto's code:

Traceback (most recent call last):
  File "[my dir]/./test.py", line 5, in <module>
    wf.debug('wavetable.wav')
  File "[my dir]/wavfile.py", line 419, in debug
    format_str = format.decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 1: invalid start byte

and here is the wavetable i'm testing; hopefully sndup left it intact

1 Answers

Adding these conditions to the read function returns a dict of markers, it seems that one of the markers is currupt so I added except pass, it's a bit janky but works.

    elif chunk_id == b'':
        break
    elif chunk_id == b'clm ':
        str1 = fid.read(8)
        
        size, numcue = struct.unpack('<ii', str1)
        for c in range(numcue):
            try:
                str1 = fid.read(24)
                idx, position, datachunkid, chunkstart, blockstart, sampleoffset = struct.unpack(
                    '<iiiiii', str1)
                # _cue.append(position)
                _markersdict[idx][
                    'position'] = position  # needed to match labels and markers
            except:
                pass
Related