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

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

?? pa_unix_oss.c

?? 一個任天堂掌上游戲機NDS的源代碼
?? C
字號:
/*
 * PortAudio Portable Real-Time Audio Library
 * Latest Version at: http://www.portaudio.com
 * Linux OSS Implementation by douglas repetto and Phil Burk
 *
 * Copyright (c) 1999-2000 Phil Burk
 *
 * 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.
 *
 */

/* Modification history:
   20020621: pa_unix_oss.c split into pa_unix.c, pa_unix.h, pa_unix_oss.c by
       Augustus Saunders. See pa_unix.c for previous history. Pa_FlushStream
       added by Augustus Saunders for Solaris compatibility.
   PLB20021018 - Fill device info table with actual sample rates instead of wished for rates.
               - Allow stream to open if sample rate within 10% of desired rate.
   20030630 - Thomas Richter - eliminated unused variable warnings.
*/

#include "pa_unix.h"

#ifdef __linux__
#include <linux/soundcard.h>
#else
#include <machine/soundcard.h> /* JH20010905 */
#endif


#ifndef AFMT_S16_NE
#define AFMT_S16_NE  Get_AFMT_S16_NE()
/*********************************************************************
 * Some versions of OSS do not define AFMT_S16_NE. So check CPU.
 * PowerPC is Big Endian. X86 is Little Endian.
 */
int Get_AFMT_S16_NE( void )
{
    long testData = 1; 
    char *ptr = (char *) &testData;
    int isLittle = ( *ptr == 1 ); /* Does address point to least significant byte? */
    return isLittle ? AFMT_S16_LE : AFMT_S16_BE;
}
#endif /* AFMT_S16_NE */


/*********************************************************************
 * Try to open the named device.
 * If it opens, try to set various rates and formats and fill in 
 * the device info structure.
 */
