naudio / NAudio

Audio and MIDI library for .NET
MIT License
5.5k stars 1.1k forks source link

SoundFont sample data has a 12 bytes offset #444

Closed faelenor closed 2 years ago

faelenor commented 5 years ago

In NAudio.SoundFont.SampleDataChunk constructor, only the id of the "sdta" chunk header is read before calling the GetData function. This is wrong because the size of that chunk is still unread, as long as the next "smpl" sub-chunk header! Because of this, the sample data is read from the file 12 bytes before it really starts (4 bytes for "sdta" chunk size + 4 bytes for "smpl" chunk id + 4 bytes for "smpl" chunk size). The total size of the sample data is also wrong because it's set to the size of the "LIST" chunk.

As a side note, there seems to be some confusion with ReadChunkID. This is sometimes called on a chunk created by GetNextSubChunk and this function already calls ReadChunkID. The result of that call is that it will read the next chunk ID! In the SoundFont constructor, this line is commented: //RiffChunk r = list.GetNextSubChunk(); This kind of confirms that whoever changed that did not fully understand what he was doing.

markheath commented 5 years ago

The SoundFont support was a very early part of NAudio and is only really experimental. I have considered removing it, but I am also happy to accept PRs to fix this

oggy22 commented 2 years ago

Are there any news on soundfonts progress? I'd be really happy to be able to use them.

sinshu commented 2 years ago

@oggy22 I've implemented a SoundFont parser and synthesizer which can work with NAudio. Please check this out if you are interested. https://github.com/sinshu/meltysynth

markheath commented 2 years ago

@sinshu thanks for sharing, looks like a great project

sinshu commented 1 year ago

@rjjaret This is NAudio's issue page, and it's not suitable for asking about MeltySynth. For questions about MeltySynth, please check the issue page below, and create a new issue if necessary. https://github.com/sinshu/meltysynth/issues