Browse Source

Put audio in namespace

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
d62b8d5845
7 changed files with 42 additions and 36 deletions
  1. +4
    -2
      include/app/AudioWidget.hpp
  2. +5
    -3
      include/audio.hpp
  3. +2
    -2
      include/bridge.hpp
  4. +1
    -1
      src/Core/AudioInterface.cpp
  5. +4
    -4
      src/app/AudioWidget.cpp
  6. +23
    -21
      src/audio.cpp
  7. +3
    -3
      src/bridge.cpp

+ 4
- 2
include/app/AudioWidget.hpp View File

@@ -6,12 +6,14 @@
namespace rack { namespace rack {




struct AudioIO;
namespace audio {
struct IO;
}




struct AudioWidget : LedDisplay { struct AudioWidget : LedDisplay {
/** Not owned */ /** Not owned */
AudioIO *audioIO = NULL;
audio::IO *audioIO = NULL;
LedDisplayChoice *driverChoice; LedDisplayChoice *driverChoice;
LedDisplaySeparator *driverSeparator; LedDisplaySeparator *driverSeparator;
LedDisplayChoice *deviceChoice; LedDisplayChoice *deviceChoice;


+ 5
- 3
include/audio.hpp View File

@@ -11,9 +11,10 @@




namespace rack { namespace rack {
namespace audio {




struct AudioIO {
struct IO {
// Stream properties // Stream properties
int driver = 0; int driver = 0;
int device = -1; int device = -1;
@@ -27,8 +28,8 @@ struct AudioIO {
/** Cached */ /** Cached */
RtAudio::DeviceInfo deviceInfo; RtAudio::DeviceInfo deviceInfo;


AudioIO();
virtual ~AudioIO();
IO();
virtual ~IO();


std::vector<int> getDrivers(); std::vector<int> getDrivers();
std::string getDriverName(int driver); std::string getDriverName(int driver);
@@ -62,4 +63,5 @@ struct AudioIO {
}; };




} // namespace audio
} // namespace rack } // namespace rack

+ 2
- 2
include/bridge.hpp View File

@@ -24,8 +24,8 @@ struct BridgeMidiDriver : midi::Driver {


void bridgeInit(); void bridgeInit();
void bridgeDestroy(); void bridgeDestroy();
void bridgeAudioSubscribe(int channel, AudioIO *audio);
void bridgeAudioUnsubscribe(int channel, AudioIO *audio);
void bridgeAudioSubscribe(int channel, audio::IO *audio);
void bridgeAudioUnsubscribe(int channel, audio::IO *audio);




} // namespace rack } // namespace rack

+ 1
- 1
src/Core/AudioInterface.cpp View File

@@ -17,7 +17,7 @@
using namespace rack; using namespace rack;




struct AudioInterfaceIO : AudioIO {
struct AudioInterfaceIO : audio::IO {
std::mutex engineMutex; std::mutex engineMutex;
std::condition_variable engineCv; std::condition_variable engineCv;
std::mutex audioMutex; std::mutex audioMutex;


+ 4
- 4
src/app/AudioWidget.cpp View File

@@ -7,7 +7,7 @@ namespace rack {




struct AudioDriverItem : MenuItem { struct AudioDriverItem : MenuItem {
AudioIO *audioIO;
audio::IO *audioIO;
int driver; int driver;
void onAction(event::Action &e) override { void onAction(event::Action &e) override {
audioIO->setDriver(driver); audioIO->setDriver(driver);
@@ -35,7 +35,7 @@ struct AudioDriverChoice : LedDisplayChoice {




struct AudioDeviceItem : MenuItem { struct AudioDeviceItem : MenuItem {
AudioIO *audioIO;
audio::IO *audioIO;
int device; int device;
int offset; int offset;
void onAction(event::Action &e) override { void onAction(event::Action &e) override {
@@ -87,7 +87,7 @@ struct AudioDeviceChoice : LedDisplayChoice {




struct AudioSampleRateItem : MenuItem { struct AudioSampleRateItem : MenuItem {
AudioIO *audioIO;
audio::IO *audioIO;
int sampleRate; int sampleRate;
void onAction(event::Action &e) override { void onAction(event::Action &e) override {
audioIO->setSampleRate(sampleRate); audioIO->setSampleRate(sampleRate);
@@ -119,7 +119,7 @@ struct AudioSampleRateChoice : LedDisplayChoice {




struct AudioBlockSizeItem : MenuItem { struct AudioBlockSizeItem : MenuItem {
AudioIO *audioIO;
audio::IO *audioIO;
int blockSize; int blockSize;
void onAction(event::Action &e) override { void onAction(event::Action &e) override {
audioIO->setBlockSize(blockSize); audioIO->setBlockSize(blockSize);


+ 23
- 21
src/audio.cpp View File

@@ -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

+ 3
- 3
src/bridge.cpp View File

@@ -22,7 +22,7 @@ namespace rack {


struct BridgeClientConnection; struct BridgeClientConnection;
static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {}; static BridgeClientConnection *connections[BRIDGE_NUM_PORTS] = {};
static AudioIO *audioListeners[BRIDGE_NUM_PORTS] = {};
static audio::IO *audioListeners[BRIDGE_NUM_PORTS] = {};
static std::thread serverThread; static std::thread serverThread;
static bool serverRunning = false; static bool serverRunning = false;
static BridgeMidiDriver *driver = NULL; static BridgeMidiDriver *driver = NULL;
@@ -416,7 +416,7 @@ void bridgeDestroy() {
serverThread.join(); serverThread.join();
} }


void bridgeAudioSubscribe(int port, AudioIO *audio) {
void bridgeAudioSubscribe(int port, audio::IO *audio) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS)) if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return; return;
// Check if an Audio is already subscribed on the port // Check if an Audio is already subscribed on the port
@@ -427,7 +427,7 @@ void bridgeAudioSubscribe(int port, AudioIO *audio) {
connections[port]->refreshAudio(); connections[port]->refreshAudio();
} }


void bridgeAudioUnsubscribe(int port, AudioIO *audio) {
void bridgeAudioUnsubscribe(int port, audio::IO *audio) {
if (!(0 <= port && port < BRIDGE_NUM_PORTS)) if (!(0 <= port && port < BRIDGE_NUM_PORTS))
return; return;
if (audioListeners[port] != audio) if (audioListeners[port] != audio)


Loading…
Cancel
Save