PaError Pa_QueryDevice( const char *deviceName, internalPortAudioDevice *pad )
{
    int result = paHostError;
    int tempDevHandle;
    int numChannels, maxNumChannels;
    int format;
    int numSampleRates;
    int sampleRate;
    int numRatesToTry;
    int lastRate;
    int ratesToTry[9] = {96000, 48000, 44100, 32000, 24000, 22050, 16000, 11025, 8000};
    int i;

    /* douglas:
     we have to do this querying in a slightly different order. apparently
     some sound cards will give you different info based on their settings. 
     e.g. a card might give you stereo at 22kHz but only mono at 44kHz.
     the correct order for OSS is: format, channels, sample rate
     
    */
    if ( (tempDevHandle = open(deviceName,O_WRONLY|O_NONBLOCK))  == -1 )
    {
        DBUG(("Pa_QueryDevice: could not open %s\n", deviceName ));
        return paHostError;
    }

    /*  Ask OSS what formats are supported by the hardware. */
    pad->pad_Info.nativeSampleFormats = 0;

    if (ioctl(tempDevHandle, SNDCTL_DSP_GETFMTS, &format) == -1)
    {
        ERR_RPT(("Pa_QueryDevice: could not get format info\n" ));
        goto error;
    }
    if( format & AFMT_U8 )     pad->pad_Info.nativeSampleFormats |= paUInt8;
    if( format & AFMT_S16_NE ) pad->pad_Info.nativeSampleFormats |= paInt16;

    /* Negotiate for the maximum number of channels for this device. PLB20010927
     * Consider up to 16 as the upper number of channels.
     * Variable numChannels should contain the actual upper limit after the call.
     * Thanks to John Lazzaro and Heiko Purnhagen for suggestions.
     */
    maxNumChannels = 0;
    for( numChannels = 1; numChannels <= 16; numChannels++ )
    {
        int temp = numChannels;
        DBUG(("Pa_QueryDevice: use SNDCTL_DSP_CHANNELS, numChannels = %d\n", numChannels ))
        if(ioctl(tempDevHandle, SNDCTL_DSP_CHANNELS, &temp) < 0 )
        {
            /* ioctl() failed so bail out if we already have stereo */
            if( numChannels > 2 ) break;
        }
        else
        {
            /* ioctl() worked but bail out if it does not support numChannels.
             * We don't want to leave gaps in the numChannels supported.
             */
            if( (numChannels > 2) && (temp != numChannels) ) break;
            DBUG(("Pa_QueryDevice: temp = %d\n", temp ))
            if( temp > maxNumChannels ) maxNumChannels = temp; /* Save maximum. */
        }
    }

    /* The above negotiation may fail for an old driver so try this older technique. */
    if( maxNumChannels < 1 )
    {
        int stereo = 1;
        if(ioctl(tempDevHandle, SNDCTL_DSP_STEREO, &stereo) < 0)
        {
            maxNumChannels = 1;
        }
        else
        {
            maxNumChannels = (stereo) ? 2 : 1;
        }
        DBUG(("Pa_QueryDevice: use SNDCTL_DSP_STEREO, maxNumChannels = %d\n", maxNumChannels ))
    }

    pad->pad_Info.maxOutputChannels = maxNumChannels;
    DBUG(("Pa_QueryDevice: maxNumChannels = %d\n", maxNumChannels))

    /* During channel negotiation, the last ioctl() may have failed. This can
     * also cause sample rate negotiation to fail. Hence the following, to return
     * to a supported number of channels. SG20011005 */
    {
        int temp = maxNumChannels;
        if( temp > 2 ) temp = 2; /* use most reasonable default value */
        ioctl(tempDevHandle, SNDCTL_DSP_CHANNELS, &temp);
    }

    /* FIXME - for now, assume maxInputChannels = maxOutputChannels.
     *    Eventually do separate queries for O_WRONLY and O_RDONLY
    */
    pad->pad_Info.maxInputChannels = pad->pad_Info.maxOutputChannels;

    DBUG(("Pa_QueryDevice: maxInputChannels = %d\n",
          pad->pad_Info.maxInputChannels))


    /* Determine available sample rates by trying each one and seeing result.
     * OSS often supports funky rates such as 44188 instead of 44100!
     */
    numSampleRates = 0;
    lastRate = 0;
    numRatesToTry = sizeof(ratesToTry)/sizeof(int);
    for (i = 0; i < numRatesToTry; i++)
    {
        sampleRate = ratesToTry[i];

        if (ioctl(tempDevHandle, SNDCTL_DSP_SPEED, &sampleRate) >= 0 ) /* PLB20010817 */
        {
            /* Use whatever rate OSS tells us. PLB20021018 */
            if (sampleRate != lastRate)
            {
                DBUG(("Pa_QueryDevice: adding sample rate: %d\n", sampleRate))
                pad->pad_SampleRates[numSampleRates] = (float)sampleRate;
                numSampleRates++;
                lastRate = sampleRate;
            }
            else
            {
                DBUG(("Pa_QueryDevice: dang - got sample rate %d again!\n", sampleRate))
            }
        }
    }

    DBUG(("Pa_QueryDevice: final numSampleRates = %d\n", numSampleRates))
    if (numSampleRates==0)   /* HP20010922 */
    {
        /* Desparate attempt to keep running even though no good rates found! */
        ERR_RPT(("Pa_QueryDevice: no supported sample rate (or SNDCTL_DSP_SPEED ioctl call failed). Force 44100 Hz\n" ));
        pad->pad_SampleRates[numSampleRates++] = 44100;
    }

    pad->pad_Info.numSampleRates = numSampleRates;
    pad->pad_Info.sampleRates = pad->pad_SampleRates; /* use pointer to embedded array */

    pad->pad_Info.name = deviceName;

    result = paNoError;

error:
    /* We MUST close the handle here or we won't be able to reopen it later!!!  */
    close(tempDevHandle);

    return result;
}

