2 * Copyright (C) 2015 Robin Gareus <robin@gareus.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <CoreServices/CoreServices.h>
20 #include <CoreAudio/CoreAudio.h>
21 #include <AudioUnit/AudioUnit.h>
23 #include <AudioUnit/AudioUnit.h>
24 #include <AudioToolbox/AudioToolbox.h>
29 #define AUHAL_OUTPUT_ELEMENT 0
30 #define AUHAL_INPUT_ELEMENT 1
39 int state (void) const { return _state; }
40 uint32_t n_playback_channels (void) const { return _playback_channels; }
41 uint32_t n_capture_channels (void) const { return _capture_channels; }
44 void device_list(std::map<size_t, std::string> &devices) const { devices = _devices;}
48 uint32_t input_device,
49 uint32_t output_device,
51 uint32_t samples_per_period,
52 int (process_callback (void*)),
56 void set_error_callback (
57 void ( error_callback (void*)),
60 _error_callback = error_callback;
61 _error_arg = error_arg;
64 // must be called from process_callback;
65 int get_capture_channel (uint32_t chn, float *input, uint32_t n_samples);
66 int set_playback_channel (uint32_t chn, const float *input, uint32_t n_samples);
67 uint32_t n_samples() const { return _cur_samples_per_period; };
70 OSStatus render_callback (
71 AudioUnitRenderActionFlags* ioActionFlags,
72 const AudioTimeStamp* inTimeStamp,
74 UInt32 inNumberFrames,
75 AudioBufferList* ioData);
77 void hwPropertyChange();
81 AudioDeviceID* _deviceIDs;
82 AudioBufferList* _inputAudioBufferList;
83 AudioBufferList* _outputAudioBufferList;
87 uint32_t _max_samples_per_period;
88 uint32_t _cur_samples_per_period;
89 uint32_t _capture_channels;
90 uint32_t _playback_channels;
94 int (* _process_callback) (void*);
97 void (* _error_callback) (void*);
100 std::map<size_t, std::string> _devices;
101 // TODO proper device info struct
102 uint32_t * _device_ins;
103 uint32_t * _device_outs;