~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/audio/audio-macosx.h

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 /*
  2  * audio-macosx.h --
  3  *
  4  * Audio support for Mac OS X using the CoreAudio framework.
  5  *
  6  * Copyright (c) 2000-2002 The Regents of the University of California.
  7  * All rights reserved.
  8  *
  9  * Redistribution and use in source and binary forms, with or without
 10  * modification, are permitted provided that the following conditions are met:
 11  *
 12  * A. Redistributions of source code must retain the above copyright notice,
 13  *    this list of conditions and the following disclaimer.
 14  * B. Redistributions in binary form must reproduce the above copyright notice,
 15  *    this list of conditions and the following disclaimer in the documentation
 16  *    and/or other materials provided with the distribution.
 17  * C. Neither the names of the copyright holders nor the names of its
 18  *    contributors may be used to endorse or promote products derived from this
 19  *    software without specific prior written permission.
 20  *
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 22  * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 23  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 24  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  */
 33 #ifndef MASH_AUDIO_MACOSX_H
 34 #define MASH_AUDIO_MACOSX_H
 35 
 36 #include <Carbon/Carbon.h>
 37 #include <CoreAudio/CoreAudio.h>
 38 #include <AudioUnit/AudioUnit.h>
 39 #include <AudioToolbox/DefaultAudioOutput.h>
 40 #include <AudioToolbox/AudioConverter.h>
 41 #include <tcl.h>
 42 #include "audio.h"
 43 
 44 class MacOSXAudio : public Audio {
 45 public:
 46     // Constructors.
 47     MacOSXAudio();
 48 
 49     // Destructor.
 50     ~MacOSXAudio();
 51 
 52     // Minimum necessary functions.
 53     virtual int FrameReady();
 54     virtual u_char* Read();
 55     virtual void Write(u_char*);
 56     virtual void Obtain();
 57     virtual void Release();
 58 
 59     // Overriden functions.
 60     virtual int haveaudio() const { return obtained_; }
 61     virtual int command(int argc, const char*const* argv);
 62     virtual void SetRGain(int level);
 63     virtual void RMute();
 64     virtual void RUnmute();
 65     virtual void SetPGain(int level);
 66     virtual void PMute();
 67     virtual void PUnmute();
 68 
 69     // Static audio processing functions.
 70     static void dispatchHandler(ClientData cd);
 71     static OSStatus audioIOProc(AudioDeviceID inDevice, const AudioTimeStamp* inNow, const AudioBufferList* inInputData, const AudioTimeStamp* inInputTime, AudioBufferList* outOutputData, const AudioTimeStamp* inOutputTime, void* inClientData);
 72     static OSStatus outputRenderer(void *inRefCon, AudioUnitRenderActionFlags inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, AudioBuffer *ioData);
 73 
 74     // 16-bit stereo functions.
 75     virtual int getSampleRate() { return (int)mashStreamBasicDescription_.mSampleRate; }
 76     virtual int use16bits() { return use16RawPCM_; }
 77     virtual int inStereo() { return (mashStreamBasicDescription_.mChannelsPerFrame == 2); }
 78     virtual void reinitialize();
 79 
 80     // The read and write function buffers.
 81     //
 82     // The ring buffer factor should be large enough to avoid overlapping data access,
 83     // but small enough to catch up fairly quickly if the process is suspended.
 84     //
 85     // Reading and writing from the buffers is done by two separate threads.
 86     static const int ringBufferFactor_ = 16;
 87     int readBufferSize_, writeBufferSize_;
 88     u_char* readBuffer_;
 89     int inputReadIndex_, inputWriteIndex_;
 90     SInt16* writeBuffer_;
 91     int outputReadIndex_, outputWriteIndex_;
 92 
 93     // The input device ID.
 94     AudioDeviceID inputDeviceID_;
 95 
 96     // The output audio unit.
 97     AudioUnit outputUnit_;
 98 
 99     // The input stream description.
100     AudioStreamBasicDescription inputStreamBasicDescription_;
101 
102     // The Mash stream description.
103     AudioStreamBasicDescription mashStreamBasicDescription_;
104 
105     // True if input and output is possible.
106     Boolean input_, output_;
107 
108     // Mute booleans.
109     Boolean muteInput_, muteOutput_;
110 
111     // Input and output volume gain values. The slider value 0-255 will be
112     // divided by the gain divisor to determine the gain factor.
113     static const Float32 inputGainDivisor_ = 2.56;
114     static const Float32 outputGainDivisor_ = 40.0;
115     Float32 inputGain_, outputGain_;
116 
117     // True if audio I/O has been started.
118     Boolean obtained_;
119 
120     // 16-bit stereo support.
121     int use16RawPCM_;
122 
123     // The decimation Z delay line and the current FIR filter phase.
124     double* zLine_;
125     int currentPhase_;
126 
127     // The number of available input frames.
128     int availableInput_;
129 
130     // The timer token returned by Tcl_CreateTimerHandler.
131     Tcl_TimerToken tclTimerToken_;
132 
133     // A simple exception handler class.
134     class Exception {
135     public:
136         Exception(char* s) {
137             string = s;
138         }
139 
140         char* string;
141     };
142 };
143 
144 /*****************************************************************************
145 *
146 * Name: resamp.h
147 *
148 * Synopsis:
149 *
150 *   Resamples a signal.  For more information about resampling, see dspGuru's
151 *   Multirate FAQ at:
152 *
153 *       http://www.dspguru.com/info/faqs/mrfaq.htm
154 *
155 * by Grant R. Griffin
156 * Provided by Iowegian's "dspGuru" service (http://www.dspguru.com).
157 * Copyright 2001, Iowegian International Corporation (http://www.iowegian.com)
158 *
159 *                          The Wide Open License (WOL)
160 *
161 * Permission to use, copy, modify, distribute and sell this software and its
162 * documentation for any purpose is hereby granted without fee, provided that
163 * the above copyright notice and this license appear in all source copies. 
164 * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY OF
165 * ANY KIND. See http://www.dspguru.com/wol.htm for more information.
166 *
167 *****************************************************************************/
168 
169 /*****************************************************************************
170 Description:
171 
172 resamp - "resamples" a signal by changing its sampling rate by a
173 rational factor via FIR filtering.
174 
175 Two similar implementations are supplied, resamp0 and resamp1, which can
176 be selected via the "#define resamp" below.  resamp0 is simpler (and 
177                                                                  therefore easier to understand), but resamp1 is faster.
178 
179 Inputs:
180 
181 interp_factor_L:
182 the interpolation factor (must be >= 1)
183 
184 decim_factor_M:
185 the decimation factor (must be >= 1)
186 
187 num_taps_per_phase:
188 the number of taps per polyphase filter, which is the total number of
189 taps in the filter divided by interp_factor_L.
190 
191 p_H:
192 pointer to the array of coefficients for the resampling filter.
193 (The number of total taps in p_H is interp_factor * num_taps_per_phase,
194  so be sure to design your filter using a number of taps which is evenly
195  divisible by interp_factor.)
196 
197 num_inp:
198 the number of input samples
199 
200 p_inp:
201 pointer to the input samples
202 
203 Input/Outputs:
204 
205 p_current_phase:
206 pointer to the current phase (must be >= 0 and <= interp_factor_L)
207 
208 p_Z:
209 pointer to the delay line array (must have num_taps_per_phase
210                                  elements)    
211 
212 Outputs:
213 
214 p_out:
215 pointer to the output sample array.
216 
217 p_num_out:
218 pointer to the number of output samples
219 
220 *****************************************************************************/
221 void resamp(int interp_factor_L, int decim_factor_M, int num_taps_per_phase,
222             int *p_current_phase, const double *const p_H, double *const p_Z,
223             int num_inp, const double *p_inp, double *p_out, int *p_num_out);
224 #endif
225 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.