/*******************************************************************************************/
PaError Pa_SetupDeviceFormat( int devHandle, int numChannels, int sampleRate )
{
    PaError result = paNoError;
    int     tmp;

    /* Set format, channels, and rate in this order to keep OSS happy. */
    /* Set data format. FIXME - handle more native formats. */
    tmp = AFMT_S16_NE;
    if( ioctl(devHandle,SNDCTL_DSP_SETFMT,&tmp) == -1)
    {
        ERR_RPT(("Pa_SetupDeviceFormat: could not SNDCTL_DSP_SETFMT\n" ));
        return paHostError;
    }
    if( tmp != AFMT_S16_NE )
    {
        ERR_RPT(("Pa_SetupDeviceFormat: HW does not support AFMT_S16_NE\n" ));
        return paHostError;
    }


    /* Set number of channels. */
    tmp = numChannels;
    if (ioctl(devHandle, SNDCTL_DSP_CHANNELS, &numChannels) == -1)
    {
        ERR_RPT(("Pa_SetupDeviceFormat: could not SNDCTL_DSP_CHANNELS\n" ));
        return paHostError;
    }
    if( tmp != numChannels)
    {
        ERR_RPT(("Pa_SetupDeviceFormat: HW does not support %d channels\n", numChannels ));
        return paHostError;
    }

    /* Set playing frequency. */
    tmp = sampleRate;
    if( ioctl(devHandle,SNDCTL_DSP_SPEED,&tmp) == -1)
    {
        ERR_RPT(("Pa_SetupDeviceFormat: could not SNDCTL_DSP_SPEED\n" ));
        return paHostError;
    }
    else if( tmp != sampleRate )
    {
        int percentError = abs( (100 * (sampleRate - tmp)) / sampleRate );
        PRINT(("Pa_SetupDeviceFormat: warning - requested sample rate = %d Hz - closest = %d\n",
            sampleRate, tmp ));
        /* Allow sample rate within 10% off of requested rate. PLB20021018
        * Sometimes OSS uses a funky rate like 44188 instead of 44100.
        */
        if( percentError > 10 )
        {
            ERR_RPT(("Pa_SetupDeviceFormat: HW does not support %d Hz sample rate\n",sampleRate ));
           return paHostError;
        }
    }
    
    return result;
}

PaError Pa_SetupOutputDeviceFormat( int devHandle, int numChannels, int sampleRate )
{
  return Pa_SetupDeviceFormat(devHandle, numChannels, sampleRate);
}

PaError Pa_SetupInputDeviceFormat( int devHandle, int numChannels, int sampleRate )
{
  return Pa_SetupDeviceFormat(devHandle, numChannels, sampleRate);
}


/*******************************************************************************************
** Set number of fragments and size of fragments to achieve desired latency.
*/

static int CalcHigherLogTwo( int n )
{
    int log2 = 0;
    while( (1<<log2) < n ) log2++;
    return log2;
}

void Pa_SetLatency( int devHandle, int numBuffers, int framesPerBuffer, int channelsPerFrame  )
{
    int     tmp;
    int     bufferSize, powerOfTwo;

    /* Increase size of buffers and reduce number of buffers to reduce latency inside driver. */
    while( numBuffers > 8 )
    {
        numBuffers = (numBuffers + 1) >> 1;
        framesPerBuffer = framesPerBuffer << 1;
    }

    /* calculate size of buffers in bytes */
    bufferSize = framesPerBuffer * channelsPerFrame * sizeof(short); /* FIXME - other sizes? */

    /* Calculate next largest power of two */
    powerOfTwo = CalcHigherLogTwo( bufferSize );
    DBUG(("Pa_SetLatency: numBuffers = %d, framesPerBuffer = %d, powerOfTwo = %d\n",
          numBuffers, framesPerBuffer, powerOfTwo ));

    /* Encode info into a single int */
    tmp=(numBuffers<<16) + powerOfTwo;

    if(ioctl(devHandle,SNDCTL_DSP_SETFRAGMENT,&tmp) == -1)
    {
        ERR_RPT(("Pa_SetLatency: could not SNDCTL_DSP_SETFRAGMENT\n" ));
        /* Don't return an error. Best to just continue and hope for the best. */
        ERR_RPT(("Pa_SetLatency: numBuffers = %d, framesPerBuffer = %d, powerOfTwo = %d\n",
                 numBuffers, framesPerBuffer, powerOfTwo ));
    }
}

