diff options
Diffstat (limited to 'examples/multimedia/spectrum/engine.h')
-rw-r--r-- | examples/multimedia/spectrum/engine.h | 140 |
1 files changed, 50 insertions, 90 deletions
diff --git a/examples/multimedia/spectrum/engine.h b/examples/multimedia/spectrum/engine.h index 7f7028bab..9e8ba51d0 100644 --- a/examples/multimedia/spectrum/engine.h +++ b/examples/multimedia/spectrum/engine.h @@ -1,52 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the examples of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause #ifndef ENGINE_H #define ENGINE_H @@ -60,17 +13,17 @@ #include <QByteArray> #include <QDir> #include <QList> -#include <QObject> #include <QMediaDevices> -#include <QWaveDecoder> +#include <QObject> #include <QTimer> +#include <QWaveDecoder> #ifdef DUMP_CAPTURED_AUDIO -#define DUMP_DATA +# define DUMP_DATA #endif #ifdef DUMP_SPECTRUM -#define DUMP_DATA +# define DUMP_DATA #endif class FrequencySpectrum; @@ -90,14 +43,18 @@ class Engine : public QObject Q_OBJECT public: - explicit Engine(QObject *parent = 0); + explicit Engine(QObject *parent = nullptr); ~Engine(); const QList<QAudioDevice> &availableAudioInputDevices() const - { return m_availableAudioInputDevices; } + { + return m_availableAudioInputDevices; + } const QList<QAudioDevice> &availableAudioOutputDevices() const - { return m_availableAudioOutputDevices; } + { + return m_availableAudioOutputDevices; + } QAudioDevice::Mode mode() const { return m_mode; } QAudio::State state() const { return m_state; } @@ -106,7 +63,7 @@ public: * \return Current audio format * \note May be QAudioFormat() if engine is not initialized */ - const QAudioFormat& format() const { return m_format; } + const QAudioFormat &format() const { return m_format; } /** * Stop any ongoing recording or playback, and reset to ground state. @@ -246,6 +203,7 @@ signals: void bufferChanged(qint64 position, qint64 length, const QByteArray &buffer); private slots: + void initAudioDevices(); void audioNotify(); void audioStateChanged(QAudio::State state); void audioDataReady(); @@ -269,7 +227,10 @@ private: #ifdef DUMP_DATA void createOutputDir(); - QString outputPath() const { return m_outputDir.path(); } + QString outputPath() const + { + return m_outputDir.path(); + } #endif #ifdef DUMP_CAPTURED_AUDIO @@ -277,53 +238,52 @@ private: #endif private: - QAudioDevice::Mode m_mode; - QAudio::State m_state; - QMediaDevices *m_devices; + QAudioDevice::Mode m_mode; + QAudio::State m_state; + QMediaDevices *m_devices; - bool m_generateTone; - SweptTone m_tone; + bool m_generateTone; + SweptTone m_tone; - QWaveDecoder* m_file; + QWaveDecoder *m_file; // We need a second file handle via which to read data into m_buffer // for analysis - QWaveDecoder* m_analysisFile; + QWaveDecoder *m_analysisFile; - QAudioFormat m_format; + QAudioFormat m_format; - const QList<QAudioDevice> m_availableAudioInputDevices; - QAudioDevice m_audioInputDevice; - QAudioSource* m_audioInput; - QIODevice* m_audioInputIODevice; - qint64 m_recordPosition; + QList<QAudioDevice> m_availableAudioInputDevices; + QAudioDevice m_audioInputDevice; + QAudioSource *m_audioInput; + QIODevice *m_audioInputIODevice; + qint64 m_recordPosition; - const QList<QAudioDevice> m_availableAudioOutputDevices; - QAudioDevice m_audioOutputDevice; - QAudioSink* m_audioOutput; - qint64 m_playPosition; - QBuffer m_audioOutputIODevice; + QList<QAudioDevice> m_availableAudioOutputDevices; + QAudioDevice m_audioOutputDevice; + QAudioSink *m_audioOutput; + qint64 m_playPosition; + QBuffer m_audioOutputIODevice; - QByteArray m_buffer; - qint64 m_bufferPosition; - qint64 m_bufferLength; - qint64 m_dataLength; + QByteArray m_buffer; + qint64 m_bufferPosition; + qint64 m_bufferLength; + qint64 m_dataLength; - int m_levelBufferLength; - qreal m_rmsLevel; - qreal m_peakLevel; + int m_levelBufferLength; + qreal m_rmsLevel; + qreal m_peakLevel; - int m_spectrumBufferLength; - QByteArray m_spectrumBuffer; - SpectrumAnalyser m_spectrumAnalyser; - qint64 m_spectrumPosition; + int m_spectrumBufferLength; + QByteArray m_spectrumBuffer; + SpectrumAnalyser m_spectrumAnalyser; + qint64 m_spectrumPosition; - int m_count; + int m_count; QTimer *m_notifyTimer = nullptr; #ifdef DUMP_DATA - QDir m_outputDir; + QDir m_outputDir; #endif - }; #endif // ENGINE_H |