Browse Source

Implement and enable the audio sliders

It was about time
pull/1631/head
tux3 10 years ago
parent
commit
4a40269698
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
  1. 26
      src/audio.cpp
  2. 13
      src/audio.h
  3. 2
      src/core/coreav.cpp
  4. 6
      src/widget/form/settings/avform.cpp
  5. 6
      src/widget/form/settings/avsettings.ui

26
src/audio.cpp

@ -71,6 +71,32 @@ Audio::~Audio()
delete audioOutLock; delete audioOutLock;
} }
float Audio::getOutputVolume()
{
return outputVolume;
}
void Audio::setOutputVolume(float volume)
{
outputVolume = volume;
alSourcef(alMainSource, AL_GAIN, outputVolume);
for (const ToxGroupCall& call : Core::groupCalls)
{
if (!call.active)
continue;
for (ALuint source : call.alSources)
alSourcef(source, AL_GAIN, outputVolume);
}
for (const ToxCall& call : Core::calls)
{
if (!call.active)
continue;
alSourcef(call.alSource, AL_GAIN, outputVolume);
}
}
void Audio::suscribeInput() void Audio::suscribeInput()
{ {
if (!alInDev) if (!alInDev)

13
src/audio.h

@ -45,6 +45,9 @@ class Audio : QObject
public: public:
static Audio& getInstance(); ///< Returns the singleton's instance. Will construct on first call. static Audio& getInstance(); ///< Returns the singleton's instance. Will construct on first call.
static float getOutputVolume(); ///< Returns the current output volume, between 0 and 1
static void setOutputVolume(float volume); ///< The volume must be between 0 and 1
static void suscribeInput(); ///< Call when you need to capture sound from the open input device. static void suscribeInput(); ///< Call when you need to capture sound from the open input device.
static void unsuscribeInput(); ///< Call once you don't need to capture on the open input device anymore. static void unsuscribeInput(); ///< Call once you don't need to capture on the open input device anymore.
@ -75,12 +78,6 @@ public slots:
void playGroupAudio(int group, int peer, const int16_t* data, void playGroupAudio(int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate); unsigned samples, uint8_t channels, unsigned sample_rate);
public:
static QThread* audioThread;
static ALCcontext* alContext;
static ALuint alMainSource;
static float outputVolume;
private: private:
explicit Audio()=default; explicit Audio()=default;
~Audio(); ~Audio();
@ -91,6 +88,10 @@ private:
static std::atomic<int> userCount; static std::atomic<int> userCount;
static ALCdevice* alOutDev, *alInDev; static ALCdevice* alOutDev, *alInDev;
static QMutex* audioInLock, *audioOutLock; static QMutex* audioInLock, *audioOutLock;
static float outputVolume;
static ALuint alMainSource;
static QThread* audioThread;
static ALCcontext* alContext;
}; };
#endif // AUDIO_H #endif // AUDIO_H

2
src/core/coreav.cpp

@ -586,7 +586,7 @@ void Core::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, un
ALint state; ALint state;
alGetSourcei(alSource, AL_SOURCE_STATE, &state); alGetSourcei(alSource, AL_SOURCE_STATE, &state);
alSourcef(alSource, AL_GAIN, Audio::outputVolume); alSourcef(alSource, AL_GAIN, Audio::getOutputVolume());
if (state != AL_PLAYING) if (state != AL_PLAYING)
{ {
alSourcePlay(alSource); alSourcePlay(alSource);

6
src/widget/form/settings/avform.cpp

@ -54,8 +54,6 @@ AVForm::AVForm() :
connect(bodyUI->rescanButton, &QPushButton::clicked, this, [=](){getAudioInDevices(); getAudioOutDevices();}); connect(bodyUI->rescanButton, &QPushButton::clicked, this, [=](){getAudioInDevices(); getAudioOutDevices();});
bodyUI->playbackSlider->setValue(100); bodyUI->playbackSlider->setValue(100);
bodyUI->microphoneSlider->setValue(100); bodyUI->microphoneSlider->setValue(100);
bodyUI->playbackSlider->setEnabled(false);
bodyUI->microphoneSlider->setEnabled(false);
for (QComboBox* cb : findChildren<QComboBox*>()) for (QComboBox* cb : findChildren<QComboBox*>())
{ {
@ -285,13 +283,13 @@ void AVForm::on_ContrastSlider_valueChanged(int value)
void AVForm::on_playbackSlider_valueChanged(int value) void AVForm::on_playbackSlider_valueChanged(int value)
{ {
Audio::getInstance().outputVolume = value / 100.0; Audio::setOutputVolume(value / 100.0);
bodyUI->playbackMax->setText(QString::number(value)); bodyUI->playbackMax->setText(QString::number(value));
} }
void AVForm::on_microphoneSlider_valueChanged(int value) void AVForm::on_microphoneSlider_valueChanged(int value)
{ {
Audio::getInstance().outputVolume = value / 100.0; Audio::setOutputVolume(value / 100.0);
bodyUI->microphoneMax->setText(QString::number(value)); bodyUI->microphoneMax->setText(QString::number(value));
} }

6
src/widget/form/settings/avsettings.ui

@ -75,6 +75,9 @@
<string>Use slider to set volume of your microphone. <string>Use slider to set volume of your microphone.
WARNING: slider is not supposed to work yet.</string> WARNING: slider is not supposed to work yet.</string>
</property> </property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
@ -85,6 +88,9 @@ WARNING: slider is not supposed to work yet.</string>
<property name="toolTip"> <property name="toolTip">
<string>Use slider to set volume of your speakers.</string> <string>Use slider to set volume of your speakers.</string>
</property> </property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>

Loading…
Cancel
Save