Naudio sound normalize

ⅰ亾dé卋堺 提交于 2019-12-11 07:45:48

问题


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].


回答1:


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.




回答2:


float to short:

float num1; short num6 = (short)num1;

http://www.convertdatatypes.com/Convert-short-to-byte-in-CSharp.html

http://www.c-sharpcorner.com/uploadfile/mahesh/convert-long-short-single-to-byte-array-in-C-Sharp/



来源:https://stackoverflow.com/questions/9802461/naudio-sound-normalize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!