user123_456
user123_456

Reputation: 5805

Naudio sound normalize

I am using Naudio and I have a stream which I need to read as array and then when I have found maximum I need to multiply each value with ( 1/ biggest ) and then I should have values in my array as [-1,1].

Upvotes: 1

Views: 1528

Answers (2)

YoryeNathan
YoryeNathan

Reputation: 14542

I don't see really what you mean by "convert", but instead of the code you wrote you could just do:

var bytes = stream.ToArray();
var biggest = (float)bytes.Max();
var floats = bytes.Select(b => b / biggest).ToArray();

This will result with floats between 0 and 1, since bytes are always positive.

Upvotes: 2

Related Questions