naudio / NLayer

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

The example of the use of NLayer is not precise #11

Closed r2123b closed 3 years ago

r2123b commented 5 years ago

I think the example should be like the following

var fileName = "myMp3File.mp3";
var mpegFile = new MpegFile(filename);
int audioDataLength = (int)(mpegFile.Length/sizeof(float));
float[] samples = new float[audioDataLength ];
mpegFile.ReadSamples(samples, 0, audioDataLength);
markheath commented 5 years ago

The example shows how to read 1 second's worth of samples (or 0.5 seconds for stereo).

Your sample shows reading the entire file into memory, which may not always be desirable for very large files.

r2123b commented 5 years ago

Oh~That's why you set a constant as the array size. Thank you for your reply.