Skip to content

Commit

Permalink
Fixed audio recording noise
Browse files Browse the repository at this point in the history
  • Loading branch information
FangCunWuChang committed Dec 3, 2024
1 parent 3ca7fc7 commit f6af7ac
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/audioCore/graph/SourceRecordProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const std::set<int>&>::invoke(
Expand Down
6 changes: 4 additions & 2 deletions src/audioCore/misc/RecordTemp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>& 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();
}
Expand All @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion src/audioCore/misc/RecordTemp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>& buffer, const juce::MidiBuffer& midiMessages);

void setRecordMIDI(bool recordMIDI);
Expand Down

0 comments on commit f6af7ac

Please sign in to comment.