Код:
ALerror = alGetError();
pDevice = alcOpenDevice(ui->comboBox->itemText(ui->comboBox->currentIndex()).toAscii());
if(pDevice)
{
pContext = alcCreateContext(pDevice, NULL);
if (pContext)
{
// this->showError(QString("Opened %1 Device").arg(alcGetString(pDevice, ALC_DEVICE_SPECIFIER)));
qDebug() << QString("Opened %1 Device").arg(alcGetString(pDevice, ALC_DEVICE_SPECIFIER));
}
else
{
alcCloseDevice(pDevice);
this->getSoundError();
this->showError(QString("Error open device"));
exit(-1);
}
}
else
{
this->showError(QString("Error open device"));
exit(-1);
}
alcMakeContextCurrent(pContext);
this->getSoundError();
alGenBuffers( 1, &uiBuffer );
this->getSoundError();
alGenSources(1, &sources);
this->getSoundError();
this->fillBuffer(Buffer, 1, ui->lineEdit->text().toInt(), Freq);
alBufferData(uiBuffer, AL_FORMAT_MONO16, Buffer, 1*Freq, Freq);
this->getSoundError();
// Attach Source to Buffer
alSourcei(sources, AL_BUFFER, uiBuffer);
this->getSoundError();
// Play Source
alSourcePlay(sources);
this->getSoundError();
do
{
qApp->processEvents();
// Get Source State
alGetSourcei(sources, AL_SOURCE_STATE, &iState);
//qDebug() << "play";
} while (iState == AL_PLAYING);
alSourceStop(sources);
alDeleteSources(1, &sources);
alDeleteBuffers(1, &uiBuffer);
this->getSoundError();
alcMakeContextCurrent(NULL);
alcDestroyContext(pContext);
alcCloseDevice(pDevice);
this->getSoundError();