updated .gitignore, cleared unwanted files and folders, added close stream functionality
This commit is contained in:
parent
d32989cc81
commit
f2f1f091bf
92 changed files with 95 additions and 14610 deletions
36
test/deviceSwitch.js
Normal file
36
test/deviceSwitch.js
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
const nodeAudio = require('bindings')('nodeaudio.node');
|
||||
|
||||
let inputDevice;
|
||||
let outputDevice;
|
||||
|
||||
const setStreams = () => {
|
||||
|
||||
const defaultInput = nodeAudio.GetDefaultInputDevice();
|
||||
const defaultOutput = nodeAudio.GetDefaultOutputDevice();
|
||||
console.log(`Input: ${defaultInput}, Output: ${defaultOutput}`);
|
||||
|
||||
if (inputDevice !== defaultInput) {
|
||||
inputDevice = defaultInput;
|
||||
nodeAudio.CloseInputStream(inputDevice);
|
||||
nodeAudio.OpenInputStream(inputDevice);
|
||||
}
|
||||
|
||||
if (outputDevice !== defaultOutput) {
|
||||
outputDevice = defaultOutput;
|
||||
nodeAudio.CloseOutputStream(outputDevice);
|
||||
nodeAudio.OpenOutputStream(outputDevice);
|
||||
}
|
||||
}
|
||||
|
||||
function x() {
|
||||
console.log("emitting");
|
||||
}
|
||||
|
||||
nodeAudio.Initialize(x);
|
||||
|
||||
const id = setInterval(setStreams, 3000);
|
||||
|
||||
setTimeout(() => {
|
||||
clearInterval(id);
|
||||
nodeAudio.Terminate();
|
||||
}, 11000);
|
||||
51
test/readWrite.js
Normal file
51
test/readWrite.js
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
const nodeAudio = require('bindings')('nodeaudio.node'),
|
||||
EventEmitter = require('events'),
|
||||
sleep = require('sleep'),
|
||||
emitter = new EventEmitter();
|
||||
|
||||
let recording = false;
|
||||
|
||||
const chunks = [];
|
||||
emitter.on("data", (int16Arr) => {
|
||||
if (recording) {
|
||||
console.log(`Captured ${int16Arr.length} frames`);
|
||||
chunks.push(int16Arr);
|
||||
}
|
||||
});
|
||||
|
||||
nodeAudio.Initialize(emitter.emit.bind(emitter)); /* Accepts an event emitter */
|
||||
|
||||
nodeAudio.OpenInputStream(nodeAudio.GetDefaultInputDevice());
|
||||
nodeAudio.OpenOutputStream(nodeAudio.GetDefaultOutputDevice());
|
||||
|
||||
recording = true;
|
||||
|
||||
setTimeout(() => {
|
||||
|
||||
recording = false;
|
||||
pcmAudio = mergeChunks(chunks);
|
||||
chunks.lengh = 0;
|
||||
|
||||
nodeAudio.WriteToOutputStream(pcmAudio.buffer);
|
||||
|
||||
setTimeout(nodeAudio.Terminate, 5000);
|
||||
|
||||
}, 2000);
|
||||
|
||||
const mergeChunks = (chunks) => {
|
||||
const chunkLengths = chunks.map((b) => b.length), // as well as here...
|
||||
totalChunkLength = chunkLengths.reduce((p, c) => p+c, 0),
|
||||
int16Arr = new Int16Array(totalChunkLength);
|
||||
|
||||
console.log(`${totalChunkLength} frames captured in total.`);
|
||||
|
||||
let offset = 0;
|
||||
for (var i = 0; i < chunks.length; i++) { // and here...
|
||||
int16Arr.set(chunks[i], offset); // seg fault happens here.
|
||||
offset += chunkLengths[i];
|
||||
}
|
||||
|
||||
return int16Arr;
|
||||
}
|
||||
|
||||
// we can also set js-created TypedArrays in line 41.
|
||||
Loading…
Reference in a new issue