나는 소리를 내기 위해 portaudio
을 사용하고 있습니다. UI를 통해 출력을 선택할 수 있어야합니다.잘못된 오류 코드
PaError err = Pa_Initialize();
if(err != paNoError)
return false;
qDebug() <<"Port audio succeed initialization !";
int numDevices;
numDevices = Pa_GetDeviceCount();
if(numDevices <= 0)
{
qDebug() << "ERROR: Pa_CountDevices returned " << numDevices;
return false;
}
const PaDeviceInfo *deviceInfo;
bool isThereOutput = false;
int i = 0;
while(i < numDevices and !isThereOutput)
{
deviceInfo = Pa_GetDeviceInfo(i);
isThereOutput = (deviceInfo->maxOutputChannels > 0);
i++;
}
if(!isThereOutput)
{
qDebug() << "No output device";
return false;
}
PaError errorOpening;
if(outputDevice != "")
{
PaStreamParameters outputDeviceInfo;
int numDevices = Pa_GetDeviceCount();
const PaDeviceInfo *deviceInfo;
for(int i = 0; i<numDevices; i++)
{
deviceInfo = Pa_GetDeviceInfo(i);
if(deviceInfo->maxOutputChannels > 0 && deviceInfo->name == outputDevice)
{
outputDeviceInfo.device = i;
outputDeviceInfo.channelCount = 1;
outputDeviceInfo.sampleFormat = paInt8;
outputDeviceInfo.suggestedLatency = deviceInfo->defaultLowOutputLatency;
}
}
if(outputDeviceInfo.channelCount > 1)
{
errorOpening = Pa_OpenStream(&stream, NULL, &outputDeviceInfo, SAMPLE_RATE, FRAME_PER_BUFFER, paNoFlag, audioCallback, this);
}
}
if(outputDevice == "" or errorOpening != paNoError)
{
if(errorOpening != paNoError)
qDebug() << "Can't open selected device ("<< outputDevice <<"), switching to the default one. Error : " << Pa_GetErrorText(errorOpening);
errorOpening = Pa_OpenDefaultStream(&stream,
0, /* no input channels */
1, /* mono output */
paInt8, /* 8 bits output */
SAMPLE_RATE,
FRAME_PER_BUFFER, /* frames per buffer, i.e. the number
of sample frames that PortAudio will
request from the callback. Many apps
may want to use
paFramesPerBufferUnspecified, which
tells PortAudio to pick the best,
possibly changing, buffer size.*/
audioCallback, /* this is your callback function */
this); /*This is a pointer that will be passed to
your callback*/
}
if(errorOpening != paNoError)
return false;
if(Pa_StartStream(stream) != paNoError)
return false;
을 그리고 그것은 실패 : 나는 그런 식으로 관리
("출격 intégr")를 선택한 장치를 열 수 없습니다, 기본 하나의 전환. 오류 : 잘못된 오류 코드 (0보다 큰 값)
그러나 OpenStream
이상한 오류 코드와 마법처럼 Pa_OpenDefaultStream
작품 실패 이유를 알아낼 수 없습니다.
그래서 :
- 은 왜 실패 하는가?
- 왜 잘못된 오류 코드가 발생합니까? (코드에서
and
및or
호기심이 몇 가지 있기는하지만.)
오디오 출력 "Sortie intégr"이 이미 다른 응용 프로그램에서 사용하고 있는지 확인 했습니까? 그런 경우에는 PortAudio가 액세스 할 수 없다고 생각합니다. –
@StephaneRolland 그것은 자유롭고'OpenDefaultStream'을 통해 선택된 것입니다. –