gpt4 book ai didi

c - 端口音频 :How to solve the error of finding default devices in PortAudio(Windows)?

转载 作者:太空宇宙 更新时间:2023-11-04 07:02:52 26 4
gpt4 key购买 nike

我想运行一个生成和播放正弦波的 PortAudio 测试程序。为此,我包含了所有必需的头文件。事实上,该程序编译得很好,但是当我运行它时,它在控制台中显示“未找到默认设备”。所以,任何人都可以给我它的解决方案。

操作系统:Windows 8.1

编码语言:C

程序如下:-

typedef struct
{
float sine[TABLE_SIZE];
int left_phase;
int right_phase;
char message[20];
}
paTestData;

static int patestCallback(...)//Callback Function
{....
}

static void StreamFinished( void* userData )
{
paTestData *data = (paTestData *) userData;
printf( "Stream Completed: %s\n", data->message );
}


int main(void)//main function
{
PaStreamParameters outputParameters;
PaStream *stream;
PaError err;
paTestData data;

int i;

printf("PortAudio Test: output sine wave. SR = %d, BufSize = %d\n", SAMPLE_RATE, FRAMES_PER_BUFFER);

/* initialise sinusoidal wavetable */

for( i=0; i<TABLE_SIZE; i++ )
{
data.sine[i] = (float) sin( ((double)i/(double)TABLE_SIZE) * M_PI * 2. );
}

data.left_phase = data.right_phase = 0;

err = Pa_Initialize();

if( err != paNoError )
{
printf("Error in Initialize:-",err);
goto error;
}

outputParameters.device = Pa_GetDefaultOutputDevice(); /* default output device */

if (outputParameters.device == paNoDevice)
{
fprintf(stderr,"Error: No default output device.\n");
goto error;
}

outputParameters.channelCount = 2; /* stereo output */
outputParameters.sampleFormat = paFloat32; /* 32 bit floating point output */
outputParameters.suggestedLatency = Pa_GetDeviceInfo( outputParameters.device )->defaultLowOutputLatency;
outputParameters.hostApiSpecificStreamInfo = NULL;

err = Pa_OpenStream
(
&stream,
NULL, /* no input */
&outputParameters,
SAMPLE_RATE,
FRAMES_PER_BUFFER,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
patestCallback,
&data
);

if( err != paNoError )
goto error;

sprintf( data.message, "No Message" );
err = Pa_SetStreamFinishedCallback( stream, &StreamFinished );

if( err != paNoError )
goto error;

err = Pa_StartStream( stream );

if( err != paNoError )
goto error;

printf("Play for %d seconds.\n", NUM_SECONDS );
Pa_Sleep( NUM_SECONDS * 1000 );

err = Pa_StopStream( stream );

if( err != paNoError )
goto error;

err = Pa_CloseStream( stream );

if( err != paNoError )
goto error;

Pa_Terminate();
printf("Test finished.\n");

return err;

error:
Pa_Terminate();

fprintf( stderr, "An error occured while using the portaudio stream\n" );
fprintf( stderr, "Error number: %d\n", err );
fprintf( stderr, "Error message: %s\n", Pa_GetErrorText( err ) );

return err;
}

在编译和运行后,我在控制台中得到以下输出:-

PortAudio Test: output sine wave. SR = 44100, BufSize = 64
Error: No default output device.
An error occured while using the portaudio stream
Error number: 0
Error message: Success

Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.

谁能解决这个问题。

最佳答案

第一步,检查 PortAudio 是否检测到任何设备。您可以通过打印调用 Pa_GetDeviceCount() 的结果来执行此操作,或者您可以编译并运行 examples/pa_devs.cpa_devs 将为您提供 PortAudio 检测到的设备列表。如果列表不为空,您可以尝试手动将设备索引替换为 outputParameters.device

但是,如果没有可用的默认设备,那么我怀疑您会发现根本没有注册任何设备。在那种情况下,最可能的原因是没有编译主机 API。你没有说你是如何编译 PortAudio 的,但通常当你从源代码编译它时,你需要通过定义预处理器符号来指定要构建的主机 API,例如作为 PA_USE_WMMEPA_USE_WASAPI(例如,对编译器使用 -D 标志)。有一个完整的列表 supported Windows preprocessor defines在这里。

detailed build instructions对于文档中的各种工具链。

关于c - 端口音频 :How to solve the error of finding default devices in PortAudio(Windows)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35967529/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com