⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pa_linux_asihpi.c

📁 一个开源的sip源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
            /* First add all input streams as devices */            for( j=0; j < inStreams; ++j )            {                PaAsiHpiDeviceInfo *hpiDevice = &hpiDeviceList[deviceIndex];                PaDeviceInfo *baseDeviceInfo = &hpiDevice->baseDeviceInfo;                char srcName[72];                char *deviceName;                memset( hpiDevice, 0, sizeof(PaAsiHpiDeviceInfo) );                /* Set implementation-specific device details */                hpiDevice->subSys = hpiHostApi->subSys;                hpiDevice->adapterIndex = i;                hpiDevice->adapterType = type;                hpiDevice->adapterVersion = version;                hpiDevice->adapterSerialNumber = serial;                hpiDevice->streamIndex = j;                hpiDevice->streamIsOutput = 0;                /* Set common PortAudio device stats */                baseDeviceInfo->structVersion = 2;                /* Make sure name string is owned by API info structure */                sprintf( srcName,                         "Adapter %d (%4X) - Input Stream %d", i+1, type, j+1 );                PA_UNLESS_( deviceName = (char *) PaUtil_GroupAllocateMemory(                                             hpiHostApi->allocations, strlen(srcName) + 1 ), paInsufficientMemory );                strcpy( deviceName, srcName );                baseDeviceInfo->name = deviceName;                baseDeviceInfo->hostApi = hpiHostApi->hostApiIndex;                baseDeviceInfo->maxInputChannels = HPI_MAX_CHANNELS;                baseDeviceInfo->maxOutputChannels = 0;                /* Default latency values for interactive performance */                baseDeviceInfo->defaultLowInputLatency = 0.01;                baseDeviceInfo->defaultLowOutputLatency = -1.0;                /* Default latency values for robust non-interactive applications (eg. playing sound files) */                baseDeviceInfo->defaultHighInputLatency = 0.2;                baseDeviceInfo->defaultHighOutputLatency = -1.0;                /* HPI interface can actually handle any sampling rate to 1 Hz accuracy,                * so this default is as good as any */                baseDeviceInfo->defaultSampleRate = 44100;                /* Store device in global PortAudio list */                hostApi->deviceInfos[deviceIndex++] = (PaDeviceInfo *) hpiDevice;            }            /* Now add all output streams as devices (I know, the repetition is painful) */            for( j=0; j < outStreams; ++j )            {                PaAsiHpiDeviceInfo *hpiDevice = &hpiDeviceList[deviceIndex];                PaDeviceInfo *baseDeviceInfo = &hpiDevice->baseDeviceInfo;                char srcName[72];                char *deviceName;                memset( hpiDevice, 0, sizeof(PaAsiHpiDeviceInfo) );                /* Set implementation-specific device details */                hpiDevice->subSys = hpiHostApi->subSys;                hpiDevice->adapterIndex = i;                hpiDevice->adapterType = type;                hpiDevice->adapterVersion = version;                hpiDevice->adapterSerialNumber = serial;                hpiDevice->streamIndex = j;                hpiDevice->streamIsOutput = 1;                /* Set common PortAudio device stats */                baseDeviceInfo->structVersion = 2;                /* Make sure name string is owned by API info structure */                sprintf( srcName,                         "Adapter %d (%4X) - Output Stream %d", i+1, type, j+1 );                PA_UNLESS_( deviceName = (char *) PaUtil_GroupAllocateMemory(                                             hpiHostApi->allocations, strlen(srcName) + 1 ), paInsufficientMemory );                strcpy( deviceName, srcName );                baseDeviceInfo->name = deviceName;                baseDeviceInfo->hostApi = hpiHostApi->hostApiIndex;                baseDeviceInfo->maxInputChannels = 0;                baseDeviceInfo->maxOutputChannels = HPI_MAX_CHANNELS;                /* Default latency values for interactive performance. */                baseDeviceInfo->defaultLowInputLatency = -1.0;                baseDeviceInfo->defaultLowOutputLatency = 0.01;                /* Default latency values for robust non-interactive applications (eg. playing sound files). */                baseDeviceInfo->defaultHighInputLatency = -1.0;                baseDeviceInfo->defaultHighOutputLatency = 0.2;                /* HPI interface can actually handle any sampling rate to 1 Hz accuracy,                * so this default is as good as any */                baseDeviceInfo->defaultSampleRate = 44100;                /* Store device in global PortAudio list */                hostApi->deviceInfos[deviceIndex++] = (PaDeviceInfo *) hpiDevice;            }        }    }    /* Finally acknowledge checked devices */    baseApiInfo->deviceCount = deviceIndex;error:    return result;}/** Initialize host API implementation. This is the only function exported beyond this file. It is called by PortAudio to initialize the host API. It stores API info, finds and registers all devices, and sets up callback and blocking interfaces.  @param hostApi Pointer to host API struct  @param hostApiIndex Index of current (HPI) host API  @return PortAudio error code */PaError PaAsiHpi_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex hostApiIndex ){    PaError result = paNoError;    PaAsiHpiHostApiRepresentation *hpiHostApi = NULL;    PaHostApiInfo *baseApiInfo;    /* Allocate host API structure */    PA_UNLESS_( hpiHostApi = (PaAsiHpiHostApiRepresentation*) PaUtil_AllocateMemory(                                 sizeof(PaAsiHpiHostApiRepresentation) ), paInsufficientMemory );    PA_UNLESS_( hpiHostApi->allocations = PaUtil_CreateAllocationGroup(), paInsufficientMemory );    hpiHostApi->hostApiIndex = hostApiIndex;    hpiHostApi->subSys = NULL;    /* Try to initialize HPI subsystem */    if( ( hpiHostApi->subSys = HPI_SubSysCreate() ) == NULL)    {        /* the V19 development docs say that if an implementation         * detects that it cannot be used, it should return a NULL         * interface and paNoError */        PA_DEBUG(( "Could not open HPI interface\n" ));        result = paNoError;        *hostApi = NULL;        goto error;    }    else    {        HW32 hpiVersion;        PA_ASIHPI_UNLESS_( HPI_SubSysGetVersion( hpiHostApi->subSys, &hpiVersion ), paUnanticipatedHostError );        PA_DEBUG(( "HPI interface v%d.%02d\n",                   hpiVersion >> 8, 10*((hpiVersion & 0xF0) >> 4) + (hpiVersion & 0x0F) ));    }    *hostApi = &hpiHostApi->baseHostApiRep;    baseApiInfo = &((*hostApi)->info);    /* Fill in common API details */    baseApiInfo->structVersion = 1;    baseApiInfo->type = paAudioScienceHPI;    baseApiInfo->name = "AudioScience HPI";    baseApiInfo->deviceCount = 0;    baseApiInfo->defaultInputDevice = paNoDevice;    baseApiInfo->defaultOutputDevice = paNoDevice;    PA_ENSURE_( PaAsiHpi_BuildDeviceList( hpiHostApi ) );    (*hostApi)->Terminate = Terminate;    (*hostApi)->OpenStream = OpenStream;    (*hostApi)->IsFormatSupported = IsFormatSupported;    PaUtil_InitializeStreamInterface( &hpiHostApi->callbackStreamInterface, CloseStream, StartStream,                                      StopStream, AbortStream, IsStreamStopped, IsStreamActive,                                      GetStreamTime, GetStreamCpuLoad,                                      PaUtil_DummyRead, PaUtil_DummyWrite,                                      PaUtil_DummyGetReadAvailable, PaUtil_DummyGetWriteAvailable );    PaUtil_InitializeStreamInterface( &hpiHostApi->blockingStreamInterface, CloseStream, StartStream,                                      StopStream, AbortStream, IsStreamStopped, IsStreamActive,                                      GetStreamTime, PaUtil_DummyGetCpuLoad,                                      ReadStream, WriteStream, GetStreamReadAvailable, GetStreamWriteAvailable );    /* Store identity of main thread */    PA_ENSURE_( PaUnixThreading_Initialize() );    return result;error:    /* Clean up memory */    Terminate( (PaUtilHostApiRepresentation *)hpiHostApi );    return result;}/** Terminate host API implementation. This closes all HPI adapters and frees the HPI subsystem. It also frees the host API struct memory. It should be called once for every PaAsiHpi_Initialize call.  @param Pointer to host API struct */static void Terminate( struct PaUtilHostApiRepresentation *hostApi ){    PaAsiHpiHostApiRepresentation *hpiHostApi = (PaAsiHpiHostApiRepresentation*)hostApi;    int i;    PaError result = paNoError;    if( hpiHostApi )    {        /* Get rid of HPI-specific structures */        if( hpiHostApi->subSys )        {            HW16 lastAdapterIndex = HPI_MAX_ADAPTERS;            /* Iterate through device list and close adapters */            for( i=0; i < hostApi->info.deviceCount; ++i )            {                PaAsiHpiDeviceInfo *hpiDevice = (PaAsiHpiDeviceInfo *) hostApi->deviceInfos[ i ];                /* Close adapter only if it differs from previous one */                if( hpiDevice->adapterIndex != lastAdapterIndex )                {                    /* Ignore errors (report only during debugging) */                    PA_ASIHPI_UNLESS_( HPI_AdapterClose( hpiHostApi->subSys,                                                         hpiDevice->adapterIndex ), paNoError );                    lastAdapterIndex = hpiDevice->adapterIndex;                }            }            /* Finally dismantle HPI subsystem */            HPI_SubSysFree( hpiHostApi->subSys );        }        if( hpiHostApi->allocations )        {            PaUtil_FreeAllAllocations( hpiHostApi->allocations );            PaUtil_DestroyAllocationGroup( hpiHostApi->allocations );        }        PaUtil_FreeMemory( hpiHostApi );    }error:    return;}/** Converts PortAudio sample format to equivalent HPI format.  @param paFormat PortAudio sample format  @return HPI sample format */static HW16 PaAsiHpi_PaToHpiFormat( PaSampleFormat paFormat ){    /* Ignore interleaving flag */    switch( paFormat & ~paNonInterleaved )    {    case paFloat32:        return HPI_FORMAT_PCM32_FLOAT;    case paInt32:        return HPI_FORMAT_PCM32_SIGNED;    case paInt24:        return HPI_FORMAT_PCM24_SIGNED;    case paInt16:        return HPI_FORMAT_PCM16_SIGNED;    case paUInt8:        return HPI_FORMAT_PCM8_UNSIGNED;        /* Default is 16-bit signed */    case paInt8:    default:        return HPI_FORMAT_PCM16_SIGNED;    }}/** Converts HPI sample format to equivalent PortAudio format.  @param paFormat HPI sample format  @return PortAudio sample format */static PaSampleFormat PaAsiHpi_HpiToPaFormat( HW16 hpiFormat ){    switch( hpiFormat )    {    case HPI_FORMAT_PCM32_FLOAT:        return paFloat32;    case HPI_FORMAT_PCM32_SIGNED:        return paInt32;    case HPI_FORMAT_PCM24_SIGNED:        return paInt24;    case HPI_FORMAT_PCM16_SIGNED:        return paInt16;    case HPI_FORMAT_PCM8_UNSIGNED:        return paUInt8;        /* Default is custom format (e.g. for HPI MP3 format) */    default:        return paCustomFormat;    }}/** Creates HPI format struct based on PortAudio parameters. This also does some checks to see whether the desired format is valid, and whether  the device allows it. This only checks the format of one half (input or output) of the PortAudio stream.  @param hostApi Pointer to host API struct  @param parameters Pointer to stream parameter struct  @param sampleRate Desired sample rate  @param hpiDevice Pointer to HPI device struct  @param hpiFormat Resulting HPI format returned here   @return PortAudio error code (typically indicating a problem with stream format) */static PaError PaAsiHpi_CreateFormat( struct PaUtilHostApiRepresentation *hostApi,                                      const PaStreamParameters *parameters, double sampleRate,                                      PaAsiHpiDeviceInfo **hpiDevice, HPI_FORMAT *hpiFormat ){    int maxChannelCount = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -