private static void Conversion()
{
string filename = "audio_bin2";
byte[] myBytes =File.ReadAllBytes(filename); // entre 0 et 255 short
short[] myShort = new short[myBytes.Length]; // entre 0 et | 257
short[] myShortDouble = new short[myBytes.Length*2];
byte[] myBytes16MHz = new byte[myShortDouble.Length * 2];
int short_intervalle = short.MaxValue - short.MinValue;
int multiplieur = short_intervalle/Byte.MaxValue;
for (int i = 0; i < myBytes.Length; i++)
{
short sh = myBytes[i];
int tampon = short.MinValue + (sh * multiplieur);
myShort[i] = (short)(tampon);
}
for (int i = 0; i < myShort.Length; i++)
{
myShortDouble[2*i] = myShort[i];
if (i < myShort.Length-1)
{
short half1 = (short)(myShort[i] / 2);
short half2 = (short)(myShort[i + 1] / 2);
myShortDouble[2 * i + 1] = (short)(half1 + half2);
}
if (i == myShort.Length - 1)
{
myShortDouble[2 * i+1] = myShort[i];
}
}
for (int i = 0; i < myShortDouble.Length; i++)
{
myBytes16MHz[2*i] = (byte)myShortDouble[i];
myBytes16MHz[2*i+1] = (byte)(myShortDouble[i] >> 8);
}
/* DateTime d = DateTime.Now;
string datePatt = @"Mdyyyyhhmmsstt";
string filename2 = "audio_raw_" + d.ToString(datePatt);
FileStream fileStream2 = new FileStream(filename2, FileMode.Create);
fileStream2.Write((byte[])myBytes16MHz, 0, myBytes16MHz.Length);
fileStream2.Close();*///MemoryStream get buffer
DateTime d = DateTime.Now;
string datePatt = @"Mdyyyyhhmmsstt";
Console.WriteLine("Conversion finie !!");
string outputFile = "audio_flac_" + d.ToString(datePatt) + ".flac";
FlakeWriter flac = new FlakeWriter(null, 16, 1, 16000, File.Create(outputFile));
//FlacWriter flac = new FlacWriter(File.Create(outputFile), 16, 1, 16000);
//flac.Write(myBytes16MHz, 0, myBytes16MHz.Length);
//flac.Write();
flac.Close();
}