public Wavefile(int fs, WaveBit bit, double[] data, string hash = "", string filePath = "") { Fs = fs; Bit = bit; Data = data; Hash = hash; FilePath = filePath; }
public void Initialize(int fs, WaveBit bit, int sampleLength) { var format = new WAVEFORMATEX(); format.wFormatTag = (ushort)(bit != WaveBit.Bit32 ? 0x01 : 0x03); format.nChannels = 0x01; format.nSamplesPerSec = (uint)fs; format.nBlockAlign = (ushort)((int)bit / 8); format.wBitsPerSample = (ushort)bit; format.nAvgBytesPerSec = (uint)(fs * format.nBlockAlign); RawRIFF = "RIFF".ToCharArray(); RawWAVE = "WAVE".ToCharArray(); Rawfmt = "fmt ".ToCharArray(); TotalSize = sampleLength * format.nBlockAlign + Marshal.SizeOf <WaveHeader>() - 2; // 8 - sizeof(format.cbSize); FmtSize = 16; Format = format; }
async void ExportWave(string filePath, WaveBit bit, double[] newF0) { Player?.Stop(); await Task.Run(() => { var edited = AnalyzedAudio.AnalyzedAudio.ReplaceF0(newF0); var synthesizedAudio = AudioOperatorPlugins.Find(p => p.GetType() == AnalyzedAudio.OperatorType).Synthesize(edited, (p) => { Dispatcher.Invoke(() => { MainView.Progress = p; }); }); var waveFile = new Wavefile(synthesizedAudio.SampleRate, bit, synthesizedAudio.Wave); waveFile.Write(filePath); Dispatcher.Invoke(() => { Lock = false; }); }); }