36void AudioInputExample::setup()
39 destinationFile.setFileName(
"/tmp/test.raw");
40 destinationFile.open( QIODevice::WriteOnly | QIODevice::Truncate );
44 format.setSampleRate(44100);
45 format.setChannelCount(1);
46 format.setSampleFormat(QAudioFormat::Int16);
48 QAudioDevice info = QMediaDevices::defaultAudioInput();
49 if (!info.isFormatSupported(format)) {
50 qWarning() <<
"Default format not supported, trying to use the nearest.";
53 audio =
new QAudioSource(format,
this);
54 connect(audio, &QAudioSource::stateChanged,
this, &AudioInputExample::handleStateChanged);
56 QTimer::singleShot(3000,
this, &AudioInputExample::stopRecording);
57 audio->start(&destinationFile);
115 sourceFile.setFileName(
"/tmp/test.raw");
116 sourceFile.open(QIODevice::ReadOnly);
120 format.setSampleRate(44100);
121 format.setChannelCount(1);
122 format.setSampleFormat(QAudioFormat::Int16);
124 QAudioDevice info(QMediaDevices::defaultAudioOutput());
125 if (!info.isFormatSupported(format)) {
126 qWarning() <<
"Raw audio format not supported by backend, cannot play audio.";
130 audio =
new QAudioSink(format,
this);
131 connect(audio, QAudioSink::stateChanged,
this, &AudioInputExample::handleStateChanged);
132 audio->start(&sourceFile);
197 QAudioFormat desiredFormat;
198 desiredFormat.setChannelCount(2);
199 desiredFormat.setSampleFormat(QAudioFormat::Int16);
200 desiredFormat.setSampleRate(48000);
202 QAudioDecoder *decoder =
new QAudioDecoder(
this);
203 decoder->setAudioFormat(desiredFormat);
204 decoder->setSource(
"level1.mp3");
206 connect(decoder, &QAudioDecoder::bufferReady,
this, &AudioDecodingExample::readBuffer);
220 qreal linearVolume = QtAudio::convertVolume(volumeSliderValue / qreal(100.0),
221 QtAudio::LogarithmicVolumeScale,
222 QtAudio::LinearVolumeScale);
224 player.setVolume(qRound(linearVolume * 100));