Skip to content

Commit

Permalink
refactor(equalizer): update vibrato
Browse files Browse the repository at this point in the history
  • Loading branch information
twlite committed Mar 11, 2023
1 parent 48988b6 commit 06fbd44
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
1 change: 0 additions & 1 deletion examples/karasu/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ __metadata:
spotify-url-info: ^3.2.3
youtube-sr: ^4.3.4
peerDependencies:
discord-player: "*"
play-dl: 1.x
ytdl-core: 4.x
languageName: node
Expand Down
17 changes: 3 additions & 14 deletions packages/equalizer/src/audio/AudioFilter.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { TransformCallback } from 'stream';
import { PCMTransformer, PCMTransformerOptions } from '../utils';
import { AFPulsatorConfig, AFTremoloConfig, AFVibratoConfig, LR, applyEqualization, applyPulsator, applyTremolo, applyVibrato } from './transformers';
import { Equalizer, EqualizerBand } from '../equalizer';
import { AFPulsatorConfig, AFTremoloConfig, AFVibratoConfig, LR, applyPulsator, applyTremolo, applyVibrato } from './transformers';
import { EqualizerBand } from '../equalizer';

export const AudioFilters = {
'8D': '8D',
Tremolo: 'Tremolo',
Vibrato: 'Vibrato',
BassBoost: 'BassBoost'
Vibrato: 'Vibrato'
} as const;

export type PCMFilters = keyof typeof AudioFilters;
Expand All @@ -27,10 +26,6 @@ export const BASS_EQ_BANDS: EqualizerBand[] = Array.from({ length: 3 }, (_, i) =
// based on lavadsp
export class AudioFilter extends PCMTransformer {
public filters: PCMFilters[] = [];
public bassEQ = new Equalizer(
2,
BASS_EQ_BANDS.map((m) => m.gain)
);
public targetSampleRate = this.sampleRate;
public totalSamples = 0;
private _processedSamples = 0;
Expand Down Expand Up @@ -106,8 +101,6 @@ export class AudioFilter extends PCMTransformer {
return false;
}

this.bassEQ.bandMultipliers = filters.includes('BassBoost') ? BASS_EQ_BANDS.map((m) => m.gain) : [];

this.filters = filters;

this.onUpdate?.();
Expand Down Expand Up @@ -169,10 +162,6 @@ export class AudioFilter extends PCMTransformer {
public applyFilters(byte: number, channel: LR) {
if (this.filters.length) {
for (const filter of this.filters) {
if (filter === 'BassBoost' && this.bassEQ) {
byte = applyEqualization(this.bassEQ, byte);
}

if (filter === '8D') {
byte = applyPulsator(this.pulsatorConfig, byte, channel);
}
Expand Down
3 changes: 1 addition & 2 deletions packages/equalizer/src/audio/transformers/dsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ export function applyTremolo(config: AFTremoloConfig, int: number, sampleRate: n
return modSignal * int;
}

// TODO
export function applyVibrato(config: AFVibratoConfig, int: number, sampleRate: number) {
const fOffset = 1.0 - config.depth;
const modSignal = fOffset + config.depth * Math.sin(config.phase);
const modSignal = fOffset + config.depth * Math.sin(2 * Math.PI * config.phase);
config.phase += ((2 * Math.PI) / sampleRate) * config.frequency;
return modSignal * int;
}
Expand Down

0 comments on commit 06fbd44

Please sign in to comment.