Skip to content
This repository was archived by the owner on Jun 18, 2025. It is now read-only.
Merged
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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,11 @@ fft(index: number,

Parameters:

- `index: number` : The index of the bucket to return the value from.
- `buckets: number`: The number of buckets to combine the underlying FFT data
- `index: number` (default: 0): The index of the bucket to return the value from.
- `buckets: number` (default:1): The number of buckets to combine the underlying FFT data
too. Defaults to 8.
- `options?: { min?: number; max?: number, scale?: number }`:
- `options?: { min?: number; max?: number, scale?: number } | string`:
- if string, it sets the `analyzerId` option directly
- `min?: number`: Minimum clamp value of the underlying data. Defaults to
-150.
- `max?: number`: Maximum clamp value of the underlying data. Defaults to 0.
Expand Down
42 changes: 36 additions & 6 deletions packages/web/src/lib/hydra-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,46 @@ export class HydraWrapper {
// Enables Hydra to use Strudel frequency data
// with `.scrollX(() => fft(1,0)` it will influence the x-axis, according to the fft data
// first number is the index of the bucket, second is the number of buckets to aggregate the number too
window.fft = (
index: number,
buckets: number = 8,
window.fft = fftImpl;

const self = this;

function fftImpl(
index?: number,
buckets?: number,
options?: string,
): number;
function fftImpl(
index?: number,
buckets?: number,
options?: {
min?: number;
max?: number;
scale?: number;
analyzerId?: string;
},
) => {
): number;
function fftImpl(
index?: number,
buckets?: number,
options?:
| {
min?: number;
max?: number;
scale?: number;
analyzerId?: string;
}
| string,
): number {
index = index ?? 0;
buckets = buckets ?? 1;
options =
options != null
? typeof options === "string"
? { analyzerId: options }
: options
: options;

const analyzerId = options?.analyzerId ?? "flok-master";
const min = options?.min ?? -150;
const scale = options?.scale ?? 1;
Expand All @@ -128,7 +158,7 @@ export class HydraWrapper {
if (window.strudel == undefined) return 0.5;

// If display settings are not enabled, we just return a default value
if (!(this._displaySettings.enableFft ?? true)) return 0.5;
if (!(self._displaySettings.enableFft ?? true)) return 0.5;

// Enable auto-analyze
window.strudel.enableAutoAnalyze = true;
Expand All @@ -155,7 +185,7 @@ export class HydraWrapper {
.slice(bucketSize * index, bucketSize * (index + 1))
.reduce((a, b) => a + b, 0) / bucketSize
);
};
}

this.initialized = true;
console.log("Hydra initialized");
Expand Down