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 {


struct AudioIO;
namespace audio {
struct IO;
}


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


+ 5
- 3
include/audio.hpp View File

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


namespace rack {
namespace audio {


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

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

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


} // namespace audio
} // namespace rack

+ 2
- 2
include/bridge.hpp View File

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

void bridgeInit();
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

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

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


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


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

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


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


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


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


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


+ 23
- 21
src/audio.cpp View File

@@ -6,17 +6,18 @@


namespace rack {
namespace audio {


AudioIO::AudioIO() {
IO::IO() {
setDriver(RtAudio::UNSPECIFIED);
}

AudioIO::~AudioIO() {
IO::~IO() {
closeStream();
}

std::vector<int> AudioIO::getDrivers() {
std::vector<int> IO::getDrivers() {
std::vector<RtAudio::Api> apis;
RtAudio::getCompiledApi(apis);
std::vector<int> drivers;
@@ -28,7 +29,7 @@ std::vector<int> AudioIO::getDrivers() {
return drivers;
}

std::string AudioIO::getDriverName(int driver) {
std::string IO::getDriverName(int driver) {
switch (driver) {
case RtAudio::UNSPECIFIED: return "Unspecified";
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
setDevice(-1, 0);

@@ -66,7 +67,7 @@ void AudioIO::setDriver(int driver) {
}
}

int AudioIO::getDeviceCount() {
int IO::getDeviceCount() {
if (rtAudio) {
return rtAudio->getDeviceCount();
}
@@ -76,7 +77,7 @@ int AudioIO::getDeviceCount() {
return 0;
}

bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) {
bool IO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) {
if (!deviceInfo)
return false;

@@ -99,7 +100,7 @@ bool AudioIO::getDeviceInfo(int device, RtAudio::DeviceInfo *deviceInfo) {
return false;
}

int AudioIO::getDeviceChannels(int device) {
int IO::getDeviceChannels(int device) {
if (device < 0)
return 0;

@@ -114,7 +115,7 @@ int AudioIO::getDeviceChannels(int device) {
return 0;
}

std::string AudioIO::getDeviceName(int device) {
std::string IO::getDeviceName(int device) {
if (device < 0)
return "";

@@ -129,7 +130,7 @@ std::string AudioIO::getDeviceName(int device) {
return "";
}

std::string AudioIO::getDeviceDetail(int device, int offset) {
std::string IO::getDeviceDetail(int device, int offset) {
if (device < 0)
return "";

@@ -153,14 +154,14 @@ std::string AudioIO::getDeviceDetail(int device, int offset) {
return "";
}

void AudioIO::setDevice(int device, int offset) {
void IO::setDevice(int device, int offset) {
closeStream();
this->device = device;
this->offset = offset;
openStream();
}

std::vector<int> AudioIO::getSampleRates() {
std::vector<int> IO::getSampleRates() {
if (rtAudio) {
try {
RtAudio::DeviceInfo deviceInfo = rtAudio->getDeviceInfo(device);
@@ -174,7 +175,7 @@ std::vector<int> AudioIO::getSampleRates() {
return {};
}

void AudioIO::setSampleRate(int sampleRate) {
void IO::setSampleRate(int sampleRate) {
if (sampleRate == this->sampleRate)
return;
closeStream();
@@ -182,14 +183,14 @@ void AudioIO::setSampleRate(int sampleRate) {
openStream();
}

std::vector<int> AudioIO::getBlockSizes() {
std::vector<int> IO::getBlockSizes() {
if (rtAudio) {
return {64, 128, 256, 512, 1024, 2048, 4096};
}
return {};
}

void AudioIO::setBlockSize(int blockSize) {
void IO::setBlockSize(int blockSize) {
if (blockSize == this->blockSize)
return;
closeStream();
@@ -197,7 +198,7 @@ void AudioIO::setBlockSize(int blockSize) {
openStream();
}

void AudioIO::setChannels(int numOutputs, int numInputs) {
void IO::setChannels(int numOutputs, int numInputs) {
this->numOutputs = numOutputs;
this->numInputs = numInputs;
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) {
AudioIO *audioIO = (AudioIO*) userData;
IO *audioIO = (IO*) userData;
assert(audioIO);
audioIO->processStream((const float *) inputBuffer, (float *) outputBuffer, nFrames);
return 0;
}

void AudioIO::openStream() {
void IO::openStream() {
if (device < 0)
return;

@@ -288,7 +289,7 @@ void AudioIO::openStream() {
}
}

void AudioIO::closeStream() {
void IO::closeStream() {
setChannels(0, 0);

if (rtAudio) {
@@ -319,7 +320,7 @@ void AudioIO::closeStream() {
onCloseStream();
}

json_t *AudioIO::toJson() {
json_t *IO::toJson() {
json_t *rootJ = json_object();
json_object_set_new(rootJ, "driver", json_integer(driver));
std::string deviceName = getDeviceName(device);
@@ -331,7 +332,7 @@ json_t *AudioIO::toJson() {
return rootJ;
}

void AudioIO::fromJson(json_t *rootJ) {
void IO::fromJson(json_t *rootJ) {
closeStream();

json_t *driverJ = json_object_get(rootJ, "driver");
@@ -370,4 +371,5 @@ void AudioIO::fromJson(json_t *rootJ) {
}


} // namespace audio
} // namespace rack

+ 3
- 3
src/bridge.cpp View File

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

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

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

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


Loading…
Cancel
Save