Exemplo n.º 1
0
void UOpenALAudioSubsystem::RegisterSound( USound* Sound )
{
	guard(UOpenALAudioSubsystem::RegisterSound);

	checkSlow(Sound);
	if( !Sound->Handle )
	{
		// Set the handle to avoid reentrance.
		Sound->Handle = (void*)-1;

		// Load the data.
		Sound->Data.Load();
		debugf( NAME_DevSound, TEXT("Register sound: %s (%i)"), Sound->GetPathName(), Sound->Data.Num() );
		check(Sound->Data.Num()>0);

		// Flush errors.
		alGetError();

		// Create the buffer.
		FAudioBuffer *Sample = new FAudioBuffer;
		Sample->Id = alureCreateBufferFromMemory( &Sound->Data(0), Sound->Data.Num() );
		if( Sample->Id == AL_NONE )
			appErrorf(
				TEXT("Couldn't create buffer for sound '%s': %s"),
				Sound->GetPathName(), alureGetErrorString()
			);
		Sound->Handle = Sample;

		// Unload the data.
		Sound->Data.Unload();
	}

	unguard;
}
Exemplo n.º 2
0
bool NSoundData::Load(std::string FileName)
{
    std::stringstream Message;
    ALenum Error = alGetError(); //Ensure all errors are cleared before making alure load the sound file, else it won't load.
    while (Error != AL_NO_ERROR)
    {
        switch(Error)
        {
            case AL_INVALID_NAME:
            {
                Message << "Invalid name parameter";
                break;
            }
            case AL_INVALID_ENUM:
            {
                Message << "Invalid parameter";
                break;
            }
            case AL_INVALID_VALUE:
            {
                Message << "Invalid enum parameter value";
                break;
            }
            case AL_INVALID_OPERATION:
            {
                Message << "Illegal call";
                break;
            }
            case AL_OUT_OF_MEMORY:
            {
                Message << "Unable to allocate memory";
                break;
            }
            default:
            {
                Message << "Unkown error";
                break;
            }
        }
        Error = alGetError();
    }
    GetGame()->GetLog()->Send("OPENAL",1,Message.str());
    NReadFile File = GetGame()->GetFileSystem()->GetReadFile(FileName);
    if (!File.Good())
    {
        GetGame()->GetLog()->Send("ALURE",1,"Failed to open " + FileName + " as a sound file, it doesn't exist!");
        return 1;
    }
    unsigned char* Data = new unsigned char[File.Size()];
    File.Read(Data,File.Size());
    ID = alureCreateBufferFromMemory(Data,File.Size());
    delete[] Data;
    if (ID == AL_NONE)
    {
        GetGame()->GetLog()->Send("ALURE",1,"Failed to open " + FileName + " as a sound file for reason: " + alureGetErrorString() + "!");
        return 1;
    }
    return 0;
}
Exemplo n.º 3
0
static ALuint GetSound(const std::string& name)
{
	BufferMap::iterator iter = sounds.find(name);
	if (iter != sounds.end())
		return iter->second;
	size_t length;
	ALubyte* data = GetSoundData("Sounds/" + name, length);
	ALuint buf = alureCreateBufferFromMemory(data, length);
	free(data);
	sounds.insert(std::make_pair(name, buf));
	return buf;
}
Exemplo n.º 4
0
int is::SoundBuffer::load() {
    is::File::Read file( m_dir );
    unsigned char* data = new unsigned char[ file.size() ];
    file.read( data, file.size() );
    m_id = alureCreateBufferFromMemory( data, file.size() );
    delete[] data;
    if ( m_id == AL_NONE ) {
        os->printf( "ERR Alure failed to open file % as a sound file!\n", m_dir );
        audio->checkErrorSimple();
        return 1;
    }
    m_loaded = true;
    return 0;
}
Exemplo n.º 5
0
static ALuint GetSound(const std::string& name)
{
	BufferMap::iterator iter = sounds.find(name);
	if (iter != sounds.end())
		return iter->second;
	size_t length;
	ALubyte* data = GetSoundData("Sounds/" + name, length);
	ALuint buf = alureCreateBufferFromMemory(data, length);
	free(data);
	sounds.insert(std::make_pair(name, buf));
#ifndef NDEBUG
    const ALchar* err = alureGetErrorString();
    if (strcmp(err, "No error"))
    {
        LOG("Sound", LOG_ERROR, "GetSound: %s", err);
        exit(1);
    }
#endif
	return buf;
}
Exemplo n.º 6
0
void Sound::run() {
    QFile audio_file(mResourcePath);
    if(audio_file.open(QIODevice::ReadOnly)) {
        QByteArray audio_data = audio_file.readAll();
        audio_file.close();

        ALuint src, buf;

        buf = alureCreateBufferFromMemory((const unsigned char*)audio_data.constData(), audio_data.size());

        alGenSources(1, &src);
        if(alGetError() != AL_NO_ERROR) {
            qDebug() << "Failed to create OpenAL source!";
        }

        if(!buf) {
            qDebug() << "Could not load sound: " << alureGetErrorString();
            alDeleteSources(1, &src);
        }

        alSourcei(src, AL_BUFFER, buf);
        alSourcef(src, AL_GAIN, 0.8f * mVolume);
        if(alurePlaySource(src, eos_callback, this) == AL_FALSE) {
            qDebug() << "Failed to start source!";
            alDeleteSources(1, &src);
            alDeleteBuffers(1, &buf);
        }

        while(!mIsDone) {
            alureSleep(0.125);
            alureUpdate();
        }

        alDeleteSources(1, &src);
        alDeleteBuffers(1, &buf);
    }
}