Skip to content

Commit

Permalink
Bump web-audio-oscillators
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehorvat committed Feb 21, 2024
1 parent de3a209 commit 57bc965
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 49 deletions.
10 changes: 5 additions & 5 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"soundbank-reverb": "^1.1.2",
"three": "0.161.0",
"tonal": "^6.0.0",
"web-audio-oscillators": "^1.0.4",
"web-audio-oscillators": "^2.0.0",
"wrap-index": "^1.1.0"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/oscillation-graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Note, NoteLiteral } from 'tonal';
import Reverb, { ReverbNode } from 'soundbank-reverb';
import oscillators, { CustomOscillatorType } from 'web-audio-oscillators';
import { CustomOscillatorType, customOscillators } from 'web-audio-oscillators';

export class OscillationGraph {
private readonly volume: GainNode;
Expand Down Expand Up @@ -51,7 +51,7 @@ export class OscillationGraph {
}

// Replace with new oscillator.
noteOscillator = oscillators[oscillatorType](noteGate.context);
noteOscillator = customOscillators[oscillatorType](noteGate.context);
noteOscillator.frequency.value = Note.freq(note)!;
noteOscillator.connect(noteGate);
noteOscillator.start();
Expand Down
13 changes: 6 additions & 7 deletions src/lib/synthesizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { NoteLiteral, Range, Scale } from 'tonal';
import wrapIndex from 'wrap-index';
import * as ThreeUtils from './three-utils';
import { OscillationGraph } from './oscillation-graph';
import oscillators, { CustomOscillatorType } from 'web-audio-oscillators';
import {
CustomOscillatorType,
customOscillatorTypes,
} from 'web-audio-oscillators';

export class Synthesizer extends THREE.Group {
private static readonly keyPressHeight = 0.6;
Expand Down Expand Up @@ -127,14 +130,10 @@ export class Synthesizer extends THREE.Group {
this.previousButton === this.clickedChild
) {
this.clickedChild.position.y += Synthesizer.buttonPressHeight;
const oscillatorTypes = Object.keys(
oscillators
) as CustomOscillatorType[];
const oscillatorIndex = oscillatorTypes.indexOf(this.oscillatorType);
const increment = this.clickedChild === this.nextButton ? 1 : -1;
this.oscillatorType = wrapIndex(
oscillatorIndex + increment,
oscillatorTypes
customOscillatorTypes.indexOf(this.oscillatorType) + increment,
customOscillatorTypes
);
this.oscillationGraph.rebuildOscillators(this.oscillatorType);
this.setScreenText();
Expand Down
34 changes: 0 additions & 34 deletions src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,3 @@ declare module 'wrap-index' {
function wrapIndex<T>(index: number, array: T[]): T;
export default wrapIndex;
}

declare module 'web-audio-oscillators' {
export type CustomOscillatorType =
| 'sine'
| 'square'
| 'square2'
| 'sawtooth'
| 'triangle'
| 'triangle2'
| 'chiptune'
| 'organ'
| 'organ2'
| 'organ3'
| 'organ4'
| 'organ5'
| 'bass'
| 'bass2'
| 'bass3'
| 'bass4'
| 'brass'
| 'brass2'
| 'aah'
| 'ooh'
| 'eeh'
| 'buzz'
| 'buzz2'
| 'dissonance';

const oscillators: {
[T in CustomOscillatorType]: (context: BaseAudioContext) => OscillatorNode;
};

export default oscillators;
}

0 comments on commit 57bc965

Please sign in to comment.