Skip to content
Snippets Groups Projects
Commit b41183d8 authored by jsiegle's avatar jsiegle
Browse files

AudioComponent closes device when not in use. Closes #10.

The AudioComponent now closes the audio device when it's not in use,
saving CPU cycles. Previously, background CPU levels would be between
8 and 10%. Now, when acquisition is not active (and audio device settings
are not being actively edited), background CPU levels drop to 2%. More
optimization will be necessary to get it down to zero, but 2% is still
a big improvement over what we had previously.
parent 40501ceb
Branches
Tags
No related merge requests found
......@@ -68,7 +68,10 @@ AudioComponent::AudioComponent() : isPlaying(false)
std::cout << "Audio device sample rate: " << sr << std::endl;
std::cout << "Audio device buffer size: " << buffSize << std::endl << std::endl;
graphPlayer = new AudioProcessorPlayer();
graphPlayer = new AudioProcessorPlayer();
stopDevice(); // reduces the amount of background processing when
// device is not in use
}
......@@ -99,8 +102,22 @@ bool AudioComponent::callbacksAreActive() {
return isPlaying;
}
void AudioComponent::restartDevice()
{
deviceManager.restartLastAudioDevice();
}
void AudioComponent::stopDevice()
{
deviceManager.closeAudioDevice();
}
void AudioComponent::beginCallbacks() {
restartDevice();
std::cout << std::endl << "Adding audio callback." << std::endl;
deviceManager.addAudioCallback(graphPlayer);
isPlaying = true;
......@@ -113,5 +130,7 @@ void AudioComponent::endCallbacks() {
deviceManager.removeAudioCallback(graphPlayer);
isPlaying = false;
stopDevice();
}
......@@ -56,6 +56,9 @@ public:
bool callbacksAreActive();
void restartDevice();
void stopDevice();
AudioDeviceManager deviceManager;
private:
......
......@@ -136,16 +136,23 @@ void AudioEditor::buttonClicked(Button* button)
{
if (acw == 0) {
AudioComponent* ac = getAudioComponent();
if (ac != 0)
acw = new AudioConfigurationWindow(ac->deviceManager, (Button*) audioWindowButton);
// AudioComponent* audioComponent = getAudioComponent();
// audioComponent->restartDevice();
// if (audioComponent != 0) {
acw = new AudioConfigurationWindow(getAudioComponent()->deviceManager, (Button*) audioWindowButton);
acw->setUIComponent(getUIComponent());
//}
}
getAudioComponent()->restartDevice();
acw->setVisible(true);
} else {
acw->setVisible(false);
//deleteAndZero(acw);
getAudioComponent()->stopDevice();
}
}
......@@ -205,6 +212,7 @@ AudioConfigurationWindow::~AudioConfigurationWindow()
void AudioConfigurationWindow::closeButtonPressed()
{
controlButton->setToggleState(false,false);
getAudioComponent()->stopDevice();
setVisible(false);
}
......
......@@ -48,7 +48,8 @@ class AudioWindowButton : public Button
Font font;
};
class AudioConfigurationWindow : public DocumentWindow
class AudioConfigurationWindow : public DocumentWindow,
public AccessClass
{
public:
AudioConfigurationWindow(AudioDeviceManager& adm, Button* b);
......
......@@ -79,8 +79,8 @@ GenericEditor::GenericEditor (GenericProcessor* owner)//, FilterViewport* vp)
audioChannels.clear();
recordChannels.clear();
backgroundGradient = ColourGradient(Colour(190, 190, 190), 0.0f, 0.0f,
Colour(145, 145, 145), 0.0f, 150.0f, false);
backgroundGradient = ColourGradient(Colour(190, 190, 190), 0.0f, 150.0f,
Colour(145, 145, 145), 0.0f, 0.0f, false);
//grad.addColour(0.5f, Colour(170, 170, 170));
//grad.addColour(0.5, Colours::lightgrey);
......
......@@ -28,7 +28,7 @@
OpenGLCanvas::OpenGLCanvas() : //OpenGLComponent(OpenGLComponent::OpenGLType::openGLDefault, true),
scrollPix(0), scrollTime(0), scrollDiff(0), originalScrollPix(0),
scrollBarWidth(15), PI(3.1415926), showScrollTrack(true),
animationIsActive(false), refreshMs(100)
animationIsActive(false), refreshMs(50)
{
loadFonts();
......
......@@ -687,13 +687,26 @@ void SignalChainTabButton::paintButton(Graphics &g, bool isMouseOver, bool isBut
}
if (isMouseOver) {
grad1 = ColourGradient(Colour(255, 255, 255), 0.0f, 20.0f,
Colour(180, 180, 180), 0.0f, 0.0f,
false);
grad1.multiplyOpacity(0.7f);
grad2.multiplyOpacity(0.7f);
// grad1 = ColourGradient(Colour(255, 255, 255), 0.0f, 20.0f,
// Colour(180, 180, 180), 0.0f, 0.0f,
// false);
// grad2 = ColourGradient(Colour(255, 255, 255), 0.0f, 0.0f,
// Colour(180, 180, 180), 0.0f, 20.0f,
// false);
}
if (isButtonDown) {
// ColourGradient grad3 = grad1;
// grad1 = grad2;
// grad2 = grad3;
// grad1.multiplyOpacity(0.7f);
// grad2.multiplyOpacity(0.7f);
grad2 = ColourGradient(Colour(255, 255, 255), 0.0f, 0.0f,
Colour(180, 180, 180), 0.0f, 20.0f,
false);
}
g.setGradientFill(grad2);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment