3 * Copyright 2006,2010 Free Software Foundation, Inc.
5 * This file is part of GNU Radio.
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
23 #ifndef INCLUDED_AUDIO_OSX_SOURCE_H
24 #define INCLUDED_AUDIO_OSX_SOURCE_H
26 #include <gr_sync_block.h>
28 #include <AudioToolbox/AudioToolbox.h>
29 #include <AudioUnit/AudioUnit.h>
30 #include <circular_buffer.h>
32 class audio_osx_source;
33 typedef boost::shared_ptr<audio_osx_source> audio_osx_source_sptr;
36 audio_osx_make_source (int sample_rate = 44100,
37 const std::string device_name = "",
39 int channel_config = -1,
40 int max_sample_count = -1);
43 * \brief audio source using OSX
45 * Input signature is one or two streams of floats.
46 * Samples must be in the range [-1,1].
49 class audio_osx_source : public gr_sync_block {
50 friend audio_osx_source_sptr
51 audio_osx_make_source (int sample_rate,
52 const std::string device_name,
55 int max_sample_count);
57 Float64 d_deviceSampleRate, d_outputSampleRate;
59 UInt32 d_inputBufferSizeFrames, d_inputBufferSizeBytes;
60 UInt32 d_outputBufferSizeFrames, d_outputBufferSizeBytes;
61 UInt32 d_deviceBufferSizeFrames, d_deviceBufferSizeBytes;
62 UInt32 d_leadSizeFrames, d_leadSizeBytes;
63 UInt32 d_trailSizeFrames, d_trailSizeBytes;
64 UInt32 d_extraBufferSizeFrames, d_extraBufferSizeBytes;
65 UInt32 d_queueSampleCount, d_max_sample_count;
66 UInt32 d_n_AvailableInputFrames, d_n_ActualInputFrames;
67 UInt32 d_n_user_channels, d_n_max_channels, d_n_deviceChannels;
68 bool d_do_block, d_passThrough, d_waiting_for_data;
69 gruel::mutex* d_internal;
70 gruel::condition_variable* d_cond_data;
71 circular_buffer<float>** d_buffers;
73 // AudioUnits and Such
75 AudioBufferList* d_InputBuffer;
76 AudioBufferList* d_OutputBuffer;
77 AudioConverterRef d_AudioConverter;
80 audio_osx_source (int sample_rate = 44100,
81 const std::string device_name = "",
83 int channel_config = -1,
84 int max_sample_count = -1);
93 bool check_topology (int ninputs, int noutputs);
95 int work (int noutput_items,
96 gr_vector_const_void_star &input_items,
97 gr_vector_void_star &output_items);
100 void SetDefaultInputDeviceAsCurrent ();
102 void AllocAudioBufferList (AudioBufferList** t_ABL,
104 UInt32 inputBufferSizeBytes);
106 void FreeAudioBufferList (AudioBufferList** t_ABL);
108 static OSStatus ConverterCallback (AudioConverterRef inAudioConverter,
109 UInt32* ioNumberDataPackets,
110 AudioBufferList* ioData,
111 AudioStreamPacketDescription** outASPD,
114 static OSStatus AUInputCallback (void *inRefCon,
115 AudioUnitRenderActionFlags *ioActionFlags,
116 const AudioTimeStamp *inTimeStamp,
118 UInt32 inNumberFrames,
119 AudioBufferList *ioData);
120 #if _OSX_DO_LISTENERS_
121 static OSStatus UnitListener (void *inRefCon,
123 AudioUnitPropertyID inID,
124 AudioUnitScope inScope,
125 AudioUnitElement inElement);
127 static OSStatus HardwareListener (AudioHardwarePropertyID inPropertyID,
132 #endif /* INCLUDED_AUDIO_OSX_SOURCE_H */