LMMS
Loading...
Searching...
No Matches
AudioDevice.h
Go to the documentation of this file.
1/*
2 * AudioDevice.h - base-class for audio-devices, used by LMMS audio engine
3 *
4 * Copyright (c) 2004-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_AUDIO_DEVICE_H
26#define LMMS_AUDIO_DEVICE_H
27
28#include <QMutex>
29#include <samplerate.h>
30
31#include "LmmsTypes.h"
32
33class QThread;
34
35namespace lmms
36{
37
38class AudioEngine;
39class AudioBusHandle;
40class SampleFrame;
41
42
44{
45public:
46 AudioDevice( const ch_cnt_t _channels, AudioEngine* audioEngine );
47 virtual ~AudioDevice();
48
49 // if audio-driver supports ports, classes inheriting AudioBusHandle
50 // (e.g. channel-tracks) can register themselves for making
51 // audio-driver able to collect their individual output and provide
52 // them at a specific port - currently only supported by JACK
53 virtual void registerPort(AudioBusHandle* port);
54 virtual void unregisterPort(AudioBusHandle* port);
55 virtual void renamePort(AudioBusHandle* port);
56
57 inline bool supportsCapture() const
58 {
59 return m_supportsCapture;
60 }
61
63 {
64 return m_sampleRate;
65 }
66
67 void startProcessing();
68
69 void stopProcessing();
70
71 bool isRunning() const { return m_running.test(std::memory_order_acquire); }
72
73protected:
74 // convert a given audio-buffer to a buffer in signed 16-bit samples
75 // returns num of bytes in outbuf
76 int convertToS16(const SampleFrame* _ab, const f_cnt_t _frames, int_sample_t* _output_buffer,
77 const bool _convert_endian = false);
78
79 // clear given signed-int-16-buffer
80 void clearS16Buffer(int_sample_t* _outbuf, const f_cnt_t _frames);
81
82 ch_cnt_t channels() const { return m_channels; }
83
85
86 void setSampleRate(const sample_rate_t _new_sr) { m_sampleRate = _new_sr; }
88
89 static void stopProcessingThread( QThread * thread );
90protected:
92
93private:
94 virtual void startProcessingImpl() = 0;
95 virtual void stopProcessingImpl() = 0;
96
100 std::atomic_flag m_running = ATOMIC_FLAG_INIT;
101};
102
103} // namespace lmms
104
105#endif // LMMS_AUDIO_DEVICE_H
Job between PlayHandle and MixerChannel.
Definition AudioBusHandle.h:55
virtual void startProcessingImpl()=0
AudioEngine * audioEngine()
Definition AudioDevice.h:84
bool m_supportsCapture
Definition AudioDevice.h:91
virtual ~AudioDevice()
Definition AudioDevice.cpp:43
virtual void stopProcessingImpl()=0
void setSampleRate(const sample_rate_t _new_sr)
Definition AudioDevice.h:86
sample_rate_t m_sampleRate
Definition AudioDevice.h:97
AudioEngine * m_audioEngine
Definition AudioDevice.h:99
void startProcessing()
Definition AudioDevice.cpp:48
void stopProcessing()
Definition AudioDevice.cpp:54
AudioDevice(const ch_cnt_t _channels, AudioEngine *audioEngine)
Definition AudioDevice.cpp:33
static void stopProcessingThread(QThread *thread)
Definition AudioDevice.cpp:60
int convertToS16(const SampleFrame *_ab, const f_cnt_t _frames, int_sample_t *_output_buffer, const bool _convert_endian=false)
Definition AudioDevice.cpp:93
void setChannels(const ch_cnt_t channels)
Definition AudioDevice.h:87
bool supportsCapture() const
Definition AudioDevice.h:57
virtual void renamePort(AudioBusHandle *port)
Definition AudioDevice.cpp:89
bool isRunning() const
Definition AudioDevice.h:71
virtual void unregisterPort(AudioBusHandle *port)
Definition AudioDevice.cpp:82
sample_rate_t sampleRate() const
Definition AudioDevice.h:62
void clearS16Buffer(int_sample_t *_outbuf, const f_cnt_t _frames)
Definition AudioDevice.cpp:130
virtual void registerPort(AudioBusHandle *port)
Definition AudioDevice.cpp:75
ch_cnt_t m_channels
Definition AudioDevice.h:98
ch_cnt_t channels() const
Definition AudioDevice.h:82
std::atomic_flag m_running
Definition AudioDevice.h:100
Definition AudioEngine.h:66
Definition SampleFrame.h:41
Definition AudioAlsa.cpp:35
std::uint16_t ch_cnt_t
Definition LmmsTypes.h:44
std::uint32_t sample_rate_t
Definition LmmsTypes.h:42
std::int16_t int_sample_t
Definition LmmsTypes.h:40
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43