|
From: <cn...@us...> - 2009-11-06 06:45:18
|
Revision: 602
http://hgengine.svn.sourceforge.net/hgengine/?rev=602&view=rev
Author: cnlohr
Date: 2009-11-06 06:45:08 +0000 (Fri, 06 Nov 2009)
Log Message:
-----------
ok - sound is in there
Modified Paths:
--------------
Mercury2/adv_set.c
Mercury2/base_set.sh
Mercury2/src/Mercury2.cpp
Mercury2/src/MercurySound.cpp
Mercury2/src/MercurySoundDriverALSA.cpp
Mercury2/src/MercurySoundSourceVorbis.cpp
Mercury2/src/MercurySoundSourceVorbis.h
Modified: Mercury2/adv_set.c
===================================================================
--- Mercury2/adv_set.c 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/adv_set.c 2009-11-06 06:45:08 UTC (rev 602)
@@ -14,7 +14,8 @@
src/Camera.cpp src/MercuryInput.cpp src/MQuaternion.cpp src/ModuleManager.cpp src/MercuryFBO.cpp \
src/GLHelpers.cpp src/FullscreenQuad.cpp src/MercuryNamedResource.cpp src/MercuryPrefs.cpp \
src/MercuryTheme.cpp src/Orthographic.cpp src/Light.cpp src/RenderDeferredLights.cpp \
- src/MercuryLog.cpp src/MercuryCTA.cpp src/DataTypes/MTriangle.cpp src/StateChanger.cpp"
+ src/MercuryLog.cpp src/MercuryCTA.cpp src/DataTypes/MTriangle.cpp src/StateChanger.cpp \
+ src/MercurySound.cpp src/MercurySoundSourceRAM.cpp "
SOURCES="$SOURCES src/MercuryFileDriverDirect.cpp src/MercuryFileDriverMem.cpp \
src/MercuryFileDriverPacked.cpp src/MercuryFileDriverZipped.cpp"
@@ -30,6 +31,14 @@
SOURCES="$SOURCES src/X11Window.cpp"
#endif
+#ifdef USE_ALSA
+SOURCES="$SOURCES src/MercurySoundDriverALSA.cpp"
+#endif
+
+#ifdef _HAVE_LIB_ogg
+SOURCES="$SOURCES src/MercurySoundSourceVorbis.cpp"
+#endif
+
PROJ="mercury"
CFLAGS="$CFLAGS -DHAVE_CONFIG -DHGENGINE -fno-exceptions -fPIC -Isrc -Isrc/DataStructures -Isrc/DataTypes -g -rdynamic"
LDFLAGS="$LDFLAGS -rdynamic -g -fPIC "
Modified: Mercury2/base_set.sh
===================================================================
--- Mercury2/base_set.sh 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/base_set.sh 2009-11-06 06:45:08 UTC (rev 602)
@@ -8,7 +8,7 @@
ISMAC=1; fi
-OPTIONS="X11 libxml OGL sse gprof glprofile instancewatch"
+OPTIONS="X11 libxml OGL sse gprof glprofile instancewatch alsa ogg"
OPT_X11=1
OPT_OGL=1
OPT_libxml=1
@@ -16,7 +16,10 @@
OPT_gprof=0
OPT_glprofile=0
OPT_instancewatch=1
+OPT_alsa=1
+OPT_ogg=1
+
DEFINES="WAS_CONFIGURED USE_MSTRING"
CC_BASE="-O2 -g0 -Wall"
@@ -77,7 +80,7 @@
fi
if test $OPT_OGL = 1; then
- NEED_H="GL/gl.h"
+ NEED_H="$NEED_H GL/gl.h"
NEED_L="$NEED_L GL GLU"
fi
@@ -94,6 +97,17 @@
DEFINES="$DEFINES INSTANCE_WATCH"
fi
+if test $OPT_alsa = 1; then
+ NEED_L="$NEED_L asound"
+ NEED_H="$NEED_H alsa/asoundlib.h"
+ DEFINES="$DEFINES USE_ALSA"
+fi
+
+if test $OPT_ogg = 1; then
+ NEED_H="$NEED_H ogg/ogg.h"
+ NEED_L="$NEED_L vorbisfile ogg"
+fi
+
ARCH=`uname -m`
if test $ARCH = "i686" || test $ARCH = "i586"; then
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/src/Mercury2.cpp 2009-11-06 06:45:08 UTC (rev 602)
@@ -11,7 +11,7 @@
#include <MercuryCrash.h>
#include <MercuryBacktrace.h>
#include <MercuryMessageManager.h>
-
+#include <MercurySound.h>
#include <MercuryTimer.h>
#include <RenderGraph.h>
#include <Texture.h>
@@ -102,7 +102,9 @@
cnset_execute_on_crash( SignalHandler );
HandleCommandLineParameters( argc, argv );
-
+
+ //Sound first.
+ SOUNDMAN->Init( "" );
MercuryWindow* w = MercuryWindow::MakeWindow();
#ifdef WIN32
Modified: Mercury2/src/MercurySound.cpp
===================================================================
--- Mercury2/src/MercurySound.cpp 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/src/MercurySound.cpp 2009-11-06 06:45:08 UTC (rev 602)
@@ -136,8 +136,6 @@
pc->FillBuffer( cBufferToFill, iCount );
}
-
- printf( "%f %p\n", cBufferToFill[44], & cBufferToFill[44] );
}
void MercurySoundManager::PostFill()
Modified: Mercury2/src/MercurySoundDriverALSA.cpp
===================================================================
--- Mercury2/src/MercurySoundDriverALSA.cpp 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/src/MercurySoundDriverALSA.cpp 2009-11-06 06:45:08 UTC (rev 602)
@@ -4,7 +4,7 @@
#include "MercurySound.h"
#include <alsa/asoundlib.h>
-#define LOW_LATENCY
+//#define LOW_LATENCY
class MercurySoundDriverALSA
{
Modified: Mercury2/src/MercurySoundSourceVorbis.cpp
===================================================================
--- Mercury2/src/MercurySoundSourceVorbis.cpp 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/src/MercurySoundSourceVorbis.cpp 2009-11-06 06:45:08 UTC (rev 602)
@@ -70,12 +70,11 @@
vorbisCallbacks.close_func = vorbis_close_func;
vorbisCallbacks.tell_func = vorbis_tell_func;
- int ret = ov_open_callbacks( f, vorbisFile, NULL, 0, vorbisCallbacks );
+ ov_open_callbacks( f, vorbisFile, NULL, 0, vorbisCallbacks );
vorbis_info* info = ov_info(vorbisFile, -1);
unsigned VorbisChannels = info->channels;
- unsigned VorbisSamplerate = info->rate;
-
+// unsigned VorbisSamplerate = info->rate;
unsigned VorbisSamples = ov_pcm_total( vorbisFile, 0 );
unsigned Vorbisbytes_read;
@@ -116,19 +115,19 @@
//Now, the section on the regular MercurySoundSource
-/*
REGISTER_SOUND_SOURCE( MercurySoundSourceVorbis, "Vorbis" );
MercurySoundSourceVorbis::MercurySoundSourceVorbis( MercurySoundSource * chain ) :
- MercurySoundSource( chain )
+ MercurySoundSource( chain ), iBufferSize( 32768 ), iBufferLoad(1), iBufferPlay(0)
{
+ iBuffer = (short*)malloc( sizeof( short ) * iBufferSize * 2 );
}
-void MercurySoundSourceVorbis::~MercurySoundSourceVorbis()
+MercurySoundSourceVorbis::~MercurySoundSourceVorbis()
{
- SAFE_DELETE(m_File);
- SAFE_DELETE(f);
- SAFE_DELETE(vorbisFile);
+ delete m_File;
+ delete iBuffer;
+ delete vorbisFile;
}
@@ -136,15 +135,10 @@
{
MAutoPtr< HGRawSound > r;
MAutoPtr< HGRawSound > * g;
- if( ( g = g_SoundLibrary.get( sDescriptor ) ) )
- {
- m_Sound = *g;
- return true;
- }
m_File = FILEMAN.Open( sDescriptor );
- OggVorbis_File * vorbisFile = new OggVorbis_File;
+ vorbisFile = new OggVorbis_File;
ov_callbacks vorbisCallbacks;
vorbisCallbacks.read_func = vorbis_read_func;
@@ -152,19 +146,18 @@
vorbisCallbacks.close_func = vorbis_close_func;
vorbisCallbacks.tell_func = vorbis_tell_func;
- int ret = ov_open_callbacks( f, vorbisFile, NULL, 0, vorbisCallbacks );
+ ov_open_callbacks( m_File, vorbisFile, NULL, 0, vorbisCallbacks );
vorbis_info* info = ov_info(vorbisFile, -1);
- unsigned VorbisChannels = info->channels;
- unsigned VorbisSamplerate = info->rate;
-
+// unsigned VorbisChannels = info->channels;
+// unsigned VorbisSamplerate = info->rate;
unsigned VorbisSamples = ov_pcm_total( vorbisFile, 0 );
unsigned Vorbisbytes_read;
if( VorbisSamples <= 0 )
{
- delete f;
+ delete m_File;
delete vorbisFile;
return false;
@@ -175,44 +168,54 @@
void MercurySoundSourceVorbis::FillBuffer( float * cBufferToFill, int iCount )
{
+ //Don't worry our circular queue is threadsafe.
+ for( unsigned i = 0; i < iCount; i++ )
+ {
+ if( PlayLeft() <= 2 ) break;
+ cBufferToFill[i*2+0] = float(iBuffer[iBufferPlay*2+0])/32768.;
+ cBufferToFill[i*2+1] = float(iBuffer[iBufferPlay*2+1])/32768.;
+ iBufferPlay=(iBufferPlay+1)%iBufferSize;
+ }
+ //If we run out... that's okay. It'll just be silent and have time to fill.
}
bool MercurySoundSourceVorbis::PostFill()
{
unsigned Vorbistotal_bytes_read = 0;
+ unsigned Vorbisbytes_read;
int VorbisAbstream;
- short * VorbisData = new short[VorbisSamples*VorbisChannels];
+ unsigned long BF = BufferFree();
+ unsigned long BFL = BF;
+ short tibuf[BF * 2];
- while( (Vorbisbytes_read = ov_read(vorbisFile, ((char*)VorbisData) +
- Vorbistotal_bytes_read, VorbisSamples*VorbisChannels*2 -
- Vorbistotal_bytes_read, 0, 2, 1, &VorbisAbstream)) > 0 )
+ do
{
- if( VorbisAbstream == 0 )
- Vorbistotal_bytes_read+= Vorbisbytes_read;
- }
+ Vorbisbytes_read = ov_read(vorbisFile, ((char*)&(tibuf[0]) + Vorbistotal_bytes_read),
+ BFL * 4, 0, 2, 1, &VorbisAbstream);
+ BFL -= Vorbisbytes_read / 4;
+ Vorbistotal_bytes_read += Vorbisbytes_read;
+ } while( Vorbisbytes_read > 0 && BFL );
+ if( Vorbisbytes_read < 0 )
+ return false;
- r = new HGRawSound(new float[VorbisSamples*VorbisChannels],VorbisSamples);
-
- for( unsigned i = 0; i < VorbisSamples*VorbisChannels; i++ )
+ for( unsigned i = 0; i < BF; i++ )
{
- r->fSound[i] = ((float)VorbisData[i])/32768.0;
+ iBuffer[iBufferLoad*2+0] = tibuf[i*2+0];
+ iBuffer[iBufferLoad*2+1] = tibuf[i*2+1];
+ iBufferLoad=(iBufferLoad+1)%iBufferSize;
}
- delete vorbisFile;
- delete f;
-
- m_Sound = r;
- g_SoundLibrary[sDescriptor] = r;
- return true;
+ if( Vorbisbytes_read == 0 && PlayLeft() == 0 )
+ return false;
+ else
+ return true;
}
-*/
-
/****************************************************************************
* Copyright (C) 2009 by Charles Lohr *
* *
Modified: Mercury2/src/MercurySoundSourceVorbis.h
===================================================================
--- Mercury2/src/MercurySoundSourceVorbis.h 2009-11-05 23:48:55 UTC (rev 601)
+++ Mercury2/src/MercurySoundSourceVorbis.h 2009-11-06 06:45:08 UTC (rev 602)
@@ -15,7 +15,6 @@
static MHash< MAutoPtr< HGRawSound > > g_SoundLibrary;
};
-/*
class OggVorbis_File;
class vorbis_info;
class MercuryFile;
@@ -34,10 +33,17 @@
protected:
MercuryFile * m_File;
OggVorbis_File * vorbisFile;
- vorbis_info * info
+ vorbis_info * info;
+
+ unsigned BufferFree() { return ((iBufferPlay + iBufferSize) - iBufferLoad )%iBufferSize; }
+ unsigned PlayLeft() { return ((iBufferLoad + iBufferSize) - iBufferPlay - 1 )%iBufferSize; }
+ unsigned iBufferSize;
+ unsigned iBufferPlay;
+ unsigned iBufferLoad;
+ short * iBuffer;
};
-*/
+
#endif
/****************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|