/// <summary> /// Create a new file based on the given filename and start recording to it. /// Filename must include its full path. /// </summary> /// <param name="fileName">The name of a file to be created. Include its full path</param> /// <param name="codec">The codec to record in</param> /// <param name="bitRate">The bitrate of the file</param> /// <param name="channels">The channels to record</param> public void StartCapture(string fileName, AvailableCodecs codec, int bitRate, Channels channels) { if (!ReadyToRecord()) { throw new NullReferenceException("There is no SoundInSource configured for the recorder."); } fileName = $"{fileName}.{codec.ToString().ToLower()}"; WaveFormat waveSource; switch (channels) { case Channels.Mono: waveSource = _soundInSource.ToMono().WaveFormat; break; case Channels.Stereo: waveSource = _soundInSource.ToStereo().WaveFormat; break; default: throw new ArgumentException("The selected channel option could not be found."); } switch (codec) { case AvailableCodecs.MP3: _writer = MediaFoundationEncoder.CreateMP3Encoder(waveSource, fileName, bitRate); break; case AvailableCodecs.AAC: _writer = MediaFoundationEncoder.CreateAACEncoder(waveSource, fileName, bitRate); break; case AvailableCodecs.WMA: _writer = MediaFoundationEncoder.CreateWMAEncoder(waveSource, fileName, bitRate); break; case AvailableCodecs.WAV: _writer = new WaveWriter(fileName, waveSource); break; default: throw new ArgumentException("The specified codec was not found."); } byte[] buffer = new byte[waveSource.BytesPerSecond]; _soundInSource.DataAvailable += (s, e) => { int read = _waveStream.Read(buffer, 0, buffer.Length); _writer.Write(buffer, 0, read); }; // Start recording _soundInSource.SoundIn.Start(); _state = RecordingState.Recording; }
private void TryReplacingTrackContents(Blackboard blackboard, TemporaryTrack track) { if (track.ExpectedName == null) { return; } var originalCodec = AvailableCodecs.GetCodec(track.CurrentCodec); if (originalCodec == null) { blackboard.Logger.Error($"The track ({track.ExpectedName}) uses the {track.OriginalEntry.Codec} Codec, but AudioMog has no handler to replace it! Skipping!"); return; } var typelessFilePath = Path.Combine(_hcaFilesFolder, track.ExpectedName); if (blackboard.Settings.UseWavFilesIfAvailable) { var wavFilePath = AddExtension(typelessFilePath, ".wav"); if (File.Exists(wavFilePath)) { blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, ".wav")}!"); var wavFileBytes = File.ReadAllBytes(wavFilePath); var wavReader = new WaveReader(); var audioData = wavReader.Read(wavFileBytes); var hcaWriter = new HcaWriter(); var hcaFileBytes = hcaWriter.GetFile(audioData); track.RawPortion = hcaFileBytes; track.CurrentCodec = MaterialCodecType.HCA; return; } } var hcaFilePath = AddExtension(typelessFilePath, ".hca"); if (File.Exists(hcaFilePath)) { blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, ".hca")}!"); var hcaFileBytes = File.ReadAllBytes(hcaFilePath); track.RawPortion = hcaFileBytes; track.CurrentCodec = MaterialCodecType.HCA; return; } var rawFilePath = AddExtension(typelessFilePath, originalCodec.FileFormat); if (File.Exists(rawFilePath)) { blackboard.Logger.Log($"Appending {AddExtension(track.ExpectedName, originalCodec.FileFormat)}!"); var hcaFileBytes = File.ReadAllBytes(rawFilePath); track.RawPortion = hcaFileBytes; track.CurrentCodec = track.OriginalEntry.Codec; return; } blackboard.Logger.Log($"Found no replacement to {track.ExpectedName}, using original track from uexp!"); }
private void FixHeader(TemporaryTrack track) { var codec = AvailableCodecs.GetCodec(track.CurrentCodec); if (codec == null) { return; } codec.FixHeader(track); }
public void RefreshCodecs() { // Available Codecs AvailableCodecs.Clear(); AvailableCodecs.Add(new AviCodec("Gif")); foreach (var codec in AviWriter.EnumerateEncoders()) { AvailableCodecs.Add(codec); } SelectedCodec = AviCodec.MotionJpeg; }
public void LoadSettings() { // Fetch the saved settings this._writeDir = Properties.Settings.Default.writeDir; this._inputDevice = Properties.Settings.Default.inputDevice; this._writeAvailableCodecs = (AvailableCodecs)Properties.Settings.Default.writeCodec; // Set the write directory to the saved value this.saveDirectoryTextBox.Text = this._writeDir; //Load the user selected availableCodecs in this.recordingFormatComboBox.SelectedItem = this._writeAvailableCodecs; }
public static void RefreshCodecs() { // Available Codecs AvailableCodecs.Clear(); AvailableCodecs.Add(new AviCodec("Gif")); foreach (var Codec in AviWriter.EnumerateEncoders()) { AvailableCodecs.Add(Codec); } if (Instance != null) { Instance.EncodersBox.SelectedIndex = 2; } }
private void WriteOutAudioFile(byte[] fileBytes, string outputFolder, MaterialSection.MaterialEntry entry) { var extractedFilePath = Path.Combine(outputFolder, _materialIndexToFileName[entry.EntryIndex]); var fullFilePath = Path.GetFullPath(extractedFilePath); var fullFolderPath = Path.GetDirectoryName(fullFilePath); if (!Directory.Exists(fullFolderPath)) { Directory.CreateDirectory(fullFolderPath); Logger.Log($"Created folder at: {fullFolderPath}"); } var codec = AvailableCodecs.GetCodec(entry.Codec); if (codec == null) { Logger.Error( $"The track ({_materialIndexToFileName[entry.EntryIndex]}) uses the {entry.Codec} Codec, but AudioMog has no handler to extract it! Skipping!"); return; } if (Settings.AudioExtractor.ExtractAsRaw) { var rawPath = ExtensionMethods.ChangeExtension(fullFilePath, codec.FileFormat); codec.ExtractOriginal(Logger, entry, fileBytes, rawPath); } if (Settings.AudioExtractor.ExtractAsWav) { try { var wavPath = ExtensionMethods.ChangeExtension(fullFilePath, ".wav"); codec.ExtractAsWav(Logger, entry, fileBytes, wavPath); } catch (Exception e) { Logger.Error("Failed to convert to wav! Will attempt to continue extraction!"); Logger.Error(e.ToString()); } } }