/* Copyright 2020-2021 Brad Parker Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef NO_SOUND #include #include #endif #include #include "mainwindow.h" #ifndef NO_SOUND void MainWindow::startAudio(QAudioFormat *format) { m_audioOutput = new QAudioOutput(*format, this); connect(m_audioOutput, &QAudioOutput::stateChanged, this, &MainWindow::audioStateChanged); m_audioStream = m_audioOutput->start(); } void MainWindow::audioStateChanged(QAudio::State state) { if(state == QAudio::IdleState) { if(!m_audioReady) { m_audioReady = true; std::cout << "ready to play audio." << std::endl; emit audioStreamReady(); } } } #endif void MainWindow::onAudioSample(int16_t left, int16_t right) { #ifndef NO_SOUND m_audioStream->write(reinterpret_cast(left), sizeof(int16_t)); m_audioStream->write(reinterpret_cast(right), sizeof(int16_t)); #endif } void MainWindow::onAudioSampleBatch(const int16_t *data, size_t frames) { #ifndef NO_SOUND // each "frame" is two int16_t's (one for each channel of a stereo track) m_audioStream->write(reinterpret_cast(data), frames * sizeof(int16_t) * 2); #endif }