GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2006,2010 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio. 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_AUDIO_OSX_SOURCE_H 00024 #define INCLUDED_AUDIO_OSX_SOURCE_H 00025 00026 #include <gr_sync_block.h> 00027 #include <string> 00028 #include <AudioToolbox/AudioToolbox.h> 00029 #include <AudioUnit/AudioUnit.h> 00030 #include <circular_buffer.h> 00031 00032 class audio_osx_source; 00033 typedef boost::shared_ptr<audio_osx_source> audio_osx_source_sptr; 00034 00035 audio_osx_source_sptr 00036 audio_osx_make_source (int sample_rate = 44100, 00037 const std::string device_name = "", 00038 bool do_block = true, 00039 int channel_config = -1, 00040 int max_sample_count = -1); 00041 00042 /*! 00043 * \brief audio source using OSX 00044 * 00045 * Input signature is one or two streams of floats. 00046 * Samples must be in the range [-1,1]. 00047 */ 00048 00049 class audio_osx_source : public gr_sync_block { 00050 friend audio_osx_source_sptr 00051 audio_osx_make_source (int sample_rate, 00052 const std::string device_name, 00053 bool do_block, 00054 int channel_config, 00055 int max_sample_count); 00056 00057 Float64 d_deviceSampleRate, d_outputSampleRate; 00058 int d_channel_config; 00059 UInt32 d_inputBufferSizeFrames, d_inputBufferSizeBytes; 00060 UInt32 d_outputBufferSizeFrames, d_outputBufferSizeBytes; 00061 UInt32 d_deviceBufferSizeFrames, d_deviceBufferSizeBytes; 00062 UInt32 d_leadSizeFrames, d_leadSizeBytes; 00063 UInt32 d_trailSizeFrames, d_trailSizeBytes; 00064 UInt32 d_extraBufferSizeFrames, d_extraBufferSizeBytes; 00065 UInt32 d_queueSampleCount, d_max_sample_count; 00066 UInt32 d_n_AvailableInputFrames, d_n_ActualInputFrames; 00067 UInt32 d_n_user_channels, d_n_max_channels, d_n_deviceChannels; 00068 bool d_do_block, d_passThrough, d_waiting_for_data; 00069 gruel::mutex* d_internal; 00070 gruel::condition_variable* d_cond_data; 00071 circular_buffer<float>** d_buffers; 00072 00073 // AudioUnits and Such 00074 AudioUnit d_InputAU; 00075 AudioBufferList* d_InputBuffer; 00076 AudioBufferList* d_OutputBuffer; 00077 AudioConverterRef d_AudioConverter; 00078 00079 protected: 00080 audio_osx_source (int sample_rate = 44100, 00081 const std::string device_name = "", 00082 bool do_block = true, 00083 int channel_config = -1, 00084 int max_sample_count = -1); 00085 00086 public: 00087 ~audio_osx_source (); 00088 00089 bool start (); 00090 bool stop (); 00091 bool IsRunning (); 00092 00093 bool check_topology (int ninputs, int noutputs); 00094 00095 int work (int noutput_items, 00096 gr_vector_const_void_star &input_items, 00097 gr_vector_void_star &output_items); 00098 00099 private: 00100 void SetDefaultInputDeviceAsCurrent (); 00101 00102 void AllocAudioBufferList (AudioBufferList** t_ABL, 00103 UInt32 n_channels, 00104 UInt32 inputBufferSizeBytes); 00105 00106 void FreeAudioBufferList (AudioBufferList** t_ABL); 00107 00108 static OSStatus ConverterCallback (AudioConverterRef inAudioConverter, 00109 UInt32* ioNumberDataPackets, 00110 AudioBufferList* ioData, 00111 AudioStreamPacketDescription** outASPD, 00112 void* inUserData); 00113 00114 static OSStatus AUInputCallback (void *inRefCon, 00115 AudioUnitRenderActionFlags *ioActionFlags, 00116 const AudioTimeStamp *inTimeStamp, 00117 UInt32 inBusNumber, 00118 UInt32 inNumberFrames, 00119 AudioBufferList *ioData); 00120 #if _OSX_DO_LISTENERS_ 00121 static OSStatus UnitListener (void *inRefCon, 00122 AudioUnit ci, 00123 AudioUnitPropertyID inID, 00124 AudioUnitScope inScope, 00125 AudioUnitElement inElement); 00126 00127 static OSStatus HardwareListener (AudioHardwarePropertyID inPropertyID, 00128 void *inClientData); 00129 #endif 00130 }; 00131 00132 #endif /* INCLUDED_AUDIO_OSX_SOURCE_H */