question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Read custom chunks from a midi file, when chunk header contains no size information

See original GitHub issue

Hi. I have a midi file which contains one track with some nested chunks. One of the complex chunks (these ones contains multiple simple chunks or complex chunks, in a nested structure) contains information about waveform data, and the waveform data itself. Yes, wave data in midi file structure. The structure is like this:

AWav- ComplexChunk
    |- WAVE (no chunk size, only these 4 bytes, as a marker)
    |- Afmt SimpleChunk contains chunk size information
    |- Sfmt SimpleChunk contains chunk size information
etc...

using this code

public sealed class AWavChunk : ComplexChunk
    {
        public const string Id = "AWav";

        public AWavChunk() :
            base(Id, new ChunkTypesCollection
            {
                { typeof(WAVEChunk), WAVEChunk.Id },
                //{ typeof(AfmtChunk), AfmtChunk.Id },
                //{ typeof(SfmtChunk), SfmtChunk.Id },
                //{ typeof(SdecChunk), SdecChunk.Id },
                //{ typeof(AdatChunk), AdatChunk.Id },
                //{ typeof(AInfChunk), AInfChunk.Id }
            })
        {
        }

        public override MidiChunk Clone()
        {
            return new AWavChunk
            {
                Chunks = Chunks.Select(c => c.Clone()).ToList()
            };
        }
    }

I’m getting an InvalidChunkSizeException for WAVE chunk. (Actual size (1366657) of a WAVE chunk differs from the one declared in the chunk’s header (1097231732)). But, as I said, WAVE chunks does not have any size, they are only like markers in this midi file structure. If I comment { typeof(WAVEChunk), WAVEChunk.Id }, in the code above, and uncomment the others I get NotEnoughBytesException

the structure of SimpleChunk and ComplexChunk are the same from #100

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
valimatiescommented, Jun 10, 2022

Thank you Maxim. Till I will make all classes which modifies my file to be able to save it, I will close this issue. In theory, it must work!

1reaction
melanchallcommented, Jun 9, 2022
protected override void ReadContent(MidiReader reader, ReadingSettings settings, uint size)
{
    reader.Position += 4; // skip WAVE marker
    base.ReadContent(reader, settings, size - 4);
}

protected override void WriteContent(MidiWriter writer, WritingSettings settings)
{
    writer.WriteString("WAVE");
    base.WriteContent(writer, settings);
}

protected override uint GetContentSize(WritingSettings settings)
{
    return base.GetContentSize(settings) + 4;
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing MIDI with incorrect track chunk size?
From what I understand, the chunk size refers to the amount of bytes before the start of the next track chunk, or else...
Read more >
Class MidiChunk | DryWetMIDI
MIDI files are made up of chunks. Each chunk has a 4-character type ID and a 32-bit length, which is the number of...
Read more >
Header chunk (of a MIDI file) | RecordingBlogs
The "size" of the header chunk is always six for the six bytes that follow the size (for the format type, number of...
Read more >
Standard MIDI-File Format Spec. 1.1, updated
MIDI Files contain two types of chunks: header chunks and track chunks. A -header- chunk provides a minimal amount of information pertaining to...
Read more >
Edit/Delete/Save OTS chunks · Issue #94
Hi. After I was able to read custom OTS Chunk, I must Clone - Edit that Chunk and write to another midi file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found