private void ConvertToMp3() { string audio_path = GetWavAudioName(); string mp3Path = GetMp3AudioPath(); if (mAudioWriter != null) { mAudioWriter.Dispose(); //Release file mAudioWriter.WavToMP3(audio_path, mp3Path); } }
private string SaveAudioFromBufferToFile() { try { string fileName = GetWavAudioChildName((mListOfflineAudioFile.Count + 1).ToString()); Queue <WaveInEventArgs> remainRawData = new Queue <WaveInEventArgs>(); double savedAudioLengthInArrayLength = 0; double saveAudioLengthInSecond = 0; int remainAudioLength = 0; AudioWriter wavWriter = new AudioWriter(fileName); lock (balanceLock) { while (saveAudioLengthInSecond < Int16.Parse(mRecordingTime) * 60 && mRawAudioData.Count > 0) { WaveInEventArgs rawData = mRawAudioData.Dequeue(); if (saveAudioLengthInSecond >= (Int16.Parse(mRecordingTime) * 60 - 3)) { remainRawData.Enqueue(rawData); remainAudioLength += rawData.BytesRecorded; } wavWriter.WriteStream(rawData.Buffer, rawData.BytesRecorded); savedAudioLengthInArrayLength += rawData.BytesRecorded; saveAudioLengthInSecond = savedAudioLengthInArrayLength / (16000 * 2); } while (mRawAudioData.Count > 0) { remainRawData.Enqueue(mRawAudioData.Dequeue()); } mRawAudioData = remainRawData; mRawAudioLength = remainAudioLength; } wavWriter.Dispose(); string mp3FileName = GetMp3AudioChildPath((mListOfflineAudioFile.Count + 1).ToString()); wavWriter.WavToMP3(fileName, mp3FileName); //Remove wavfile File.Delete(fileName); return(mp3FileName); } catch { return(null); } }
private string SaveAllAudioFromBufferFile() { lock (balanceLock) { if (mRawAudioData.Count < 20) { mRawAudioData.Clear(); mRawAudioLength = 0; return(null); } } try { string fileName = GetWavAudioChildName((mListOfflineAudioFile.Count + 1).ToString()); AudioWriter wavWriter = new AudioWriter(fileName); lock (balanceLock) { while (mRawAudioData.Count > 0) { WaveInEventArgs rawData = mRawAudioData.Dequeue(); wavWriter.WriteStream(rawData.Buffer, rawData.BytesRecorded); } mRawAudioLength = 0; } wavWriter.Dispose(); string mp3FileName = GetMp3AudioChildPath((mListOfflineAudioFile.Count + 1).ToString()); wavWriter.WavToMP3(fileName, mp3FileName); //Remove wavfile File.Delete(fileName); return(mp3FileName); } catch { return(null); } }
/// <summary> /// Renders a listener to a file, and returns some measurements of the render. /// </summary> public static RenderStats WriteRender(Listener listener, Track target, AudioWriter writer, TaskEngine taskEngine, bool dynamicOnly, bool heightOnly) { RenderStats stats = new(listener); const long updateInterval = 50000; long rendered = 0, untilUpdate = updateInterval; double samplesToProgress = 1.0 / target.Length, samplesToSeconds = 1.0 / listener.SampleRate; bool customMuting = dynamicOnly || heightOnly; DateTime start = DateTime.Now; while (rendered < target.Length) { float[] result = listener.Render(); #if DEBUG if (rendered > 2500000 && WaveformUtils.GetPeakSigned(result) > .5f) { ; // TODO: debug, Amaze will follow with a heavy gain frame and then a normal frame after this detection } #endif if (target.Length - rendered < listener.UpdateRate) { Array.Resize(ref result, (int)(target.Length - rendered)); } if (writer != null) { writer.WriteBlock(result, 0, result.LongLength); } if (rendered > firstFrame) { stats.Update(); } if (customMuting) { IReadOnlyList <Source> objects = target.Renderer.Objects; for (int i = 0, c = objects.Count; i < c; ++i) { Vector3 rawPos = objects[i].Position / Listener.EnvironmentSize; objects[i].Mute = (dynamicOnly && MathF.Abs(rawPos.X) % 1 < .01f && MathF.Abs(rawPos.Y) % 1 < .01f && MathF.Abs(rawPos.Z % 1) < .01f) || (heightOnly && rawPos.Y == 0); } } rendered += listener.UpdateRate; if ((untilUpdate -= listener.UpdateRate) <= 0) { double progress = rendered * samplesToProgress; double speed = rendered * samplesToSeconds / (DateTime.Now - start).TotalSeconds; taskEngine.UpdateStatusLazy($"Rendering... ({progress:0.00%}, speed: {speed:0.00}x)"); taskEngine.UpdateProgressBar(progress); untilUpdate = updateInterval; } } if (writer != null) { writer.Dispose(); } return(stats); }