naudio / NLayer

MPEG 1 & 2 Decoder for Layers 1, 2, & 3
MIT License
124 stars 30 forks source link

8-bit & 16-bit PCM implementations. #23

Closed roncli closed 2 years ago

roncli commented 3 years ago

Background: Some time ago I had a need to obtain 16-bit PCM data from NLayer to use with OpenTK/OpenAL. I didn't see a function for it in NLayer, so I decided to write it (along with an 8-bit PCM function). I've been using it for a while and decided to PR it back to the project.

roncli commented 3 years ago

This should be good, although I don't have any code of my own that references the case of bitDepth == 32. The test project ran successfully, and created a .wav from an .mp3 that played in VLC, and the project that I'm using NLayer for had no issues with the updated code.

The major difference between the two functions outside of the logic - and the reason I split them to begin with - was the use of Array buffer vs. byte[] buffer. However, I took a closer look at what that actually meant, and was able to refactor the code to work with the original Array type.

Thanks for taking a look at it!