Я использую portaudio
для воспроизведения звука. Я хочу иметь возможность выбирать выход через пользовательский интерфейс. Мне удалось это так:Неверный код ошибки
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;
И это не удается:
Невозможно открыть выбранное устройство ("вылазку встр"), переход по умолчанию. Ошибка: недопустимый код ошибки (значение больше нуля)
Но я не могу понять, почему OpenStream
терпит неудачу со странным кодом ошибки и Pa_OpenDefaultStream
работает как шарм.
Итак:
- Почему это не удастся?
- Зачем он ошибается?
Вы проверили, если ваш аудиовыход «Sortie intégr» уже используется другим приложением? В таком случае я думаю, что PortAudio не смог бы получить доступ к нему. –
@StephaneRolland Это бесплатно, и он выбирается после 'OpenDefaultStream' –