Added CD Audio support for OpenAL.

Updated Scons & Makefiles to cope
This commit is contained in:
Kester Maddock 2004-04-02 13:15:18 +00:00
parent 51830fa0e2
commit 2ccb9cf785
8 changed files with 339 additions and 10 deletions

@ -42,7 +42,7 @@ DIRS += dummy
ifneq ($(NAN_NO_OPENAL),true)
ifeq ($(OS),windows)
DIRS += fmod
DIRS += openal
DIRS += openal sdl
endif
#ifeq ($(OS),darwin)
# DIRS += fmod
@ -52,7 +52,7 @@ ifneq ($(NAN_NO_OPENAL),true)
endif
ifeq ($(OS),$(findstring $(OS), "linux"))
ifeq ($(CPU),i386)
DIRS += openal
DIRS += openal sdl
endif
endif
else

@ -24,12 +24,15 @@ soundsys_env.Append (CPPPATH = ['.',
'../moto/include',
'../string',
'dummy',
'openal'])
'openal',
'sdl'])
if user_options_dict['USE_OPENAL'] == 1:
source_files += ['openal/SND_OpenALDevice.cpp',
'openal/pthread_cancel.cpp']
'openal/pthread_cancel.cpp',
'sdl/SND_SDLCDDevice.cpp']
soundsys_env.Append (CPPPATH=user_options_dict['OPENAL_INCLUDE'])
soundsys_env.Append (CPPPATH=user_options_dict['SDL_INCLUDE'])
if user_options_dict['USE_FMOD'] == 1:
source_files += ['fmod/SND_FmodDevice.cpp']

@ -44,3 +44,4 @@ CPPFLAGS += -I$(NAN_MOTO)/include
CPPFLAGS += -I../intern
CPPFLAGS += -I..
CPPFLAGS += -I.
CPPFLAGS += -I../sdl

@ -40,6 +40,7 @@
#endif //WIN32
#include "SND_OpenALDevice.h"
#include "SND_SDLCDDevice.h"
#include "SoundDefines.h"
#include "SND_Utils.h"
@ -275,9 +276,16 @@ SND_OpenALDevice::SND_OpenALDevice()
{
m_wavecache = new SND_WaveCache();
}
m_cdrom = new SND_SDLCDDevice();
}
void SND_OpenALDevice::UseCD(void) const
{
// only fmod has CD support, so only create it here
SND_CDObject::CreateSystem();
}
void SND_OpenALDevice::MakeCurrent() const
{
@ -299,6 +307,18 @@ SND_OpenALDevice::~SND_OpenALDevice()
if (m_sourcesinitialized)
alDeleteSources(NUM_SOURCES, m_sources);
}
// let's see if we used the cd. if not, just leave it alone
SND_CDObject* pCD = SND_CDObject::Instance();
if (pCD)
{
this->StopCD();
SND_CDObject::DisposeSystem();
}
if (m_cdrom)
delete m_cdrom;
}
@ -435,6 +455,8 @@ void SND_OpenALDevice::SetListenerRollOffFactor(MT_Scalar rollofffactor) const
void SND_OpenALDevice::NextFrame() const
{
// CD
m_cdrom->NextFrame();
// not needed by openal
}
@ -596,6 +618,11 @@ void SND_OpenALDevice::SetObjectLoop(int id, unsigned int loopmode) const
alSourcei (m_sources[id], AL_LOOPING, AL_TRUE);
}
void SND_OpenALDevice::SetObjectLoopPoints(int id, unsigned int loopstart, unsigned int loopend) const
{
}
void SND_OpenALDevice::SetObjectMinGain(int id, MT_Scalar mingain) const
@ -660,3 +687,34 @@ void SND_OpenALDevice::SetObjectTransform(int id,
#endif
}
void SND_OpenALDevice::PlayCD(int track) const
{
m_cdrom->PlayCD(track);
}
void SND_OpenALDevice::PauseCD(bool pause) const
{
m_cdrom->PauseCD(pause);
}
void SND_OpenALDevice::StopCD() const
{
SND_CDObject* pCD = SND_CDObject::Instance();
if (pCD && pCD->GetUsed())
{
m_cdrom->StopCD();
}
}
void SND_OpenALDevice::SetCDPlaymode(int playmode) const
{
m_cdrom->SetCDPlaymode(playmode);
}
void SND_OpenALDevice::SetCDGain(MT_Scalar gain) const
{
m_cdrom->SetCDGain(gain);
}

@ -35,6 +35,8 @@
#include "SND_AudioDevice.h"
#include "SoundDefines.h"
typedef struct SDL_CD;
class SND_OpenALDevice : public SND_AudioDevice
{
public:
@ -54,6 +56,7 @@ public:
void MakeCurrent() const;
void NextFrame() const;
void UseCD() const;
void SetObjectBuffer(int id, unsigned int buffer);
@ -64,7 +67,7 @@ public:
void PauseObject(int id) const;
void SetObjectLoop(int id, unsigned int loopmode) const;
void SetObjectLoopPoints(int id, unsigned int loopstart, unsigned int loopend) const {};
void SetObjectLoopPoints(int id, unsigned int loopstart, unsigned int loopend) const;
void SetObjectPitch(int id, MT_Scalar pitch) const;
void SetObjectGain(int id, MT_Scalar gain) const;
void SetObjectMinGain(int id, MT_Scalar mingain) const;
@ -80,11 +83,11 @@ public:
const MT_Scalar& rollofffactor) const;
void ObjectIs2D(int id) const;
void PlayCD(int track) const {};
void PauseCD(bool pause) const {};
void StopCD() const {};
void SetCDPlaymode(int playmode) const {};
void SetCDGain(MT_Scalar gain) const {};
void PlayCD(int track) const;
void PauseCD(bool pause) const;
void StopCD() const;
void SetCDPlaymode(int playmode) const;
void SetCDGain(MT_Scalar gain) const;
void StartUsingDSP() {};
float* GetSpectrum() { return NULL; }
@ -97,6 +100,8 @@ private:
unsigned int m_sources[NUM_SOURCES];
bool m_buffersinitialized;
bool m_sourcesinitialized;
class SND_SDLCDDevice* m_cdrom;
};
#endif //SND_OPENALDEVICE

