Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 17 additions & 8 deletions src/FaustAudioWorkletProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
AudioWorkletGlobalScope,
LooseFaustDspFactory,
FaustDspMeta,
FaustFeatureFlags,
FaustUIItem
} from './types';
import type {
Expand All @@ -27,6 +28,7 @@ export interface FaustData {
dspMeta: FaustDspMeta;
poly: boolean;
effectMeta?: FaustDspMeta;
features: FaustFeatureFlags;
}
export interface FaustAudioWorkletProcessorDependencies<
Poly extends boolean = false
Expand Down Expand Up @@ -92,7 +94,10 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(
FaustAudioWorkletProcessorCommunicator
} = dependencies;

const { processorName, dspName, dspMeta, effectMeta, poly } = faustData;
const { processorName, dspName, dspMeta, effectMeta, poly, features } =
faustData;
const needsSensors = features.hasAcc || features.hasGyr;
const isPoly = !!(poly || features.hasPoly);

// Analyse voice JSON to generate AudioParam parameters
const analysePolyParameters = (
Expand All @@ -109,7 +114,7 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(
const isPolyReserved =
'address' in item &&
!!polyKeywords.find((k) => item.address.endsWith(k));
if (poly && isPolyReserved) return null;
if (isPoly && isPolyReserved) return null;
if (
item.type === 'vslider' ||
item.type === 'hslider' ||
Expand Down Expand Up @@ -146,15 +151,19 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(
protected paramValuesCache: Record<string, number> = {};

protected wamInfo?: { moduleId: string; instanceId: string };
protected fCommunicator: FaustAudioWorkletProcessorCommunicator;
protected fCommunicator?: FaustAudioWorkletProcessorCommunicator;
protected readonly features: FaustFeatureFlags;

constructor(options: FaustAudioWorkletNodeOptions<Poly>) {
super(options);

// Setup port message handling
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator(
this.port
);
this.features = features;
if (needsSensors) {
this.fCommunicator = new FaustAudioWorkletProcessorCommunicator(
this.port
);
}

const { parameterDescriptors } = this
.constructor as typeof AudioWorkletProcessor;
Expand Down Expand Up @@ -212,15 +221,15 @@ const getFaustAudioWorkletProcessor = <Poly extends boolean = false>(
this.setParamValue(path, paramValue);
}
}
if (this.fCommunicator.getNewAccDataAvailable()) {
if (needsSensors && this.fCommunicator?.getNewAccDataAvailable()) {
const acc = this.fCommunicator.getAcc();
if (acc) {
this.fCommunicator.setNewAccDataAvailable(false);
const { invert, ...data } = acc;
this.propagateAcc(data, invert);
}
}
if (this.fCommunicator.getNewGyrDataAvailable()) {
if (needsSensors && this.fCommunicator?.getNewGyrDataAvailable()) {
const gyr = this.fCommunicator.getGyr();
if (gyr) {
this.fCommunicator.setNewGyrDataAvailable(false);
Expand Down
Loading