public void Start() { int NumSamples = InputBitmap.Width * InputBitmap.Height; byte[] Samples = new byte[NumSamples]; OutputWav = new WaveFile(1, 16, 44000); if (InputBitmap == null) { throw new Exception(NoInputBitmap); } double[] data = new double[InputBitmap.Height]; int w = 0; for (int i = 0; i < InputBitmap.Width; i++) { for (int j = 0; j < InputBitmap.Height; j++) { Color C = InputBitmap.GetPixel(i, j); data[j] = (C.R + C.G + C.B) / 3; } FFT_Img2Wav.inverse(data); // Ciclo per tutti i data for (int x = 0; x < data.Length; x++) { Samples[w] = (byte)(MAX_DATA * data[x]); w++; } } OutputWav.SetData(Samples, NumSamples); }
public static void KcsEncode300(Stream stream, byte[] dataBytes) { if (sampleRate % 300 != 0) { throw new ArgumentException("Sample rate not evenly divisible by baud."); } const uint bitSamples = sampleRate / 300; const uint frameSize = 11; // leading zero, eight data bits, two trailing ones WaveFile waveFile = new WaveFile(sampleRate, 1, 8); // signed byte buffer = dataBytes * byte frameSize * samples/bit sbyte[] waveData = new sbyte[dataBytes.Length * frameSize * bitSamples]; // bytes * bits/byte * samples/bit = samples uint index = 0; for (int i = 0; i < dataBytes.Length; i++) { bool[] bits = GetBits(dataBytes[i]); index = WriteBit300(waveData, index, false, bitSamples); for (int j = 0; j < 8; j++) { index = WriteBit300(waveData, index, bits[j], bitSamples); } index = WriteBit300(waveData, index, true, bitSamples); index = WriteBit300(waveData, index, true, bitSamples); } byte[] outputBytes = new byte[waveData.Length]; Buffer.BlockCopy(waveData, 0, outputBytes, 0, outputBytes.Length); waveFile.SetData(outputBytes); waveFile.WriteToStream(stream); }