moved to sampler
This commit is contained in:
parent
0f4e6af49d
commit
3cefbf80bf
2 changed files with 24 additions and 24 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import { getBaseURL, getCommonSampleInfo } from './util.mjs';
|
import { getBaseURL, getCommonSampleInfo } from './util.mjs';
|
||||||
import { registerSound, registerWaveTable } from './index.mjs';
|
import { registerSound, registerWaveTable, soundMap } from './index.mjs';
|
||||||
import { getAudioContext } from './audioContext.mjs';
|
import { getAudioContext } from './audioContext.mjs';
|
||||||
import {
|
import {
|
||||||
getADSRValues,
|
getADSRValues,
|
||||||
|
|
@ -30,6 +30,29 @@ function humanFileSize(bytes, si) {
|
||||||
return bytes.toFixed(1) + ' ' + units[u];
|
return bytes.toFixed(1) + ' ' + units[u];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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,getDur
|
||||||
|
* @tag samples
|
||||||
|
* @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);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDur = getDuration;
|
||||||
|
|
||||||
export function getSampleInfo(hapValue, bank) {
|
export function getSampleInfo(hapValue, bank) {
|
||||||
const { speed = 1.0 } = hapValue;
|
const { speed = 1.0 } = hapValue;
|
||||||
const { transpose, url, index, midi, label } = getCommonSampleInfo(hapValue, bank);
|
const { transpose, url, index, midi, label } = getCommonSampleInfo(hapValue, bank);
|
||||||
|
|
|
||||||
|
|
@ -85,29 +85,6 @@ export function setGainCurve(newGainCurveFunc) {
|
||||||
gainCurveFunc = 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,getDur
|
|
||||||
* @tag samples
|
|
||||||
* @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);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDur = getDuration;
|
|
||||||
|
|
||||||
function aliasBankMap(aliasMap) {
|
function aliasBankMap(aliasMap) {
|
||||||
// Make all bank keys lower case for case insensitivity
|
// Make all bank keys lower case for case insensitivity
|
||||||
for (const key in aliasMap) {
|
for (const key in aliasMap) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue