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

📄 pa_jack.c

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 C
📖 第 1 页 / 共 3 页
字号:
       goto error;    }    jackHostApi->deviceInfoMemory = PaUtil_CreateAllocationGroup();    if( !jackHostApi->deviceInfoMemory )    {        result = paInsufficientMemory;        goto error;    }    jackHostApi->hostApiIndex = hostApiIndex;    *hostApi = &jackHostApi->commonHostApiRep;    (*hostApi)->info.structVersion = 1;    (*hostApi)->info.type = paInDevelopment;    (*hostApi)->info.name = "JACK Audio Connection Kit";    (*hostApi)->info.defaultInputDevice = paNoDevice;  /* set in BuildDeviceList() */    (*hostApi)->info.defaultOutputDevice = paNoDevice; /* set in BuildDeviceList() */    (*hostApi)->info.deviceCount = 0; /* set in BuildDeviceList() */    /* Build a device list by querying the JACK server */    result = BuildDeviceList( jackHostApi );    if( result != paNoError )       goto error;    /* Register functions */    (*hostApi)->Terminate = Terminate;    (*hostApi)->OpenStream = OpenStream;    (*hostApi)->IsFormatSupported = IsFormatSupported;    PaUtil_InitializeStreamInterface( &jackHostApi->callbackStreamInterface,                                      CloseStream, StartStream,                                      StopStream, AbortStream,                                      IsStreamStopped, IsStreamActive,                                      GetStreamTime, GetStreamCpuLoad,                                      PaUtil_DummyRead, PaUtil_DummyWrite,                                      PaUtil_DummyGetReadAvailable,                                      PaUtil_DummyGetWriteAvailable );    return result;error:    if( jackHostApi )    {        if( jackHostApi->deviceInfoMemory )        {            PaUtil_FreeAllAllocations( jackHostApi->deviceInfoMemory );            PaUtil_DestroyAllocationGroup( jackHostApi->deviceInfoMemory );        }        PaUtil_FreeMemory( jackHostApi );    }    return result;}static void Terminate( struct PaUtilHostApiRepresentation *hostApi ){    PaJackHostApiRepresentation *jackHostApi = (PaJackHostApiRepresentation*)hostApi;    jack_client_close( jackHostApi->jack_client );    if( jackHostApi->deviceInfoMemory )    {        PaUtil_FreeAllAllocations( jackHostApi->deviceInfoMemory );        PaUtil_DestroyAllocationGroup( jackHostApi->deviceInfoMemory );    }    PaUtil_FreeMemory( jackHostApi );}static PaError IsFormatSupported( struct PaUtilHostApiRepresentation *hostApi,                                  const PaStreamParameters *inputParameters,                                  const PaStreamParameters *outputParameters,                                  double sampleRate ){    int inputChannelCount, outputChannelCount;    PaSampleFormat inputSampleFormat, outputSampleFormat;    if( inputParameters )    {        inputChannelCount = inputParameters->channelCount;        inputSampleFormat = inputParameters->sampleFormat;        /* unless alternate device specification is supported, reject the use of            paUseHostApiSpecificDeviceSpecification */        if( inputParameters->device == paUseHostApiSpecificDeviceSpecification )            return paInvalidDevice;        /* check that input device can support inputChannelCount */        if( inputChannelCount > hostApi->deviceInfos[ inputParameters->device ]->maxInputChannels )            return paInvalidChannelCount;        /* validate inputStreamInfo */        if( inputParameters->hostApiSpecificStreamInfo )            return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */    }    else    {        inputChannelCount = 0;    }    if( outputParameters )    {        outputChannelCount = outputParameters->channelCount;        outputSampleFormat = outputParameters->sampleFormat;        /* unless alternate device specification is supported, reject the use of            paUseHostApiSpecificDeviceSpecification */        if( outputParameters->device == paUseHostApiSpecificDeviceSpecification )            return paInvalidDevice;        /* check that output device can support inputChannelCount */        if( outputChannelCount > hostApi->deviceInfos[ outputParameters->device ]->maxOutputChannels )            return paInvalidChannelCount;        /* validate outputStreamInfo */        if( outputParameters->hostApiSpecificStreamInfo )            return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */    }    else    {        outputChannelCount = 0;    }    /*        The following check is not necessary for JACK.                    - if a full duplex stream is requested, check that the combination                of input and output parameters is supported        Because the buffer adapter handles conversion between all standard        sample formats, the following checks are only required if paCustomFormat        is implemented, or under some other unusual conditions.                    - check that input device can support inputSampleFormat, or that                we have the capability to convert from outputSampleFormat to                a native format            - check that output device can support outputSampleFormat, or that                we have the capability to convert from outputSampleFormat to                a native format    */    /* check that the device supports sampleRate */    #define ABS(x) ( (x) > 0 ? (x) : -(x) )    if( ABS(sampleRate - hostApi->deviceInfos[0]->defaultSampleRate) > 1 )       return paInvalidSampleRate;#undef ABS    return paFormatIsSupported;}/* PaJackStream - a stream data structure specifically for this implementation */typedef struct PaJackStream{    PaUtilStreamRepresentation streamRepresentation;    PaUtilBufferProcessor bufferProcessor;    PaUtilCpuLoadMeasurer cpuLoadMeasurer;    /* our input and output ports */    jack_port_t **local_input_ports;    jack_port_t **local_output_ports;    /* the input and output ports of the client we are connecting to */    jack_port_t **remote_input_ports;    jack_port_t **remote_output_ports;    int num_incoming_connections;    int num_outgoing_connections;    jack_client_t *jack_client;    /* The stream is running if it's still producing samples.     * The stream is active if samples it produced are still being heard.     */    int is_running;    int is_active;    jack_nframes_t t0;    unsigned long total_frames_sent;    PaUtilAllocationGroup *stream_memory;}PaJackStream;static PaError OpenStream( struct PaUtilHostApiRepresentation *hostApi,                           PaStream** s,                           const PaStreamParameters *inputParameters,                           const PaStreamParameters *outputParameters,                           double sampleRate,                           unsigned long framesPerBuffer,                           PaStreamFlags streamFlags,                           PaStreamCallback *streamCallback,                           void *userData ){    PaError result = paNoError;    PaJackHostApiRepresentation *jackHostApi = (PaJackHostApiRepresentation*)hostApi;    PaJackStream *stream = 0;    char port_string[100];    char regex_pattern[100];    const char **jack_ports;    int jack_max_buffer_size = jack_get_buffer_size( jackHostApi->jack_client );    int i;    int inputChannelCount, outputChannelCount;    PaSampleFormat inputSampleFormat, outputSampleFormat;    /* the client has no say over the frames per callback */    if( framesPerBuffer == paFramesPerBufferUnspecified )        framesPerBuffer = jack_max_buffer_size;    /* Preliminary checks */    if( inputParameters )    {        inputChannelCount = inputParameters->channelCount;        inputSampleFormat = inputParameters->sampleFormat;        /* unless alternate device specification is supported, reject the use of            paUseHostApiSpecificDeviceSpecification */        if( inputParameters->device == paUseHostApiSpecificDeviceSpecification )            return paInvalidDevice;        /* check that input device can support inputChannelCount */        if( inputChannelCount > hostApi->deviceInfos[ inputParameters->device ]->maxInputChannels )            return paInvalidChannelCount;        /* validate inputStreamInfo */        if( inputParameters->hostApiSpecificStreamInfo )            return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */    }    else    {        inputChannelCount = 0;    }    if( outputParameters )    {        outputChannelCount = outputParameters->channelCount;        outputSampleFormat = outputParameters->sampleFormat;        /* unless alternate device specification is supported, reject the use of            paUseHostApiSpecificDeviceSpecification */        if( outputParameters->device == paUseHostApiSpecificDeviceSpecification )            return paInvalidDevice;        /* check that output device can support inputChannelCount */        if( outputChannelCount > hostApi->deviceInfos[ outputParameters->device ]->maxOutputChannels )            return paInvalidChannelCount;        /* validate outputStreamInfo */        if( outputParameters->hostApiSpecificStreamInfo )            return paIncompatibleHostApiSpecificStreamInfo; /* this implementation doesn't use custom stream info */    }    else    {        outputChannelCount = 0;    }    /* ... check that the sample rate exactly matches the ONE acceptable rate */#define ABS(x) ( (x) > 0 ? (x) : -(x) )    if( ABS(sampleRate - hostApi->deviceInfos[0]->defaultSampleRate) > 1 )       return paInvalidSampleRate;#undef ABS    /* Allocate memory for structuures */#define MALLOC(size) \    (PaUtil_GroupAllocateMemory( stream->stream_memory, (size) ))#define MEMVERIFY(ptr) \    if( (ptr) == NULL ) \    { \        result = paInsufficientMemory; \        goto error; \    }    stream = (PaJackStream*)PaUtil_AllocateMemory( sizeof(PaJackStream) );    MEMVERIFY( stream );    stream->stream_memory = PaUtil_CreateAllocationGroup();    stream->jack_client = jackHostApi->jack_client;    PaUtil_InitializeCpuLoadMeasurer( &stream->cpuLoadMeasurer, sampleRate );    stream->local_input_ports =        (jack_port_t**) MALLOC(sizeof(jack_port_t*) * inputChannelCount );    stream->local_output_ports =        (jack_port_t**) MALLOC( sizeof(jack_port_t*) * outputChannelCount );    stream->remote_output_ports =        (jack_port_t**) MALLOC( sizeof(jack_port_t*) * inputChannelCount );    stream->remote_input_ports =        (jack_port_t**) MALLOC( sizeof(jack_port_t*) * outputChannelCount );    MEMVERIFY( stream->local_input_ports );    MEMVERIFY( stream->local_output_ports );    MEMVERIFY( stream->remote_input_ports );    MEMVERIFY( stream->remote_output_ports );    stream->num_incoming_connections = inputChannelCount;    stream->num_outgoing_connections = outputChannelCount;    if( streamCallback )    {        PaUtil_InitializeStreamRepresentation( &stream->streamRepresentation,              &jackHostApi->callbackStreamInterface, streamCallback, userData );    }    else    {        /* we do not support blocking I/O */        return paBadIODeviceCombination;    }    /* create the JACK ports.  We cannot connect them until audio     * processing begins */    for( i = 0; i < inputChannelCount; i++ )    {        sprintf( port_string, "in_%d", i );        stream->local_input_ports[i] = jack_port_register(              jackHostApi->jack_client, port_string,

⌨️ 快捷键说明

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