Initial update to ALSA

This commit is contained in:
Logan Cusano
2023-03-26 00:03:38 -04:00
parent ce072d9287
commit d96b8ee05b
3 changed files with 39 additions and 24 deletions

View File

@@ -1,9 +1,11 @@
// Config
import {getDeviceID} from '../utilities/configHandler.js'
import {getDeviceID} from '../utilities/configHandler.js';
// Modules
import portAudio from 'naudiodon';
import alsaInstance from 'alsa-capture';
import executeConsoleCommand from "../utilities/executeConsoleCommand.js";
// Debug
import ModuleDebugBuilder from "../utilities/moduleDebugBuilder.js";
// Global Vars
const log = new ModuleDebugBuilder("bot", "audioController");
/**
@@ -27,16 +29,9 @@ export function confirmAudioDevice({deviceName = undefined, deviceId = undefined
* @returns {unknown[]}
*/
export function getAudioDevices(){
const deviceList = portAudio.getDevices().map((device) => {
if (device.defaultSampleRate === 48000 || device.maxInputChannels > 0) {
return device;
}
else {
return null;
}
}).filter(Boolean);
//log.DEBUG("Device List: ", deviceList);
return deviceList;
// Exec output contains both stderr and stdout outputs
const deviceList = executeConsoleCommand("arecord -L");
log.DEBUG("Device list: ", deviceList);
}
/**
@@ -49,15 +44,13 @@ export function createAudioInstance() {
const selectedDevice = confirmAudioDevice({deviceId: getDeviceID()});//{deviceName: "VoiceMeeter VAIO3 Output (VB-Au"});
log.DEBUG("Device selected from config: ", selectedDevice);
// Create an instance of AudioIO with outOptions (defaults are as below), which will return a WritableStream
return new portAudio.AudioIO({
inOptions: {
channelCount: 2,
sampleFormat: portAudio.SampleFormat16Bit,
sampleRate: 48000,
deviceId: selectedDevice.id, // Use -1 or omit the deviceId to select the default device
closeOnError: true, // Close the stream if an audio error is detected, if set false then just log the error
framesPerBuffer: 100, //(48000 / 1000) * 20, //(48000 * 16 * 2) / 1000 * 20 // (48000 * (16 / 8) * 2) / 60 / 1000 * 20 //0.025 * 48000 / 2
highwaterMark: 3840
},
return new alsaInstance({
channels: 2,
format: "S16_BE",
rate: 48000,
device: selectedDevice.id ?? "default", // Use -1 or omit the deviceId to select the default device
periodSize: 100, //(48000 / 1000) * 20, //(48000 * 16 * 2) / 1000 * 20 // (48000 * (16 / 8) * 2) / 60 / 1000 * 20 //0.025 * 48000 / 2
periodTime: undefined,
// highwaterMark: 3840
});
}