@ -0,0 +1,46 @@
#
# $Id$
#
# ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. The Blender
# Foundation also sells licenses for use in proprietary software under
# the Blender License. See http://www.blender.org/BL/ for information
# about this.
#
# 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
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
# All rights reserved.
#
# The Original Code is: all of this file.
#
# Contributor(s): none yet.
#
# ***** END GPL/BL DUAL LICENSE BLOCK *****
#
#
LIBNAME = SDLSoundSystem
DIR = $(OCGDIR)/intern/$(LIBNAME)
include nan_compile.mk
CCFLAGS += $(LEVEL_1_CPP_WARNINGS)
CPPFLAGS += $(NAN_SDLCFLAGS)
CPPFLAGS += -I$(NAN_STRING)/include
CPPFLAGS += -I$(NAN_MOTO)/include
CPPFLAGS += -I../intern
CPPFLAGS += -I..
CPPFLAGS += -I.

@ -0,0 +1,155 @@
/*
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
* SND_SDLCDDevice
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#ifdef WIN32
#pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
#endif //WIN32
#include "MT_Scalar.h"
#include "SND_SDLCDDevice.h"
#include "SoundDefines.h"
#include <SDL.h>
SND_SDLCDDevice::SND_SDLCDDevice() :
m_cdrom(NULL),
m_cdplaying(false),
m_cdtrack(0),
m_cdplaymode(SND_CD_TRACK),
m_frame(0)
{
init();
}
void SND_SDLCDDevice::init()
{
if (SDL_InitSubSystem(SDL_INIT_CDROM))
{
fprintf(stderr, "Error initializing CDROM\n");
return;
}
/* Check for CD drives */
if(!SDL_CDNumDrives())
{
/* None found */
fprintf(stderr, "No CDROM devices available\n");
return;
}
/* Open the default drive */
m_cdrom = SDL_CDOpen(0);
/* Did if open? Check if cdrom is NULL */
if(!m_cdrom)
{
fprintf(stderr, "Couldn't open drive: %s", SDL_GetError());
return;
}
}
SND_SDLCDDevice::~SND_SDLCDDevice()
{
StopCD();
SDL_CDClose(m_cdrom);
}
void SND_SDLCDDevice::NextFrame()
{
m_frame++;
m_frame &= 127;
if (!m_frame && m_cdrom && m_cdplaying && SDL_CDStatus(m_cdrom) == CD_STOPPED)
{
switch (m_cdplaymode)
{
case SND_CD_ALL:
if (m_cdtrack < m_cdrom->numtracks)
PlayCD(m_cdtrack + 1);
else
m_cdplaying = false;
break;
default:
case SND_CD_TRACK:
m_cdplaying = false;
break;
case SND_CD_TRACKLOOP:
PlayCD(m_cdtrack);
break;
}
}
}
void SND_SDLCDDevice::PlayCD(int track)
{
if ( m_cdrom && CD_INDRIVE(SDL_CDStatus(m_cdrom)) ) {
SDL_CDPlayTracks(m_cdrom, track-1, 0, track, 0);
m_cdplaying = true;
m_cdtrack = track;
}
}
void SND_SDLCDDevice::PauseCD(bool pause)
{
if (!m_cdrom)
return;
if (pause)
SDL_CDPause(m_cdrom);
else
SDL_CDResume(m_cdrom);
}
void SND_SDLCDDevice::StopCD()
{
if (m_cdrom)
SDL_CDStop(m_cdrom);
m_cdplaying = false;
}
void SND_SDLCDDevice::SetCDPlaymode(int playmode)
{
m_cdplaymode = playmode;
}
void SND_SDLCDDevice::SetCDGain(MT_Scalar gain)
{
}

@ -0,0 +1,61 @@
/**
* $Id$
*
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender
* Foundation also sells licenses for use in proprietary software under
* the Blender License. See http://www.blender.org/BL/ for information
* about this.
*
* 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
* along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#ifndef SND_SDLCDDEVICE
#define SND_SDLCDDEVICE
typedef struct SDL_CD;
class SND_SDLCDDevice
{
public:
SND_SDLCDDevice();
~SND_SDLCDDevice();
void NextFrame();
void PlayCD(int track);
void PauseCD(bool pause);
void StopCD();
void SetCDPlaymode(int playmode);
void SetCDGain(MT_Scalar gain);
private:
void init();
/* CD Audio */
SDL_CD* m_cdrom;
bool m_cdplaying;
int m_cdtrack;
unsigned char m_cdplaymode;
unsigned char m_frame;
};
#endif