diff --git a/AV.cc b/AV.cc
index 8c64f9f..8e4ef3b 100644
--- a/AV.cc
+++ b/AV.cc
@@ -17,6 +17,15 @@ using namespace std;
#define CALLBACK_SAMPLES 4096
#define CHANNELS 2
#define BYTES_PER_SAMPLE 2
+#if AV_SOUND_FORMAT == AUDIO_S16SYS
+# define SAMPLE_MIN SHRT_MIN
+# define SAMPLE_MAX SHRT_MAX
+#elif AV_SOUND_FORMAT == AUDIO_U16SYS
+# define SAMPLE_MIN 0
+# define SAMPLE_MAX USHRT_MAX
+#else
+# error Unknown AV_SOUND_FORMAT
+#endif
void AV_sound_callback(void * userdata, Uint8 * stream, int len)
{
@@ -56,12 +65,13 @@ AV::AV()
desired.samples = CALLBACK_SAMPLES;
desired.callback = AV_sound_callback;
desired.userdata = this;
+ desired.silence = 0;
if (SDL_OpenAudio(&desired, NULL) < 0)
{
cerr << "SDL_OpenAudio() error." << endl;
exit(3);
}
- m_sound_buffer = new int16_t[CALLBACK_SAMPLES * CHANNELS];
+ m_sound_buffer = new sample_t[CALLBACK_SAMPLES * CHANNELS];
m_active_sounds_mutex = SDL_CreateMutex();
}
@@ -76,7 +86,7 @@ AV::~AV()
delete[] m_sound_buffer;
}
-void AV::start(int width, int height, bool fullscreen, bool grab_input,
+bool AV::start(int width, int height, bool fullscreen, bool grab_input,
int samples)
{
if (m_surface == NULL)
@@ -96,6 +106,31 @@ void AV::start(int width, int height, bool fullscreen, bool grab_input,
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples);
}
m_surface = SDL_SetVideoMode(width, height, 32, flags);
+ if (m_surface == NULL)
+ {
+ if (samples > 1)
+ {
+ cerr << "Error setting video mode, trying again without multisampling" << endl;
+ /* failed to set SDL video mode with multisampling, try without */
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
+ m_surface = SDL_SetVideoMode(width, height, 32, flags);
+ if (m_surface != NULL)
+ {
+ cerr << "Successfully set video mode without multisampling" << endl;
+ }
+ }
+ }
+ if (m_surface == NULL)
+ {
+ cerr << "Error setting SDL video mode." << endl;
+ cerr << "Parameters:" << endl;
+ cerr << " width = " << width << endl;
+ cerr << " height = " << height << endl;
+ cerr << " fullscreen = " << fullscreen << endl;
+ cerr << " input grab = " << grab_input << endl;
+ return false;
+ }
if (grab_input)
{
SDL_ShowCursor(SDL_DISABLE);
@@ -119,6 +154,7 @@ void AV::start(int width, int height, bool fullscreen, bool grab_input,
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
+ return true;
}
void AV::stop()
@@ -161,7 +197,7 @@ void AV::stopSound(AV::Sound * s)
void AV::playCallback(Uint8 * stream, int len)
{
- uint16_t * stream16 = (uint16_t *) stream;
+ sample_t * stream16 = (sample_t *) stream;
memset(stream, 0, len);
SDL_mutexP(m_active_sounds_mutex);
#ifdef DEBUG
@@ -188,7 +224,7 @@ void AV::playCallback(Uint8 * stream, int len)
i++)
{
int sample_val = stream16[i] + (int)(volume * m_sound_buffer[i]);
- stream16[i] = min(SHRT_MAX, max(SHRT_MIN, sample_val));
+ stream16[i] = min(SAMPLE_MAX, max(SAMPLE_MIN, sample_val));
}
}
int sz = m_active_sounds.size();
@@ -237,10 +273,9 @@ bool AV::Sound::load(FileLoader & fileLoader, const FileLoader::Path & path)
}
else
{
- SDL_FreeRW(m_rwops);
- m_rwops = NULL;
cerr << "Error loading sound " << path.toString() << ": "
<< Sound_GetError() << endl;
+ m_rwops = NULL;
}
}
return false;
diff --git a/AV.h b/AV.h
index a56039e..8d2c760 100644
--- a/AV.h
+++ b/AV.h
@@ -11,9 +11,18 @@
#include "FileLoader/FileLoader.h"
#include "refptr/refptr.h"
+#define AV_SOUND_FORMAT AUDIO_S16SYS
+
class AV
{
public:
+#if AV_SOUND_FORMAT == AUDIO_S16SYS
+ typedef int16_t sample_t;
+#elif AV_SOUND_FORMAT == AUDIO_U16SYS
+ typedef uint16_t sample_t;
+#else
+# error Unknown AV_SOUND_FORMAT
+#endif
class Sound
{
public:
@@ -41,7 +50,7 @@ class AV
AV();
~AV();
- void start(int width = 0, int height = 0,
+ bool start(int width = 0, int height = 0,
bool fullscreen = true, bool grab_input = true,
int samples = 4);
void stop();
@@ -87,7 +96,7 @@ class AV
#endif
std::set< Sound * > m_active_sounds;
SDL_mutex * m_active_sounds_mutex;
- int16_t * m_sound_buffer;
+ sample_t * m_sound_buffer;
};
#endif
diff --git a/anaglym.cc b/anaglym.cc
index febeb99..bf9ce6a 100644
--- a/anaglym.cc
+++ b/anaglym.cc
@@ -13,6 +13,12 @@ static void usage();
static void usage()
{
cerr << "Usage: anaglym [options] program.lua[c]" << endl;
+ cerr << "Options:" << endl;
+ cerr << " -w
sound = ag.loadSound(sound_name)
++This routine loads a sound object from file +sound_name and returns a Lua reference to the loaded sound. +The sound_name should contain the file extension, +since multiple formats are supported (.wav, .mp3, etc...). +
+texture = ag.loadTexture(texture_name)
@@ -925,6 +938,135 @@ Newly created objects are visible by default.joint:setAMotorAxis(anum, rel, x, y, z)
++Set axis parameters of the AMotor joint. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorNumAxes(num)
++Set the number of axes of the AMotor joint. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorAngle(anum, angle)
++Set the angle of the specified of axis of the AMotor joint. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorLoStop(anum, lostop)
++Set the low stop angle of the specified axis of the AMotor joint. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorHiStop(anum, histop)
++Set the high stop angle of the specified axis of the AMotor joint. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorVel(vel)
++Set the velocity of the AMotor joint. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorFMax(vel)
++Set the maximum force that the AMotor joint will apply to +maintain its constraints. +See ag.createAMotor() for more information. +
+ + +joint:setAMotorBounce(bounce)
++Set the bounciness of the AMotor joint. +See ag.createAMotor() for more information. +
+ +snd:play()
++Begins playing the snd sound at the beginning. +
+ + +snd:resume()
++Begins playing the snd sound where it stopped after calling +stop(). +
+ + +snd:stop()
++Stops playing the snd sound at its current position. +
+ + +snd:loop(count)
++Begins playing the snd sound at the beginning and sets the loop +count to count. snd:loop(1) is equivalent to +snd:play(). +
+ + +snd:loopForever()
++Begins playing the snd sound at the beginning and sets the loop +count to infinity. This routine is good for background music. +
+ + +snd:getVolume()
++Get the volume for the snd sound. +
+ + +snd:setVolume(vol)
++Set the volume for the snd sound to snd. +snd should be between 0.0 and 1.0. +
+ +