@kidlib/web-audio 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,3 +27,5 @@ player.play(60);
27
27
 
28
28
  UI elements such as `KnobElement` are available only from the optional
29
29
  `@kidlib/web-audio/components` entry point.
30
+
31
+ ### Live demo app: [Hljóð-Smali](https://kristinnroach.github.io/hljod-smali)
package/dist/index.d.ts CHANGED
@@ -788,8 +788,6 @@ declare type RecorderOptions = {
788
788
  autoStop: boolean;
789
789
  stopThreshold: number;
790
790
  silenceTimeoutMs: number;
791
- preprocess: boolean;
792
- preprocessOptions: object;
793
791
  };
794
792
 
795
793
  export declare type RecorderStartOptions = Partial<RecorderOptions> & {
@@ -825,6 +823,7 @@ export declare class SamplePlayer implements ILibInstrumentNode {
825
823
  readonly nodeId: NodeID_2;
826
824
  readonly nodeType: "sample-player";
827
825
  readonly context: AudioContext;
826
+ static readonly MAX_LAYERS = 4;
828
827
  randomizeVelocity: boolean;
829
828
  voicePool: SampleVoicePool;
830
829
  outBus: InstrumentBus;
@@ -851,7 +850,18 @@ export declare class SamplePlayer implements ILibInstrumentNode {
851
850
  setModulationWaveform(modType?: "AM" | "FM", waveform?: CustomLibWaveform | OscillatorType | PeriodicWave, customWaveOptions?: WaveformOptions): void;
852
851
  syncLFOsToNoteFreq(lfoId: "gain-lfo" | "pitch-lfo", enabled: boolean): void;
853
852
  freezeActiveVoices(freeze: boolean): this;
853
+ /**
854
+ * Load a single sample. Equivalent to `loadLayers([buffer])`: any previously
855
+ * loaded extra layers are cleared.
856
+ */
854
857
  loadSample(buffer: AudioBuffer | ArrayBuffer, modSampleRate?: number, preprocessOptions?: Partial<PreProcessOptions>): Promise<AudioBuffer | null>;
858
+ /**
859
+ * Replace the whole layer set. Layers are summed inside the voice worklet at
860
+ * one shared playhead, so they play in unison and layer 0 is the authority
861
+ * for duration, loop points, start/end and zero crossings. Layers shorter
862
+ * than layer 0 fall silent at their own end; longer ones are truncated.
863
+ */
864
+ loadLayers(buffers: (AudioBuffer | ArrayBuffer)[], modSampleRate?: number, preprocessOptions?: Partial<PreProcessOptions>): Promise<AudioBuffer[] | null>;
855
865
  cropSample(startSeconds?: number, endSeconds?: number, fadeMs?: number): Promise<AudioBuffer | null>;
856
866
  detectPitch(buffer: AudioBuffer): Promise<{
857
867
  frequency: number;
@@ -956,6 +966,8 @@ export declare class SamplePlayer implements ILibInstrumentNode {
956
966
  get loopEnd(): number;
957
967
  get isLoaded(): boolean;
958
968
  get audiobuffer(): AudioBuffer | null;
969
+ /** All loaded layers. Index 0 is the authority layer (=== `audiobuffer`). */
970
+ get layers(): readonly AudioBuffer[];
959
971
  dispose(): void;
960
972
  }
961
973
 
@@ -1035,6 +1047,13 @@ declare class SampleVoice {
1035
1047
  });
1036
1048
  init(): Promise<void>;
1037
1049
  loadBuffer(buffer: AudioBuffer, zeroCrossings?: number[]): Promise<boolean>;
1050
+ /**
1051
+ * Replace the whole layer set. Layers are summed at one shared playhead, so
1052
+ * layer 0 is the authority for duration and all range math; the rest only
1053
+ * add samples. A layer at the wrong sample rate is dropped on its own,
1054
+ * leaving the others playable, except layer 0: losing it fails the load.
1055
+ */
1056
+ loadLayers(buffers: AudioBuffer[], zeroCrossings?: number[]): Promise<boolean>;
1038
1057
  freeze(freeze: boolean): this;
1039
1058
  setGlideTime(seconds: number): void;
1040
1059
  trigger(options: {
@@ -1144,7 +1163,7 @@ declare class SampleVoicePool implements LibNode {
1144
1163
  disconnect(): void;
1145
1164
  onMessage(type: string, handler: MessageHandler<Message>): () => void;
1146
1165
  sendUpstreamMessage(type: string, data: any): this;
1147
- setBuffer(buffer: AudioBuffer, zeroCrossings?: number[]): this;
1166
+ setLayers(buffers: AudioBuffer[], zeroCrossings?: number[]): this;
1148
1167
  allocate(available?: Set<SampleVoice>, releasing?: Set<SampleVoice>): SampleVoice | undefined;
1149
1168
  prevMidiNote: number;
1150
1169
  noteOn(midiNote: MidiValue, velocity?: MidiValue, secondsFromNow?: number, glideTime?: number): MidiValue | null;