2014-01-31 3 views
1

나는 소리를 내기 위해 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 작품 실패 이유를 알아낼 수 없습니다.

그래서 :

  • 은 왜 실패 하는가?
  • 왜 잘못된 오류 코드가 발생합니까? (코드에서 andor 호기심이 몇 가지 있기는하지만.)
+0

오디오 출력 "Sortie intégr"이 이미 다른 응용 프로그램에서 사용하고 있는지 확인 했습니까? 그런 경우에는 PortAudio가 액세스 할 수 없다고 생각합니다. –

+0

@StephaneRolland 그것은 자유롭고'OpenDefaultStream'을 통해 선택된 것입니다. –

답변

1

나는 ++은 C를 사용하는 가정

for 루프가 outputDeviceInfo이 남아 해제를 한 후 eviceInfo->maxOutputChannels > 0 && deviceInfo->name == outputDevice을 만족하는 모든 PaDeviceInfo 발견하지 않은 경우 - 초기화되었습니다. 즉, channelConnect은 큰 음수 값을 포함하여 모든 값을 가질 수 있습니다. 그런 다음 Pa_OpenStream이 호출되지 않고 errorOpening 초기화되지 않은 상태로 남습니다. 에 피드를 입력하면 그 이유가 Invalid error code (value greater than zero)입니다.

+0

* 초기화되지 않은 변수는 맞지만'for' 루프가 장치를 찾아서 Pa_OpenStream에 장치를 제공하기 때문에 문제가 해결되지 않습니다 –

+0

사실, 당신은 옳습니다. 문제는 구조체의 부분 초기화에서 발생했습니다. –