rochars / wavefile

Create, read and write wav files according to the specs. :star: :notes: :heart:
MIT License
228 stars 48 forks source link

Bug in read of RIFF signature..? #31

Open christophe-hall opened 1 year ago

christophe-hall commented 1 year ago

WAV with RIFF chunks like:

image

is read by wavefile with a funky signature like:

{
  "chunkId": "RIFF",
  "chunkSize": 639470,
  "format": "WAVE",
  "subChunks": [
    {
      "chunkId": "fmt ",
      "chunkSize": 16,
      "chunkData": {
        "start": 20,
        "end": 36
      }
    },
    {
      "chunkId": "data",
      "chunkSize": 639096,
      "chunkData": {
        "start": 44,
        "end": 639140
      }
    },
    {
      "chunkId": "LIST",
      "chunkSize": 68,
      "format": "INFO",
      "subChunks": [
        {
          "chunkId": "INAM",
          "chunkSize": 14,
          "chunkData": {
            "start": 639160,
            "end": 639174
          }
        },
        {
          "chunkId": "ISFT",
          "chunkSize": 34,
          "chunkData": {
            "start": 639182,
            "end": 639216
          }
        },
        {
          "chunkId": "cue ",
          "chunkSize": 76,
          "chunkData": {
            "start": 639224,
            "end": 639300
          }
        },
        {
          "chunkId": "LIST",
          "chunkSize": 102,
          "format": "adtl",
          "subChunks": [
            {
              "chunkId": "ltxt",
              "chunkSize": 20,
              "chunkData": {
                "start": 639320,
                "end": 639340
              }
            },
            {
              "chunkId": "labl",
              "chunkSize": 16,
              "chunkData": {
                "start": 639348,
                "end": 639364
              }
            },
            {
              "chunkId": "labl",
              "chunkSize": 16,
              "chunkData": {
                "start": 639372,
                "end": 639388
              }
            },
            {
              "chunkId": "labl",
              "chunkSize": 14,
              "chunkData": {
                "start": 639396,
                "end": 639410
              }
            },
            {
              "chunkId": "smpl",
              "chunkSize": 60,
              "chunkData": {
                "start": 639418,
                "end": 639478
              }
            }
          ]
        },
        {
          "chunkId": "smpl",
          "chunkSize": 60,
          "chunkData": {
            "start": 639418,
            "end": 639478
          }
        }
      ]
    },
    {
      "chunkId": "cue ",
      "chunkSize": 76,
      "chunkData": {
        "start": 639224,
        "end": 639300
      }
    },
    {
      "chunkId": "LIST",
      "chunkSize": 102,
      "format": "adtl",
      "subChunks": [
        {
          "chunkId": "ltxt",
          "chunkSize": 20,
          "chunkData": {
            "start": 639320,
            "end": 639340
          }
        },
        {
          "chunkId": "labl",
          "chunkSize": 16,
          "chunkData": {
            "start": 639348,
            "end": 639364
          }
        },
        {
          "chunkId": "labl",
          "chunkSize": 16,
          "chunkData": {
            "start": 639372,
            "end": 639388
          }
        },
        {
          "chunkId": "labl",
          "chunkSize": 14,
          "chunkData": {
            "start": 639396,
            "end": 639410
          }
        },
        {
          "chunkId": "smpl",
          "chunkSize": 60,
          "chunkData": {
            "start": 639418,
            "end": 639478
          }
        }
      ]
    },
    {
      "chunkId": "smpl",
      "chunkSize": 60,
      "chunkData": {
        "start": 639418,
        "end": 639478
      }
    }
  ]
}

This causes an exception where wavefile makes one LIST type (INFO or adtl) a subchunk of the other LIST type.

erikh2000 commented 1 year ago

I think I saw the same problem. I'll add a little more information here.

I get an exception inside of readLISTINFOSubChunks_() where the second subChunk param has a subchunk similar to the one shown above. This causes an exception on this line:

this.head = subChunk.chunkData.start;

...and you can see that the code here is ready to deal with the passed-in structure.

If someone will help me resolve my build issue, I'm happy to contribute a failing test and maybe a fix. The WAV files that fail for me are generated in Audition and contain markers.

erikh2000 commented 1 year ago

Here is a WAV file that should reproduce the exception: female-sad-2.wav

I have all rights to the file and it's MIT-licensed from my repo. I am fine with it being included as a test wav in this repo.