亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? pa_mac_core.c

?? ppciaxclient softphone
?? C
?? 第 1 頁 / 共 5 頁
字號:
/*
 * $Id: pa_mac_core.c,v 1.8.4.12 2003/04/16 19:06:01 philburk Exp $
 * pa_mac_core.c
 * Implementation of PortAudio for Mac OS X Core Audio
 *
 * PortAudio Portable Real-Time Audio Library
 * Latest Version at: http://www.portaudio.com
 *
 * Authors: Ross Bencina and Phil Burk
 * Copyright (c) 1999-2002 Ross Bencina and Phil Burk
 *
 * Theory of Operation
 *
 * This code uses the HAL (Hardware Access Layer) of the Apple CoreAudio library.
 * This is the layer closes to the hardware.
 * The HAL layer only supports the native HW supported sample rates.
 * So if the chip only supports 44100 Hz, then the HAL only supports 44100.
 * To provide other rates we use the handy Apple AudioConverter which provides
 * sample rate conversion, mono-to-stereo conversion, and buffer size adaptation.
 *
 * There are four modes of operation:
 *    PA_MODE_OUTPUT_ONLY,
 *    PA_MODE_INPUT_ONLY,
 *    PA_MODE_IO_ONE_DEVICE,
 *    PA_MODE_IO_TWO_DEVICES
 *    
 * The processing pipeline for PA_MODE_IO_ONE_DEVICE is in one thread:
 *
 * PaOSX_CoreAudioIOCallback() input buffers -> RingBuffer -> input.AudioConverter ->
 *    PortAudio callback -> output.AudioConverter -> PaOSX_CoreAudioIOCallback() output buffers
 *
 * For two separate devices, we have to use two separate callbacks.
 * We pass data between them using a RingBuffer FIFO.
 * The processing pipeline for PA_MODE_IO_TWO_DEVICES is split into two threads:
 *
 * PaOSX_CoreAudioInputCallback() input buffers -> RingBuffer
 *
 * RingBuffer -> input.AudioConverter ->
 *    PortAudio callback -> output.AudioConverter -> PaOSX_CoreAudioIOCallback() output buffers
 *
 * License
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files
 * (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * Any person wishing to distribute modifications to the Software is
 * requested to send the modifications to the original developer so that
 * they can be incorporated into the canonical version.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * CHANGE HISTORY:
 
 3.29.2001 - Phil Burk - First pass... converted from Window MME code with help from Darren.
 3.30.2001 - Darren Gibbs - Added more support for dynamically querying device info.
 12.7.2001 - Gord Peters - Tweaks to compile on PA V17 and OS X 10.1
 2.7.2002 - Darren and Phil - fixed isInput so GetProperty works better, 
             fixed device queries for numChannels and sampleRates,
            one CoreAudio device now maps to separate input and output PaDevices,
            audio input works if using same CoreAudio device (some HW devices make separate CoreAudio devices).
 2.22.2002 - Stephane Letz - Explicit cast needed for compilation with Code Warrior 7
 3.19.2002 - Phil Burk - Added paInt16, paInt8, format using new "pa_common/pa_convert.c" file.
            Return error if opened in mono mode cuz not supported. [Supported 10.12.2002]
            Add support for Pa_GetCPULoad();
            Fixed timestamp in callback and Pa_StreamTime() (Thanks n++k for the advice!)
            Check for invalid sample rates and return an error.
            Check for getenv("PA_MIN_LATENCY_MSEC") to set latency externally.
            Better error checking for invalid channel counts and invalid devices.
 3.29.2002 - Phil Burk - Fixed Pa_GetCPULoad() for small buffers.
 3.31.2002 - Phil Burk - Use getrusage() instead of gettimeofday() for CPU Load calculation.
 10.12.2002 - Phil Burk - Use AudioConverter to allow wide range of sample rates, and mono.
              Use FIFO (from pablio/rinbuffer.h) so that we can pull data through converter.
              Added PaOSX_FixVolumeScalar() to make iMic audible.
 10.17.2002 - Phil Burk - Support full duplex between two different devices.
              Name internal functions PaOSX_*
              Dumped useless PA_MIN_LATENCY_MSEC environment variable.
              Use kAudioDevicePropertyStreamFormatMatch to determine max channels.
 02.03.2003 - Phil Burk - always use AudioConverters so that we can adapt when format changes.
              Synchronize with device when format changes.
 02.13.2003 - Phil Burk - scan for maxChannels because FormatMatch won't tell us.
 03.05.2003 - Phil Burk and Dominic Mazzoni - interleave and deinterleave multiple
              CoreAudio buffers. Needed for MOTU828 and some other N>2 channel devices.
              See code related to "streamInterleavingBuffer".
 03.06.2003 - Phil Burk and Ryan Francesconi - fixed numChannels query for MOTU828.
              Handle fact that MOTU828 gives you 8 channels even when you ask for 2!
 04.06.2003 - Phil Burk - Combine Dominic Mazzoni's technique of using Configuration to query maxChannels
              with old technique of scanning for mormat.
              Increase channel scan by 1 to handle mono USB microphones.
              Do not merge or split channels in AudioConverter to handle 2+2 channels
              of Quattro which has a format of 2 channels.
 04.07.2003 - Phil Burk - use AudioGetCurrentHostTime instead of getrusage() which can lock threads.
 04.10.2003 - Phil Burk - fixed pointer bug with input deinterleaving loop.
              Detect and ignore NULL inputData and outputData in CodeAudio callback.
              Overlap creation and deletion of AudioConverters to prevent thread death when device rate changes.
 04.16.2003 - Phil Burk - Fixed input channel scrambling when numChannels != 2^N. Caused by alignment
              error when filling RingBuffer with 2^N zero bytes.
*/

#include <CoreServices/CoreServices.h>
#include <CoreAudio/CoreAudio.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioToolbox/DefaultAudioOutput.h>
#include <AudioToolbox/AudioConverter.h>
#include <CoreAudio/HostTime.h>

#include "portaudio.h"
#include "pa_host.h"
#include "pa_trace.h"
#include "ringbuffer.h"

/************************************************* Configuration ********/
#define PA_ENABLE_LOAD_MEASUREMENT  (1)

/************************************************* Constants ********/
#define SET_DEVICE_BUFFER_SIZE   (1)

/* To trace program, enable TRACE_REALTIME_EVENTS in pa_trace.h */
#define PA_TRACE_RUN             (0)
#define PA_TRACE_START_STOP      (0)

#define PA_MIN_LATENCY_MSEC      (20) /* FIXME */
#define MIN_TIMEOUT_MSEC         (3000)

#define PRINT(x) { printf x; fflush(stdout); }
#define PRINT_ERR( msg, err ) PRINT(( msg ": error = 0x%0lX = '%s'\n", (err), ErrorToString(err)) )
#define DBUG(x)    /* PRINT(x) */
#define DBUGBACK(x) /* if( sMaxBackgroundErrorMessages-- > 0 ) PRINT(x) */
#define DBUGX(x)

// define value of isInput passed to CoreAudio routines
#define IS_INPUT    (true)
#define IS_OUTPUT   (false)

typedef enum PaDeviceMode
{
    PA_MODE_OUTPUT_ONLY,
    PA_MODE_INPUT_ONLY,
    PA_MODE_IO_ONE_DEVICE,
    PA_MODE_IO_TWO_DEVICES
} PaDeviceMode;

#define PA_USING_OUTPUT   (pahsc->mode != PA_MODE_INPUT_ONLY)
#define PA_USING_INPUT    (pahsc->mode != PA_MODE_OUTPUT_ONLY)

/**************************************************************
 * Information needed by PortAudio specific to a CoreAudio device.
 */
typedef struct PaHostInOut_s
{
    AudioDeviceID      audioDeviceID; /* CoreAudio specific ID */
    int                bytesPerUserNativeBuffer; /* User buffer size in native host format. Depends on numChannels. */
    AudioConverterRef  converter;
    void              *converterBuffer;
    int                numChannels;
    /** Used for interleaving or de-interleaving multiple streams for devices like MOTU828. */
    int                streamInterleavingBufferLen; /**< size in bytes */
    Float32           *streamInterleavingBuffer; 
} PaHostInOut;

/**************************************************************
 * Structure for internal host specific stream data.
 * This is allocated on a per stream basis.
 */
typedef struct PaHostSoundControl
{
    PaHostInOut        input;
    PaHostInOut        output;
    AudioDeviceID      primaryDeviceID;
    PaDeviceMode       mode;
    RingBuffer         ringBuffer;
    char              *ringBufferData;
    Boolean            formatListenerCalled;
    /* For measuring CPU utilization. */
    UInt64             entryTime;
    double             inverseHostTicksPerBuffer; /* 1/Ticks of real-time audio per user buffer. */
} PaHostSoundControl;

/**************************************************************
 * Structure for internal extended device info query.
 * There will be one or two PortAudio devices for each Core Audio device:
 *   one input and or one output.
 */
typedef struct PaHostDeviceInfo
{
    PaDeviceInfo      paInfo;
    AudioDeviceID     audioDeviceID;
}
PaHostDeviceInfo;

/************************************************* Shared Data ********/
/* FIXME - put Mutex around this shared data. */
static int sNumPaDevices = 0;   /* Total number of PaDeviceInfos */
static int sNumInputDevices = 0; /* Total number of input PaDeviceInfos */
static int sNumOutputDevices = 0;
static int sNumCoreDevices = 0;
static AudioDeviceID *sCoreDeviceIDs;   // Array of Core AudioDeviceIDs
static PaHostDeviceInfo *sDeviceInfos = NULL;
static int sDefaultInputDeviceID = paNoDevice;
static int sDefaultOutputDeviceID = paNoDevice;
static int sSavedHostError = 0;

static const double supportedSampleRateRange[] = { 8000.0, 96000.0 }; /* FIXME - go to double HW rate. */
static const char sMapperSuffixInput[] = " - Input";
static const char sMapperSuffixOutput[] = " - Output";

/* Debug support. */
//static int sMaxBackgroundErrorMessages = 100;
//static int sCoverageCounter = 1; // used to check code coverage during validation

/* We index the input devices first, then the output devices. */
#define LOWEST_INPUT_DEVID     (0)
#define HIGHEST_INPUT_DEVID    (sNumInputDevices - 1)
#define LOWEST_OUTPUT_DEVID    (sNumInputDevices)
#define HIGHEST_OUTPUT_DEVID   (sNumPaDevices - 1)

/************************************************* Macros ********/

/************************************************* Prototypes **********/

static PaError PaOSX_QueryDevices( void );
static int PaOSX_ScanDevices( Boolean isInput );
static int PaOSX_QueryDeviceInfo( PaHostDeviceInfo *hostDeviceInfo, int coreDeviceIndex, Boolean isInput );
static PaDeviceID PaOSX_QueryDefaultInputDevice( void );
static PaDeviceID PaOSX_QueryDefaultOutputDevice( void );
static void PaOSX_CalcHostBufferSize( internalPortAudioStream *past );

static OSStatus PAOSX_DevicePropertyListener (AudioDeviceID					inDevice,
								UInt32							inChannel,
								Boolean							isInput,
								AudioDevicePropertyID			inPropertyID,
								void*							inClientData);
                                
/**********************************************************************/
/* OS X errors are 4 character ID that can be printed.
 * Note that uses a static pad so result must be printed immediately.
 */
static OSStatus statusText[2] = { 0, 0 };
static const char *ErrorToString( OSStatus err )
{
    const char *str;

    switch (err)
    {
    case kAudioHardwareUnspecifiedError:
        str = "kAudioHardwareUnspecifiedError";
        break;
    case kAudioHardwareNotRunningError:
        str = "kAudioHardwareNotRunningError";
        break;
    case kAudioHardwareUnknownPropertyError:
        str = "kAudioHardwareUnknownPropertyError";
        break;
    case kAudioDeviceUnsupportedFormatError:
        str = "kAudioDeviceUnsupportedFormatError";
        break;
    case kAudioHardwareBadPropertySizeError:
        str = "kAudioHardwareBadPropertySizeError";
        break;
    case kAudioHardwareIllegalOperationError:
        str = "kAudioHardwareIllegalOperationError";
        break;
    default:
        statusText[0] = err;
    	str = (const char *)statusText;
        break;
    }

    return str;
}

/**********************************************************************/
static unsigned long RoundUpToNextPowerOf2( unsigned long n )
{
    long numBits = 0;
    if( ((n-1) & n) == 0) return n; /* Already Power of two. */
    while( n > 0 )
    {
        n= n>>1;
        numBits++;
    }
    return (1<<numBits);
}

/********************************* BEGIN CPU UTILIZATION MEASUREMENT ****/
static void Pa_StartUsageCalculation( internalPortAudioStream   *past )
{
    PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData;
    if( pahsc == NULL ) return;
    /* Query user CPU timer for usage analysis and to prevent overuse of CPU. */
    pahsc->entryTime = AudioGetCurrentHostTime();
}

/******************************************************************************
** Measure fractional CPU load based on real-time it took to calculate
** buffers worth of output.
*/
static void Pa_EndUsageCalculation( internalPortAudioStream   *past )
{
    UInt64   exitTime;
    UInt64   ticksElapsed;
    double   newUsage;
    
#define LOWPASS_COEFFICIENT_0   (0.95)
#define LOWPASS_COEFFICIENT_1   (0.99999 - LOWPASS_COEFFICIENT_0)

    PaHostSoundControl *pahsc = (PaHostSoundControl *) past->past_DeviceData;
    if( pahsc == NULL ) return;
    
    exitTime = AudioGetCurrentHostTime();
    
    ticksElapsed = exitTime - pahsc->entryTime;

    /* Use inverse because it is faster than the divide. */
	newUsage =  ticksElapsed * pahsc->inverseHostTicksPerBuffer;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品免费播放| 日韩精品在线一区二区| 中文字幕亚洲视频| 91一区二区在线| 亚洲影院免费观看| 制服.丝袜.亚洲.中文.综合| 日韩电影一区二区三区四区| 日韩一区二区三区观看| 国内精品久久久久影院色| 日韩精品一区二区三区视频 | 成人av电影在线播放| 一区二区激情视频| 91精品国产综合久久久久久| 精品综合久久久久久8888| 中文av一区特黄| 色婷婷狠狠综合| 首页综合国产亚洲丝袜| 久久久国际精品| 色婷婷一区二区三区四区| 日日夜夜免费精品| 国产欧美一区二区三区鸳鸯浴| 成人av电影免费在线播放| 亚洲综合成人在线| 日韩视频在线你懂得| 成人涩涩免费视频| 色噜噜狠狠色综合中国| 午夜成人免费视频| 国产欧美一区二区精品秋霞影院| 91国产成人在线| 精品一区二区三区日韩| 一区二区三区美女视频| 26uuu久久天堂性欧美| 色综合色狠狠综合色| 加勒比av一区二区| 亚洲一区在线播放| 国产精品久线在线观看| 欧美大片日本大片免费观看| 一本大道久久a久久精品综合| 久草精品在线观看| 亚洲一区二区高清| 国产精品免费久久久久| 精品久久久久久久久久久久包黑料| 99久久精品免费看国产免费软件| 久久国产生活片100| 亚洲国产精品一区二区久久| 久久午夜电影网| 欧美疯狂性受xxxxx喷水图片| 99riav久久精品riav| 国产一区二区三区在线看麻豆| 亚洲福利一区二区| 亚洲欧美国产三级| 国产视频一区在线播放| 精品国产一区二区三区av性色 | 欧洲色大大久久| 成人av第一页| 国产91丝袜在线播放0| 男人的j进女人的j一区| 亚洲福利一区二区| 夜夜精品视频一区二区| 亚洲免费在线观看视频| 亚洲欧洲精品天堂一级| 欧美国产精品专区| 国产亚洲欧美日韩俺去了| 日韩欧美视频在线| 欧美一区二区三区在线看| 精品婷婷伊人一区三区三| 色国产精品一区在线观看| 色综合中文字幕国产 | jlzzjlzz欧美大全| 国产成人精品亚洲777人妖| 国产精品一区在线观看你懂的| 蜜桃av噜噜一区二区三区小说| 午夜久久久影院| 亚洲成人动漫av| 视频在线观看国产精品| 日韩精品欧美成人高清一区二区| 亚洲综合色成人| 亚洲电影第三页| 亚洲风情在线资源站| 亚洲丶国产丶欧美一区二区三区| 亚洲mv在线观看| 日本不卡中文字幕| 精品亚洲免费视频| 国产美女av一区二区三区| 国产寡妇亲子伦一区二区| 国产v日产∨综合v精品视频| 99久久国产免费看| 色嗨嗨av一区二区三区| 欧美日韩国产在线播放网站| 制服丝袜亚洲网站| 精品欧美一区二区在线观看| 久久久精品国产99久久精品芒果| 国产精品色噜噜| 亚洲欧美自拍偷拍色图| 亚洲综合一二三区| 日本不卡的三区四区五区| 久久国产精品区| 国产风韵犹存在线视精品| 97久久人人超碰| 欧美日韩在线精品一区二区三区激情| 欧美福利视频一区| 久久精品在线免费观看| 亚洲精品第1页| 男女性色大片免费观看一区二区| 国产精品一区免费视频| 91婷婷韩国欧美一区二区| 欧美性高清videossexo| 欧美变态tickle挠乳网站| 欧美激情中文字幕一区二区| 亚洲免费观看视频| 久久99精品久久久久久 | 97国产精品videossex| 欧美日韩一级视频| 国产欧美中文在线| 午夜精品福利一区二区蜜股av| 极品美女销魂一区二区三区免费| 成人网男人的天堂| 欧美一区三区二区| 国产精品久久久久久户外露出 | 国产精品伊人色| 欧美在线你懂的| 久久久国产午夜精品| 午夜精品影院在线观看| 国内偷窥港台综合视频在线播放| 色综合天天综合狠狠| 精品动漫一区二区三区在线观看| 亚洲精品视频在线观看免费| 黑人巨大精品欧美一区| 在线观看av不卡| 欧美激情一区二区三区不卡| 日韩高清不卡在线| 色国产综合视频| 国产精品天美传媒沈樵| 另类的小说在线视频另类成人小视频在线| 99久久综合99久久综合网站| 日韩区在线观看| 天堂久久久久va久久久久| k8久久久一区二区三区| 久久久三级国产网站| 午夜视频在线观看一区二区三区| 成人av先锋影音| 久久久久国产一区二区三区四区 | 国产宾馆实践打屁股91| 日韩美女视频一区二区在线观看| 亚洲国产日韩综合久久精品| eeuss国产一区二区三区| 精品国产乱码久久| 麻豆视频一区二区| 337p亚洲精品色噜噜噜| 亚洲成a天堂v人片| 欧美在线综合视频| 亚洲黄色av一区| 色综合久久久久网| 国产精品成人网| 成人动漫精品一区二区| 国产欧美日韩三区| 国产成人精品免费| 国产欧美视频一区二区| 高清在线不卡av| 久久久久9999亚洲精品| 国产一区二区三区久久悠悠色av| 日韩免费性生活视频播放| 日韩在线一二三区| 欧美一级片免费看| 美女尤物国产一区| 欧美大片在线观看| 国产精品一二三在| 中文字幕第一区第二区| 成人一区二区视频| 日韩美女啊v在线免费观看| yourporn久久国产精品| 亚洲色欲色欲www| 一本久道中文字幕精品亚洲嫩| 国产精品美女一区二区在线观看| 国产91丝袜在线18| 亚洲卡通欧美制服中文| 在线观看免费一区| 午夜久久久久久久久| 欧美不卡一区二区三区| 国产精品1024久久| 中文字幕一区二区三区不卡在线 | 日韩精品91亚洲二区在线观看| 日韩午夜精品电影| 久久超碰97中文字幕| 久久久激情视频| 99re热视频精品| 日韩国产高清在线| 国产日韩欧美精品电影三级在线| 95精品视频在线| 午夜欧美大尺度福利影院在线看| 日韩精品一区二区三区四区视频 | 久久99精品久久久久| 国产色婷婷亚洲99精品小说| 不卡电影一区二区三区| 亚洲成人1区2区| 欧美精品一区二区蜜臀亚洲| 91亚洲精品久久久蜜桃网站| 亚洲国产一二三| 久久九九影视网| 色狠狠综合天天综合综合|