Skip to content

Commit

Permalink
Set audio device type via HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
medengineer committed May 9, 2024
1 parent 58414d7 commit 567385b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion Source/Audio/AudioComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ String AudioComponent::getDeviceType()
void AudioComponent::setDeviceType(String deviceType)
{
deviceManager.setCurrentAudioDeviceType(deviceType, true);

CoreServices::sendStatusMessage("Set device type to " + String(deviceManager.getCurrentDeviceTypeObject()->getTypeName()));
}

void AudioComponent::connectToProcessorGraph(AudioProcessorGraph* processorGraph)
Expand Down Expand Up @@ -346,5 +348,5 @@ void AudioComponent::loadStateFromXml(XmlElement* parent)
LOGE("Buffer size out of range.");
}

std::cout << deviceManager.setAudioDeviceSetup(setup, true) << std::endl;
LOGC(deviceManager.setAudioDeviceSetup(setup, true));
}
22 changes: 16 additions & 6 deletions Source/Utils/OpenEphysHttpServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ class OpenEphysHttpServer : juce::Thread {
return;
}

try {
int sample_rate = request_json["sample_rate"];
LOGD("Found 'sample_rate': ", sample_rate);
const MessageManagerLock mml;
AccessClass::getAudioComponent()->setSampleRate(sample_rate);
}
catch (json::exception& e) {
LOGD("'sample_rate' not specified'");
}

try {
int buffer_size = request_json["buffer_size"];
LOGD("Found 'buffer_size': ", buffer_size);
Expand All @@ -178,13 +188,13 @@ class OpenEphysHttpServer : juce::Thread {
}

try {
int sample_rate = request_json["sample_rate"];
LOGD("Found 'sample_rate': ", sample_rate);
std::string device_type = request_json["device_type"];
LOGD("Found 'device_type': ", device_type);
const MessageManagerLock mml;
AccessClass::getAudioComponent()->setSampleRate(sample_rate);
AccessClass::getAudioComponent()->setDeviceType(String(device_type));
}
catch (json::exception& e) {
LOGD("'sample_rate' not specified'");
LOGD("'device_type' not specified'");
}

json ret;
Expand Down Expand Up @@ -1025,12 +1035,12 @@ class OpenEphysHttpServer : juce::Thread {
inline static void audio_info_to_json(const ProcessorGraph* graph, json* ret)
{

(*ret)["device"] = AccessClass::getAudioComponent()->getDeviceType().toStdString();

(*ret)["sample_rate"] = AccessClass::getAudioComponent()->getSampleRate();

(*ret)["buffer_size"] = AccessClass::getAudioComponent()->getBufferSize();

(*ret)["device_type"] = AccessClass::getAudioComponent()->getDeviceType().toStdString();

}

inline static void recording_info_to_json(const ProcessorGraph* graph, json* ret)
Expand Down

0 comments on commit 567385b

Please sign in to comment.