[Solved] How to read wav-markers in Unity?

Hello. I’ve been experimenting with making an interactive music system in Unity, and I think it would be really useful to be able to read markers within wav-files. In a DAW such as Reaper, I can put markers in a project like so:

I can then render the project as a wav-file, and Reaper will put the markers in the header of the file:

This is what it looks like if I import a wav-file with markers into Reaper:

Is there any way to read the header information of wav-files, in order to retrieve these markers within a Unity script?

I’ve attached the test.wav file above for anyone who might want to experiment with solutions.

5672920–591340–test.zip (2.59 KB)

Did you ever find a solution for this? :slight_smile:

You might want to check out this: Audio-Video Markers

Oh hey Nikolaj. I’m Mordi. No, unfortunately I haven’t found a solution yet. Giving it another go now, to hopefully use this method for a dynamic game soundtrack.

This is a great lead. Thanks for posting!

Repear saves the marker metadata differently than audition, seems like the markers are saved as “Cue Points” which is binary data. You can extract that data with exiftool -b.

Binary data, unknown how to extract time markers from that. Looks like the markers are saved in those 3 areas where is says “data”.

Well I saved the file with Audition and can parse the markers just fine.

public void PopulateMetadata() {       
    wrapper.Run("F:/Users/Selzier/Documents/Unity5/SmokeAndChill360/Assets/_Music/test2.wav", false);
    Debug.Log("metadata done");
    foreach (ExifTagItem i in wrapper) {
        Debug.Log("Group: " + i.group + "; Name: " + i.name + "; Value: " + i.value);
    }
}

Aha, I see. I guess that exiftool won’t help in my case then. I actually managed to start reading a wav-file yesterday, by studying the wav-specification. This is a good source, as well as this one.

I’m literally just reading the file using a standard FileStream object.

FileStream fs = new FileStream(path, FileMode.Open);
for (int i = 0; i < x; i++) {
    int b = fs.ReadByte();
}

Something like this.

Hopefully I can manage to read the cue points today. I’ll post here if I have any breakthroughs.

Just going to throw down a shameless plug here for Koreographer. It provides Cue Point-like functionality… on steroids. The base edition is sufficient for basic Cue Point style work. The Professional Edition provides you with a MIDI Converter (convert MIDI events into Cue Points/markers), expanded Payload types, and added integrations with third party audio engines.

Regardless, best of luck finding a solution to parsing the Cue Points from your raw WAV files!

I managed to eat my way into my wav file even more today. I’ve gotten to the bext-chunk now, which I think is where the cue-chunk is hiding.

As a reference, I am using this specification - although it doesn’t mention a cue chunk.

Also, I stumbled upon this library (Audio Tools Library for .NET). Could be a good alternative to my method.

Edit: Aha! The cue chunk was after the data chunk. Success!

I used this page as a reference.

1 Like

Mission accomplished!

3 Likes

Someone messaged me to ask how this works, so I’ll just share the solution I ended up with here.

It’s fairly straightforward to use. Should be something like this:

using MordiAudio;

class Example {
    Wave.Metadata metadata = Wave.Reader.GetMetadata("Audio/whatever.wav");
}

The metadata object contains all sorts of info, including a list of cues.
I’ve tested it with a handful of wave files exported from various DAWs, and haven’t run into any issues yet.

7642879–952369–WaveFile.cs (26.2 KB)

11 Likes