Skip to content

Commit

Permalink
feat: added ts interface for AnalyserNode
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Makowski committed Dec 18, 2024
1 parent e23123b commit d68b172
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/react-native-audio-api/src/core/AnalyserNode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { IAnalyserNode } from '../interfaces';
import AudioNode from './AudioNode';
import BaseAudioContext from './BaseAudioContext';

export default class AnalyserNode extends AudioNode {
fftSize: number;
readonly frequencyBinCount: number;
minDecibels: number;
maxDecibels: number;
smoothingTimeConstant: number;

constructor(context: BaseAudioContext, analyser: IAnalyserNode) {
super(context, analyser);

this.fftSize = analyser.fftSize;
this.frequencyBinCount = analyser.frequencyBinCount;
this.minDecibels = analyser.minDecibels;
this.maxDecibels = analyser.maxDecibels;
this.smoothingTimeConstant = analyser.smoothingTimeConstant;
}

getFloatFrequencyData(array: number[]): void {
(this.node as IAnalyserNode).getFloatFrequencyData(array);
}

getByteFrequencyData(array: number[]): void {
(this.node as IAnalyserNode).getByteFrequencyData(array);
}

getFloatTimeDomainData(array: number[]): void {
(this.node as IAnalyserNode).getFloatTimeDomainData(array);
}

getByteTimeDomainData(array: number[]): void {
(this.node as IAnalyserNode).getByteTimeDomainData(array);
}
}
1 change: 1 addition & 0 deletions packages/react-native-audio-api/src/index.native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { default as AudioBufferSourceNode } from './core/AudioBufferSourceNode';
export { default as AudioContext } from './core/AudioContext';
export { default as AudioDestinationNode } from './core/AudioDestinationNode';
export { default as AudioNode } from './core/AudioNode';
export { default as AnalyserNode } from './core/AnalyserNode';
export { default as AudioParam } from './core/AudioParam';
export { default as AudioScheduledSourceNode } from './core/AudioScheduledSourceNode';
export { default as BaseAudioContext } from './core/BaseAudioContext';
Expand Down
34 changes: 34 additions & 0 deletions packages/react-native-audio-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,40 @@ export class AudioNode {
}
}

export class AnalyserNode extends AudioNode {
readonly fftSize: number;
readonly frequencyBinCount: number;
readonly minDecibels: number;
readonly maxDecibels: number;
readonly smoothingTimeConstant: number;

constructor(context: AudioContext, node: globalThis.AnalyserNode) {
super(context, node);

this.fftSize = node.fftSize;
this.frequencyBinCount = node.frequencyBinCount;
this.minDecibels = node.minDecibels;
this.maxDecibels = node.maxDecibels;
this.smoothingTimeConstant = node.smoothingTimeConstant;
}

public getByteFrequencyData(array: Uint8Array): void {
(this.node as globalThis.AnalyserNode).getByteFrequencyData(array);
}

public getByteTimeDomainData(array: Uint8Array): void {
(this.node as globalThis.AnalyserNode).getByteTimeDomainData(array);
}

public getFloatFrequencyData(array: Float32Array): void {
(this.node as globalThis.AnalyserNode).getFloatFrequencyData(array);
}

public getFloatTimeDomainData(array: Float32Array): void {
(this.node as globalThis.AnalyserNode).getFloatTimeDomainData(array);
}
}

export class AudioScheduledSourceNode extends AudioNode {
private hasBeenStarted: boolean = false;

Expand Down
13 changes: 13 additions & 0 deletions packages/react-native-audio-api/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,16 @@ export interface IAudioParam {
}

export interface IPeriodicWave {}

export interface IAnalyserNode extends IAudioNode {
fftSize: number;
readonly frequencyBinCount: number;
minDecibels: number;
maxDecibels: number;
smoothingTimeConstant: number;

getFloatFrequencyData: (array: number[]) => void;
getByteFrequencyData: (array: number[]) => void;
getFloatTimeDomainData: (array: number[]) => void;
getByteTimeDomainData: (array: number[]) => void;
}

0 comments on commit d68b172

Please sign in to comment.