Added getDuration, need to fix failing test
This commit is contained in:
parent
6b00837a4d
commit
c20a6673af
1 changed files with 21 additions and 1 deletions
|
|
@ -25,7 +25,7 @@ import {
|
|||
import { map } from 'nanostores';
|
||||
import { logger } from './logger.mjs';
|
||||
import { connectLFO, connectEnvelope, connectBusModulator } from './modulators.mjs';
|
||||
import { loadBuffer } from './sampler.mjs';
|
||||
import { getSampleBufferSource, loadBuffer } from './sampler.mjs';
|
||||
import { getAudioContext } from './audioContext.mjs';
|
||||
import { SuperdoughAudioController } from './superdoughoutput.mjs';
|
||||
import { resetSeenKeys } from './wavetable.mjs';
|
||||
|
|
@ -85,6 +85,26 @@ export function setGainCurve(newGainCurveFunc) {
|
|||
gainCurveFunc = newGainCurveFunc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the duration, in seconds, of the given sample.
|
||||
* Has optional param `n` (for instance, the `2` in `s("casio:2")`)
|
||||
*
|
||||
* Note: `must` be called with await, otherwise you'll get a pending Promise object.
|
||||
*
|
||||
* @name getDuration
|
||||
* @param {string} sampleName
|
||||
* @param {number} (optional) n
|
||||
*
|
||||
* @example
|
||||
* // Set a patterns cycle length to exactly the length of the sample
|
||||
* samples('github:tidalcycles/dirt-samples')
|
||||
* let k = await getDuration('sax')
|
||||
* s("sax").cps(1/k)
|
||||
*/
|
||||
export const getDuration = (s, n = 0) => {
|
||||
return getSampleBufferSource({ s, n }, soundMap.get(s)[s].data.samples).then((x) => x.bufferDuration);
|
||||
};
|
||||
|
||||
function aliasBankMap(aliasMap) {
|
||||
// Make all bank keys lower case for case insensitivity
|
||||
for (const key in aliasMap) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue