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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? 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;

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产精品少妇自拍| 国产成人精品在线看| 夜夜夜精品看看| 国产精品日韩精品欧美在线| ww久久中文字幕| 日韩欧美国产一区在线观看| 91精品国产综合久久久蜜臀粉嫩 | 在线亚洲人成电影网站色www| 懂色av一区二区夜夜嗨| 国产精品99精品久久免费| 久久97超碰国产精品超碰| 精品一区二区三区在线播放视频 | 欧美精品v国产精品v日韩精品 | 欧美日本一区二区在线观看| 欧美性猛片xxxx免费看久爱| 欧美日韩一区二区三区不卡| 欧美亚洲一区二区在线观看| 欧美三区在线视频| 欧美性猛交一区二区三区精品| 欧美日韩一本到| 91 com成人网| 欧美电影免费观看高清完整版在| 欧美一级一区二区| 日韩美女视频一区二区在线观看| 欧美一区二区三区系列电影| 日韩欧美一级在线播放| 久久伊99综合婷婷久久伊| 久久精品一区二区三区不卡| 国产欧美日韩精品一区| 国产精品每日更新在线播放网址| 亚洲人成伊人成综合网小说| 亚洲一级二级三级在线免费观看| 天天影视网天天综合色在线播放| 奇米色一区二区| 国产精品一卡二卡在线观看| www.亚洲精品| 精品视频1区2区3区| 日韩午夜激情av| 久久精品亚洲一区二区三区浴池| 国产精品白丝在线| 亚洲大尺度视频在线观看| 美腿丝袜亚洲色图| 国产精品亚洲а∨天堂免在线| 成人av小说网| 欧美日韩激情一区二区三区| 2014亚洲片线观看视频免费| 国产精品久久久久7777按摩| 亚洲成a人片在线观看中文| 精品一区二区三区免费视频| 99久久久久久| 欧美丰满少妇xxxxx高潮对白| 久久综合色天天久久综合图片| **网站欧美大片在线观看| 日韩精品福利网| 国产精品一色哟哟哟| 色婷婷狠狠综合| 精品日韩在线观看| 亚洲卡通动漫在线| 激情综合网最新| 日本精品免费观看高清观看| 欧美成人性战久久| 伊人婷婷欧美激情| 另类专区欧美蜜桃臀第一页| 91麻豆免费观看| 欧美va亚洲va在线观看蝴蝶网| 亚洲色图在线播放| 黄页网站大全一区二区| 欧美亚洲国产一区在线观看网站| 久久久青草青青国产亚洲免观| 亚洲午夜三级在线| 国产99久久久国产精品潘金网站| 欧美军同video69gay| 综合av第一页| 国产一区在线精品| 欧美这里有精品| 国产精品福利在线播放| 久久99久久精品| 欧美日本在线播放| 一区在线观看视频| 国产乱人伦偷精品视频不卡 | 亚洲精品乱码久久久久久| 美女国产一区二区三区| 欧美主播一区二区三区| 国产精品乱码久久久久久 | 日韩欧美国产三级| 亚洲自拍偷拍欧美| 97久久精品人人爽人人爽蜜臀| 久久中文娱乐网| 蜜桃免费网站一区二区三区| 欧美性生交片4| 中文字幕日韩精品一区| 国产999精品久久久久久绿帽| 日韩精品一区国产麻豆| 午夜电影一区二区三区| 欧美性生活一区| 亚洲猫色日本管| 成人18精品视频| 欧美韩国日本不卡| 国产成人小视频| 久久亚洲免费视频| 久久国产精品区| 欧美一级久久久| 日韩黄色免费网站| 欧美日韩夫妻久久| 夜夜嗨av一区二区三区四季av| 94-欧美-setu| 136国产福利精品导航| 99视频在线精品| 国产精品久久久久久久久果冻传媒 | 在线视频国产一区| 亚洲激情自拍偷拍| 色88888久久久久久影院按摩 | 国产91精品一区二区麻豆网站| 精品国产露脸精彩对白| 久久爱www久久做| 日韩精品最新网址| 韩国三级中文字幕hd久久精品| 精品成人佐山爱一区二区| 捆绑调教美女网站视频一区| 欧美r级电影在线观看| 国模少妇一区二区三区| 国产午夜一区二区三区| 成人黄色综合网站| 中文字幕中文字幕在线一区| 99re8在线精品视频免费播放| 亚洲男人的天堂在线观看| 国产精品色呦呦| av中文字幕在线不卡| 亚洲欧美一区二区三区极速播放| 在线观看成人小视频| 肉色丝袜一区二区| 日韩欧美精品在线视频| 国产精品综合在线视频| 国产精品对白交换视频| 欧美亚洲国产一区在线观看网站| 午夜久久久久久久久| 日韩欧美国产综合| 高潮精品一区videoshd| 亚洲精品欧美二区三区中文字幕| 欧美伊人精品成人久久综合97 | 在线影院国内精品| 秋霞国产午夜精品免费视频| 久久免费视频色| 色综合网站在线| 三级成人在线视频| 国产日韩av一区| 在线观看网站黄不卡| 麻豆精品视频在线观看| 国产精品乱码一区二区三区软件| 欧日韩精品视频| 久久er精品视频| 亚洲欧洲精品一区二区精品久久久| 欧美综合色免费| 久久99精品久久久久久| 中文字幕av一区二区三区| 欧美综合色免费| 国产专区欧美精品| 亚洲精品v日韩精品| 欧美成人午夜电影| 色偷偷一区二区三区| 久久99国产精品久久| 亚洲精品视频在线观看网站| 日韩欧美一级二级| 日韩精品专区在线影院重磅| 成人av动漫网站| 日韩av中文在线观看| 中文字幕乱码日本亚洲一区二区| 欧美日韩精品电影| hitomi一区二区三区精品| 午夜激情一区二区三区| 中文字幕亚洲电影| 欧美大度的电影原声| 91免费视频大全| 国产精品综合网| 天堂一区二区在线免费观看| 国产精品视频yy9299一区| 日韩欧美在线一区二区三区| 日本精品一区二区三区高清| 国产一区二区h| 日韩精品一区第一页| 中文字幕亚洲欧美在线不卡| 久久综合色播五月| 欧美日韩免费在线视频| www.成人网.com| 国产一区在线看| 免费观看在线综合色| 亚洲一区二区不卡免费| 国产精品久线在线观看| 久久久噜噜噜久久中文字幕色伊伊| 欧美老肥妇做.爰bbww| 91精品办公室少妇高潮对白| www.在线欧美| 国产成人在线看| 韩国欧美国产1区| 青青草国产成人av片免费| 亚洲国产精品一区二区尤物区| 国产精品成人一区二区三区夜夜夜 | 欧美一级在线免费| 欧美电影一区二区三区| 欧美三区在线视频|