Skip to content

Commit 34f2d42

Browse files
committed
fix: small cleanup
1 parent c472fd5 commit 34f2d42

File tree

24 files changed

+230
-52
lines changed

24 files changed

+230
-52
lines changed

packages/audiodocs/docs/fundamentals/introduction.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar_position: 1
88

99
React Native Audio API is an imperative, high-level API for processing and synthesizing audio in React Native Applications. React Native Audio API follows the [Web Audio Specification](https://www.w3.org/TR/webaudio-1.1/) making it easier to write audio-heavy applications for iOS, Android and Web with just one codebase.
1010

11-
import OscillatorSquare from '@site/src/components/LandingPage/OscillatorSquare';
11+
import OscillatorSquare from '@site/src/components/OscillatorSquare';
1212

1313
<OscillatorSquare />
1414

packages/audiodocs/src/audio/utils.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,30 @@ export function downSampleLog(
77
): number[] {
88
const nyquist = sampleRate / 2;
99
const binCount = fft.length;
10-
1110
const maxFreq = nyquist;
1211

1312
const buckets = new Array<number>(targetBucketCount).fill(0);
1413
const bucketCounts = new Array<number>(targetBucketCount).fill(0);
1514

16-
for (let i = 0; i < binCount; i++) {
15+
for (let i = 0; i < binCount; i += 1) {
1716
const freq = (i / binCount) * nyquist;
18-
19-
if (freq < minFreq) continue; // skip sub-audible bins
20-
21-
const norm = Math.log(freq / minFreq) / Math.log(maxFreq / minFreq);
22-
const band = Math.min(
23-
targetBucketCount - 1,
24-
Math.floor(norm * targetBucketCount)
17+
const safeFreq = Math.max(freq, minFreq);
18+
const norm = Math.log(safeFreq / minFreq) / Math.log(maxFreq / minFreq);
19+
const band = Math.max(
20+
0,
21+
Math.min(targetBucketCount - 1, Math.round(norm * (targetBucketCount - 1)))
2522
);
2623

2724
buckets[band] += fft[i];
28-
bucketCounts[band]++;
25+
bucketCounts[band] += 1;
2926
}
3027

31-
// Normalize by count
32-
for (let i = 0; i < targetBucketCount; i++) {
33-
if (bucketCounts[i] > 0) {
34-
buckets[i] /= bucketCounts[i];
35-
}
28+
for (let i = 0; i < targetBucketCount; i += 1) {
29+
if (bucketCounts[i] > 0) {
30+
buckets[i] /= bucketCounts[i];
31+
} else {
32+
buckets[i] = buckets[Math.max(0, i - 1)];
33+
}
3634
}
3735

3836
return buckets;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
export default function clearCanvas(canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D) {
3+
ctx.fillStyle = '#fcfcff';
4+
ctx.clearRect(0, 0, canvas.width, canvas.height);
5+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
export default function drawSpectroLines(
4+
ctx: CanvasRenderingContext2D,
5+
bars: number[],
6+
drawCount: number,
7+
bucketShift: number,
8+
barHeight: number,
9+
barWidth: number,
10+
barSpacing: number,
11+
colorMode: 'dark' | 'light',
12+
) {
13+
for (let i = 0; i < drawCount + 2 * bucketShift; i += 1) {
14+
const value = bars[i] || 0;
15+
const height = Math.max((value / 255) * barHeight, 2);
16+
const offset = barHeight - height;
17+
const x = (barWidth + barSpacing) * (i);
18+
19+
const gradient = ctx.createLinearGradient(0, offset + height, 0, offset);
20+
21+
if (colorMode === 'dark') {
22+
gradient.addColorStop(0, '#FF6259');
23+
gradient.addColorStop(0.85, '#232736');
24+
} else {
25+
gradient.addColorStop(0, '#FF6259');
26+
gradient.addColorStop(0.85, '#fcfcff');
27+
}
28+
29+
ctx.fillStyle = gradient;
30+
ctx.fillRect(x, offset, barWidth, height);
31+
}
32+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
export default function getBarWidth(canvasWidth: number, bucketCount: number, barSpacing: number): number {
3+
const initialWidth = Math.max(20, canvasWidth / bucketCount);
4+
5+
return canvasWidth / Math.floor(canvasWidth / (initialWidth + barSpacing)) - barSpacing;
6+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as clearCanvas } from './clearCanvas';
2+
export { default as getBarWidth } from './getBarWidth';
3+
export { default as drawSpectroLines } from './drawSpectroLines';

packages/audiodocs/src/components/OldLandingExamples/LandingExample.tsx renamed to packages/audiodocs/src/componentGraveyard/OldLandingExamples/LandingExample.tsx

File renamed without changes.

packages/audiodocs/src/components/OldLandingExamples/Piano/index.tsx renamed to packages/audiodocs/src/componentGraveyard/OldLandingExamples/Piano/index.tsx

File renamed without changes.

packages/audiodocs/src/components/OldLandingExamples/Piano/styles.module.css renamed to packages/audiodocs/src/componentGraveyard/OldLandingExamples/Piano/styles.module.css

File renamed without changes.

packages/audiodocs/src/components/OldLandingExamples/StepSequencer/index.tsx renamed to packages/audiodocs/src/componentGraveyard/OldLandingExamples/StepSequencer/index.tsx

File renamed without changes.

0 commit comments

Comments
 (0)