Gegenseitige Hilfe
Skip to content
by Guest » 05 Jan 2025, 11:49
Code: Select all
public EditorViewModel() { _outputDevice = new WaveOutEvent(); _mixer = new MixingSampleProvider(WaveFormat.CreateIeeeFloatWaveFormat(48000, 2)) { ReadFully = true }; _bufferedWaveProvider = new BufferedWaveProvider(_mixer.WaveFormat); _outputDevice.Init(_bufferedWaveProvider); }
private void MixAudioTracks() { _mixer.RemoveAllMixerInputs(); _audioFileReaders = []; foreach (var track in Tracks) { foreach (var segment in track.Segments) { var inputStream = new AudioFileReader(segment.AudioPath) { Volume = segment.Volume }; var offsetProvider = new OffsetSampleProvider(inputStream.ToSampleProvider()) { DelayBy = TimeSpan.FromTicks(segment.StartTime), SkipOver = TimeSpan.FromTicks(segment.StartTimeOffset), Take = TimeSpan.FromTicks(segment.Length - segment.EndTimeOffset) }; var pitchProvider = new SmbPitchShiftingSampleProvider(offsetProvider) { PitchFactor = segment.SpeedFactor / SpeedFactor //Segment vs previewer speed }; _audioFileReaders.Add(inputStream); _mixer.AddMixerInput(pitchProvider); } } FillBuffer(true); }
private void SeekAudio() { foreach (var fileReader in _audioFileReaders) { fileReader.CurrentTime = TimeSpan.FromTicks(CurrentTime); //TODO: Adjust with segment Start and Offsets } FillBuffer(true); } private void FillBuffer(bool force = false) { if (!force && _lastSampleTime >= 0 && (_lastSampleTime < CurrentTime || _lastSampleTime + _bufferedWaveProvider.BufferDuration.Ticks < CurrentTime)) return; //if (force || CurrentTime < _lastSampleTime) _bufferedWaveProvider.ClearBuffer(); var floatBuffer = new float[_bufferedWaveProvider.BufferLength / 4]; var bytesRead = _mixer.Read(floatBuffer, 0, floatBuffer.Length); //Convert float array to byte array var byteBuffer = new byte[bytesRead * 4]; //4 bytes per float Buffer.BlockCopy(floatBuffer, 0, byteBuffer, 0, byteBuffer.Length); _bufferedWaveProvider.AddSamples(byteBuffer, 0, byteBuffer.Length); //Update the last sample timestamp. _lastSampleTime = CurrentTime; }
Top