|
@@ -6,17 +6,18 @@ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace rack { |
|
|
namespace rack { |
|
|
|
|
|
namespace audio { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AudioIO::AudioIO() { |
|
|
|
|
|
|
|
|
IO::IO() { |
|
|
setDriver(RtAudio::UNSPECIFIED); |
|
|
setDriver(RtAudio::UNSPECIFIED); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
AudioIO::~AudioIO() { |
|
|
|
|
|
|
|
|
IO::~IO() { |
|
|
closeStream(); |
|
|
closeStream(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<int> AudioIO::getDrivers() { |
|
|
|
|
|
|
|
|
std::vector<int> IO::getDrivers() { |
|
|
std::vector<RtAudio::Api> apis; |
|
|
std::vector<RtAudio::Api> apis; |
|
|
RtAudio::getCompiledApi(apis); |
|
|
RtAudio::getCompiledApi(apis); |
|
|
std::vector<int> drivers; |
|
|
std::vector<int> drivers; |
|
@@ -28,7 +29,7 @@ std::vector<int> AudioIO::getDrivers() { |
|
|
return drivers; |
|
|
return drivers; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string AudioIO::getDriverName(int driver) { |
|
|
|
|
|
|
|
|
std::string IO::getDriverName(int driver) { |
|
|
switch (driver) { |
|
|
switch (driver) { |
|
|
case RtAudio::UNSPECIFIED: return "Unspecified"; |
|
|
case RtAudio::UNSPECIFIED: return "Unspecified"; |
|
|
case RtAudio::LINUX_ALSA: return "ALSA"; |
|
|
case RtAudio::LINUX_ALSA: return "ALSA"; |
|
@@ -45,7 +46,7 @@ std::string AudioIO::getDriverName(int driver) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::setDriver(int driver) { |
|
|
|
|
|
|
|
|
void IO::setDriver(int driver) { |
|
|
// Close device |
|
|
// Close device |
|
|
setDevice(-1, 0); |
|
|
setDevice(-1, 0); |
|
|
|
|
|
|
|
@@ -66,7 +67,7 @@ void AudioIO::setDriver(int driver) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int AudioIO::getDeviceCount() { |
|
|
|
|
|
|
|
|
int IO::getDeviceCount() { |
|
|
if (rtAudio) { |
|
|
if (rtAudio) { |
|
|
return rtAudio->getDeviceCount(); |
|
|
return rtAudio->getDeviceCount(); |
|
|
} |
|
|
} |
|
@@ -76,7 +77,7 @@ int AudioIO::getDeviceCount() { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { |
|
|
|
|
|
|
|
|
bool IO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { |
|
|
if (!deviceInfo) |
|
|
if (!deviceInfo) |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
@@ -99,7 +100,7 @@ bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int AudioIO::getDeviceChannels(int device) { |
|
|
|
|
|
|
|
|
int IO::getDeviceChannels(int device) { |
|
|
if (device < 0) |
|
|
if (device < 0) |
|
|
return 0; |
|
|
return 0; |
|
|
|
|
|
|
|
@@ -114,7 +115,7 @@ int AudioIO::getDeviceChannels(int device) { |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string AudioIO::getDeviceName(int device) { |
|
|
|
|
|
|
|
|
std::string IO::getDeviceName(int device) { |
|
|
if (device < 0) |
|
|
if (device < 0) |
|
|
return ""; |
|
|
return ""; |
|
|
|
|
|
|
|
@@ -129,7 +130,7 @@ std::string AudioIO::getDeviceName(int device) { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::string AudioIO::getDeviceDetail(int device, int offset) { |
|
|
|
|
|
|
|
|
std::string IO::getDeviceDetail(int device, int offset) { |
|
|
if (device < 0) |
|
|
if (device < 0) |
|
|
return ""; |
|
|
return ""; |
|
|
|
|
|
|
|
@@ -153,14 +154,14 @@ std::string AudioIO::getDeviceDetail(int device, int offset) { |
|
|
return ""; |
|
|
return ""; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::setDevice(int device, int offset) { |
|
|
|
|
|
|
|
|
void IO::setDevice(int device, int offset) { |
|
|
closeStream(); |
|
|
closeStream(); |
|
|
this->device = device; |
|
|
this->device = device; |
|
|
this->offset = offset; |
|
|
this->offset = offset; |
|
|
openStream(); |
|
|
openStream(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<int> AudioIO::getSampleRates() { |
|
|
|
|
|
|
|
|
std::vector<int> IO::getSampleRates() { |
|
|
if (rtAudio) { |
|
|
if (rtAudio) { |
|
|
try { |
|
|
try { |
|
|
RtAudio::DeviceInfo deviceInfo = rtAudio->getDeviceInfo(device); |
|
|
RtAudio::DeviceInfo deviceInfo = rtAudio->getDeviceInfo(device); |
|
@@ -174,7 +175,7 @@ std::vector<int> AudioIO::getSampleRates() { |
|
|
return {}; |
|
|
return {}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::setSampleRate(int sampleRate) { |
|
|
|
|
|
|
|
|
void IO::setSampleRate(int sampleRate) { |
|
|
if (sampleRate == this->sampleRate) |
|
|
if (sampleRate == this->sampleRate) |
|
|
return; |
|
|
return; |
|
|
closeStream(); |
|
|
closeStream(); |
|
@@ -182,14 +183,14 @@ void AudioIO::setSampleRate(int sampleRate) { |
|
|
openStream(); |
|
|
openStream(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<int> AudioIO::getBlockSizes() { |
|
|
|
|
|
|
|
|
std::vector<int> IO::getBlockSizes() { |
|
|
if (rtAudio) { |
|
|
if (rtAudio) { |
|
|
return {64, 128, 256, 512, 1024, 2048, 4096}; |
|
|
return {64, 128, 256, 512, 1024, 2048, 4096}; |
|
|
} |
|
|
} |
|
|
return {}; |
|
|
return {}; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::setBlockSize(int blockSize) { |
|
|
|
|
|
|
|
|
void IO::setBlockSize(int blockSize) { |
|
|
if (blockSize == this->blockSize) |
|
|
if (blockSize == this->blockSize) |
|
|
return; |
|
|
return; |
|
|
closeStream(); |
|
|
closeStream(); |
|
@@ -197,7 +198,7 @@ void AudioIO::setBlockSize(int blockSize) { |
|
|
openStream(); |
|
|
openStream(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::setChannels(int numOutputs, int numInputs) { |
|
|
|
|
|
|
|
|
void IO::setChannels(int numOutputs, int numInputs) { |
|
|
this->numOutputs = numOutputs; |
|
|
this->numOutputs = numOutputs; |
|
|
this->numInputs = numInputs; |
|
|
this->numInputs = numInputs; |
|
|
onChannelsChange(); |
|
|
onChannelsChange(); |
|
@@ -205,13 +206,13 @@ void AudioIO::setChannels(int numOutputs, int numInputs) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int rtCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData) { |
|
|
static int rtCallback(void *outputBuffer, void *inputBuffer, unsigned int nFrames, double streamTime, RtAudioStreamStatus status, void *userData) { |
|
|
AudioIO *audioIO = (AudioIO*) userData; |
|
|
|
|
|
|
|
|
IO *audioIO = (IO*) userData; |
|
|
assert(audioIO); |
|
|
assert(audioIO); |
|
|
audioIO->processStream((const float *) inputBuffer, (float *) outputBuffer, nFrames); |
|
|
audioIO->processStream((const float *) inputBuffer, (float *) outputBuffer, nFrames); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::openStream() { |
|
|
|
|
|
|
|
|
void IO::openStream() { |
|
|
if (device < 0) |
|
|
if (device < 0) |
|
|
return; |
|
|
return; |
|
|
|
|
|
|
|
@@ -288,7 +289,7 @@ void AudioIO::openStream() { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::closeStream() { |
|
|
|
|
|
|
|
|
void IO::closeStream() { |
|
|
setChannels(0, 0); |
|
|
setChannels(0, 0); |
|
|
|
|
|
|
|
|
if (rtAudio) { |
|
|
if (rtAudio) { |
|
@@ -319,7 +320,7 @@ void AudioIO::closeStream() { |
|
|
onCloseStream(); |
|
|
onCloseStream(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
json_t *AudioIO::toJson() { |
|
|
|
|
|
|
|
|
json_t *IO::toJson() { |
|
|
json_t *rootJ = json_object(); |
|
|
json_t *rootJ = json_object(); |
|
|
json_object_set_new(rootJ, "driver", json_integer(driver)); |
|
|
json_object_set_new(rootJ, "driver", json_integer(driver)); |
|
|
std::string deviceName = getDeviceName(device); |
|
|
std::string deviceName = getDeviceName(device); |
|
@@ -331,7 +332,7 @@ json_t *AudioIO::toJson() { |
|
|
return rootJ; |
|
|
return rootJ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void AudioIO::fromJson(json_t *rootJ) { |
|
|
|
|
|
|
|
|
void IO::fromJson(json_t *rootJ) { |
|
|
closeStream(); |
|
|
closeStream(); |
|
|
|
|
|
|
|
|
json_t *driverJ = json_object_get(rootJ, "driver"); |
|
|
json_t *driverJ = json_object_get(rootJ, "driver"); |
|
@@ -370,4 +371,5 @@ void AudioIO::fromJson(json_t *rootJ) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace audio |
|
|
} // namespace rack |
|
|
} // namespace rack |