hydrogen 1.2.3
CoreAudioDriver.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://hydrogen.sourceforge.net
7 *
8 * CoreAudio Driver for Hydrogen
9 * Copyright(c) 2005 by Jonathan Dempsey [jonathandempsey@fastmail.fm]
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY, without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see https://www.gnu.org/licenses
23 *
24 * Rewrote CoreAudio driver, now using AUHAL (2005/03/02 Jonathan Dempsey)
25 * Cleaned up the code a bit and updated (2005/11/29 Jonathan Dempsey)
26 * More cleaning . . . (2005/12/31 Jonathan Dempsey)
27 */
28
29#ifndef COREAUDIO_DRIVER_H
30#define COREAUDIO_DRIVER_H
31
32#include <core/IO/AudioOutput.h>
33#include <core/IO/NullDriver.h>
34
35#if defined(H2CORE_HAVE_COREAUDIO) || _DOXYGEN_
36#include <AudioUnit/AudioUnit.h>
37#include <AudioToolbox/AudioToolbox.h>
38#include <AudioUnit/AudioComponent.h>
39#endif
40
42#include <inttypes.h>
43#include <vector>
44
45
46namespace H2Core
47{
48
49#if defined(H2CORE_HAVE_COREAUDIO) || _DOXYGEN_
50
52class CoreAudioDriver : public Object<CoreAudioDriver>, public AudioOutput
53{
55public:
56
59
60 AudioUnit m_outputUnit;
61 AudioDeviceID m_outputDevice;
62
63 float* m_pOut_L;
64 float* m_pOut_R;
65
66 CoreAudioDriver( audioProcessCallback processCallback );
67 virtual ~CoreAudioDriver();
68
69 virtual int init( unsigned nBufferSize ) override;
70
71 virtual unsigned getSampleRate() override;
72 virtual unsigned getBufferSize() override;
73
74 virtual int connect() override;
75 virtual void disconnect() override;
76
77 virtual float* getOut_L() override;
78 virtual float* getOut_R() override;
79
80 static QStringList getDevices();
81
82 virtual int getLatency() override;
83
84private:
85 AudioDeviceID defaultOutputDevice(void);
86 void retrieveBufferSize(void);
87 void printStreamInfo(void);
88
89 // Find the name of a given audio device
90 static QString deviceName( AudioDeviceID deviceID );
91
92 // Find suitable audio output devices
93 static std::vector< AudioDeviceID > outputDeviceIDs();
94
95 AudioDeviceID preferredOutputDevice();
96
98 unsigned m_nSampleRate;
99 unsigned oSampleRate;
100};
101
102#else
103
105class CoreAudioDriver : public Object<CoreAudioDriver>, public NullDriver
106{
108public:
109 CoreAudioDriver( audioProcessCallback processCallback ) : NullDriver ( processCallback ) {}
110
111};
112
113#endif // H2CORE_HAVE_COREAUDIO
114
115}
116
117#endif
#define H2_OBJECT(name)
Definition Object.h:224
Base abstract class for audio output classes.
Definition AudioOutput.h:39
virtual void disconnect() override
virtual float * getOut_L() override
virtual int init(unsigned nBufferSize) override
virtual int getLatency() override
Approximate audio latency (in frames) A reasonable approximation is the buffer time on most audio sys...
virtual float * getOut_R() override
virtual unsigned getBufferSize() override
audioProcessCallback mProcessCallback
virtual int connect() override
static QStringList getDevices()
AudioDeviceID preferredOutputDevice()
static QString deviceName(AudioDeviceID deviceID)
AudioDeviceID defaultOutputDevice(void)
static std::vector< AudioDeviceID > outputDeviceIDs()
virtual unsigned getSampleRate() override
CoreAudioDriver(audioProcessCallback processCallback)
int(* audioProcessCallback)(uint32_t, void *)
Definition AudioOutput.h:32