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 inline void lock()
50 {
51 m_devMutex.lock();
52 }
53
54 inline void unlock()
55 {
56 m_devMutex.unlock();
57 }
58
59
60 // if audio-driver supports ports, classes inheriting AudioBusHandle
61 // (e.g. channel-tracks) can register themselves for making
62 // audio-driver able to collect their individual output and provide
63 // them at a specific port - currently only supported by JACK
64 virtual void registerPort(AudioBusHandle* port);
65 virtual void unregisterPort(AudioBusHandle* port);
66 virtual void renamePort(AudioBusHandle* port);
67
68 inline bool supportsCapture() const
69 {
70 return m_supportsCapture;
71 }
72
74 {
75 return m_sampleRate;
76 }
77
78 void processNextBuffer();
79
80 virtual void startProcessing()
81 {
82 m_inProcess = true;
83 }
84
85 virtual void stopProcessing();
86
87protected:
88 // subclasses can re-implement this for being used in conjunction with
89 // processNextBuffer()
90 virtual void writeBuffer(const SampleFrame* /* _buf*/, const f_cnt_t /*_frames*/) {}
91
92 // called by according driver for fetching new sound-data
94
95 // convert a given audio-buffer to a buffer in signed 16-bit samples
96 // returns num of bytes in outbuf
97 int convertToS16(const SampleFrame* _ab,
98 const f_cnt_t _frames,
99 int_sample_t * _output_buffer,
100 const bool _convert_endian = false );
101
102 // clear given signed-int-16-buffer
103 void clearS16Buffer( int_sample_t * _outbuf,
104 const f_cnt_t _frames );
105
107 {
108 return m_channels;
109 }
110
111 inline void setSampleRate( const sample_rate_t _new_sr )
112 {
113 m_sampleRate = _new_sr;
114 }
115
117 {
119 }
120
122 {
123 return m_audioEngine;
124 }
125
126 static void stopProcessingThread( QThread * thread );
127
128
129protected:
131
132
133private:
138
140
142
143};
144
145} // namespace lmms
146
147#endif // LMMS_AUDIO_DEVICE_H
Job between PlayHandle and MixerChannel.
Definition AudioBusHandle.h:55
AudioEngine * audioEngine()
Definition AudioDevice.h:121
bool m_supportsCapture
Definition AudioDevice.h:130
void lock()
Definition AudioDevice.h:49
SampleFrame * m_buffer
Definition AudioDevice.h:141
void processNextBuffer()
Definition AudioDevice.cpp:55
void unlock()
Definition AudioDevice.h:54
virtual ~AudioDevice()
Definition AudioDevice.cpp:45
void setSampleRate(const sample_rate_t _new_sr)
Definition AudioDevice.h:111
virtual void startProcessing()
Definition AudioDevice.h:80
virtual void writeBuffer(const SampleFrame *, const f_cnt_t)
Definition AudioDevice.h:90
sample_rate_t m_sampleRate
Definition AudioDevice.h:134
AudioEngine * m_audioEngine
Definition AudioDevice.h:136
bool m_inProcess
Definition AudioDevice.h:137
QMutex m_devMutex
Definition AudioDevice.h:139
virtual void stopProcessing()
Definition AudioDevice.cpp:81
AudioDevice(const ch_cnt_t _channels, AudioEngine *audioEngine)
Definition AudioDevice.cpp:33
static void stopProcessingThread(QThread *thread)
Definition AudioDevice.cpp:95
int convertToS16(const SampleFrame *_ab, const f_cnt_t _frames, int_sample_t *_output_buffer, const bool _convert_endian=false)
Definition AudioDevice.cpp:128
void setChannels(const ch_cnt_t channels)
Definition AudioDevice.h:116
bool supportsCapture() const
Definition AudioDevice.h:68
virtual void renamePort(AudioBusHandle *port)
Definition AudioDevice.cpp:124
virtual void unregisterPort(AudioBusHandle *port)
Definition AudioDevice.cpp:117
sample_rate_t sampleRate() const
Definition AudioDevice.h:73
void clearS16Buffer(int_sample_t *_outbuf, const f_cnt_t _frames)
Definition AudioDevice.cpp:165
virtual void registerPort(AudioBusHandle *port)
Definition AudioDevice.cpp:110
ch_cnt_t m_channels
Definition AudioDevice.h:135
f_cnt_t getNextBuffer(SampleFrame *_ab)
Definition AudioDevice.cpp:65
ch_cnt_t channels() const
Definition AudioDevice.h:106
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