Reinitialize audio when changing device in examples
Different devices might have different audio formats supported. Always relying on the format of the default device can cause the audio endpoint to not start/initialize. Change-Id: I4d05949fd023f2cc7eb1f75db3577242e0e66680 Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
This commit is contained in:
@@ -237,7 +237,7 @@ InputTest::InputTest()
|
||||
, m_audioInfo(0)
|
||||
, m_audioInput(0)
|
||||
, m_input(0)
|
||||
, m_pullMode(false)
|
||||
, m_pullMode(true)
|
||||
, m_buffer(BufferSize, 0)
|
||||
{
|
||||
initializeWindow();
|
||||
@@ -291,8 +291,6 @@ void InputTest::initializeWindow()
|
||||
|
||||
void InputTest::initializeAudio()
|
||||
{
|
||||
m_pullMode = true;
|
||||
|
||||
m_format.setSampleRate(8000);
|
||||
m_format.setChannelCount(1);
|
||||
m_format.setSampleSize(16);
|
||||
@@ -300,12 +298,14 @@ void InputTest::initializeAudio()
|
||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_format.setCodec("audio/pcm");
|
||||
|
||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice());
|
||||
QAudioDeviceInfo info(m_device);
|
||||
if (!info.isFormatSupported(m_format)) {
|
||||
qWarning() << "Default format not supported - trying to use nearest";
|
||||
m_format = info.nearestFormat(m_format);
|
||||
}
|
||||
|
||||
if (m_audioInfo)
|
||||
delete m_audioInfo;
|
||||
m_audioInfo = new AudioInfo(m_format, this);
|
||||
connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay()));
|
||||
|
||||
@@ -381,7 +381,7 @@ void InputTest::deviceChanged(int index)
|
||||
delete m_audioInput;
|
||||
|
||||
m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();
|
||||
createAudioInput();
|
||||
initializeAudio();
|
||||
}
|
||||
|
||||
void InputTest::sliderChanged(int value)
|
||||
|
||||
@@ -167,6 +167,7 @@ AudioTest::AudioTest()
|
||||
, m_generator(0)
|
||||
, m_audioOutput(0)
|
||||
, m_output(0)
|
||||
, m_pullMode(true)
|
||||
, m_buffer(BufferSize, 0)
|
||||
{
|
||||
initializeWindow();
|
||||
@@ -222,8 +223,6 @@ void AudioTest::initializeAudio()
|
||||
{
|
||||
connect(m_pushTimer, SIGNAL(timeout()), SLOT(pushTimerExpired()));
|
||||
|
||||
m_pullMode = true;
|
||||
|
||||
m_format.setSampleRate(DataSampleRateHz);
|
||||
m_format.setChannelCount(1);
|
||||
m_format.setSampleSize(16);
|
||||
@@ -231,12 +230,14 @@ void AudioTest::initializeAudio()
|
||||
m_format.setByteOrder(QAudioFormat::LittleEndian);
|
||||
m_format.setSampleType(QAudioFormat::SignedInt);
|
||||
|
||||
QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
|
||||
QAudioDeviceInfo info(m_device);
|
||||
if (!info.isFormatSupported(m_format)) {
|
||||
qWarning() << "Default format not supported - trying to use nearest";
|
||||
m_format = info.nearestFormat(m_format);
|
||||
}
|
||||
|
||||
if (m_generator)
|
||||
delete m_generator;
|
||||
m_generator = new Generator(m_format, DurationSeconds*1000000, ToneSampleRateHz, this);
|
||||
|
||||
createAudioOutput();
|
||||
@@ -264,7 +265,7 @@ void AudioTest::deviceChanged(int index)
|
||||
m_audioOutput->stop();
|
||||
m_audioOutput->disconnect(this);
|
||||
m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>();
|
||||
createAudioOutput();
|
||||
initializeAudio();
|
||||
}
|
||||
|
||||
void AudioTest::volumeChanged(int value)
|
||||
|
||||
Reference in New Issue
Block a user