From f6af7acfbbd0db82cd3e03810c33022919cf9bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=84=A1=E5=B8=B8?= <3142324836@qq.com> Date: Tue, 3 Dec 2024 23:12:34 +0800 Subject: [PATCH] Fixed audio recording noise --- src/audioCore/graph/SourceRecordProcessor.cpp | 7 +++---- src/audioCore/misc/RecordTemp.cpp | 6 ++++-- src/audioCore/misc/RecordTemp.h | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/audioCore/graph/SourceRecordProcessor.cpp b/src/audioCore/graph/SourceRecordProcessor.cpp index c76596c..470d5d0 100644 --- a/src/audioCore/graph/SourceRecordProcessor.cpp +++ b/src/audioCore/graph/SourceRecordProcessor.cpp @@ -23,13 +23,12 @@ void SourceRecordProcessor::processBlock( if (!playHead) { return; } auto playPosition = playHead->getPosition(); if (!playPosition->getIsPlaying() || !playPosition->getIsRecording()) { return; } - int timeInSamples = playPosition->getTimeInSamples().orFallback(0); - double timeInSeconds = playPosition->getTimeInSeconds().orFallback(0); + int64_t timeInSamples = playPosition->getTimeInSamples().orFallback(0); /** Record Data Temp */ - RecordTemp::getInstance()->recordData(timeInSeconds, buffer, midiMessages); + RecordTemp::getInstance()->recordData((uint64_t)timeInSamples, buffer, midiMessages); - /** TODO Callback */ + /** Callback */ /*if (trackIndexList.size() > 0 && buffer.getNumSamples() > 0) { this->limitedCall.call([trackIndexList] { UICallbackAPI&>::invoke( diff --git a/src/audioCore/misc/RecordTemp.cpp b/src/audioCore/misc/RecordTemp.cpp index 2184f86..28e76b2 100644 --- a/src/audioCore/misc/RecordTemp.cpp +++ b/src/audioCore/misc/RecordTemp.cpp @@ -20,12 +20,14 @@ void RecordTemp::setInputChannelNum(int channels) { std::max(this->audioBuffer.getNumSamples(), AUDIO_BUFFER_MIN), true, true, true); } -void RecordTemp::recordData(double timeSec, +void RecordTemp::recordData(uint64_t timeSample, const juce::AudioBuffer& buffer, const juce::MidiBuffer& midiMessages) { /** Lock */ juce::GenericScopedLock locker(this->lock); /** Set Start Time */ + double timeSec = timeSample / this->sampleRate; + uint64_t bufferStartSample = this->startTime * this->sampleRate; if (timeSec < this->startTime) { this->clearAll(); } @@ -44,7 +46,7 @@ void RecordTemp::recordData(double timeSec, /** Write Audio Buffer */ if (this->recordAudio) { - uint64_t startSample = (timeSec - this->startTime) * this->sampleRate; + uint64_t startSample = timeSample - bufferStartSample; uint64_t endSample = startSample + buffer.getNumSamples(); if (this->tryToEnsureAudioBufferSamplesAllocated(endSample)) { int channelNum = std::min(buffer.getNumChannels(), this->audioBuffer.getNumChannels()); diff --git a/src/audioCore/misc/RecordTemp.h b/src/audioCore/misc/RecordTemp.h index 459a8ac..03a2a2d 100644 --- a/src/audioCore/misc/RecordTemp.h +++ b/src/audioCore/misc/RecordTemp.h @@ -8,7 +8,7 @@ class RecordTemp final : private juce::DeletedAtShutdown { void setInputSampleRate(double sampleRate); void setInputChannelNum(int channels); - void recordData(double timeSec, + void recordData(uint64_t timeSample, const juce::AudioBuffer& buffer, const juce::MidiBuffer& midiMessages); void setRecordMIDI(bool recordMIDI);