/***********************************************************************/
PaTimestamp Pa_StreamTime( PortAudioStream *stream )
{
    internalPortAudioStream *past = (internalPortAudioStream *) stream;
    PaHostSoundControl *pahsc;

    count_info    info;
    int           delta;

    if( past == NULL ) return paBadStreamPtr;
    
    pahsc = (PaHostSoundControl *) past->past_DeviceData;

    if( pahsc->pahsc_NativeOutputBuffer )
    {
       ioctl(pahsc->pahsc_OutputHandle, SNDCTL_DSP_GETOPTR, &info);
       delta = (info.bytes - pahsc->pahsc_LastPosPtr) & 0x000FFFFF;
       return (pahsc->pahsc_LastStreamBytes + delta) / (past->past_NumOutputChannels * sizeof(short));
    }
    else
    {
       ioctl(pahsc->pahsc_InputHandle, SNDCTL_DSP_GETIPTR, &info);
       delta = (info.bytes - pahsc->pahsc_LastPosPtr) & 0x000FFFFF;
       return (pahsc->pahsc_LastStreamBytes + delta) / (past->past_NumInputChannels * sizeof(short));
    }
}

void Pa_UpdateStreamTime(PaHostSoundControl *pahsc)
{
    count_info   info;
    int          delta;

  /* Update current stream time (using a double so that
     we don't wrap around like info.bytes does) */
  if( pahsc->pahsc_NativeOutputBuffer )
  {
    ioctl(pahsc->pahsc_OutputHandle, SNDCTL_DSP_GETOPTR, &info);
  }
  else
  {
    ioctl(pahsc->pahsc_InputHandle, SNDCTL_DSP_GETIPTR, &info);
  }
  delta = (info.bytes - pahsc->pahsc_LastPosPtr) & 0x000FFFFF;
  pahsc->pahsc_LastStreamBytes += delta;
  pahsc->pahsc_LastPosPtr = info.bytes;
}

