Port Audio:How 解决PortAudio(Windows) 找不到默认设备的错误?
Port Audio:How to solve the error of finding default devices in PortAudio(Windows)?
我想运行一个生成和播放正弦波的PortAudio测试程序。为此,我包含了所有必需的头文件。事实上程序编译得很好但是当我 运行 它在控制台中显示 "No Default Device found" 。
所以,任何人都可以给我它的解决方案。
OS:Windows 8.1
编码Language: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.c
。 pa_devs
将为您提供 PortAudio 检测到的设备列表。如果列表不为空,您可以尝试手动将设备索引替换为 outputParameters.device
.
但是,如果没有可用的默认设备,那么我怀疑您会发现根本没有注册任何设备。在那种情况下,最可能的原因是没有编译主机 API。你没有说你是如何编译 PortAudio 的,但通常当你从源代码编译它时,你需要通过定义预处理器符号来指定要构建的主机 API,例如作为 PA_USE_WMME
或 PA_USE_WASAPI
(例如,对编译器使用 -D
标志)。这里有 supported Windows preprocessor defines 的完整列表。
文档中有 detailed build instructions 各种工具链。
我想运行一个生成和播放正弦波的PortAudio测试程序。为此,我包含了所有必需的头文件。事实上程序编译得很好但是当我 运行 它在控制台中显示 "No Default Device found" 。 所以,任何人都可以给我它的解决方案。
OS:Windows 8.1
编码Language: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.c
。 pa_devs
将为您提供 PortAudio 检测到的设备列表。如果列表不为空,您可以尝试手动将设备索引替换为 outputParameters.device
.
但是,如果没有可用的默认设备,那么我怀疑您会发现根本没有注册任何设备。在那种情况下,最可能的原因是没有编译主机 API。你没有说你是如何编译 PortAudio 的,但通常当你从源代码编译它时,你需要通过定义预处理器符号来指定要构建的主机 API,例如作为 PA_USE_WMME
或 PA_USE_WASAPI
(例如,对编译器使用 -D
标志)。这里有 supported Windows preprocessor defines 的完整列表。
文档中有 detailed build instructions 各种工具链。