mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Implement and enable the audio sliders
It was about time
This commit is contained in:
parent
42a26505fa
commit
4a40269698
|
@ -71,6 +71,32 @@ Audio::~Audio()
|
|||
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()
|
||||
{
|
||||
if (!alInDev)
|
||||
|
|
13
src/audio.h
13
src/audio.h
|
@ -45,6 +45,9 @@ class Audio : QObject
|
|||
public:
|
||||
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 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,
|
||||
unsigned samples, uint8_t channels, unsigned sample_rate);
|
||||
|
||||
public:
|
||||
static QThread* audioThread;
|
||||
static ALCcontext* alContext;
|
||||
static ALuint alMainSource;
|
||||
static float outputVolume;
|
||||
|
||||
private:
|
||||
explicit Audio()=default;
|
||||
~Audio();
|
||||
|
@ -91,6 +88,10 @@ private:
|
|||
static std::atomic<int> userCount;
|
||||
static ALCdevice* alOutDev, *alInDev;
|
||||
static QMutex* audioInLock, *audioOutLock;
|
||||
static float outputVolume;
|
||||
static ALuint alMainSource;
|
||||
static QThread* audioThread;
|
||||
static ALCcontext* alContext;
|
||||
};
|
||||
|
||||
#endif // AUDIO_H
|
||||
|
|
|
@ -586,7 +586,7 @@ void Core::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, un
|
|||
|
||||
ALint state;
|
||||
alGetSourcei(alSource, AL_SOURCE_STATE, &state);
|
||||
alSourcef(alSource, AL_GAIN, Audio::outputVolume);
|
||||
alSourcef(alSource, AL_GAIN, Audio::getOutputVolume());
|
||||
if (state != AL_PLAYING)
|
||||
{
|
||||
alSourcePlay(alSource);
|
||||
|
|
|
@ -54,8 +54,6 @@ AVForm::AVForm() :
|
|||
connect(bodyUI->rescanButton, &QPushButton::clicked, this, [=](){getAudioInDevices(); getAudioOutDevices();});
|
||||
bodyUI->playbackSlider->setValue(100);
|
||||
bodyUI->microphoneSlider->setValue(100);
|
||||
bodyUI->playbackSlider->setEnabled(false);
|
||||
bodyUI->microphoneSlider->setEnabled(false);
|
||||
|
||||
for (QComboBox* cb : findChildren<QComboBox*>())
|
||||
{
|
||||
|
@ -285,13 +283,13 @@ void AVForm::on_ContrastSlider_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));
|
||||
}
|
||||
|
||||
void AVForm::on_microphoneSlider_valueChanged(int value)
|
||||
{
|
||||
Audio::getInstance().outputVolume = value / 100.0;
|
||||
Audio::setOutputVolume(value / 100.0);
|
||||
bodyUI->microphoneMax->setText(QString::number(value));
|
||||
}
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@
|
|||
<string>Use slider to set volume of your microphone.
|
||||
WARNING: slider is not supposed to work yet.</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
@ -85,6 +88,9 @@ WARNING: slider is not supposed to work yet.</string>
|
|||
<property name="toolTip">
|
||||
<string>Use slider to set volume of your speakers.</string>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
|
|
Loading…
Reference in New Issue
Block a user