PaError Pa_FlushStream(int devHandle)
{
  /* AS: This doesn't do anything under OSS; it was added for Solaris.*/
  devHandle = devHandle; /* unused */
  return paNoError;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精选午夜久久久乱码6080| 欧美日韩日本视频| 在线观看视频一区二区| 久久综合视频网| 亚洲一级不卡视频| 国产福利一区在线| 日韩精品一区二区三区视频| 亚洲欧美日韩国产一区二区三区| 久久99精品久久久久久动态图 | 成人免费视频视频| 欧美高清激情brazzers| 亚洲色图清纯唯美| 不卡视频一二三| 国产亚洲欧美日韩俺去了| 日本美女视频一区二区| 日本高清视频一区二区| 久久久国产午夜精品| 麻豆成人久久精品二区三区小说| 色狠狠综合天天综合综合| 中文字幕不卡在线| 国产一区二区福利视频| 精品免费日韩av| 美女在线视频一区| 日韩精品最新网址| 久久电影网站中文字幕| 欧美一区二区在线播放| 日韩黄色免费电影| 日韩午夜中文字幕| 日本va欧美va瓶| 欧美一区在线视频| 另类欧美日韩国产在线| 日韩片之四级片| 久久成人羞羞网站| 精品久久久久一区| 国产一区二区精品久久99 | 欧美日韩一区二区三区免费看| 国产精品视频免费看| 成人午夜又粗又硬又大| 国产欧美一区二区三区在线看蜜臀| 韩日精品视频一区| 欧美激情资源网| 成人免费视频免费观看| 国产精品久久久久久久久久免费看 | 国产宾馆实践打屁股91| 国产精品青草久久| 91天堂素人约啪| 亚洲一区二区偷拍精品| 欧美无砖专区一中文字| 图片区小说区区亚洲影院| 日韩免费高清电影| 国产·精品毛片| 亚洲黄网站在线观看| 欧美日韩免费观看一区三区| 蜜桃视频在线一区| 中文字幕一区二区三中文字幕| 色婷婷国产精品久久包臀| 日韩精品电影一区亚洲| 久久婷婷国产综合精品青草| www.性欧美| 天天做天天摸天天爽国产一区| 日韩免费在线观看| av动漫一区二区| 日韩福利视频导航| 国产精品伦一区| 91麻豆精品久久久久蜜臀| 久久99精品国产| 亚洲欧洲精品一区二区精品久久久| 欧美三级韩国三级日本三斤| 狠狠色丁香九九婷婷综合五月| 136国产福利精品导航| 91精品国产手机| 99久久精品国产网站| 免费看日韩精品| 亚洲精品成人少妇| 国产日本欧美一区二区| 欧美日本高清视频在线观看| 成人免费毛片嘿嘿连载视频| 午夜av区久久| 亚洲欧美日韩电影| 国产午夜精品久久久久久免费视| 欧美日韩国产首页在线观看| 国产成人精品影院| 久久电影网站中文字幕| 亚洲精品你懂的| 国产精品热久久久久夜色精品三区| 777色狠狠一区二区三区| 不卡av在线免费观看| 久久国产精品第一页| 亚洲第一主播视频| 亚洲嫩草精品久久| 国产精品欧美综合在线| 26uuu国产日韩综合| 欧美电影影音先锋| 色综合久久久久网| gogogo免费视频观看亚洲一| 国产在线不卡一区| 久久精品国产成人一区二区三区 | 欧美一区二区三区四区高清| 成人精品视频网站| 国产精品一级片在线观看| 天天影视涩香欲综合网| 亚洲乱码国产乱码精品精小说 | 捆绑调教一区二区三区| 日韩电影在线一区二区| 亚洲线精品一区二区三区| 亚洲色图一区二区三区| 中文字幕日韩av资源站| 国产精品美女一区二区| 久久久蜜桃精品| 久久精品网站免费观看| 国产午夜精品久久久久久免费视| 精品国产乱码久久久久久1区2区| 91精品国产麻豆国产自产在线 | 国产精品视频观看| 中文字幕一区日韩精品欧美| 国产精品久久久久9999吃药| 国产精品美女一区二区在线观看| 亚洲国产成人一区二区三区| 国产精品久久久久久一区二区三区| 欧美精彩视频一区二区三区| 久久精品视频免费| 中日韩免费视频中文字幕| 国产情人综合久久777777| 中文字幕av一区二区三区高| 国产精品免费久久| 亚洲欧美国产毛片在线| 一区二区高清在线| 肉色丝袜一区二区| 九九精品一区二区| 成人中文字幕电影| 色猫猫国产区一区二在线视频| 欧美日韩中文字幕一区二区| 欧美精品乱人伦久久久久久| 91精品国产免费| 欧美韩日一区二区三区| 亚洲精品综合在线| 日本欧美一区二区三区| 国产成人8x视频一区二区| 99热在这里有精品免费| 欧美日韩mp4| 久久综合成人精品亚洲另类欧美 | 肉色丝袜一区二区| 国产精品综合网| www.欧美日韩| 7777精品伊人久久久大香线蕉经典版下载 | 国产女人18毛片水真多成人如厕| 国产精品国产自产拍在线| 亚洲一区二区三区四区五区中文| 五月天婷婷综合| 国产高清不卡一区二区| 欧美中文字幕亚洲一区二区va在线| 日韩一区二区免费视频| 国产精品情趣视频| 视频精品一区二区| 不卡av电影在线播放| 91精品黄色片免费大全| 久久综合久久99| 亚洲一区二区在线视频| 国产精品原创巨作av| 欧美日韩一区二区三区不卡| 国产欧美日韩视频一区二区| 无码av中文一区二区三区桃花岛| 成人毛片视频在线观看| 欧美日韩高清一区二区三区| 久久久久久电影| 天涯成人国产亚洲精品一区av| aaa欧美大片| 2023国产精华国产精品| 亚洲国产精品嫩草影院| 国产精品一区二区久久不卡| 7777精品伊人久久久大香线蕉完整版| 国产精品美女久久久久久久久久久| 日本美女一区二区三区视频| 色综合中文综合网| 97国产精品videossex| 日韩欧美国产三级电影视频| 一区二区三区鲁丝不卡| 国产成人免费视频网站| 欧美一区二区福利在线| 亚洲午夜一区二区三区| 99久久精品费精品国产一区二区| 久久综合999| 看国产成人h片视频| 欧美剧情片在线观看| 五月天网站亚洲| 91蜜桃网址入口| 亚洲日本丝袜连裤袜办公室| 久久99精品久久久| 欧美一区二区三区在线| 亚洲成人av一区二区| 日本韩国欧美一区| 一区二区三区精密机械公司| 99re66热这里只有精品3直播 | 欧美高清视频www夜色资源网| 亚洲人吸女人奶水| 不卡影院免费观看| 国产精品素人一区二区| 岛国av在线一区| 国产精品天天看| 99久久99久久精品国产片果冻|