1 /* 2 Copyright © 2019 by The qTox Project Contributors 3 4 This file is part of qTox, a Qt-based graphical interface for Tox. 5 6 qTox is libre software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 qTox is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with qTox. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef ALSINK_H 21 #define ALSINK_H 22 23 #include <QMutex> 24 #include <QObject> 25 26 #include "src/model/interface.h" 27 #include "src/audio/iaudiosink.h" 28 #include "src/util/compatiblerecursivemutex.h" 29 30 class OpenAL; 31 class QMutex; 32 class AlSink : public QObject, public IAudioSink 33 { 34 Q_OBJECT 35 public: 36 AlSink(OpenAL& al, uint sourceId); 37 AlSink(const AlSink& src) = delete; 38 AlSink& operator=(const AlSink&) = delete; 39 AlSink(AlSink&& other) = delete; 40 AlSink& operator=(AlSink&& other) = delete; 41 ~AlSink(); 42 43 void playAudioBuffer(const int16_t* data, int samples, unsigned channels, int sampleRate) const override; 44 void playMono16Sound(const IAudioSink::Sound& sound) override; 45 void startLoop() override; 46 void stopLoop() override; 47 48 operator bool() const override; 49 50 uint getSourceId() const; 51 void kill(); 52 53 SIGNAL_IMPL(AlSink, finishedPlaying) 54 SIGNAL_IMPL(AlSink, invalidated) 55 56 private: 57 OpenAL& audio; 58 uint sourceId; 59 bool killed = false; 60 mutable CompatibleRecursiveMutex killLock; 61 }; 62 63 #endif // ALSINK_H 64