Skip to content

Commit

Permalink
Fix exponential smoothing calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Eliastik committed Mar 4, 2024
1 parent 3172754 commit 9ab87c3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/cjs/SimpleSoundStudioLibrary.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/SimpleSoundStudioLibrary.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/SimpleSoundStudioLibrary.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/esm/SimpleSoundStudioLibrary.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/filters/PassThroughFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export default class PassThroughFilter extends AbstractAudioFilterWorklet<PassTh
return;
}

if (this.eventEmitter && timeDifferenceSamplePerSecond >= 1000) {
this.calculateSmoothedSamplePerSecond(timeDifferenceSamplePerSecond, samplesProcessed);
this.calculateSmoothedSamplePerSecond(timeDifferenceSamplePerSecond, samplesProcessed);

if (this.eventEmitter && timeDifferenceSamplePerSecond >= 1000) {
const remainingTimeSeconds = remainingSamples / this.samplePerSecond;

this.currentTimeSamplesPerSecond = currentTime;
Expand All @@ -90,7 +90,7 @@ export default class PassThroughFilter extends AbstractAudioFilterWorklet<PassTh
private calculateSmoothedSamplePerSecond(timeDifferenceSamplePerSecond: number, samplesProcessed: number): void {
if (timeDifferenceSamplePerSecond > 0) {
const currentSampleRate = (samplesProcessed - this.lastSampleCount) / (timeDifferenceSamplePerSecond / 1000);
this.samplePerSecond = Constants.TREATMENT_TIME_COUNTING_SMOOTHING_FACTOR * this.samplePerSecond + (1 - Constants.TREATMENT_TIME_COUNTING_SMOOTHING_FACTOR) * currentSampleRate;
this.samplePerSecond = (Constants.TREATMENT_TIME_COUNTING_SMOOTHING_FACTOR * currentSampleRate) + ((1 - Constants.TREATMENT_TIME_COUNTING_SMOOTHING_FACTOR) * this.samplePerSecond);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/model/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const Constants = {
VALID_SAMPLE_RATES: [0, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000],
// Interval used by the treatment percent counter. The event will be dispatched each ms defined here
TREATMENT_TIME_COUNTING_THROTTLE_INTERVAL: 100,
TREATMENT_TIME_COUNTING_SMOOTHING_FACTOR: 0.005
TREATMENT_TIME_COUNTING_SMOOTHING_FACTOR: 0.5
};

export default Constants;

0 comments on commit 9ab87c3

Please sign in to comment.