WavTagReader takes a very long time reading non ID3/LIST chunks

Issue #126 resolved
Dan Gravell created an issue

I was seeing load times of ~90s for a WAV file! So I debugged it...

WavInfoReader seems to read the file fine. But WavTagReader seemed wrong - my profiler counted over 4m invocations of the readChunk(RandomAccessFile, WavTag) method...

I looked at the file with showriff:

$ showriff ~/bliss-test/2446-onefile/01-01-THE_TEARDROP_EXPLODES-Ha_Ha_I_m_Drowning-LLS.wav 
Contents of file /home/gravelld/bliss-test/2446-onefile/01-01-THE_TEARDROP_EXPLODES-Ha_Ha_I_m_Drowning-LLS.wav (39384204/0x9384204 bytes):

(0x00000000)       ID:<RIFF>   Size: 0x0258f484
                   Form Type = <WAVE>
(0x0000000c)           ID:<id3 >   Size: 0x00000804
(0x00000818)           ID:<LIST>   Size: 0x000000e0
                       List Type = <INFO>
(0x00000824)               ID:<IPRD>   Size: 0x00000013
(0x00000840)               ID:<INAM>   Size: 0x00000030
(0x00000878)               ID:<IPRT>   Size: 0x00000002
(0x00000882)               ID:<IFRM>   Size: 0x00000003
(0x0000088e)               ID:<ICRD>   Size: 0x00000005
(0x0000089c)               ID:<ICOP>   Size: 0x0000000d
(0x000008b2)               ID:<IGNR>   Size: 0x00000009
(0x000008c4)               ID:<IART>   Size: 0x00000016
(0x000008e2)               ID:<ISTR>   Size: 0x00000016
(0x00000900)           ID:<JUNK>   Size: 0x00003704
(0x0000400c)           ID:<fmt >   Size: 0x00000010
    format       = 1
    channels     = 2
    rate         = 44100
    av_bps       = 176400
    blockalign   = 4
    size         = 16
(0x00004024)           ID:<data>   Size: 0x0258b460

Then I debugged. When readChunk is called in WavInfoReader and the chunk type is not recognised, it skips the bytes for the chunk:

        //Unknown chunk type just skip
        else
        {
            logger.config("Skipping chunk bytes:" + chunkHeader.getSize());
            raf.skipBytes((int)chunkHeader.getSize());
        }

This doesn't happen in WavTagReader. Instead I think we must rely on ensureOnEqualBoundary to skip bytes one-by-one until we get to the next chunk! In this example, the ID3 and LIST chunks are read, then we read byte by byte on the remaining three chunks until the rest of the file.

It might be that this file is in an unexpected structure. I haven't had this problem in other files.

Is my reading of this incorrect?

Comments (8)

  1. IJabz repo owner

    I looked at the code and I think that WavTagReader does skip bytes if it knows the chunktype, but doesnt if it doesnt. And in this file there is a JUNK chunk which is unknown, I don't think it skip bytes for the fmt and data chunks though. So I have put in a fix to deal with unknown chunks such as the JUNK chunk so as I dont have the datafile please test and see if it fixes it.

  2. Dan Gravell reporter

    Yeah that's what it looks like for me. Just needs a code block like the one in WavInfoReader?

    Do you still need the WAV? Bear in mind I'm on rural broadband here... ;-)

  3. IJabz repo owner

    How do you run your business on rural broadband, I dont need the wav if you can download code and try it out to confirm to me the issue is fixed.

  4. Dan Gravell reporter

    So long as you remember to shovel enough coal into the router I can get about 128kbps...

    Sure I can test - I'm about to go on paternity leave however! So might be a few days before I get back to you.

  5. Log in to comment