forked from feross/timidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
61 lines (53 loc) · 1.5 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*! timidity. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
/*! Lumière Élevé <https://ltgc.cc/project/?view=timidity-sf2> */
"use strict";
// Initialization
const Debug = require('debug');
const EventEmitter = require('events').EventEmitter;
const fs = require('fs');
const LibTimidity = require('./libtimidity');
const debug = Debug('timidity');
const debugVerbose = Debug('timidity:verbose');
// The processor we'll be dealing with
let processor;
// Legit values for the buffer
const legitBuffer = [
4096, // 92.88ms
8192, // 185.76ms
16384 // 371.52ms
];
// Simple generation for using SF2 SoundFont files.
const useSf2Cfg = function (name) {
return `soundfont ${name}`;
};
// Initial audio parameters
const audioParams = {
sample: 44100, // CD standard
format: 32784, // s16, CD standard
channel: 2, // Stereo
segmentByte: 4, // 2x2 (16 bits = 2 bytes, with stereo)
buffer: 16384 // Keeping the good old default
};
const audioProcessor = function (event) {
// Placeholder.
};
const setBufferSize = function (size) {
if (legitBuffer.includes(size)) {} else {
throw(new Error(`Illegal buffer size ${size}`));
};
};
const getNode = function () {
return processor;
};
const startNode = function (options = {}) {
if (!processor) {
if (options.context) {
processor = options.context.createScriptProcessor();
processor.addEventListener("audioprocess", audioProcessor);
} else {
throw(new Error("No attached context"));
};
};
return processor;
};
// No initialization yet.