mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 18:49:54 +00:00
1e41012ff3
git-svn-id: https://openmw.svn.sourceforge.net/svnroot/openmw/trunk@27 ea6a568a-9f4f-0410-981a-c910a81bb256
83 lines
2 KiB
D
83 lines
2 KiB
D
/*
|
|
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
Copyright (C) 2008 Nicolay Korslund
|
|
Email: < korslund@gmail.com >
|
|
WWW: http://openmw.snaptoad.com/
|
|
|
|
This file (audio.d) is part of the OpenMW package.
|
|
|
|
OpenMW is distributed as free software: you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License
|
|
version 3, as published by the Free Software Foundation.
|
|
|
|
This program is distributed in the hope that it will be useful, but
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
version 3 along with this program. If not, see
|
|
http://www.gnu.org/licenses/ .
|
|
|
|
*/
|
|
|
|
module sound.audio;
|
|
|
|
public import sound.sfx;
|
|
public import sound.music;
|
|
|
|
import sound.al;
|
|
import sound.alc;
|
|
|
|
import std.stdio;
|
|
import std.string;
|
|
|
|
class SoundException : Exception
|
|
{
|
|
this(char[] caller, char[] msg) { super(caller ~ " SoundException: " ~ msg); }
|
|
}
|
|
|
|
MusicManager jukebox;
|
|
MusicManager battleMusic;
|
|
|
|
ALCdevice *Device = null;
|
|
ALCcontext *Context = null;
|
|
|
|
void initializeSound()
|
|
{
|
|
Device = alcOpenDevice(null);
|
|
Context = alcCreateContext(Device, null);
|
|
|
|
if(!Device || !Context)
|
|
throw new SoundException("initializeSound()",
|
|
"Failed to initialize music device");
|
|
|
|
alcMakeContextCurrent(Context);
|
|
|
|
jukebox.initialize("Main");
|
|
battleMusic.initialize("Battle");
|
|
}
|
|
|
|
void shutdownSound()
|
|
{
|
|
jukebox.disableMusic();
|
|
battleMusic.disableMusic();
|
|
|
|
alcMakeContextCurrent(null);
|
|
if(Context) alcDestroyContext(Context);
|
|
Context = null;
|
|
if(Device) alcCloseDevice(Device);
|
|
Device = null;
|
|
}
|
|
|
|
bool checkALError(char[] what = "")
|
|
{
|
|
ALenum err = alGetError();
|
|
if(what.length) what = " while " ~ what;
|
|
if(err != AL_NO_ERROR)
|
|
writefln("WARNING: OpenAL error%s: (%x) %s", what, err,
|
|
toString(alGetString(err)));
|
|
|
|
|
|
return err != AL_NO_ERROR;
|
|
}
|