[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Stratagus-CVS] stratagus/src/sound arts_audio.c ccl_sound.c cd...
From: |
address@hidden |
Subject: |
[Stratagus-CVS] stratagus/src/sound arts_audio.c ccl_sound.c cd... |
Date: |
Tue, 23 Dec 2003 04:49:48 -0000 |
CVSROOT: /home/strat
Module name: stratagus
Changes by: <address@hidden> 03/12/23 14:48:05
Modified files:
src/sound : arts_audio.c ccl_sound.c cdaudio.c cdda.c
flac.c libcda.c mad.c music.c ogg.c oss_audio.c
sdl_audio.c sound.c sound_id.c sound_server.c
unitsound.c wav.c
Log message:
Tabs, fun!
Patches:
Index: stratagus/src/sound/arts_audio.c
diff -u stratagus/src/sound/arts_audio.c:1.8
stratagus/src/sound/arts_audio.c:1.9
--- stratagus/src/sound/arts_audio.c:1.8 Thu Oct 2 10:12:54 2003
+++ stratagus/src/sound/arts_audio.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,14 +26,14 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: arts_audio.c,v 1.8 2003/10/02 00:12:54 jsalmon3 Exp $
+// $Id: arts_audio.c,v 1.9 2003/12/23 03:48:03 jsalmon3 Exp $
//@{
-#if defined(WITH_ARTSC) // {
+#if defined(WITH_ARTSC) // {
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <artsc.h>
@@ -43,116 +43,116 @@
#include "sound_server.h"
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
static arts_stream_t stream;
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Initialize Arts daemon part for sound drivers.
+** Initialize Arts daemon part for sound drivers.
**
-** @param freq Sample frequenz (44100,22050,11025 hz).
-** @param size Sample size (8bit, 16bit)
+** @param freq Sample frequenz (44100,22050,11025 hz).
+** @param size Sample size (8bit, 16bit)
**
-** @return True if failure, false if everything ok.
+** @return True if failure, false if
everything ok.
*/
global int InitArtsSound(int freq, int size)
{
- int err;
- int frags;
+ int err;
+ int frags;
- SoundFildes = -1;
- //
- // Connect to the daemon.
- //
- if ((err = arts_init())) {
- fprintf(stderr, "Sound [arts]: %s\n", arts_error_text(err));
- return 1;
- }
-
- //
- // Open daemon stream, size bit samples, stereo.
- //
- stream = arts_play_stream(freq, size, 2, "Stratagus");
- if (stream == NULL) {
- fprintf(stderr, "Sound [arts]: Unable to open a stream\n");
- arts_free();
- return 1;
- }
-
- //
- // Set the stream to blocking: it will not block anyway, but it seems
- // to be working better
- //
- arts_stream_set(stream, ARTS_P_BLOCKING, 1);
-
- switch (freq) {
- case 11025:
- frags = ((8 << 16) | 8); // 8 Buffers of 256 Bytes
- break;
- case 22050:
- frags = ((8 << 16) | 9); // 8 Buffers of 512 Bytes
- break;
- default:
- DebugLevel0Fn("Unexpected sample frequency %d\n" _C_ freq);
- // FALL THROUGH
- case 44100:
- frags = ((8 << 16) | 10); // 8 Buffers of 1024 Bytes
- break;
- }
- if (size == 16) { // 8 bit
- ++frags; // double buffer size
- }
- arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frags);
+ SoundFildes = -1;
+ //
+ // Connect to the daemon.
+ //
+ if ((err = arts_init())) {
+ fprintf(stderr, "Sound [arts]: %s\n", arts_error_text(err));
+ return 1;
+ }
+
+ //
+ // Open daemon stream, size bit samples, stereo.
+ //
+ stream = arts_play_stream(freq, size, 2, "Stratagus");
+ if (stream == NULL) {
+ fprintf(stderr, "Sound [arts]: Unable to open a stream\n");
+ arts_free();
+ return 1;
+ }
+
+ //
+ // Set the stream to blocking: it will not block anyway, but it seems
+ // to be working better
+ //
+ arts_stream_set(stream, ARTS_P_BLOCKING, 1);
+
+ switch (freq) {
+ case 11025:
+ frags = ((8 << 16) | 8); // 8 Buffers of 256 Bytes
+ break;
+ case 22050:
+ frags = ((8 << 16) | 9); // 8 Buffers of 512 Bytes
+ break;
+ default:
+ DebugLevel0Fn("Unexpected sample frequency %d\n" _C_
freq);
+ // FALL THROUGH
+ case 44100:
+ frags = ((8 << 16) | 10); // 8 Buffers of 1024 Bytes
+ break;
+ }
+ if (size == 16) { // 8
bit
+ ++frags; //
double buffer size
+ }
+ arts_stream_set(stream, ARTS_P_PACKET_SETTINGS, frags);
#ifdef DEBUG
- frags = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
- DebugLevel0Fn("frequency %d, buffer size %d\n" _C_ freq _C_ frags);
+ frags = arts_stream_get(stream, ARTS_P_BUFFER_SIZE);
+ DebugLevel0Fn("frequency %d, buffer size %d\n" _C_ freq _C_
frags);
#endif
- SoundFildes = 0;
- return 0;
+ SoundFildes = 0;
+ return 0;
}
/**
-** Uninit Arts daemon part for sound drivers.
+** Uninit Arts daemon part for sound drivers.
*/
global void ExitArtsSound(void)
{
- if (SoundFildes == 0) {
- arts_close_stream(stream);
- arts_free();
- SoundFildes = -1;
- }
+ if (SoundFildes == 0) {
+ arts_close_stream(stream);
+ arts_free();
+ SoundFildes = -1;
+ }
}
/**
-** Write out sound data to arts daemon.
+** Write out sound data to arts daemon.
**
-** @param data Pointer to data (sample) buffer
-** @param len length of buffer
+** @param data Pointer to data (sample) buffer
+** @param len length of buffer
**
-** @return Number of written bytes on success or error code
+** @return Number of written bytes on
success or error code
*/
global int WriteArtsSound(void* data,int len)
{
- return arts_write(stream, data, len);
+ return arts_write(stream, data, len);
}
/**
-** Query available sample buffer space from arts daemon.
+** Query available sample buffer space from arts daemon.
**
-** @return Available sample buffer space
+** @return Available sample buffer space
*/
global int ArtsGetSpace(void)
{
- return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
+ return arts_stream_get(stream, ARTS_P_BUFFER_SPACE);
}
-#endif // } WITH_ARTSC
+#endif // } WITH_ARTSC
//@}
Index: stratagus/src/sound/ccl_sound.c
diff -u stratagus/src/sound/ccl_sound.c:1.60
stratagus/src/sound/ccl_sound.c:1.61
--- stratagus/src/sound/ccl_sound.c:1.60 Wed Dec 3 14:54:14 2003
+++ stratagus/src/sound/ccl_sound.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ccl_sound.c,v 1.60 2003/12/03 03:54:14 mr-russ Exp $
+// $Id: ccl_sound.c,v 1.61 2003/12/23 03:48:03 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <string.h>
@@ -39,7 +39,7 @@
#include "stratagus.h"
-#ifdef WITH_SOUND // {
+#ifdef WITH_SOUND // {
#include <stdlib.h>
@@ -50,7 +50,7 @@
#include "cdaudio.h"
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
/**
@@ -60,1635 +60,1635 @@
#if defined(USE_GUILE) || defined(USE_SIOD)
local ccl_smob_type_t SiodSoundTag;
-#define CCL_SOUNDP(x) (CclGetSmobType(x) == SiodSoundTag)
+#define CCL_SOUNDP(x) (CclGetSmobType(x) == SiodSoundTag)
#define CCL_SOUND_ID(x) ((SoundId)CclGetSmobData(x))
#elif defined(USE_LUA)
#endif
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Cast a Stratagus sound id to its scheme version
+** Cast a Stratagus sound id to its scheme version
**
-** @param id the sound id
+** @param id the sound id
**
-** @return its siod version
+** @return its siod version
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM sound_id_ccl(SoundId id)
{
- SCM sound_id;
+ SCM sound_id;
- sound_id = CclMakeSmobObj(SiodSoundTag, id);
- return sound_id;
+ sound_id = CclMakeSmobObj(SiodSoundTag, id);
+ return sound_id;
}
#endif
/**
-** Glue between c and scheme. Ask the sound system to associate a
-** sound id to a sound name.
+** Glue between c and scheme. Ask the sound system to associate a
+** sound id to a sound name.
**
-** @param name name
+** @param name name
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundForName(SCM name)
{
- SoundId id;
- char* sound_name;
+ SoundId id;
+ char* sound_name;
- sound_name = gh_scm2newstr(name, NULL);
- id = SoundIdForName(sound_name);
- free(sound_name);
+ sound_name = gh_scm2newstr(name, NULL);
+ id = SoundIdForName(sound_name);
+ free(sound_name);
- return sound_id_ccl(id);
+ return sound_id_ccl(id);
}
#elif defined(USE_LUA)
local int CclSoundForName(lua_State* l)
{
- SoundId id;
- const char* sound_name;
- LuaUserData* data;
-
- sound_name = LuaToString(l, -1);
- id = SoundIdForName(sound_name);
-
- data = lua_newuserdata(l, sizeof(LuaUserData));
- data->Type = LuaSoundType;
- data->Data = id;
- return 1;
+ SoundId id;
+ const char* sound_name;
+ LuaUserData* data;
+
+ sound_name = LuaToString(l, -1);
+ id = SoundIdForName(sound_name);
+
+ data = lua_newuserdata(l, sizeof(LuaUserData));
+ data->Type = LuaSoundType;
+ data->Data = id;
+ return 1;
}
#endif
/**
-** Get a Game Sound Id from either a siod sound id or a sound name
+** Get a Game Sound Id from either a siod sound id or a sound name
**
-** @param sound Lisp cell, SoundID or string or symbol.
-** @return The C sound id.
+** @param sound Lisp cell, SoundID or string or symbol.
+** @return The C sound id.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SoundId CclGetSoundId(SCM sound)
{
- if (CCL_SOUNDP(sound)) { // if we've got the sound id
- return CCL_SOUND_ID(sound);
- } else {
- return CCL_SOUND_ID(CclSoundForName(sound));
- }
+ if (CCL_SOUNDP(sound)) { // if we've got the sound id
+ return CCL_SOUND_ID(sound);
+ } else {
+ return CCL_SOUND_ID(CclSoundForName(sound));
+ }
}
#elif defined(USE_LUA)
local SoundId CclGetSoundId(lua_State* l)
{
- LuaUserData* data;
+ LuaUserData* data;
- if (lua_isstring(l, -1)) {
- CclSoundForName(l);
- }
- if (lua_isuserdata(l, -1)) {
- data = lua_touserdata(l, -1);
- if (data->Type == LuaSoundType) {
- return data->Data;
+ if (lua_isstring(l, -1)) {
+ CclSoundForName(l);
+ }
+ if (lua_isuserdata(l, -1)) {
+ data = lua_touserdata(l, -1);
+ if (data->Type == LuaSoundType) {
+ return data->Data;
+ }
}
- }
- lua_pushfstring(l, "CclGetSoundId: not a sound");
- lua_error(l);
- return NULL;
+ lua_pushfstring(l, "CclGetSoundId: not a sound");
+ lua_error(l);
+ return NULL;
}
#endif
/**
-** Create a sound.
+** Create a sound.
**
-** Glue between c and scheme. This function asks the sound system to
-** register a sound under a given name, wiht an associated list of files
-** (the list can be replaced by only one file).
+** Glue between c and scheme. This function asks the sound system
to
+** register a sound under a given name, wiht an associated list of
files
+** (the list can be replaced by only one file).
**
-** @param name the name of the sound
-** @param file a list of sound file names (or a file name)
+** @param name the name of the sound
+** @param file a list of sound file names (or a file
name)
**
-** @return the sound id of the created sound
+** @return the sound id of the created
sound
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMakeSound(SCM name, SCM file)
{
- SoundId id;
- char* c_name;
- char* c_file;
- char** c_files;
- int nb;
- int i;
- SCM a_file;
+ SoundId id;
+ char* c_name;
+ char* c_file;
+ char** c_files;
+ int nb;
+ int i;
+ SCM a_file;
- if (!gh_string_p(name)) {
- fprintf(stderr, "string expected\n");
- return SCM_UNSPECIFIED;
- }
- if (gh_string_p(file)) {
- // only one file
- c_name = gh_scm2newstr(name, NULL);
- c_file = gh_scm2newstr(file, NULL);
- id = MakeSound(c_name, (const char**)&c_file, 1);
- DebugLevel3("Making sound `%s' from `%s' with id %p\n" _C_ c_name _C_
- c_file _C_ id);
- // the sound name (c_name) must be kept but the file name can be freed
- // JOHNS: wrong!
- free(c_file);
- free(c_name);
- } else if (gh_list_p(file)) {
- // several files
- c_name = gh_scm2newstr(name, NULL);
- DebugLevel3("Making sound `%s'\n" _C_ c_name);
- nb = gh_length(file);
- c_files = (char**)malloc(sizeof(char*) * nb);
- for (i = 0; i < nb; ++i) {
- a_file = gh_car(file);
- if (!gh_string_p(name)) {
+ if (!gh_string_p(name)) {
fprintf(stderr, "string expected\n");
- // FIXME: memory leak!
return SCM_UNSPECIFIED;
- }
- c_files[i] = gh_scm2newstr(a_file, NULL);
- DebugLevel3("\tComponent %d: `%s'\n" _C_ i _C_ c_files[i]);
- file = gh_cdr(file);
- }
- //FIXME: check size before casting
- id = MakeSound(c_name, (const char**)c_files, (unsigned char)nb);
- for (i = 0; i < nb; ++i) {
- free(c_files[i]);
}
- free(c_name);
- free(c_files);
- } else {
- fprintf(stderr, "string or list expected\n");
- return SCM_UNSPECIFIED;
- }
- return sound_id_ccl(id);
+ if (gh_string_p(file)) {
+ // only one file
+ c_name = gh_scm2newstr(name, NULL);
+ c_file = gh_scm2newstr(file, NULL);
+ id = MakeSound(c_name, (const char**)&c_file, 1);
+ DebugLevel3("Making sound `%s' from `%s' with id %p\n" _C_
c_name _C_
+ c_file _C_ id);
+ // the sound name (c_name) must be kept but the file name can
be freed
+ // JOHNS: wrong!
+ free(c_file);
+ free(c_name);
+ } else if (gh_list_p(file)) {
+ // several files
+ c_name = gh_scm2newstr(name, NULL);
+ DebugLevel3("Making sound `%s'\n" _C_ c_name);
+ nb = gh_length(file);
+ c_files = (char**)malloc(sizeof(char*) * nb);
+ for (i = 0; i < nb; ++i) {
+ a_file = gh_car(file);
+ if (!gh_string_p(name)) {
+ fprintf(stderr, "string expected\n");
+ // FIXME: memory leak!
+ return SCM_UNSPECIFIED;
+ }
+ c_files[i] = gh_scm2newstr(a_file, NULL);
+ DebugLevel3("\tComponent %d: `%s'\n" _C_ i _C_
c_files[i]);
+ file = gh_cdr(file);
+ }
+ //FIXME: check size before casting
+ id = MakeSound(c_name, (const char**)c_files, (unsigned
char)nb);
+ for (i = 0; i < nb; ++i) {
+ free(c_files[i]);
+ }
+ free(c_name);
+ free(c_files);
+ } else {
+ fprintf(stderr, "string or list expected\n");
+ return SCM_UNSPECIFIED;
+ }
+ return sound_id_ccl(id);
}
#elif defined(USE_LUA)
local int CclMakeSound(lua_State* l)
{
- SoundId id;
- const char* c_name;
- const char* c_file;
- char** c_files;
- int args;
- int j;
- LuaUserData* data;
-
- if (lua_gettop(l) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ SoundId id;
+ const char* c_name;
+ const char* c_file;
+ char** c_files;
+ int args;
+ int j;
+ LuaUserData* data;
- c_name = LuaToString(l, 1);
- if (lua_isstring(l, 2)) {
- // only one file
- c_file = LuaToString(l, 2);
- id = MakeSound(c_name, &c_file, 1);
- DebugLevel3("Making sound `%s' from `%s' with id %p\n" _C_ c_name _C_
- c_file _C_ id);
- } else if (lua_istable(l, 2)) {
- // several files
- DebugLevel3("Making sound `%s'\n" _C_ c_name);
- args = luaL_getn(l, 2);
- c_files = malloc(args * sizeof(char*));
- for (j = 0; j < args; ++j) {
- lua_rawgeti(l, 2, j + 1);
- c_files[j] = strdup(LuaToString(l, -1));
- lua_pop(l, 1);
- DebugLevel3("\tComponent %d: `%s'\n" _C_ i _C_ c_files[j]);
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
}
- // FIXME: check size before casting
- id = MakeSound(c_name, (const char**)c_files, (unsigned char)args);
- for (j = 0; j < args; ++j) {
- free(c_files[j]);
+
+ c_name = LuaToString(l, 1);
+ if (lua_isstring(l, 2)) {
+ // only one file
+ c_file = LuaToString(l, 2);
+ id = MakeSound(c_name, &c_file, 1);
+ DebugLevel3("Making sound `%s' from `%s' with id %p\n" _C_
c_name _C_
+ c_file _C_ id);
+ } else if (lua_istable(l, 2)) {
+ // several files
+ DebugLevel3("Making sound `%s'\n" _C_ c_name);
+ args = luaL_getn(l, 2);
+ c_files = malloc(args * sizeof(char*));
+ for (j = 0; j < args; ++j) {
+ lua_rawgeti(l, 2, j + 1);
+ c_files[j] = strdup(LuaToString(l, -1));
+ lua_pop(l, 1);
+ DebugLevel3("\tComponent %d: `%s'\n" _C_ i _C_
c_files[j]);
+ }
+ // FIXME: check size before casting
+ id = MakeSound(c_name, (const char**)c_files, (unsigned
char)args);
+ for (j = 0; j < args; ++j) {
+ free(c_files[j]);
+ }
+ free(c_files);
+ } else {
+ lua_pushfstring(l, "string or table expected");
+ lua_error(l);
+ return 0;
}
- free(c_files);
- } else {
- lua_pushfstring(l, "string or table expected");
- lua_error(l);
- return 0;
- }
- data = lua_newuserdata(l, sizeof(LuaUserData));
- data->Type = LuaSoundType;
- data->Data = id;
- return 1;
+ data = lua_newuserdata(l, sizeof(LuaUserData));
+ data->Type = LuaSoundType;
+ data->Data = id;
+ return 1;
}
#endif
/**
-** Glue between c and scheme. This function asks the sound system to
-** build a special sound group.
+** Glue between c and scheme. This function asks the sound system
to
+** build a special sound group.
**
-** @param name the name of the sound
-** @param first first group played (sound-id or string)
-** @param second second group played (sound-id or string)
+** @param name the name of the sound
+** @param first first group played (sound-id or string)
+** @param second second group played (sound-id or string)
**
-** @return The sound id of the created sound
+** @return The sound id of the created
sound
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMakeSoundGroup(SCM name, SCM first, SCM second)
{
- SoundId id;
- char* c_name;
+ SoundId id;
+ char* c_name;
- if (!gh_string_p(name) && !gh_symbol_p(name)) {
- fprintf(stderr, "string or symbol expected\n");
- return SCM_UNSPECIFIED;
- }
- c_name = gh_scm2newstr(name, NULL);
+ if (!gh_string_p(name) && !gh_symbol_p(name)) {
+ fprintf(stderr, "string or symbol expected\n");
+ return SCM_UNSPECIFIED;
+ }
+ c_name = gh_scm2newstr(name, NULL);
- id = MakeSoundGroup(c_name, CclGetSoundId(first), CclGetSoundId(second));
- // JOHNS: not anymore: c_name consumed by MakeSoundGroup!
- free(c_name);
- return sound_id_ccl(id);
+ id = MakeSoundGroup(c_name, CclGetSoundId(first),
CclGetSoundId(second));
+ // JOHNS: not anymore: c_name consumed by MakeSoundGroup!
+ free(c_name);
+ return sound_id_ccl(id);
}
#elif defined(USE_LUA)
local int CclMakeSoundGroup(lua_State* l)
{
- SoundId id;
- const char* c_name;
- SoundId first;
- SoundId second;
- LuaUserData* data;
+ SoundId id;
+ const char* c_name;
+ SoundId first;
+ SoundId second;
+ LuaUserData* data;
- if (lua_gettop(l) != 3) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 3) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- c_name = LuaToString(l, 1);
+ c_name = LuaToString(l, 1);
- lua_pushvalue(l, 2);
- first = CclGetSoundId(l);
- lua_pop(l, 1);
- second = CclGetSoundId(l);
- id = MakeSoundGroup(c_name, first, second);
- data = lua_newuserdata(l, sizeof(LuaUserData));
- data->Type = LuaSoundType;
- data->Data = id;
- return 1;
+ lua_pushvalue(l, 2);
+ first = CclGetSoundId(l);
+ lua_pop(l, 1);
+ second = CclGetSoundId(l);
+ id = MakeSoundGroup(c_name, first, second);
+ data = lua_newuserdata(l, sizeof(LuaUserData));
+ data->Type = LuaSoundType;
+ data->Data = id;
+ return 1;
}
#endif
/**
-** Glue between c and scheme. Ask to the sound system to remap a sound id
-** to a given name.
+** Glue between c and scheme. Ask to the sound system to remap a
sound id
+** to a given name.
**
-** @param name the new name for the sound
-** @param sound the sound object
+** @param name the new name for the sound
+** @param sound the sound object
**
-** @return the sound object
+** @return the sound object
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMapSound(SCM name, SCM sound)
{
- char* sound_name;
+ char* sound_name;
- sound_name = gh_scm2newstr(name, NULL);
- MapSound(sound_name, CclGetSoundId(sound));
- free(sound_name);
- return sound;
+ sound_name = gh_scm2newstr(name, NULL);
+ MapSound(sound_name, CclGetSoundId(sound));
+ free(sound_name);
+ return sound;
}
#elif defined(USE_LUA)
local int CclMapSound(lua_State* l)
{
- const char* sound_name;
+ const char* sound_name;
- if (lua_gettop(l) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- sound_name = LuaToString(l, 1);
- MapSound(sound_name, CclGetSoundId(l));
- lua_pushvalue(l, 2);
- return 1;
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ sound_name = LuaToString(l, 1);
+ MapSound(sound_name, CclGetSoundId(l));
+ lua_pushvalue(l, 2);
+ return 1;
}
#endif
/**
-** Ask the sound system to play the specified sound.
+** Ask the sound system to play the specified sound.
**
-** @param sound either the sound name or the sound id
+** @param sound either the sound name or the sound id
**
-** @return SCM_UNSPECIFIED
+** @return SCM_UNSPECIFIED
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclPlaySound(SCM sound)
{
- SoundId id;
+ SoundId id;
- id = CclGetSoundId(sound);
- PlayGameSound(id, MaxSampleVolume);
- return SCM_UNSPECIFIED;
+ id = CclGetSoundId(sound);
+ PlayGameSound(id, MaxSampleVolume);
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclPlaySound(lua_State* l)
{
- SoundId id;
+ SoundId id;
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- id = CclGetSoundId(l);
- PlayGameSound(id, MaxSampleVolume);
- return 0;
+ id = CclGetSoundId(l);
+ PlayGameSound(id, MaxSampleVolume);
+ return 0;
}
#endif
/**
-** Test whether a scheme object is a clone sound id
+** Test whether a scheme object is a clone sound id
**
-** @param sound the scheme object
+** @param sound the scheme object
**
-** @return true is sound is a clone sound id
+** @return true is sound is a clone sound
id
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
global int ccl_sound_p(SCM sound)
{
- return CCL_SOUNDP(sound);
+ return CCL_SOUNDP(sound);
}
#endif
/**
-** Cast a scheme object to a clone sound id
+** Cast a scheme object to a clone sound id
**
-** @param sound the scheme object
+** @param sound the scheme object
**
-** @return the clone sound id
+** @return the clone sound id
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
global SoundId ccl_sound_id(SCM sound)
{
- return CCL_SOUND_ID(sound);
+ return CCL_SOUND_ID(sound);
}
#endif
/**
-** Glue between c and scheme. Ask the sound system to dump on the
-** standard output the mapping between sound names and sound id.
+** Glue between c and scheme. Ask the sound system to dump on the
+** standard output the mapping between sound names and sound id.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDisplaySounds(void)
{
- DisplaySoundHashTable();
- return SCM_UNSPECIFIED;
+ DisplaySoundHashTable();
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclDisplaySounds(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- DisplaySoundHashTable();
- return 0;
+ DisplaySoundHashTable();
+ return 0;
}
#endif
/**
-** Glue between c and scheme. Allows to specify some global game sounds
-** in a ccl file.
+** Glue between c and scheme. Allows to specify some global game
sounds
+** in a ccl file.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineGameSounds(SCM list)
{
- //FIXME: should allow to define ALL the game sounds
- SCM value;
- SCM data;
- SCM sublist;
- char* str;
- int i;
-
- while (!gh_null_p(list)) {
-
- value = gh_car(list);
- list = gh_cdr(list);
- if (!gh_symbol_p(value)) {
- PrintFunction();
- fprintf(stdout, "Symbol expected\n");
- return list;
- }
- // prepare for next iteration
-
- // let's handle now the different cases
- if (gh_eq_p(value, gh_symbol2scm("click"))) {
- data = gh_car(list);
- list = gh_cdr(list);
- if (!CCL_SOUNDP(data)) {
- fprintf(stderr, "Sound id expected\n");
- return list;
- }
- GameSounds.Click.Sound = CCL_SOUND_ID(data);
- } else if (gh_eq_p(value, gh_symbol2scm("placement-error"))) {
- data = gh_car(list);
- list = gh_cdr(list);
- if (!CCL_SOUNDP(data)) {
- fprintf(stderr, "Sound id expected\n");
- return list;
- }
- GameSounds.PlacementError.Sound = CCL_SOUND_ID(data);
- } else if (gh_eq_p(value, gh_symbol2scm("placement-success"))) {
- data = gh_car(list);
- list = gh_cdr(list);
- if (!CCL_SOUNDP(data)) {
- fprintf(stderr, "Sound id expected\n");
- return list;
- }
- GameSounds.PlacementSuccess.Sound = CCL_SOUND_ID(data);
- } else if (gh_eq_p(value,gh_symbol2scm("work-complete"))) {
- sublist = gh_car(list);
- list = gh_cdr(list);
- str = gh_scm2newstr(gh_car(sublist), NULL);
- for (i = 0; i < PlayerRaces.Count; ++i) {
- if (!strcmp(PlayerRaces.Name[i], str)) {
- break;
+ //FIXME: should allow to define ALL the game sounds
+ SCM value;
+ SCM data;
+ SCM sublist;
+ char* str;
+ int i;
+
+ while (!gh_null_p(list)) {
+
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (!gh_symbol_p(value)) {
+ PrintFunction();
+ fprintf(stdout, "Symbol expected\n");
+ return list;
}
- }
- if (i == PlayerRaces.Count) {
- fprintf(stderr, "Unknown race: %s\n", str);
- ExitFatal(1);
- }
- free(str);
- sublist = gh_cdr(sublist);
- data = gh_car(sublist);
- if (!CCL_SOUNDP(data)) {
- fprintf(stderr, "Sound id expected\n");
- ExitFatal(1);
- }
- GameSounds.WorkComplete[i].Sound = CCL_SOUND_ID(data);
- } else if (gh_eq_p(value,gh_symbol2scm("rescue"))) {
- sublist = gh_car(list);
- list = gh_cdr(list);
- str = gh_scm2newstr(gh_car(sublist), NULL);
- for (i = 0; i < PlayerRaces.Count; ++i) {
- if (!strcmp(PlayerRaces.Name[i], str)) {
- break;
+ // prepare for next iteration
+
+ // let's handle now the different cases
+ if (gh_eq_p(value, gh_symbol2scm("click"))) {
+ data = gh_car(list);
+ list = gh_cdr(list);
+ if (!CCL_SOUNDP(data)) {
+ fprintf(stderr, "Sound id expected\n");
+ return list;
+ }
+ GameSounds.Click.Sound = CCL_SOUND_ID(data);
+ } else if (gh_eq_p(value, gh_symbol2scm("placement-error"))) {
+ data = gh_car(list);
+ list = gh_cdr(list);
+ if (!CCL_SOUNDP(data)) {
+ fprintf(stderr, "Sound id expected\n");
+ return list;
+ }
+ GameSounds.PlacementError.Sound = CCL_SOUND_ID(data);
+ } else if (gh_eq_p(value, gh_symbol2scm("placement-success"))) {
+ data = gh_car(list);
+ list = gh_cdr(list);
+ if (!CCL_SOUNDP(data)) {
+ fprintf(stderr, "Sound id expected\n");
+ return list;
+ }
+ GameSounds.PlacementSuccess.Sound = CCL_SOUND_ID(data);
+ } else if (gh_eq_p(value,gh_symbol2scm("work-complete"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ str = gh_scm2newstr(gh_car(sublist), NULL);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], str)) {
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ fprintf(stderr, "Unknown race: %s\n", str);
+ ExitFatal(1);
+ }
+ free(str);
+ sublist = gh_cdr(sublist);
+ data = gh_car(sublist);
+ if (!CCL_SOUNDP(data)) {
+ fprintf(stderr, "Sound id expected\n");
+ ExitFatal(1);
+ }
+ GameSounds.WorkComplete[i].Sound = CCL_SOUND_ID(data);
+ } else if (gh_eq_p(value,gh_symbol2scm("rescue"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ str = gh_scm2newstr(gh_car(sublist), NULL);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], str)) {
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ fprintf(stderr, "Unknown race: %s\n", str);
+ ExitFatal(1);
+ }
+ free(str);
+ sublist = gh_cdr(sublist);
+ data = gh_car(sublist);
+ if (!CCL_SOUNDP(data)) {
+ fprintf(stderr, "Sound id expected\n");
+ ExitFatal(1);
+ }
+ GameSounds.Rescue[i].Sound = CCL_SOUND_ID(data);
+ } else {
+ errl("Unsupported tag", value);
+ return list;
}
- }
- if (i == PlayerRaces.Count) {
- fprintf(stderr, "Unknown race: %s\n", str);
- ExitFatal(1);
- }
- free(str);
- sublist = gh_cdr(sublist);
- data = gh_car(sublist);
- if (!CCL_SOUNDP(data)) {
- fprintf(stderr, "Sound id expected\n");
- ExitFatal(1);
- }
- GameSounds.Rescue[i].Sound = CCL_SOUND_ID(data);
- } else {
- errl("Unsupported tag", value);
- return list;
}
- }
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclDefineGameSounds(lua_State* l)
{
- //FIXME: should allow to define ALL the game sounds
- const char* value;
- int i;
- int args;
- int j;
- LuaUserData* data;
-
- args = lua_gettop(l);
- data = NULL;
- for (j = 0; j < args; ++j) {
- value = LuaToString(l, j + 1);
- ++j;
-
- // let's handle now the different cases
- if (!strcmp(value, "click")) {
- if (!lua_isuserdata(l, j + 1) ||
- (data = lua_touserdata(l, j + 1))->Type != LuaSoundType) {
- lua_pushfstring(l, "Sound id expected");
- lua_error(l);
- }
- GameSounds.Click.Sound = data->Data;
- } else if (!strcmp(value, "placement-error")) {
- if (!lua_isuserdata(l, j + 1) ||
- (data = lua_touserdata(l, j + 1))->Type != LuaSoundType) {
- lua_pushfstring(l, "Sound id expected");
- lua_error(l);
- }
- GameSounds.PlacementError.Sound = data->Data;
- } else if (!strcmp(value, "placement-success")) {
- if (!lua_isuserdata(l, j + 1) ||
- (data = lua_touserdata(l, j + 1))->Type != LuaSoundType) {
- lua_pushfstring(l, "Sound id expected");
- lua_error(l);
- }
- GameSounds.PlacementSuccess.Sound = data->Data;
- } else if (!strcmp(value, "work-complete")) {
- if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_rawgeti(l, j + 1, 1);
- value = LuaToString(l, -1);
- lua_pop(l, 1);
- for (i = 0; i < PlayerRaces.Count; ++i) {
- if (!strcmp(PlayerRaces.Name[i], value)) {
- break;
- }
- }
- if (i == PlayerRaces.Count) {
- lua_pushfstring(l, "Unknown race: %s", value);
- lua_error(l);
- }
- lua_rawgeti(l, j + 1, 2);
- if (!lua_isuserdata(l, -1) ||
- (data = lua_touserdata(l, -1))->Type != LuaSoundType) {
- lua_pushfstring(l, "Sound id expected");
- lua_error(l);
- }
- lua_pop(l, 1);
- GameSounds.WorkComplete[i].Sound = data->Data;
- } else if (!strcmp(value, "rescue")) {
- if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_rawgeti(l, j + 1, 1);
- value = LuaToString(l, -1);
- lua_pop(l, 1);
- for (i = 0; i < PlayerRaces.Count; ++i) {
- if (!strcmp(PlayerRaces.Name[i], value)) {
- break;
+ //FIXME: should allow to define ALL the game sounds
+ const char* value;
+ int i;
+ int args;
+ int j;
+ LuaUserData* data;
+
+ args = lua_gettop(l);
+ data = NULL;
+ for (j = 0; j < args; ++j) {
+ value = LuaToString(l, j + 1);
+ ++j;
+
+ // let's handle now the different cases
+ if (!strcmp(value, "click")) {
+ if (!lua_isuserdata(l, j + 1) ||
+ (data = lua_touserdata(l, j + 1))->Type
!= LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ GameSounds.Click.Sound = data->Data;
+ } else if (!strcmp(value, "placement-error")) {
+ if (!lua_isuserdata(l, j + 1) ||
+ (data = lua_touserdata(l, j + 1))->Type
!= LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ GameSounds.PlacementError.Sound = data->Data;
+ } else if (!strcmp(value, "placement-success")) {
+ if (!lua_isuserdata(l, j + 1) ||
+ (data = lua_touserdata(l, j + 1))->Type
!= LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ GameSounds.PlacementSuccess.Sound = data->Data;
+ } else if (!strcmp(value, "work-complete")) {
+ if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2)
{
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 1);
+ value = LuaToString(l, -1);
+ lua_pop(l, 1);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], value)) {
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ lua_pushfstring(l, "Unknown race: %s", value);
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 2);
+ if (!lua_isuserdata(l, -1) ||
+ (data = lua_touserdata(l, -1))->Type !=
LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ lua_pop(l, 1);
+ GameSounds.WorkComplete[i].Sound = data->Data;
+ } else if (!strcmp(value, "rescue")) {
+ if (!lua_istable(l, j + 1) || luaL_getn(l, j + 1) != 2)
{
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 1);
+ value = LuaToString(l, -1);
+ lua_pop(l, 1);
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!strcmp(PlayerRaces.Name[i], value)) {
+ break;
+ }
+ }
+ if (i == PlayerRaces.Count) {
+ lua_pushfstring(l, "Unknown race: %s", value);
+ lua_error(l);
+ }
+ lua_rawgeti(l, j + 1, 2);
+ if (!lua_isuserdata(l, -1) ||
+ (data = lua_touserdata(l, -1))->Type !=
LuaSoundType) {
+ lua_pushfstring(l, "Sound id expected");
+ lua_error(l);
+ }
+ lua_pop(l, 1);
+ GameSounds.Rescue[i].Sound = data->Data;
+ } else {
+ lua_pushfstring(l, "Unsupported tag: %s", value);
+ lua_error(l);
}
- }
- if (i == PlayerRaces.Count) {
- lua_pushfstring(l, "Unknown race: %s", value);
- lua_error(l);
- }
- lua_rawgeti(l, j + 1, 2);
- if (!lua_isuserdata(l, -1) ||
- (data = lua_touserdata(l, -1))->Type != LuaSoundType) {
- lua_pushfstring(l, "Sound id expected");
- lua_error(l);
- }
- lua_pop(l, 1);
- GameSounds.Rescue[i].Sound = data->Data;
- } else {
- lua_pushfstring(l, "Unsupported tag: %s", value);
- lua_error(l);
}
- }
- return 0;
+ return 0;
}
#endif
/**
-** Global volume support
+** Global volume support
**
-** @param volume new global sound volume
+** @param volume new global sound volume
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSoundVolume(SCM volume)
{
- SetGlobalVolume(gh_scm2int(volume));
- return volume;
+ SetGlobalVolume(gh_scm2int(volume));
+ return volume;
}
#elif defined(USE_LUA)
local int CclSetSoundVolume(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- SetGlobalVolume(LuaToNumber(l, 1));
- lua_pushvalue(l, 1);
- return 1;
+ SetGlobalVolume(LuaToNumber(l, 1));
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Music volume support
+** Music volume support
**
-** @param volume new global music volume
+** @param volume new global music volume
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetMusicVolume(SCM volume)
{
- SetMusicVolume(gh_scm2int(volume));
- return volume;
+ SetMusicVolume(gh_scm2int(volume));
+ return volume;
}
#elif defined(USE_LUA)
local int CclSetMusicVolume(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- SetMusicVolume(LuaToNumber(l, 1));
- lua_pushvalue(l, 1);
- return 1;
+ SetMusicVolume(LuaToNumber(l, 1));
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Set cd mode
+** Set cd mode
**
-** @param mode cd mode
+** @param mode cd mode
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetCdMode(SCM mode)
{
#ifdef USE_CDAUDIO
- CDModes cdmode;
+ CDModes cdmode;
- if (gh_eq_p(mode, gh_symbol2scm("all"))) {
- cdmode = CDModeAll;
- } else if (gh_eq_p(mode, gh_symbol2scm("random"))) {
- cdmode = CDModeRandom;
- } else if (gh_eq_p(mode, gh_symbol2scm("defined"))) {
- cdmode = CDModeDefined;
- } else if (gh_eq_p(mode, gh_symbol2scm("off"))) {
- cdmode = CDModeOff;
- } else {
- cdmode = CDModeOff;
- errl("Unsupported tag", mode);
- }
+ if (gh_eq_p(mode, gh_symbol2scm("all"))) {
+ cdmode = CDModeAll;
+ } else if (gh_eq_p(mode, gh_symbol2scm("random"))) {
+ cdmode = CDModeRandom;
+ } else if (gh_eq_p(mode, gh_symbol2scm("defined"))) {
+ cdmode = CDModeDefined;
+ } else if (gh_eq_p(mode, gh_symbol2scm("off"))) {
+ cdmode = CDModeOff;
+ } else {
+ cdmode = CDModeOff;
+ errl("Unsupported tag", mode);
+ }
- PlayCDRom(cdmode);
+ PlayCDRom(cdmode);
#endif
- return mode;
+ return mode;
}
#elif defined(USE_LUA)
local int CclSetCdMode(lua_State* l)
{
#ifdef USE_CDAUDIO
- CDModes cdmode;
- const char* mode;
+ CDModes cdmode;
+ const char* mode;
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- mode = LuaToString(l, 1);
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ mode = LuaToString(l, 1);
- if (!strcmp(mode, "all")) {
- cdmode = CDModeAll;
- } else if (!strcmp(mode, "random")) {
- cdmode = CDModeRandom;
- } else if (!strcmp(mode, "defined")) {
- cdmode = CDModeDefined;
- } else if (!strcmp(mode, "off")) {
- cdmode = CDModeOff;
- } else {
- cdmode = CDModeOff;
- lua_pushfstring(l, "Unsupported tag: %s", mode);
- lua_error(l);
- }
+ if (!strcmp(mode, "all")) {
+ cdmode = CDModeAll;
+ } else if (!strcmp(mode, "random")) {
+ cdmode = CDModeRandom;
+ } else if (!strcmp(mode, "defined")) {
+ cdmode = CDModeDefined;
+ } else if (!strcmp(mode, "off")) {
+ cdmode = CDModeOff;
+ } else {
+ cdmode = CDModeOff;
+ lua_pushfstring(l, "Unsupported tag: %s", mode);
+ lua_error(l);
+ }
- PlayCDRom(cdmode);
+ PlayCDRom(cdmode);
#endif
- lua_pushvalue(l, 1);
- return 1;
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Define play sections
+** Define play sections
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefinePlaySections(SCM list)
{
- SCM value;
- SCM sublist;
- PlaySection* p;
- int i;
-
- ++NumPlaySections;
- PlaySections = realloc(PlaySections, NumPlaySections *
sizeof(PlaySection));
- p = PlaySections + NumPlaySections - 1;
- memset(p, 0, sizeof(PlaySection));
-
- while (!gh_null_p(list)) {
- value = gh_car(list);
- list = gh_cdr(list);
- if (gh_eq_p(value, gh_symbol2scm("race"))) {
- value = gh_car(list);
- list = gh_cdr(list);
- p->Race = gh_scm2newstr(value, NULL);
- } else if (gh_eq_p(value, gh_symbol2scm("type"))) {
- value = gh_car(list);
- list = gh_cdr(list);
- if (gh_eq_p(value, gh_symbol2scm("game"))) {
- p->Type = PlaySectionGame;
- } else if (gh_eq_p(value, gh_symbol2scm("briefing"))) {
- p->Type = PlaySectionBriefing;
- } else if (gh_eq_p(value, gh_symbol2scm("stats-victory"))) {
- p->Type = PlaySectionStatsVictory;
- } else if (gh_eq_p(value, gh_symbol2scm("stats-defeat"))) {
- p->Type = PlaySectionStatsDefeat;
- } else if (gh_eq_p(value, gh_symbol2scm("main-menu"))) {
- p->Type = PlaySectionMainMenu;
- } else {
- errl("Unsupported tag", value);
- }
- } else if (gh_eq_p(value, gh_symbol2scm("cd"))) {
- sublist = gh_car(list);
- list = gh_cdr(list);
- while (!gh_null_p(sublist)) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("order"))) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("all"))) {
- p->CDOrder = PlaySectionOrderAll;
- } else if (gh_eq_p(value, gh_symbol2scm("random"))) {
- p->CDOrder = PlaySectionOrderRandom;
- } else {
- errl("Unsupported tag", value);
- }
- } else if (gh_eq_p(value, gh_symbol2scm("tracks"))) {
- SCM temp;
-
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- for (i = 0; i < (signed)gh_vector_length(value); ++i) {
- temp=gh_vector_ref(value, gh_int2scm(i));
- p->CDTracks |= (1 << gh_scm2int(temp));
- }
+ SCM value;
+ SCM sublist;
+ PlaySection* p;
+ int i;
+
+ ++NumPlaySections;
+ PlaySections = realloc(PlaySections, NumPlaySections *
sizeof(PlaySection));
+ p = PlaySections + NumPlaySections - 1;
+ memset(p, 0, sizeof(PlaySection));
+
+ while (!gh_null_p(list)) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (gh_eq_p(value, gh_symbol2scm("race"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ p->Race = gh_scm2newstr(value, NULL);
+ } else if (gh_eq_p(value, gh_symbol2scm("type"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (gh_eq_p(value, gh_symbol2scm("game"))) {
+ p->Type = PlaySectionGame;
+ } else if (gh_eq_p(value, gh_symbol2scm("briefing"))) {
+ p->Type = PlaySectionBriefing;
+ } else if (gh_eq_p(value,
gh_symbol2scm("stats-victory"))) {
+ p->Type = PlaySectionStatsVictory;
+ } else if (gh_eq_p(value,
gh_symbol2scm("stats-defeat"))) {
+ p->Type = PlaySectionStatsDefeat;
+ } else if (gh_eq_p(value, gh_symbol2scm("main-menu"))) {
+ p->Type = PlaySectionMainMenu;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("cd"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ while (!gh_null_p(sublist)) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("order"))) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value,
gh_symbol2scm("all"))) {
+ p->CDOrder =
PlaySectionOrderAll;
+ } else if (gh_eq_p(value,
gh_symbol2scm("random"))) {
+ p->CDOrder =
PlaySectionOrderRandom;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value,
gh_symbol2scm("tracks"))) {
+ SCM temp;
+
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ for (i = 0; i <
(signed)gh_vector_length(value); ++i) {
+ temp=gh_vector_ref(value,
gh_int2scm(i));
+ p->CDTracks |= (1 <<
gh_scm2int(temp));
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("no-cd"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ while (!gh_null_p(sublist)) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("order"))) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value,
gh_symbol2scm("all"))) {
+ p->FileOrder =
PlaySectionOrderAll;
+ } else if (gh_eq_p(value,
gh_symbol2scm("random"))) {
+ p->FileOrder =
PlaySectionOrderRandom;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value,
gh_symbol2scm("files"))) {
+ SCM sublist2;
+
+ sublist2 = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ i = 0;
+ while (!gh_null_p(sublist2)) {
+ value = gh_car(sublist2);
+ sublist2 = gh_cdr(sublist2);
+ ++i;
+ p->Files = realloc(p->Files, (i
+ 1) * sizeof(char*));
+ p->Files[i - 1] =
gh_scm2newstr(value, NULL);
+ p->Files[i] = NULL;
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
} else {
- errl("Unsupported tag", value);
- }
- }
- } else if (gh_eq_p(value, gh_symbol2scm("no-cd"))) {
- sublist = gh_car(list);
- list = gh_cdr(list);
- while (!gh_null_p(sublist)) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("order"))) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("all"))) {
- p->FileOrder = PlaySectionOrderAll;
- } else if (gh_eq_p(value, gh_symbol2scm("random"))) {
- p->FileOrder = PlaySectionOrderRandom;
- } else {
errl("Unsupported tag", value);
- }
- } else if (gh_eq_p(value, gh_symbol2scm("files"))) {
- SCM sublist2;
-
- sublist2 = gh_car(sublist);
- sublist = gh_cdr(sublist);
- i = 0;
- while (!gh_null_p(sublist2)) {
- value = gh_car(sublist2);
- sublist2 = gh_cdr(sublist2);
- ++i;
- p->Files = realloc(p->Files, (i + 1) * sizeof(char*));
- p->Files[i - 1] = gh_scm2newstr(value, NULL);
- p->Files[i] = NULL;
- }
- } else {
- errl("Unsupported tag", value);
}
- }
- } else {
- errl("Unsupported tag", value);
}
- }
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclDefinePlaySections(lua_State* l)
{
#if 0
- SCM value;
- SCM sublist;
- PlaySection* p;
- int i;
-
- ++NumPlaySections;
- PlaySections = realloc(PlaySections, NumPlaySections *
sizeof(PlaySection));
- p = PlaySections + NumPlaySections - 1;
- memset(p, 0, sizeof(PlaySection));
-
- while (!gh_null_p(list)) {
- value = gh_car(list);
- list = gh_cdr(list);
- if (gh_eq_p(value, gh_symbol2scm("race"))) {
- value = gh_car(list);
- list = gh_cdr(list);
- p->Race = gh_scm2newstr(value, NULL);
- } else if (gh_eq_p(value, gh_symbol2scm("type"))) {
- value = gh_car(list);
- list = gh_cdr(list);
- if (gh_eq_p(value, gh_symbol2scm("game"))) {
- p->Type = PlaySectionGame;
- } else if (gh_eq_p(value, gh_symbol2scm("briefing"))) {
- p->Type = PlaySectionBriefing;
- } else if (gh_eq_p(value, gh_symbol2scm("stats-victory"))) {
- p->Type = PlaySectionStatsVictory;
- } else if (gh_eq_p(value, gh_symbol2scm("stats-defeat"))) {
- p->Type = PlaySectionStatsDefeat;
- } else if (gh_eq_p(value, gh_symbol2scm("main-menu"))) {
- p->Type = PlaySectionMainMenu;
- } else {
- errl("Unsupported tag", value);
- }
- } else if (gh_eq_p(value, gh_symbol2scm("cd"))) {
- sublist = gh_car(list);
- list = gh_cdr(list);
- while (!gh_null_p(sublist)) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("order"))) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("all"))) {
- p->CDOrder = PlaySectionOrderAll;
- } else if (gh_eq_p(value, gh_symbol2scm("random"))) {
- p->CDOrder = PlaySectionOrderRandom;
- } else {
- errl("Unsupported tag", value);
- }
- } else if (gh_eq_p(value, gh_symbol2scm("tracks"))) {
- SCM temp;
-
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- for (i = 0; i < (signed)gh_vector_length(value); ++i) {
- temp=gh_vector_ref(value, gh_int2scm(i));
- p->CDTracks |= (1 << gh_scm2int(temp));
- }
+ SCM value;
+ SCM sublist;
+ PlaySection* p;
+ int i;
+
+ ++NumPlaySections;
+ PlaySections = realloc(PlaySections, NumPlaySections *
sizeof(PlaySection));
+ p = PlaySections + NumPlaySections - 1;
+ memset(p, 0, sizeof(PlaySection));
+
+ while (!gh_null_p(list)) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (gh_eq_p(value, gh_symbol2scm("race"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ p->Race = gh_scm2newstr(value, NULL);
+ } else if (gh_eq_p(value, gh_symbol2scm("type"))) {
+ value = gh_car(list);
+ list = gh_cdr(list);
+ if (gh_eq_p(value, gh_symbol2scm("game"))) {
+ p->Type = PlaySectionGame;
+ } else if (gh_eq_p(value, gh_symbol2scm("briefing"))) {
+ p->Type = PlaySectionBriefing;
+ } else if (gh_eq_p(value,
gh_symbol2scm("stats-victory"))) {
+ p->Type = PlaySectionStatsVictory;
+ } else if (gh_eq_p(value,
gh_symbol2scm("stats-defeat"))) {
+ p->Type = PlaySectionStatsDefeat;
+ } else if (gh_eq_p(value, gh_symbol2scm("main-menu"))) {
+ p->Type = PlaySectionMainMenu;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("cd"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ while (!gh_null_p(sublist)) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("order"))) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value,
gh_symbol2scm("all"))) {
+ p->CDOrder =
PlaySectionOrderAll;
+ } else if (gh_eq_p(value,
gh_symbol2scm("random"))) {
+ p->CDOrder =
PlaySectionOrderRandom;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value,
gh_symbol2scm("tracks"))) {
+ SCM temp;
+
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ for (i = 0; i <
(signed)gh_vector_length(value); ++i) {
+ temp=gh_vector_ref(value,
gh_int2scm(i));
+ p->CDTracks |= (1 <<
gh_scm2int(temp));
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
+ } else if (gh_eq_p(value, gh_symbol2scm("no-cd"))) {
+ sublist = gh_car(list);
+ list = gh_cdr(list);
+ while (!gh_null_p(sublist)) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value, gh_symbol2scm("order"))) {
+ value = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ if (gh_eq_p(value,
gh_symbol2scm("all"))) {
+ p->FileOrder =
PlaySectionOrderAll;
+ } else if (gh_eq_p(value,
gh_symbol2scm("random"))) {
+ p->FileOrder =
PlaySectionOrderRandom;
+ } else {
+ errl("Unsupported tag", value);
+ }
+ } else if (gh_eq_p(value,
gh_symbol2scm("files"))) {
+ SCM sublist2;
+
+ sublist2 = gh_car(sublist);
+ sublist = gh_cdr(sublist);
+ i = 0;
+ while (!gh_null_p(sublist2)) {
+ value = gh_car(sublist2);
+ sublist2 = gh_cdr(sublist2);
+ ++i;
+ p->Files = realloc(p->Files, (i
+ 1) * sizeof(char*));
+ p->Files[i - 1] =
gh_scm2newstr(value, NULL);
+ p->Files[i] = NULL;
+ }
+ } else {
+ errl("Unsupported tag", value);
+ }
+ }
} else {
- errl("Unsupported tag", value);
- }
- }
- } else if (gh_eq_p(value, gh_symbol2scm("no-cd"))) {
- sublist = gh_car(list);
- list = gh_cdr(list);
- while (!gh_null_p(sublist)) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("order"))) {
- value = gh_car(sublist);
- sublist = gh_cdr(sublist);
- if (gh_eq_p(value, gh_symbol2scm("all"))) {
- p->FileOrder = PlaySectionOrderAll;
- } else if (gh_eq_p(value, gh_symbol2scm("random"))) {
- p->FileOrder = PlaySectionOrderRandom;
- } else {
errl("Unsupported tag", value);
- }
- } else if (gh_eq_p(value, gh_symbol2scm("files"))) {
- SCM sublist2;
-
- sublist2 = gh_car(sublist);
- sublist = gh_cdr(sublist);
- i = 0;
- while (!gh_null_p(sublist2)) {
- value = gh_car(sublist2);
- sublist2 = gh_cdr(sublist2);
- ++i;
- p->Files = realloc(p->Files, (i + 1) * sizeof(char*));
- p->Files[i - 1] = gh_scm2newstr(value, NULL);
- p->Files[i] = NULL;
- }
- } else {
- errl("Unsupported tag", value);
}
- }
- } else {
- errl("Unsupported tag", value);
}
- }
#endif
- return 0;
+ return 0;
}
#endif
/**
-** Turn Off Sound (client side)
+** Turn Off Sound (client side)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundOff(void)
{
- SoundOff = 1;
- return SCM_UNSPECIFIED;
+ SoundOff = 1;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclSoundOff(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- SoundOff = 1;
- return 0;
+ SoundOff = 1;
+ return 0;
}
#endif
/**
-** Turn On Sound (client side)
+** Turn On Sound (client side)
**
-** @return true if and only if the sound is REALLY turned on
-** (uses SoundFildes)
+** @return true if and only if the sound is REALLY turned on
+** (uses SoundFildes)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundOn(void)
{
- if (SoundFildes != -1) {
- return SCM_BOOL_T;
- }
- SoundOff = 0;
- return SCM_BOOL_F;
+ if (SoundFildes != -1) {
+ return SCM_BOOL_T;
+ }
+ SoundOff = 0;
+ return SCM_BOOL_F;
}
#elif defined(USE_LUA)
local int CclSoundOn(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- if (SoundFildes != -1) {
- lua_pushboolean(l, 1);
+ if (SoundFildes != -1) {
+ lua_pushboolean(l, 1);
+ return 1;
+ }
+ SoundOff = 0;
+ lua_pushboolean(l, 0);
return 1;
- }
- SoundOff = 0;
- lua_pushboolean(l, 0);
- return 1;
}
#endif
/**
-** Turn Off Music (client side)
+** Turn Off Music (client side)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMusicOff(void)
{
- StopMusic();
- MusicOff = 1;
- return SCM_UNSPECIFIED;
+ StopMusic();
+ MusicOff = 1;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclMusicOff(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- StopMusic();
- MusicOff = 1;
- return 0;
+ StopMusic();
+ MusicOff = 1;
+ return 0;
}
#endif
/**
-** Turn On Music (client side)
+** Turn On Music (client side)
**
-** @return true if and only if the sound is REALLY turned on
-** (uses SoundFildes)
+** @return true if and only if the sound is REALLY turned on
+** (uses SoundFildes)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMusicOn(void)
{
- MusicOff = 0;
- return SCM_UNSPECIFIED;
+ MusicOff = 0;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclMusicOn(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- MusicOff = 0;
- return 0;
+ MusicOff = 0;
+ return 0;
}
#endif
/**
-** Set the cut off distance.
+** Set the cut off distance.
**
-** @param distance new cut off distance for sounds
+** @param distance new cut off distance for sounds
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetGlobalSoundRange(SCM distance)
{
- int d;
+ int d;
- // FIXME: check for errors
- d = gh_scm2int(distance);
- if (d > 0) {
- DistanceSilent = d;
- }
- return distance;
+ // FIXME: check for errors
+ d = gh_scm2int(distance);
+ if (d > 0) {
+ DistanceSilent = d;
+ }
+ return distance;
}
#elif defined(USE_LUA)
local int CclSetGlobalSoundRange(lua_State* l)
{
- int d;
+ int d;
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- // FIXME: check for errors
- d = LuaToNumber(l, 1);
- if (d > 0) {
- DistanceSilent = d;
- }
- lua_pushvalue(l, 1);
- return 1;
+ // FIXME: check for errors
+ d = LuaToNumber(l, 1);
+ if (d > 0) {
+ DistanceSilent = d;
+ }
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Ask clone to use a sound thread
+** Ask clone to use a sound thread
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundThread(void)
{
#ifdef USE_THREAD
- WithSoundThread = 1;
+ WithSoundThread = 1;
#endif
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclSoundThread(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
#ifdef USE_THREAD
- WithSoundThread = 1;
+ WithSoundThread = 1;
#endif
- return 0;
+ return 0;
}
#endif
/**
-** Set the range of a given sound.
+** Set the range of a given sound.
**
-** @param sound the sound id or name of the sound
-** @param range the new range for this sound
+** @param sound the sound id or name of the sound
+** @param range the new range for this sound
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSoundRange(SCM sound, SCM range) {
- //FIXME check for errors
- unsigned char theRange;
- int tmp;
- SoundId id;
-
- tmp = gh_scm2int(range);
- if (tmp < 0) {
- theRange = 0;
- } else if (tmp > 255) {
- theRange = 255;
- } else {
- theRange = (unsigned char)tmp;
- }
- DebugLevel3("Range: %u (%d)\n" _C_ TheRange _C_ tmp);
- id = CclGetSoundId(sound);
- SetSoundRange(id, theRange);
- return sound;
+ //FIXME check for errors
+ unsigned char theRange;
+ int tmp;
+ SoundId id;
+
+ tmp = gh_scm2int(range);
+ if (tmp < 0) {
+ theRange = 0;
+ } else if (tmp > 255) {
+ theRange = 255;
+ } else {
+ theRange = (unsigned char)tmp;
+ }
+ DebugLevel3("Range: %u (%d)\n" _C_ TheRange _C_ tmp);
+ id = CclGetSoundId(sound);
+ SetSoundRange(id, theRange);
+ return sound;
}
#elif defined(USE_LUA)
local int CclSetSoundRange(lua_State* l) {
- unsigned char theRange;
- int tmp;
-// SoundId id;
+ unsigned char theRange;
+ int tmp;
+// SoundId id;
- if (lua_gettop(l) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- tmp = LuaToNumber(l, 2);
- if (tmp < 0) {
- theRange = 0;
- } else if (tmp > 255) {
- theRange = 255;
- } else {
- theRange = (unsigned char)tmp;
- }
- DebugLevel3("Range: %u (%d)\n" _C_ TheRange _C_ tmp);
-// id = CclGetSoundId(sound);
-// SetSoundRange(id, theRange);
-// return sound;
- return 0;
+ tmp = LuaToNumber(l, 2);
+ if (tmp < 0) {
+ theRange = 0;
+ } else if (tmp > 255) {
+ theRange = 255;
+ } else {
+ theRange = (unsigned char)tmp;
+ }
+ DebugLevel3("Range: %u (%d)\n" _C_ TheRange _C_ tmp);
+// id = CclGetSoundId(sound);
+// SetSoundRange(id, theRange);
+// return sound;
+ return 0;
}
#endif
/**
-** Play a music file.
+** Play a music file.
**
-** @param name Name of the music file to play.
+** @param name Name of the music file to play.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclPlayMusic(SCM name)
{
- char* music_name;
+ char* music_name;
- music_name = gh_scm2newstr(name, NULL);
- PlayMusic(music_name);
- free(music_name);
+ music_name = gh_scm2newstr(name, NULL);
+ PlayMusic(music_name);
+ free(music_name);
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclPlayMusic(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- PlayMusic(LuaToString(l, 1));
+ PlayMusic(LuaToString(l, 1));
- return 0;
+ return 0;
}
#endif
/**
-** Play a sound file.
+** Play a sound file.
**
-** @param name Name of the sound file to play.
+** @param name Name of the sound file to play.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclPlayFile(SCM name)
{
- char* filename;
+ char* filename;
- filename = gh_scm2newstr(name, NULL);
- PlayFile(filename);
- free(filename);
+ filename = gh_scm2newstr(name, NULL);
+ PlayFile(filename);
+ free(filename);
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclPlayFile(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- PlayFile(LuaToString(l, 1));
+ PlayFile(LuaToString(l, 1));
- return 0;
+ return 0;
}
#endif
/**
-** Stop playing music.
+** Stop playing music.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclStopMusic(void)
{
- StopMusic();
+ StopMusic();
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclStopMusic(lua_State* l)
{
- if (lua_gettop(l) != 0) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
+ if (lua_gettop(l) != 0) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
- StopMusic();
+ StopMusic();
- return 0;
+ return 0;
}
#endif
/**
-** Register CCL features for sound.
+** Register CCL features for sound.
*/
global void SoundCclRegister(void)
{
#if defined(USE_GUILE) || defined(USE_SIOD)
- SiodSoundTag = CclMakeSmobType("Sound");
+ SiodSoundTag = CclMakeSmobType("Sound");
- gh_new_procedure1_0("set-sound-volume!", CclSetSoundVolume);
- gh_new_procedure1_0("set-music-volume!", CclSetMusicVolume);
- gh_new_procedure1_0("set-cd-mode!", CclSetCdMode);
-
- gh_new_procedureN("define-play-sections", CclDefinePlaySections);
-
- gh_new_procedure0_0("sound-off", CclSoundOff);
- gh_new_procedure0_0("sound-on", CclSoundOn);
- gh_new_procedure0_0("music-off", CclMusicOff);
- gh_new_procedure0_0("music-on", CclMusicOn);
- gh_new_procedure0_0("sound-thread", CclSoundThread);
- gh_new_procedure1_0("set-global-sound-range!", CclSetGlobalSoundRange);
- gh_new_procedureN("define-game-sounds", CclDefineGameSounds);
- gh_new_procedure0_0("display-sounds", CclDisplaySounds);
- gh_new_procedure2_0("map-sound", CclMapSound);
- gh_new_procedure1_0("sound-for-name", CclSoundForName);
- gh_new_procedure2_0("set-sound-range!", CclSetSoundRange);
- gh_new_procedure2_0("make-sound", CclMakeSound);
- gh_new_procedure3_0("make-sound-group", CclMakeSoundGroup);
- gh_new_procedure1_0("play-sound", CclPlaySound);
-
- gh_new_procedure1_0("play-music", CclPlayMusic);
- gh_new_procedure1_0("play-file", CclPlayFile);
- gh_new_procedure0_0("stop-music", CclStopMusic);
-#elif defined(USE_LUA)
- lua_register(Lua, "SetSoundVolume", CclSetSoundVolume);
- lua_register(Lua, "SetMusicVolume", CclSetMusicVolume);
- lua_register(Lua, "SetCdMode", CclSetCdMode);
-
- lua_register(Lua, "DefinePlaySections", CclDefinePlaySections);
-
- lua_register(Lua, "SoundOff", CclSoundOff);
- lua_register(Lua, "SoundOn", CclSoundOn);
- lua_register(Lua, "MusicOff", CclMusicOff);
- lua_register(Lua, "MusicOn", CclMusicOn);
- lua_register(Lua, "SoundThread", CclSoundThread);
- lua_register(Lua, "SetGlobalSoundRange", CclSetGlobalSoundRange);
- lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
- lua_register(Lua, "DisplaySounds", CclDisplaySounds);
- lua_register(Lua, "MapSound", CclMapSound);
- lua_register(Lua, "SoundForName", CclSoundForName);
- lua_register(Lua, "SetSoundRange", CclSetSoundRange);
- lua_register(Lua, "MakeSound", CclMakeSound);
- lua_register(Lua, "MakeSoundGroup", CclMakeSoundGroup);
- lua_register(Lua, "PlaySound", CclPlaySound);
-
- lua_register(Lua, "PlayMusic", CclPlayMusic);
- lua_register(Lua, "PlayFile", CclPlayFile);
- lua_register(Lua, "StopMusic", CclStopMusic);
+ gh_new_procedure1_0("set-sound-volume!", CclSetSoundVolume);
+ gh_new_procedure1_0("set-music-volume!", CclSetMusicVolume);
+ gh_new_procedure1_0("set-cd-mode!", CclSetCdMode);
+
+ gh_new_procedureN("define-play-sections", CclDefinePlaySections);
+
+ gh_new_procedure0_0("sound-off", CclSoundOff);
+ gh_new_procedure0_0("sound-on", CclSoundOn);
+ gh_new_procedure0_0("music-off", CclMusicOff);
+ gh_new_procedure0_0("music-on", CclMusicOn);
+ gh_new_procedure0_0("sound-thread", CclSoundThread);
+ gh_new_procedure1_0("set-global-sound-range!", CclSetGlobalSoundRange);
+ gh_new_procedureN("define-game-sounds", CclDefineGameSounds);
+ gh_new_procedure0_0("display-sounds", CclDisplaySounds);
+ gh_new_procedure2_0("map-sound", CclMapSound);
+ gh_new_procedure1_0("sound-for-name", CclSoundForName);
+ gh_new_procedure2_0("set-sound-range!", CclSetSoundRange);
+ gh_new_procedure2_0("make-sound", CclMakeSound);
+ gh_new_procedure3_0("make-sound-group", CclMakeSoundGroup);
+ gh_new_procedure1_0("play-sound", CclPlaySound);
+
+ gh_new_procedure1_0("play-music", CclPlayMusic);
+ gh_new_procedure1_0("play-file", CclPlayFile);
+ gh_new_procedure0_0("stop-music", CclStopMusic);
+#elif defined(USE_LUA)
+ lua_register(Lua, "SetSoundVolume", CclSetSoundVolume);
+ lua_register(Lua, "SetMusicVolume", CclSetMusicVolume);
+ lua_register(Lua, "SetCdMode", CclSetCdMode);
+
+ lua_register(Lua, "DefinePlaySections", CclDefinePlaySections);
+
+ lua_register(Lua, "SoundOff", CclSoundOff);
+ lua_register(Lua, "SoundOn", CclSoundOn);
+ lua_register(Lua, "MusicOff", CclMusicOff);
+ lua_register(Lua, "MusicOn", CclMusicOn);
+ lua_register(Lua, "SoundThread", CclSoundThread);
+ lua_register(Lua, "SetGlobalSoundRange", CclSetGlobalSoundRange);
+ lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
+ lua_register(Lua, "DisplaySounds", CclDisplaySounds);
+ lua_register(Lua, "MapSound", CclMapSound);
+ lua_register(Lua, "SoundForName", CclSoundForName);
+ lua_register(Lua, "SetSoundRange", CclSetSoundRange);
+ lua_register(Lua, "MakeSound", CclMakeSound);
+ lua_register(Lua, "MakeSoundGroup", CclMakeSoundGroup);
+ lua_register(Lua, "PlaySound", CclPlaySound);
+
+ lua_register(Lua, "PlayMusic", CclPlayMusic);
+ lua_register(Lua, "PlayFile", CclPlayFile);
+ lua_register(Lua, "StopMusic", CclStopMusic);
#endif
}
-#else // }{ WITH_SOUND
+#else // }{ WITH_SOUND
#include "ccl.h"
/**
-** Global volume support
+** Global volume support
**
-** @param volume new global sound volume
+** @param volume new global sound volume
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSoundVolume(SCM volume)
{
- return volume;
+ return volume;
}
#elif defined(USE_LUA)
local int CclSetSoundVolume(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_pushvalue(l, 1);
- return 1;
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Music volume support
+** Music volume support
**
-** @param volume new global music volume
+** @param volume new global music volume
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetMusicVolume(SCM volume)
{
- return volume;
+ return volume;
}
#elif defined(USE_LUA)
local int CclSetMusicVolume(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_pushvalue(l, 1);
- return 1;
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Set cd mode
+** Set cd mode
**
-** @param mode cd mode
+** @param mode cd mode
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetCdMode(SCM mode)
{
- return mode;
+ return mode;
}
#elif defined(USE_LUA)
local int CclSetCdMode(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_pushvalue(l, 1);
- return 1;
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Turn Off Sound (client side)
+** Turn Off Sound (client side)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundOff(void)
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclSoundOff(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Turn On Sound (client side)
+** Turn On Sound (client side)
**
-** @return true if and only if the sound is REALLY turned on
-** (uses SoundFildes)
+** @return true if and only if the sound is REALLY turned on
+** (uses SoundFildes)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundOn(void)
{
- return SCM_BOOL_T;
+ return SCM_BOOL_T;
}
#elif defined(USE_LUA)
local int CclSoundOn(lua_State* l)
{
- lua_pushboolean(l, 1);
- return 1;
+ lua_pushboolean(l, 1);
+ return 1;
}
#endif
/**
-** Turn Off Music (client side)
+** Turn Off Music (client side)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMusicOff(void)
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclMusicOff(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Turn On Music (client side)
+** Turn On Music (client side)
**
-** @return true if and only if the sound is REALLY turned on
-** (uses SoundFildes)
+** @return true if and only if the sound is REALLY turned on
+** (uses SoundFildes)
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMusicOn(void)
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclMusicOn(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Set the cut off distance.
+** Set the cut off distance.
**
-** @param distance new cut off distance for sounds
+** @param distance new cut off distance for sounds
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetGlobalSoundRange(SCM distance)
{
- return distance;
+ return distance;
}
#elif defined(USE_LUA)
local int CclSetGlobalSoundRange(lua_State* l)
{
- if (lua_gettop(l) != 1) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_pushvalue(l, 1);
- return 1;
+ if (lua_gettop(l) != 1) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Set the range of a given sound.
+** Set the range of a given sound.
**
-** @param sound the sound id or name of the sound
-** @param range the new range for this sound
+** @param sound the sound id or name of the sound
+** @param range the new range for this sound
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSetSoundRange(SCM sound, SCM range __attribute__((unused)))
{
- return sound;
+ return sound;
}
#elif defined(USE_LUA)
local int CclSetSoundRange(lua_State* l)
{
- if (lua_gettop(l) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_pushvalue(l, 1);
- return 1;
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 1);
+ return 1;
}
#endif
/**
-** Ask clone to use a sound thread
+** Ask clone to use a sound thread
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundThread(void)
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclSoundThread(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Glue between c and scheme. Ask the sound system to dump on the
-** standard output the mapping between sound names and sound id.
+** Glue between c and scheme. Ask the sound system to dump on the
+** standard output the mapping between sound names and sound id.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDisplaySounds(void)
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclDisplaySounds(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Glue between c and scheme. Ask the sound system to associate a sound
-** id to a sound name.
+** Glue between c and scheme. Ask the sound system to associate a
sound
+** id to a sound name.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclSoundForName(SCM name __attribute__((unused)))
{
- return NIL;
+ return NIL;
}
#elif defined(USE_LUA)
local int CclSoundForName(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Glue between c and scheme. Allows to specify some global game sounds
-** in a ccl file.
+** Glue between c and scheme. Allows to specify some global game
sounds
+** in a ccl file.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclDefineGameSounds(SCM list __attribute__((unused)))
{
- return NIL;
+ return NIL;
}
#elif defined(USE_LUA)
local SCM CclDefineGameSounds(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Glue between c and scheme. Ask to the sound system to remap a sound id
-** to a given name.
+** Glue between c and scheme. Ask to the sound system to remap a
sound id
+** to a given name.
**
-** @param name the new name for the sound
-** @param sound the sound object
+** @param name the new name for the sound
+** @param sound the sound object
**
-** @return the sound object
+** @return the sound object
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclMapSound(SCM name __attribute__((unused)), SCM sound)
{
- return sound;
+ return sound;
}
#elif defined(USE_LUA)
local int CclMapSound(lua_State* l)
{
- if (lua_gettop(l) != 2) {
- lua_pushstring(l, "incorrect argument");
- lua_error(l);
- }
- lua_pushvalue(l, 2);
- return 1;
+ if (lua_gettop(l) != 2) {
+ lua_pushstring(l, "incorrect argument");
+ lua_error(l);
+ }
+ lua_pushvalue(l, 2);
+ return 1;
}
#endif
/**
-** Play a music file.
+** Play a music file.
**
-** @param name Name of the music file to play.
+** @param name Name of the music file to play.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclPlayMusic(SCM name __attribute__((unused)))
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclPlayMusic(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Play a sound file.
+** Play a sound file.
**
-** @param name Name of the sound file to play.
+** @param name Name of the sound file to play.
*/
#if defined(USE_GUILE) || defined(USE_SIOD)
local SCM CclPlayFile(SCM name __attribute__((unused)))
{
- return SCM_UNSPECIFIED;
+ return SCM_UNSPECIFIED;
}
#elif defined(USE_LUA)
local int CclPlayFile(lua_State* l)
{
- return 0;
+ return 0;
}
#endif
/**
-** Register CCL features for sound. Dummy version.
+** Register CCL features for sound. Dummy version.
*/
global void SoundCclRegister(void)
{
#if defined(USE_GUILE) || defined(USE_SIOD)
- gh_new_procedure1_0("set-sound-volume!", CclSetSoundVolume);
- gh_new_procedure1_0("set-music-volume!", CclSetMusicVolume);
- gh_new_procedure1_0("set-cd-mode!", CclSetCdMode);
- gh_new_procedure0_0("sound-off", CclSoundOff);
- gh_new_procedure0_0("sound-on", CclSoundOn);
- gh_new_procedure0_0("music-off", CclMusicOff);
- gh_new_procedure0_0("music-on", CclMusicOn);
- gh_new_procedure0_0("sound-thread", CclSoundThread);
- gh_new_procedure1_0("set-global-sound-range!", CclSetGlobalSoundRange);
- gh_new_procedureN("define-game-sounds", CclDefineGameSounds);
- gh_new_procedure0_0("display-sounds", CclDisplaySounds);
- gh_new_procedure2_0("map-sound", CclMapSound);
- gh_new_procedure1_0("sound-for-name", CclSoundForName);
- gh_new_procedure2_0("set-sound-range!", CclSetSoundRange);
-
- gh_new_procedure1_0("play-music", CclPlayMusic);
- gh_new_procedure1_0("play-file", CclPlayFile);
-#elif defined(USE_LUA)
- lua_register(Lua, "SetSoundVolume!", CclSetSoundVolume);
- lua_register(Lua, "SetMusicVolume!", CclSetMusicVolume);
- lua_register(Lua, "SetCdMode!", CclSetCdMode);
- lua_register(Lua, "SoundOff", CclSoundOff);
- lua_register(Lua, "SoundOn", CclSoundOn);
- lua_register(Lua, "MusicOff", CclMusicOff);
- lua_register(Lua, "MusicOn", CclMusicOn);
- lua_register(Lua, "SoundThread", CclSoundThread);
- lua_register(Lua, "SetGlobalSoundRange!", CclSetGlobalSoundRange);
- lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
- lua_register(Lua, "DisplaySounds", CclDisplaySounds);
- lua_register(Lua, "MapSound", CclMapSound);
- lua_register(Lua, "SoundForName", CclSoundForName);
- lua_register(Lua, "SetSoundRange!", CclSetSoundRange);
+ gh_new_procedure1_0("set-sound-volume!", CclSetSoundVolume);
+ gh_new_procedure1_0("set-music-volume!", CclSetMusicVolume);
+ gh_new_procedure1_0("set-cd-mode!", CclSetCdMode);
+ gh_new_procedure0_0("sound-off", CclSoundOff);
+ gh_new_procedure0_0("sound-on", CclSoundOn);
+ gh_new_procedure0_0("music-off", CclMusicOff);
+ gh_new_procedure0_0("music-on", CclMusicOn);
+ gh_new_procedure0_0("sound-thread", CclSoundThread);
+ gh_new_procedure1_0("set-global-sound-range!", CclSetGlobalSoundRange);
+ gh_new_procedureN("define-game-sounds", CclDefineGameSounds);
+ gh_new_procedure0_0("display-sounds", CclDisplaySounds);
+ gh_new_procedure2_0("map-sound", CclMapSound);
+ gh_new_procedure1_0("sound-for-name", CclSoundForName);
+ gh_new_procedure2_0("set-sound-range!", CclSetSoundRange);
+
+ gh_new_procedure1_0("play-music", CclPlayMusic);
+ gh_new_procedure1_0("play-file", CclPlayFile);
+#elif defined(USE_LUA)
+ lua_register(Lua, "SetSoundVolume!", CclSetSoundVolume);
+ lua_register(Lua, "SetMusicVolume!", CclSetMusicVolume);
+ lua_register(Lua, "SetCdMode!", CclSetCdMode);
+ lua_register(Lua, "SoundOff", CclSoundOff);
+ lua_register(Lua, "SoundOn", CclSoundOn);
+ lua_register(Lua, "MusicOff", CclMusicOff);
+ lua_register(Lua, "MusicOn", CclMusicOn);
+ lua_register(Lua, "SoundThread", CclSoundThread);
+ lua_register(Lua, "SetGlobalSoundRange!", CclSetGlobalSoundRange);
+ lua_register(Lua, "DefineGameSounds", CclDefineGameSounds);
+ lua_register(Lua, "DisplaySounds", CclDisplaySounds);
+ lua_register(Lua, "MapSound", CclMapSound);
+ lua_register(Lua, "SoundForName", CclSoundForName);
+ lua_register(Lua, "SetSoundRange!", CclSetSoundRange);
- lua_register(Lua, "PlayMusic", CclPlayMusic);
- lua_register(Lua, "PlayFile", CclPlayFile);
+ lua_register(Lua, "PlayMusic", CclPlayMusic);
+ lua_register(Lua, "PlayFile", CclPlayFile);
#endif
}
-#endif // } !WITH_SOUND
+#endif // } !WITH_SOUND
//@}
Index: stratagus/src/sound/cdaudio.c
diff -u stratagus/src/sound/cdaudio.c:1.13 stratagus/src/sound/cdaudio.c:1.14
--- stratagus/src/sound/cdaudio.c:1.13 Thu Oct 2 03:52:40 2003
+++ stratagus/src/sound/cdaudio.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: cdaudio.c,v 1.13 2003/10/01 17:52:40 jsalmon3 Exp $
+// $Id: cdaudio.c,v 1.14 2003/12/23 03:48:03 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
@@ -46,429 +46,429 @@
//#include "sound_server.h"
-#if defined(USE_SDLCD)
-#include "SDL.h"
-#elif defined(USE_LIBCDA)
-#include "libcda.h"
-#elif defined(USE_CDDA)
+#if defined(USE_SDLCD)
+#include "SDL.h"
+#elif defined(USE_LIBCDA)
+#include "libcda.h"
+#elif defined(USE_CDDA)
#include "iocompat.h"
#endif
/*----------------------------------------------------------------------------
--- Declaration
+-- Declaration
----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
-global int CDTrack; /// Current cd track
+global int CDTrack; /// Current cd
track
-global int NumCDTracks; /// Number of tracks on the cd
+global int NumCDTracks; ///
Number of tracks on the cd
-#if defined(USE_SDLCD)
-local SDL_CD* CDRom; /// SDL cdrom device
-#elif defined(USE_CDDA)
-global int CDDrive; /// CDRom device
-global struct cdrom_tocentry CDtocentry[64]; /// TOC track header struct
-local struct cdrom_tochdr CDchdr; /// TOC header struct
-local struct cdrom_read_audio CDdata; /// struct for reading data
+#if defined(USE_SDLCD)
+local SDL_CD* CDRom; /// SDL cdrom
device
+#elif defined(USE_CDDA)
+global int CDDrive; /// CDRom device
+global struct cdrom_tocentry CDtocentry[64]; /// TOC track header
struct
+local struct cdrom_tochdr CDchdr; /// TOC header
struct
+local struct cdrom_read_audio CDdata; /// struct for
reading data
#endif
-global CDModes CDMode; /// CD mode
+global CDModes CDMode; /// CD mode
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
#if defined (USE_SDLCD)
/**
-** FIXME: docu
+** FIXME: docu
*/
local int InitCD(void)
{
- if (SDL_Init(SDL_INIT_CDROM)) {
- return 1;
- }
- CDRom = SDL_CDOpen(0);
- if (!SDL_CDStatus(CDRom)) {
- CDMode = CDModeOff;
- return 1;
- }
- NumCDTracks = CDRom->numtracks;
- return 0;
+ if (SDL_Init(SDL_INIT_CDROM)) {
+ return 1;
+ }
+ CDRom = SDL_CDOpen(0);
+ if (!SDL_CDStatus(CDRom)) {
+ CDMode = CDModeOff;
+ return 1;
+ }
+ NumCDTracks = CDRom->numtracks;
+ return 0;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int PlayCDTrack(int track)
{
- CDTrack = track;
- return SDL_CDPlayTracks(CDRom, track - 1, 0, 0, 0);
+ CDTrack = track;
+ return SDL_CDPlayTracks(CDRom, track - 1, 0, 0, 0);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void ResumeCD(void)
{
#ifdef USE_WIN32
- SDL_CDResume(CDRom);
+ SDL_CDResume(CDRom);
#endif
- PlayCDRom(CDModeDefined);
+ PlayCDRom(CDModeDefined);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void PauseCD(void)
{
- SDL_CDPause(CDRom);
- CDTrack = 0;
- CDMode = CDModeStopped;
+ SDL_CDPause(CDRom);
+ CDTrack = 0;
+ CDMode = CDModeStopped;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int IsAudioTrack(int track)
{
- // FIXME: what is proper way?
- return 1;
+ // FIXME: what is proper way?
+ return 1;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int IsCDPlaying(void)
{
- if (SDL_CDStatus(CDRom) == CD_PLAYING) {
- return 1;
- } else {
- return 0;
- }
+ if (SDL_CDStatus(CDRom) == CD_PLAYING) {
+ return 1;
+ } else {
+ return 0;
+ }
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int GetCDVolume(void)
{
- return 0;
+ return 0;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void SetCDVolume(int vol)
{
- return;
+ return;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void QuitCD(void)
{
- if (CDMode != CDModeOff && CDMode != CDModeStopped) {
- SDL_CDStop(CDRom);
- CDMode = CDModeStopped;
- }
- if (CDMode != CDModeStopped) {
- SDL_CDClose(CDRom);
- CDMode = CDModeOff;
- }
+ if (CDMode != CDModeOff && CDMode != CDModeStopped) {
+ SDL_CDStop(CDRom);
+ CDMode = CDModeStopped;
+ }
+ if (CDMode != CDModeStopped) {
+ SDL_CDClose(CDRom);
+ CDMode = CDModeOff;
+ }
}
#elif defined(USE_LIBCDA)
/**
-** FIXME: docu
+** FIXME: docu
*/
local int InitCD(void)
{
- if (cd_init()) {
- return -1;
- } else {
- if (cd_get_tracks(NULL, &NumCDTracks)) {
- return -1;
+ if (cd_init()) {
+ return -1;
+ } else {
+ if (cd_get_tracks(NULL, &NumCDTracks)) {
+ return -1;
+ }
+ return 0;
}
- return 0;
- }
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int PlayCDTrack(int track)
{
- CDTrack = track;
- return cd_play(track);
+ CDTrack = track;
+ return cd_play(track);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void ResumeCD(void)
{
- PlayCDRom(CDModeDefined);
+ PlayCDRom(CDModeDefined);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void PauseCD(void)
{
- cd_pause();
- CDTrack = 0;
- CDMode = CDModeStopped;
+ cd_pause();
+ CDTrack = 0;
+ CDMode = CDModeStopped;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int IsAudioTrack(int track)
{
- return cd_is_audio(track);
+ return cd_is_audio(track);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int IsCDPlaying(void)
{
- if (cd_current_track()) {
- return 1;
- } else {
- return 0;
- }
+ if (cd_current_track()) {
+ return 1;
+ } else {
+ return 0;
+ }
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int GetCDVolume(void)
{
- int vol;
+ int vol;
- cd_get_volume(&vol, &vol);
- return vol;
+ cd_get_volume(&vol, &vol);
+ return vol;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void SetCDVolume(int vol)
{
- cd_set_volume(vol, vol);
+ cd_set_volume(vol, vol);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void QuitCD(void)
{
- if (CDMode != CDModeOff && CDMode != CDModeStopped) {
- cd_stop();
- CDMode = CDModeStopped;
- }
- if (CDMode == CDModeStopped) {
- cd_close();
- cd_exit();
- CDMode = CDModeOff;
- }
+ if (CDMode != CDModeOff && CDMode != CDModeStopped) {
+ cd_stop();
+ CDMode = CDModeStopped;
+ }
+ if (CDMode == CDModeStopped) {
+ cd_close();
+ cd_exit();
+ CDMode = CDModeOff;
+ }
}
#elif defined(USE_CDDA)
/**
-** FIXME: docu
+** FIXME: docu
*/
local int InitCD(void)
{
- int i;
+ int i;
- CDDrive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
- ioctl(CDDrive, CDROMRESET);
- ioctl(CDDrive, CDROMREADTOCHDR, &CDchdr);
- for (i = CDchdr.cdth_trk0; i <= CDchdr.cdth_trk1; ++i){
- CDtocentry[i].cdte_format = CDROM_LBA;
- CDtocentry[i].cdte_track = i;
- ioctl(CDDrive, CDROMREADTOCENTRY, &CDtocentry[i]);
- }
- NumCDTracks = i - 1;
-
- if (NumCDTracks == 0) {
- CDMode = CDModeOff;
- return -1;
- }
- return 0;
+ CDDrive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
+ ioctl(CDDrive, CDROMRESET);
+ ioctl(CDDrive, CDROMREADTOCHDR, &CDchdr);
+ for (i = CDchdr.cdth_trk0; i <= CDchdr.cdth_trk1; ++i){
+ CDtocentry[i].cdte_format = CDROM_LBA;
+ CDtocentry[i].cdte_track = i;
+ ioctl(CDDrive, CDROMREADTOCENTRY, &CDtocentry[i]);
+ }
+ NumCDTracks = i - 1;
+
+ if (NumCDTracks == 0) {
+ CDMode = CDModeOff;
+ return -1;
+ }
+ return 0;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int PlayCDTrack(int track)
{
- Sample* sample;
+ Sample* sample;
- sample = LoadCD(NULL, track);
- CDTrack = track;
- MusicSample = sample;
- PlayingMusic = 1;
- return 0;
+ sample = LoadCD(NULL, track);
+ CDTrack = track;
+ MusicSample = sample;
+ PlayingMusic = 1;
+ return 0;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void ResumeCD(void)
{
- PlayCDRom(CDModeDefined);
+ PlayCDRom(CDModeDefined);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void PauseCD(void)
{
- StopMusic();
- CDTrack = 0;
- CDMode = CDModeStopped;
+ StopMusic();
+ CDTrack = 0;
+ CDMode = CDModeStopped;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int IsAudioTrack(track)
{
- return !(CDtocentry[track].cdte_ctrl & CDROM_DATA_TRACK);
+ return !(CDtocentry[track].cdte_ctrl & CDROM_DATA_TRACK);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int IsCDPlaying(void)
{
- return PlayingMusic;
+ return PlayingMusic;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global int GetCDVolume(void)
{
- return MusicVolume;
+ return MusicVolume;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void SetCDVolume(int vol)
{
- MusicVolume = vol;
+ MusicVolume = vol;
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void QuitCD(void)
{
- close(CDDrive);
+ close(CDDrive);
}
#endif
-/**
-** Check cdrom.
-**
-** Perodic called from the main loop.
+/**
+** Check cdrom.
+**
+** Perodic called from the main loop.
*/
global int CDRomCheck(void* unused __attribute__ ((unused)))
{
- if (CDMode != CDModeOff && CDMode != CDModeStopped &&
- !IsCDPlaying() && CDMode != CDModeDefined) {
- DebugLevel0Fn("Playing new track\n");
- PlayCDRom(CDMode);
- }
- return 0;
+ if (CDMode != CDModeOff && CDMode != CDModeStopped &&
+ !IsCDPlaying() && CDMode != CDModeDefined) {
+ DebugLevel0Fn("Playing new track\n");
+ PlayCDRom(CDMode);
+ }
+ return 0;
}
/*
-** Play CDRom
+** Play CDRom
**
-** @param name name of play mode, CDModeAll, CDModeRandom,
CDModeDefined
+** @param name name of play mode, CDModeAll,
CDModeRandom, CDModeDefined
*/
global int PlayCDRom(int name)
{
- int i;
- int datacd;
+ int i;
+ int datacd;
- if (name == CDModeOff) {
- CDMode = CDModeOff;
- return 1;
- }
+ if (name == CDModeOff) {
+ CDMode = CDModeOff;
+ return 1;
+ }
- if (CDMode == CDModeOff) {
- if (InitCD()) {
- fprintf(stderr, "Error initializing cdrom\n");
- CDMode = CDModeOff;
- return 1;
- }
- datacd = 1;
- for (i = 1; i <= NumCDTracks; ++i) {
- if (IsAudioTrack(i) > 0) {
- datacd = 0;
- break;
- }
- }
- if (datacd || NumCDTracks <= 0) {
- CDMode = CDModeOff;
- fprintf(stderr, "Not an audio cd\n");
- return 1;
+ if (CDMode == CDModeOff) {
+ if (InitCD()) {
+ fprintf(stderr, "Error initializing cdrom\n");
+ CDMode = CDModeOff;
+ return 1;
+ }
+ datacd = 1;
+ for (i = 1; i <= NumCDTracks; ++i) {
+ if (IsAudioTrack(i) > 0) {
+ datacd = 0;
+ break;
+ }
+ }
+ if (datacd || NumCDTracks <= 0) {
+ CDMode = CDModeOff;
+ fprintf(stderr, "Not an audio cd\n");
+ return 1;
+ }
}
- }
- StopMusic();
+ StopMusic();
- // FIXME: when would this happen
- if (NumCDTracks <= 0) {
- return 1;
- }
+ // FIXME: when would this happen
+ if (NumCDTracks <= 0) {
+ return 1;
+ }
- // if mode is play all tracks
- if (name == CDModeAll) {
- CDMode = CDModeAll;
- CDTrack = 0;
- do {
- if (CDTrack >= NumCDTracks) {
+ // if mode is play all tracks
+ if (name == CDModeAll) {
+ CDMode = CDModeAll;
CDTrack = 0;
- }
- } while (!IsAudioTrack(++CDTrack));
- if (PlayCDTrack(CDTrack)) {
- CDMode = CDModeStopped;
+ do {
+ if (CDTrack >= NumCDTracks) {
+ CDTrack = 0;
+ }
+ } while (!IsAudioTrack(++CDTrack));
+ if (PlayCDTrack(CDTrack)) {
+ CDMode = CDModeStopped;
+ }
+ return 0;
}
- return 0;
- }
- // if mode is play random tracks
- if (name == CDModeRandom) {
- CDMode = CDModeRandom;
- CDTrack = 0;
- do {
- CDTrack = MyRand() % NumCDTracks;
- } while (!IsAudioTrack(CDTrack));
- if (PlayCDTrack(CDTrack)) {
- CDMode = CDModeStopped;
+ // if mode is play random tracks
+ if (name == CDModeRandom) {
+ CDMode = CDModeRandom;
+ CDTrack = 0;
+ do {
+ CDTrack = MyRand() % NumCDTracks;
+ } while (!IsAudioTrack(CDTrack));
+ if (PlayCDTrack(CDTrack)) {
+ CDMode = CDModeStopped;
+ }
+ return 0;
}
- return 0;
- }
- if (name == CDModeDefined) {
- CDMode = CDModeDefined;
- return 0;
- }
+ if (name == CDModeDefined) {
+ CDMode = CDModeDefined;
+ return 0;
+ }
- return 1;
+ return 1;
}
-#endif // } USE_CDAUDIO
+#endif // } USE_CDAUDIO
//@}
Index: stratagus/src/sound/cdda.c
diff -u stratagus/src/sound/cdda.c:1.20 stratagus/src/sound/cdda.c:1.21
--- stratagus/src/sound/cdda.c:1.20 Thu Oct 2 03:52:40 2003
+++ stratagus/src/sound/cdda.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -31,7 +31,7 @@
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include "stratagus.h"
@@ -46,120 +46,120 @@
#include "cdaudio.h"
/*----------------------------------------------------------------------------
--- Declarations
+-- Declarations
----------------------------------------------------------------------------*/
typedef struct _cdda_data {
- int PosInCd; // Offset on CD to read from
- struct cdrom_read_audio Readdata; // Structure for IOCTL
- char* PointerInBuffer; // Position in buffer
- char* Buffer; // Buffer start
+ int PosInCd; // Offset on CD
to read from
+ struct cdrom_read_audio Readdata; // Structure for IOCTL
+ char* PointerInBuffer; // Position in buffer
+ char* Buffer; // Buffer start
} CddaData;
#define FRAME_SIZE 2352
#define CDDA_BUFFER_SIZE (12 * FRAME_SIZE)
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Type member function to read from the cd
+** Type member function to read from the cd
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int CDRead(Sample* sample, void* buf, int len)
{
- CddaData* data;
- int n;
+ CddaData* data;
+ int n;
- data = (CddaData*)sample->User;
+ data = (CddaData*)sample->User;
- data->Readdata.addr.lba = CDtocentry[CDTrack].cdte_addr.lba +
data->PosInCd / FRAME_SIZE;
- data->Readdata.addr_format = CDROM_LBA;
+ data->Readdata.addr.lba = CDtocentry[CDTrack].cdte_addr.lba +
data->PosInCd / FRAME_SIZE;
+ data->Readdata.addr_format = CDROM_LBA;
- // end of track
- if (FRAME_SIZE * (CDtocentry[CDTrack + 1].cdte_addr.lba -
- CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd < len) {
- len = FRAME_SIZE * (CDtocentry[CDTrack+1].cdte_addr.lba -
- CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd;
- data->PosInCd = 0;
- }
-
- if (sample->Length - (data->PointerInBuffer - data->Buffer) < len) {
- // need to read more data
- sample->Length -= data->PointerInBuffer - data->Buffer;
- memcpy(data->Buffer, data->PointerInBuffer, sample->Length);
- data->PointerInBuffer = data->Buffer;
-
- n = CDDA_BUFFER_SIZE - sample->Length;
-
- data->Readdata.nframes = n / FRAME_SIZE;
- data->Readdata.buf = data->PointerInBuffer + sample->Length;
- ioctl(CDDrive, CDROMREADAUDIO, &data->Readdata);
-
- sample->Length += data->Readdata.nframes * FRAME_SIZE;
- data->PosInCd += data->Readdata.nframes * FRAME_SIZE;
- }
-
- memcpy(buf, data->PointerInBuffer, len);
- data->PointerInBuffer += len;
- return len;
+ // end of track
+ if (FRAME_SIZE * (CDtocentry[CDTrack + 1].cdte_addr.lba -
+ CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd <
len) {
+ len = FRAME_SIZE * (CDtocentry[CDTrack+1].cdte_addr.lba -
+ CDtocentry[CDTrack].cdte_addr.lba) - data->PosInCd;
+ data->PosInCd = 0;
+ }
+
+ if (sample->Length - (data->PointerInBuffer - data->Buffer) < len) {
+ // need to read more data
+ sample->Length -= data->PointerInBuffer - data->Buffer;
+ memcpy(data->Buffer, data->PointerInBuffer, sample->Length);
+ data->PointerInBuffer = data->Buffer;
+
+ n = CDDA_BUFFER_SIZE - sample->Length;
+
+ data->Readdata.nframes = n / FRAME_SIZE;
+ data->Readdata.buf = data->PointerInBuffer + sample->Length;
+ ioctl(CDDrive, CDROMREADAUDIO, &data->Readdata);
+
+ sample->Length += data->Readdata.nframes * FRAME_SIZE;
+ data->PosInCd += data->Readdata.nframes * FRAME_SIZE;
+ }
+
+ memcpy(buf, data->PointerInBuffer, len);
+ data->PointerInBuffer += len;
+ return len;
}
/**
-** Type member function to free CDDA sample
+** Type member function to free CDDA sample
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void CDFree(Sample* sample)
{
- free(sample);
+ free(sample);
}
/**
-** CDDA object type structure.
+** CDDA object type structure.
*/
local const SampleType CDStreamSampleType = {
- CDRead,
- CDFree,
+ CDRead,
+ CDFree,
};
/**
-** Load CD.
+** Load CD.
**
-** @param name Unused.
-** @param flags Unused.
+** @param name Unused.
+** @param flags Unused.
**
-** @return Returns the loaded sample.
+** @return Returns the loaded sample.
**
*/
global Sample* LoadCD(const char* name __attribute__((unused)),
- int flags __attribute__((unused)))
+ int flags __attribute__((unused)))
{
- Sample* sample;
- CddaData* data;
+ Sample* sample;
+ CddaData* data;
+
+ sample = malloc(sizeof(*sample));
+ sample->Channels = 2;
+ sample->SampleSize = 16;
+ sample->Frequency = 44100;
+ sample->Type = &CDStreamSampleType;
+ sample->Length = 0;
- sample = malloc(sizeof(*sample));
- sample->Channels = 2;
- sample->SampleSize = 16;
- sample->Frequency = 44100;
- sample->Type = &CDStreamSampleType;
- sample->Length = 0;
-
- data = malloc(sizeof(CddaData));
- data->PosInCd = 0;
- data->Buffer = malloc(CDDA_BUFFER_SIZE);
- data->PointerInBuffer = data->Buffer;
- sample->User = data;
+ data = malloc(sizeof(CddaData));
+ data->PosInCd = 0;
+ data->Buffer = malloc(CDDA_BUFFER_SIZE);
+ data->PointerInBuffer = data->Buffer;
+ sample->User = data;
- return sample;
+ return sample;
}
-#endif // } USE_CDDA
+#endif // } USE_CDDA
//@}
Index: stratagus/src/sound/flac.c
diff -u stratagus/src/sound/flac.c:1.34 stratagus/src/sound/flac.c:1.35
--- stratagus/src/sound/flac.c:1.34 Thu Oct 2 03:52:40 2003
+++ stratagus/src/sound/flac.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,18 +26,18 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: flac.c,v 1.34 2003/10/01 17:52:40 jsalmon3 Exp $
+// $Id: flac.c,v 1.35 2003/12/23 03:48:03 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "stratagus.h"
-#if defined(WITH_SOUND) && defined(USE_FLAC) // {
+#if defined(WITH_SOUND) && defined(USE_FLAC) // {
#include <stdlib.h>
#include <string.h>
@@ -48,386 +48,386 @@
#include "sound_server.h"
/*----------------------------------------------------------------------------
--- Declaration
+-- Declaration
----------------------------------------------------------------------------*/
-/**
-** Private flac data structure to handle flac streaming.
+/**
+** Private flac data structure to handle flac streaming.
*/
typedef struct _flac_data_ {
- char* PointerInBuffer; /// Pointer into buffer
- CLFile* FlacFile; /// File handle
- Sample* Sample; /// Sample buffer
- int Bytes; /// Amount of data to read
- FLAC__StreamDecoder* Stream; /// Decoder stream
+ char* PointerInBuffer; /// Pointer into buffer
+ CLFile* FlacFile; ///
File handle
+ Sample* Sample; /// Sample
buffer
+ int Bytes;
/// Amount of data to read
+ FLAC__StreamDecoder* Stream; /// Decoder stream
} FlacData;
-#define FLAC_BUFFER_SIZE (12 * 1024) /// Buffer size to fill
+#define FLAC_BUFFER_SIZE (12 * 1024) /// Buffer size to fill
local const SampleType FlacSampleType;
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Read callback from FLAC stream decoder.
+** Read callback from FLAC stream decoder.
**
-** @param stream Decoder stream.
-** @param status Error state.
-** @param user User data.
+** @param stream Decoder stream.
+** @param status Error state.
+** @param user User data.
*/
local void FLAC_error_callback(
- const FLAC__StreamDecoder* stream __attribute__((unused)),
- FLAC__StreamDecoderErrorStatus status __attribute__((unused)),
- void* user __attribute__((unused)))
+ const FLAC__StreamDecoder* stream __attribute__((unused)),
+ FLAC__StreamDecoderErrorStatus status __attribute__((unused)),
+ void* user __attribute__((unused)))
{
- DebugLevel0Fn(" %s\n" _C_ FLAC__StreamDecoderErrorStatusString[status]);
+ DebugLevel0Fn(" %s\n" _C_ FLAC__StreamDecoderErrorStatusString[status]);
}
/**
-** Read callback from FLAC stream decoder.
+** Read callback from FLAC stream decoder.
**
-** @param stream Decoder stream.
-** @param buffer Buffer to be filled.
-** @param bytes Number of bytes to be filled.
-** @param user User data.
+** @param stream Decoder stream.
+** @param buffer Buffer to be filled.
+** @param bytes Number of bytes to be filled.
+** @param user User data.
**
-** @return Error status.
+** @return Error status.
*/
local FLAC__StreamDecoderReadStatus FLAC_read_callback(
- const FLAC__StreamDecoder * stream __attribute__((unused)),
- FLAC__byte buffer[], unsigned int *bytes, void *user)
+ const FLAC__StreamDecoder * stream __attribute__((unused)),
+ FLAC__byte buffer[], unsigned int *bytes, void *user)
{
- unsigned i;
- CLFile* f;
- FlacData* data;
-
- DebugLevel3Fn("Read callback %d\n" _C_ *bytes);
-
- data = (FlacData*)user;
- f = data->FlacFile;
-
- if ((i = CLread(f, buffer, *bytes)) != *bytes) {
- *bytes = i;
- if (!i) {
- return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ unsigned i;
+ CLFile* f;
+ FlacData* data;
+
+ DebugLevel3Fn("Read callback %d\n" _C_ *bytes);
+
+ data = (FlacData*)user;
+ f = data->FlacFile;
+
+ if ((i = CLread(f, buffer, *bytes)) != *bytes) {
+ *bytes = i;
+ if (!i) {
+ return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
+ }
}
- }
- return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
+ return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
}
/**
-** Write callback from FLAC stream decoder.
+** Write callback from FLAC stream decoder.
**
-** @param stream Decoder stream.
-** @param metadata metadata block
-** @param user User data.
+** @param stream Decoder stream.
+** @param metadata metadata block
+** @param user User data.
*/
local void FLAC_metadata_callback(
- const FLAC__StreamDecoder* stream __attribute__((unused)),
- const FLAC__StreamMetadata* metadata, void *user)
+ const FLAC__StreamDecoder* stream __attribute__((unused)),
+ const FLAC__StreamMetadata* metadata, void *user)
{
- Sample* sample;
- int rate;
+ Sample* sample;
+ int rate;
- if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
- sample = ((FlacData*)user)->Sample;
+ if (metadata->type == FLAC__METADATA_TYPE_STREAMINFO) {
+ sample = ((FlacData*)user)->Sample;
- sample->Channels = metadata->data.stream_info.channels;
- sample->Frequency = metadata->data.stream_info.sample_rate;
- sample->SampleSize = metadata->data.stream_info.bits_per_sample;
+ sample->Channels = metadata->data.stream_info.channels;
+ sample->Frequency = metadata->data.stream_info.sample_rate;
+ sample->SampleSize = metadata->data.stream_info.bits_per_sample;
+
+ rate = 44100 / sample->Frequency;
+ // will overbuffer, so double the amount to allocate
+ sample = realloc(sample, sizeof(*sample) + 2 * rate *
FLAC_BUFFER_SIZE);
+ ((FlacData*)(sample->User))->Sample = sample;
+ ((FlacData*)(sample->User))->PointerInBuffer = sample->Data;
- rate = 44100 / sample->Frequency;
- // will overbuffer, so double the amount to allocate
- sample = realloc(sample, sizeof(*sample) + 2 * rate * FLAC_BUFFER_SIZE);
- ((FlacData*)(sample->User))->Sample = sample;
- ((FlacData*)(sample->User))->PointerInBuffer = sample->Data;
-
- DebugLevel3Fn("Stream %d Channels, %d frequency, %d bits\n" _C_
- sample->Channels _C_ sample->Frequency _C_ sample->SampleSize);
- }
+ DebugLevel3Fn("Stream %d Channels, %d frequency, %d bits\n" _C_
+ sample->Channels _C_ sample->Frequency _C_
sample->SampleSize);
+ }
}
/**
-** Write callback from FLAC stream decoder.
+** Write callback from FLAC stream decoder.
**
-** @param stream Decoder stream.
-** @param frame Frame to decode.
-** @param buffer Buffer to be filled.
-** @param user User data.
+** @param stream Decoder stream.
+** @param frame Frame to decode.
+** @param buffer Buffer to be filled.
+** @param user User data.
**
-** @return Error status.
+** @return Error status.
*/
local FLAC__StreamDecoderWriteStatus FLAC_write_callback(
- const FLAC__StreamDecoder* stream __attribute__((unused)),
- const FLAC__Frame* frame, const FLAC__int32* const buffer[], void* user)
+ const FLAC__StreamDecoder* stream __attribute__((unused)),
+ const FLAC__Frame* frame, const FLAC__int32* const buffer[], void* user)
{
- FlacData* data;
- Sample* sample;
- unsigned i;
- unsigned channel;
- void* p;
- int rate;
- int y;
-
- DebugLevel3Fn("Write callback %d bits, %d channel, %d bytes\n" _C_
- frame->header.bits_per_sample _C_ frame->header.channels _C_
- frame->header.blocksize);
-
- data = (FlacData*)user;
-
- sample = data->Sample;
- DebugCheck(frame->header.bits_per_sample != sample->SampleSize);
-
- i = frame->header.channels * frame->header.blocksize *
- frame->header.bits_per_sample / 8;
-
- rate = 44100 / sample->Frequency;
-
- if (sample->Type == &FlacSampleType) {
- // not streaming
- sample = realloc(sample, sizeof(*sample) + sample->Length + i * rate);
- if (!sample) {
- fprintf(stderr, "Out of memory!\n");
- CLclose(data->FlacFile);
- ExitFatal(-1);
- }
- data->Sample = sample;
- data->PointerInBuffer = sample->Data;
- }
+ FlacData* data;
+ Sample* sample;
+ unsigned i;
+ unsigned channel;
+ void* p;
+ int rate;
+ int y;
+
+ DebugLevel3Fn("Write callback %d bits, %d channel, %d bytes\n" _C_
+ frame->header.bits_per_sample _C_ frame->header.channels _C_
+ frame->header.blocksize);
- p = sample->Data + sample->Length;
- sample->Length += i * rate;
- data->Bytes -= i * rate;
-
- switch (sample->SampleSize) {
- case 8:
- for (i = 0; i < frame->header.blocksize; ++i) {
- for (y = 0; y < rate; ++y) {
- for (channel = 0; channel < frame->header.channels;
channel++) {
- *((unsigned char*)p)++ = buffer[channel][i] + 128;
- }
- }
- }
- break;
- case 16:
- for (i = 0; i < frame->header.blocksize; ++i) {
- for (y = 0; y < rate; ++y) {
- for (channel = 0; channel < frame->header.channels;
channel++) {
- *((short*)p)++ = buffer[channel][i];
- }
+ data = (FlacData*)user;
+
+ sample = data->Sample;
+ DebugCheck(frame->header.bits_per_sample != sample->SampleSize);
+
+ i = frame->header.channels * frame->header.blocksize *
+ frame->header.bits_per_sample / 8;
+
+ rate = 44100 / sample->Frequency;
+
+ if (sample->Type == &FlacSampleType) {
+ // not streaming
+ sample = realloc(sample, sizeof(*sample) + sample->Length + i *
rate);
+ if (!sample) {
+ fprintf(stderr, "Out of memory!\n");
+ CLclose(data->FlacFile);
+ ExitFatal(-1);
}
- }
- break;
- default:
- fprintf(stderr, "Unsupported sample depth!\n");
- CLclose(data->FlacFile);
- ExitFatal(-1);
- }
+ data->Sample = sample;
+ data->PointerInBuffer = sample->Data;
+ }
+
+ p = sample->Data + sample->Length;
+ sample->Length += i * rate;
+ data->Bytes -= i * rate;
+
+ switch (sample->SampleSize) {
+ case 8:
+ for (i = 0; i < frame->header.blocksize; ++i) {
+ for (y = 0; y < rate; ++y) {
+ for (channel = 0; channel <
frame->header.channels; channel++) {
+ *((unsigned char*)p)++ =
buffer[channel][i] + 128;
+ }
+ }
+ }
+ break;
+ case 16:
+ for (i = 0; i < frame->header.blocksize; ++i) {
+ for (y = 0; y < rate; ++y) {
+ for (channel = 0; channel <
frame->header.channels; channel++) {
+ *((short*)p)++ =
buffer[channel][i];
+ }
+ }
+ }
+ break;
+ default:
+ fprintf(stderr, "Unsupported sample depth!\n");
+ CLclose(data->FlacFile);
+ ExitFatal(-1);
+ }
- return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
+ return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
/**
-** Type member function to read from the flac file
+** Type member function to read from the flac file
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int FlacRead(Sample* sample, void* buf, int len)
{
- char* pos;
+ char* pos;
- pos = ((FlacData*)sample->User)->PointerInBuffer;
+ pos = ((FlacData*)sample->User)->PointerInBuffer;
- if ((pos - sample->Data) + len > sample->Length) {
- len = sample->Length - (pos - sample->Data);
- }
- memcpy(buf, ((FlacData*)sample->User)->PointerInBuffer, len);
- ((FlacData*)sample->User)->PointerInBuffer += len;
+ if ((pos - sample->Data) + len > sample->Length) {
+ len = sample->Length - (pos - sample->Data);
+ }
+ memcpy(buf, ((FlacData*)sample->User)->PointerInBuffer, len);
+ ((FlacData*)sample->User)->PointerInBuffer += len;
- return len;
+ return len;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
-** Type member function to free an flac file
+** Type member function to free an flac file
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void FlacFree(Sample* sample)
{
#ifdef DEBUG
- AllocatedSoundMemory -= sample->Length;
+ AllocatedSoundMemory -= sample->Length;
#endif
- free(sample);
+ free(sample);
}
/**
-** Flac object type structure.
+** Flac object type structure.
*/
local const SampleType FlacSampleType = {
- FlacRead,
- FlacFree,
+ FlacRead,
+ FlacFree,
};
/**
-** Type member function to read from the flac file
+** Type member function to read from the flac file
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int FlacStreamRead(Sample* sample, void* buf, int len)
{
- FlacData* data;
+ FlacData* data;
- data = (FlacData*)sample->User;
+ data = (FlacData*)sample->User;
- while (FLAC__stream_decoder_get_state(data->Stream) !=
FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) {
- // read metadata
- FLAC__stream_decoder_process_single(data->Stream);
- }
+ while (FLAC__stream_decoder_get_state(data->Stream) !=
FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) {
+ // read metadata
+ FLAC__stream_decoder_process_single(data->Stream);
+ }
- if (data->PointerInBuffer - sample->Data + len > sample->Length) {
- // need to read new data
- sample->Length -= data->PointerInBuffer - sample->Data;
- memcpy(sample->Data, data->PointerInBuffer, sample->Length);
- data->PointerInBuffer = sample->Data;
+ if (data->PointerInBuffer - sample->Data + len > sample->Length) {
+ // need to read new data
+ sample->Length -= data->PointerInBuffer - sample->Data;
+ memcpy(sample->Data, data->PointerInBuffer, sample->Length);
+ data->PointerInBuffer = sample->Data;
- data->Bytes = FLAC_BUFFER_SIZE - sample->Length;
+ data->Bytes = FLAC_BUFFER_SIZE - sample->Length;
- while (data->Bytes > 0 && FLAC__stream_decoder_get_state(data->Stream)
!= FLAC__STREAM_DECODER_END_OF_STREAM) {
- FLAC__stream_decoder_process_single(data->Stream);
- }
+ while (data->Bytes > 0 &&
FLAC__stream_decoder_get_state(data->Stream) !=
FLAC__STREAM_DECODER_END_OF_STREAM) {
+ FLAC__stream_decoder_process_single(data->Stream);
+ }
- if (sample->Length < len) {
- len = sample->Length;
- }
- }
+ if (sample->Length < len) {
+ len = sample->Length;
+ }
+ }
- memcpy(buf, data->PointerInBuffer, len);
- data->PointerInBuffer += len;
- return len;
+ memcpy(buf, data->PointerInBuffer, len);
+ data->PointerInBuffer += len;
+ return len;
}
/**
-** Type member function to free an flac file
+** Type member function to free an flac file
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void FlacStreamFree(Sample* sample)
{
- FlacData* data;
+ FlacData* data;
#ifdef DEBUG
- AllocatedSoundMemory -= sizeof(*sample) + FLAC_BUFFER_SIZE;
+ AllocatedSoundMemory -= sizeof(*sample) + FLAC_BUFFER_SIZE;
#endif
- data = (FlacData*)sample->User;
- CLclose(data->FlacFile);
- FLAC__stream_decoder_finish(data->Stream);
- FLAC__stream_decoder_delete(data->Stream);
- free(data);
- free(sample);
+ data = (FlacData*)sample->User;
+ CLclose(data->FlacFile);
+ FLAC__stream_decoder_finish(data->Stream);
+ FLAC__stream_decoder_delete(data->Stream);
+ free(data);
+ free(sample);
}
/**
-** Flac stream type structure.
+** Flac stream type structure.
*/
local const SampleType FlacStreamSampleType = {
- FlacStreamRead,
- FlacStreamFree,
+ FlacStreamRead,
+ FlacStreamFree,
};
/**
-** Load flac.
+** Load flac.
**
-** @param name File name.
-** @param flags Load flags.
+** @param name File name.
+** @param flags Load flags.
**
-** @return Returns the loaded sample.
+** @return Returns the loaded sample.
*/
global Sample* LoadFlac(const char* name, int flags)
{
- CLFile* f;
- Sample* sample;
- unsigned int magic[1];
- FLAC__StreamDecoder* stream;
- FlacData* data;
-
- if (!(f = CLopen(name, CL_OPEN_READ))) {
- fprintf(stderr, "Can't open file `%s'\n", name);
- return NULL;
- }
- CLread(f, magic, sizeof(magic));
- if (AccessLE32(magic) != 0x43614C66) { // "fLaC" in ASCII
+ CLFile* f;
+ Sample* sample;
+ unsigned int magic[1];
+ FLAC__StreamDecoder* stream;
+ FlacData* data;
+
+ if (!(f = CLopen(name, CL_OPEN_READ))) {
+ fprintf(stderr, "Can't open file `%s'\n", name);
+ return NULL;
+ }
+ CLread(f, magic, sizeof(magic));
+ if (AccessLE32(magic) != 0x43614C66) { // "fLaC" in ASCII
+ CLclose(f);
+ return NULL;
+ }
+
+ DebugLevel2Fn("Loading flac file: %s\n" _C_ name);
+
+ // FIXME: ugly way to seek to start of file
CLclose(f);
- return NULL;
- }
+ if (!(f = CLopen(name,CL_OPEN_READ))) {
+ fprintf(stderr, "Can't open file `%s'\n", name);
+ return NULL;
+ }
- DebugLevel2Fn("Loading flac file: %s\n" _C_ name);
+ if (!(stream = FLAC__stream_decoder_new())) {
+ fprintf(stderr, "Can't initialize flac decoder\n");
+ CLclose(f);
+ return NULL;
+ }
- // FIXME: ugly way to seek to start of file
- CLclose(f);
- if (!(f = CLopen(name,CL_OPEN_READ))) {
- fprintf(stderr, "Can't open file `%s'\n", name);
- return NULL;
- }
+ sample = malloc(sizeof(*sample) + 2 * FLAC_BUFFER_SIZE);
- if (!(stream = FLAC__stream_decoder_new())) {
- fprintf(stderr, "Can't initialize flac decoder\n");
- CLclose(f);
- return NULL;
- }
+ data = malloc(sizeof(FlacData));
+ data->FlacFile = f;
+ data->PointerInBuffer = sample->Data;
+ data->Sample = sample;
+ data->Stream = stream;
+ data->Bytes = 0;
- sample = malloc(sizeof(*sample) + 2 * FLAC_BUFFER_SIZE);
+ sample->User = data;
+ sample->Length = 0;
- data = malloc(sizeof(FlacData));
- data->FlacFile = f;
- data->PointerInBuffer = sample->Data;
- data->Sample = sample;
- data->Stream = stream;
- data->Bytes = 0;
-
- sample->User = data;
- sample->Length = 0;
-
- FLAC__stream_decoder_set_read_callback(stream, FLAC_read_callback);
- FLAC__stream_decoder_set_write_callback(stream, FLAC_write_callback);
- FLAC__stream_decoder_set_metadata_callback(stream, FLAC_metadata_callback);
- FLAC__stream_decoder_set_error_callback(stream, FLAC_error_callback);
- FLAC__stream_decoder_set_client_data(stream, data);
- FLAC__stream_decoder_init(stream);
-
- if (flags & PlayAudioStream) {
- sample->Type = &FlacStreamSampleType;
-
- FLAC__stream_decoder_process_until_end_of_metadata(stream);
- } else {
- sample->Type = &FlacSampleType;
-
- DebugCheck(FLAC__stream_decoder_get_state(stream) !=
- FLAC__STREAM_DECODER_SEARCH_FOR_METADATA);
- FLAC__stream_decoder_process_until_end_of_stream(stream);
- DebugCheck(FLAC__stream_decoder_get_state(stream) !=
- FLAC__STREAM_DECODER_END_OF_STREAM);
-
- FLAC__stream_decoder_finish(stream);
- FLAC__stream_decoder_delete(stream);
- CLclose(f);
- }
- return data->Sample;
+ FLAC__stream_decoder_set_read_callback(stream, FLAC_read_callback);
+ FLAC__stream_decoder_set_write_callback(stream, FLAC_write_callback);
+ FLAC__stream_decoder_set_metadata_callback(stream,
FLAC_metadata_callback);
+ FLAC__stream_decoder_set_error_callback(stream, FLAC_error_callback);
+ FLAC__stream_decoder_set_client_data(stream, data);
+ FLAC__stream_decoder_init(stream);
+
+ if (flags & PlayAudioStream) {
+ sample->Type = &FlacStreamSampleType;
+
+ FLAC__stream_decoder_process_until_end_of_metadata(stream);
+ } else {
+ sample->Type = &FlacSampleType;
+
+ DebugCheck(FLAC__stream_decoder_get_state(stream) !=
+ FLAC__STREAM_DECODER_SEARCH_FOR_METADATA);
+ FLAC__stream_decoder_process_until_end_of_stream(stream);
+ DebugCheck(FLAC__stream_decoder_get_state(stream) !=
+ FLAC__STREAM_DECODER_END_OF_STREAM);
+
+ FLAC__stream_decoder_finish(stream);
+ FLAC__stream_decoder_delete(stream);
+ CLclose(f);
+ }
+ return data->Sample;
}
-#endif // } WITH_SOUND && USE_FLAC
+#endif // } WITH_SOUND && USE_FLAC
//@}
Index: stratagus/src/sound/libcda.c
diff -u stratagus/src/sound/libcda.c:1.5 stratagus/src/sound/libcda.c:1.6
--- stratagus/src/sound/libcda.c:1.5 Thu Oct 2 07:00:59 2003
+++ stratagus/src/sound/libcda.c Tue Dec 23 14:48:03 2003
@@ -15,8 +15,8 @@
#include "libcda.h"
-/* It appears not all drivers support the CDROMPLAYTRKIND ioctl yet
- * (unfortunately). Until then, we use CDROMPLAYMSF.
+/* It appears not all drivers support the CDROMPLAYTRKIND ioctl yet
+ * (unfortunately). Until then, we use CDROMPLAYMSF.
*/
#define USE_PLAYMSF
@@ -34,36 +34,36 @@
static void copy_cd_error(void)
{
- strncpy(_cd_error, strerror(errno), sizeof(_cd_error));
- _cd_error[sizeof _cd_error - 1] = 0;
+ strncpy(_cd_error, strerror(errno), sizeof(_cd_error));
+ _cd_error[sizeof _cd_error - 1] = 0;
}
static int get_tocentry(int track, struct cdrom_tocentry* e)
{
- memset(e, 0, sizeof(struct cdrom_tocentry));
- e->cdte_track = track;
- e->cdte_format = CDROM_MSF;
-
- if (ioctl(fd, CDROMREADTOCENTRY, e) < 0) {
- copy_cd_error();
- return -1;
- }
-
- return 0;
+ memset(e, 0, sizeof(struct cdrom_tocentry));
+ e->cdte_track = track;
+ e->cdte_format = CDROM_MSF;
+
+ if (ioctl(fd, CDROMREADTOCENTRY, e) < 0) {
+ copy_cd_error();
+ return -1;
+ }
+
+ return 0;
}
static int get_subchnl(struct cdrom_subchnl* s)
{
- memset(s, 0, sizeof(struct cdrom_subchnl));
- s->cdsc_format = CDROM_MSF;
- if (ioctl(fd, CDROMSUBCHNL, s) < 0) {
- copy_cd_error();
- return -1;
- }
-
- return 0;
+ memset(s, 0, sizeof(struct cdrom_subchnl));
+ s->cdsc_format = CDROM_MSF;
+ if (ioctl(fd, CDROMSUBCHNL, s) < 0) {
+ copy_cd_error();
+ return -1;
+ }
+
+ return 0;
}
@@ -72,24 +72,24 @@
*/
int cd_init(void)
{
- char *device;
+ char *device;
+
+ device = getenv("CDAUDIO");
+ if (!device) {
+ device = "/dev/cdrom";
+ }
+
+ if (fd != -1) {
+ close(fd);
+ }
- device = getenv("CDAUDIO");
- if (!device) {
- device = "/dev/cdrom";
- }
-
- if (fd != -1) {
- close(fd);
- }
-
- fd = open(device, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- copy_cd_error();
- return -1;
- }
-
- return 0;
+ fd = open(device, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ copy_cd_error();
+ return -1;
+ }
+
+ return 0;
}
@@ -98,60 +98,60 @@
*/
void cd_exit(void)
{
- if (fd != -1) {
- close(fd);
- fd = -1;
- }
+ if (fd != -1) {
+ close(fd);
+ fd = -1;
+ }
}
static int play(int t1, int t2)
{
#ifdef USE_PLAYMSF
- struct cdrom_tocentry e0, e1;
- struct cdrom_msf msf;
- int last;
-
- if (cd_get_tracks(0, &last) != 0)
- return -1;
-
- /* cdrom.h: The leadout track is always 0xAA, regardless
- * of # of tracks on disc. */
- if (t2 == last) {
- t2 = CDROM_LEADOUT;
- } else {
- ++t2;
- }
-
- if ((get_tocentry(t1, &e0) != 0) || (get_tocentry(t2, &e1) != 0)) {
- return -1;
- }
-
- msf.cdmsf_min0 = e0.cdte_addr.msf.minute;
- msf.cdmsf_sec0 = e0.cdte_addr.msf.second;
- msf.cdmsf_frame0 = e0.cdte_addr.msf.frame;
- msf.cdmsf_min1 = e1.cdte_addr.msf.minute;
- msf.cdmsf_sec1 = e1.cdte_addr.msf.second;
- msf.cdmsf_frame1 = e1.cdte_addr.msf.frame;
-
- if (ioctl(fd, CDROMPLAYMSF, &msf) < 0) {
- copy_cd_error();
- return -1;
- }
-
- return 0;
+ struct cdrom_tocentry e0, e1;
+ struct cdrom_msf msf;
+ int last;
+
+ if (cd_get_tracks(0, &last) != 0)
+ return -1;
+
+ /* cdrom.h: The leadout track is always 0xAA, regardless
+ * of # of tracks on disc. */
+ if (t2 == last) {
+ t2 = CDROM_LEADOUT;
+ } else {
+ ++t2;
+ }
+
+ if ((get_tocentry(t1, &e0) != 0) || (get_tocentry(t2, &e1) != 0)) {
+ return -1;
+ }
+
+ msf.cdmsf_min0 = e0.cdte_addr.msf.minute;
+ msf.cdmsf_sec0 = e0.cdte_addr.msf.second;
+ msf.cdmsf_frame0 = e0.cdte_addr.msf.frame;
+ msf.cdmsf_min1 = e1.cdte_addr.msf.minute;
+ msf.cdmsf_sec1 = e1.cdte_addr.msf.second;
+ msf.cdmsf_frame1 = e1.cdte_addr.msf.frame;
+
+ if (ioctl(fd, CDROMPLAYMSF, &msf) < 0) {
+ copy_cd_error();
+ return -1;
+ }
+
+ return 0;
#else
- struct cdrom_ti idx;
+ struct cdrom_ti idx;
- memset(&idx, 0, sizeof(idx));
- idx.cdti_trk0 = t1;
- idx.cdti_trk1 = t2;
- if (ioctl(fd, CDROMPLAYTRKIND, &idx) < 0) {
- copy_cd_error();
- return -1;
- }
+ memset(&idx, 0, sizeof(idx));
+ idx.cdti_trk0 = t1;
+ idx.cdti_trk1 = t2;
+ if (ioctl(fd, CDROMPLAYTRKIND, &idx) < 0) {
+ copy_cd_error();
+ return -1;
+ }
- return 0;
+ return 0;
#endif
}
@@ -161,7 +161,7 @@
*/
int cd_play(int track)
{
- return play(track, track);
+ return play(track, track);
}
@@ -170,7 +170,7 @@
*/
int cd_play_range(int start, int end)
{
- return play(start, end);
+ return play(start, end);
}
@@ -179,13 +179,13 @@
*/
int cd_play_from(int track)
{
- int last;
-
- if (cd_get_tracks(0, &last) != 0) {
- return -1;
- }
-
- return play(track, last);
+ int last;
+
+ if (cd_get_tracks(0, &last) != 0) {
+ return -1;
+ }
+
+ return play(track, last);
}
@@ -194,14 +194,14 @@
*/
int cd_current_track(void)
{
- struct cdrom_subchnl s;
+ struct cdrom_subchnl s;
- get_subchnl(&s);
- if (s.cdsc_audiostatus == CDROM_AUDIO_PLAY) {
- return s.cdsc_trk;
- } else {
- return 0;
- }
+ get_subchnl(&s);
+ if (s.cdsc_audiostatus == CDROM_AUDIO_PLAY) {
+ return s.cdsc_trk;
+ } else {
+ return 0;
+ }
}
@@ -210,7 +210,7 @@
*/
void cd_pause(void)
{
- ioctl(fd, CDROMPAUSE);
+ ioctl(fd, CDROMPAUSE);
}
@@ -219,9 +219,9 @@
*/
void cd_resume(void)
{
- if (cd_is_paused()) {
- ioctl(fd, CDROMRESUME);
- }
+ if (cd_is_paused()) {
+ ioctl(fd, CDROMRESUME);
+ }
}
@@ -230,10 +230,10 @@
*/
int cd_is_paused(void)
{
- struct cdrom_subchnl s;
+ struct cdrom_subchnl s;
- get_subchnl(&s);
- return (s.cdsc_audiostatus == CDROM_AUDIO_PAUSED);
+ get_subchnl(&s);
+ return (s.cdsc_audiostatus == CDROM_AUDIO_PAUSED);
}
@@ -242,7 +242,7 @@
*/
void cd_stop(void)
{
- ioctl(fd, CDROMSTOP);
+ ioctl(fd, CDROMSTOP);
}
@@ -251,26 +251,26 @@
*/
int cd_get_tracks(int* first, int* last)
{
- struct cdrom_tochdr toc;
+ struct cdrom_tochdr toc;
+
+ if (ioctl(fd, CDROMREADTOCHDR, &toc) < 0) {
+ copy_cd_error();
+ if (first) {
+ *first = 0;
+ }
+ if (last) {
+ *last = 0;
+ }
+ return -1;
+ }
- if (ioctl(fd, CDROMREADTOCHDR, &toc) < 0) {
- copy_cd_error();
if (first) {
- *first = 0;
+ *first = toc.cdth_trk0;
}
if (last) {
- *last = 0;
+ *last = toc.cdth_trk1;
}
- return -1;
- }
-
- if (first) {
- *first = toc.cdth_trk0;
- }
- if (last) {
- *last = toc.cdth_trk1;
- }
- return 0;
+ return 0;
}
@@ -280,12 +280,12 @@
*/
int cd_is_audio(int track)
{
- struct cdrom_tocentry e;
+ struct cdrom_tocentry e;
- if ((cd_get_tracks(0, 0) < 0) || (get_tocentry(track, &e) < 0)) {
- return -1;
- }
- return (e.cdte_ctrl & CDROM_DATA_TRACK) ? 0 : 1;
+ if ((cd_get_tracks(0, 0) < 0) || (get_tocentry(track, &e) < 0)) {
+ return -1;
+ }
+ return (e.cdte_ctrl & CDROM_DATA_TRACK) ? 0 : 1;
}
@@ -294,15 +294,15 @@
*/
void cd_get_volume(int* c0, int* c1)
{
- struct cdrom_volctrl vol;
+ struct cdrom_volctrl vol;
- ioctl(fd, CDROMVOLREAD, &vol);
- if (c0) {
- *c0 = vol.channel0;
- }
- if (c1) {
- *c1 = vol.channel1;
- }
+ ioctl(fd, CDROMVOLREAD, &vol);
+ if (c0) {
+ *c0 = vol.channel0;
+ }
+ if (c1) {
+ *c1 = vol.channel1;
+ }
}
@@ -311,13 +311,13 @@
*/
void cd_set_volume(int c0, int c1)
{
- struct cdrom_volctrl vol;
+ struct cdrom_volctrl vol;
- vol.channel0 = MID(0, c0, 255);
- vol.channel1 = MID(0, c1, 255);
- vol.channel2 = 0;
- vol.channel3 = 0;
- ioctl(fd, CDROMVOLCTRL, &vol);
+ vol.channel0 = MID(0, c0, 255);
+ vol.channel1 = MID(0, c1, 255);
+ vol.channel2 = 0;
+ vol.channel3 = 0;
+ ioctl(fd, CDROMVOLCTRL, &vol);
}
@@ -326,7 +326,7 @@
*/
void cd_eject(void)
{
- ioctl(fd, CDROMEJECT);
+ ioctl(fd, CDROMEJECT);
}
@@ -335,7 +335,7 @@
*/
void cd_close(void)
{
- ioctl(fd, CDROMCLOSETRAY);
+ ioctl(fd, CDROMCLOSETRAY);
}
#endif // linux
@@ -345,7 +345,7 @@
* Using the string interface is probably slightly slower, but damned
* if I'm going to code using the message interface.
*
- * Peter Wang <address@hidden>
+ * Peter Wang <address@hidden>
*/
#include <stdio.h>
@@ -374,186 +374,186 @@
static int command(char *fmt, ...)
{
- char buf[256];
- va_list ap;
- DWORD err;
-
- va_start(ap, fmt);
- vsprintf(buf, fmt, ap);
- va_end(ap);
-
- err = mciSendString(buf, ret, sizeof ret, 0);
- if (err) {
- mciGetErrorString(err, _cd_error, sizeof _cd_error);
- }
- return err ? -1 : 0;
+ char buf[256];
+ va_list ap;
+ DWORD err;
+
+ va_start(ap, fmt);
+ vsprintf(buf, fmt, ap);
+ va_end(ap);
+
+ err = mciSendString(buf, ret, sizeof ret, 0);
+ if (err) {
+ mciGetErrorString(err, _cd_error, sizeof _cd_error);
+ }
+ return err ? -1 : 0;
}
int cd_init(void)
{
- int err;
+ int err;
- err = command("open cdaudio wait");
- if (!err) {
- err = command("set cdaudio time format tmsf");
- }
+ err = command("open cdaudio wait");
+ if (!err) {
+ err = command("set cdaudio time format tmsf");
+ }
- paused = 0;
- return err;
+ paused = 0;
+ return err;
}
void cd_exit(void)
{
- command("close cdaudio");
+ command("close cdaudio");
}
/* internal helpers */
-#define startof(track) (MCI_MAKE_TMSF(track, 0, 0, 0))
+#define startof(track) (MCI_MAKE_TMSF(track, 0, 0, 0))
static char *lengthof(int track)
{
- command("status cdaudio length track %u", track);
- return ret;
+ command("status cdaudio length track %u", track);
+ return ret;
}
int cd_play(int track)
{
- cd_stop();
- sprintf(end_pos, "%u:%s", track, lengthof(track));
- return command("play cdaudio from %lu to %s", startof(track), end_pos);
+ cd_stop();
+ sprintf(end_pos, "%u:%s", track, lengthof(track));
+ return command("play cdaudio from %lu to %s", startof(track), end_pos);
}
int cd_play_range(int start, int end)
{
- cd_stop();
- sprintf(end_pos, "%u:%s", end, lengthof(end));
- return command("play cdaudio from %lu to %s", startof(start), end_pos);
+ cd_stop();
+ sprintf(end_pos, "%u:%s", end, lengthof(end));
+ return command("play cdaudio from %lu to %s", startof(start), end_pos);
}
int cd_play_from(int track)
{
- cd_stop();
- end_pos[0] = 0;
- return command("play cdaudio from %lu", startof(track));
+ cd_stop();
+ end_pos[0] = 0;
+ return command("play cdaudio from %lu", startof(track));
}
int cd_current_track(void)
{
- if ((command("status cdaudio mode") != 0) ||
- (strcmp(ret, "playing") != 0)) {
- return 0;
- }
-
- if (command("status cdaudio current track") != 0) {
- return 0;
- }
- return atoi(ret);
+ if ((command("status cdaudio mode") != 0) ||
+ (strcmp(ret, "playing") != 0)) {
+ return 0;
+ }
+
+ if (command("status cdaudio current track") != 0) {
+ return 0;
+ }
+ return atoi(ret);
}
void cd_pause(void)
{
- /* `pause cdaudio' works like `stop' with the MCICDA driver.
- * Therefore we hack around it.
- */
- mciSendString("status cdaudio position", paused_pos, sizeof paused_pos, 0);
- command("pause cdaudio");
- paused = 1;
+ /* `pause cdaudio' works like `stop' with the MCICDA driver.
+ * Therefore we hack around it.
+ */
+ mciSendString("status cdaudio position", paused_pos, sizeof paused_pos,
0);
+ command("pause cdaudio");
+ paused = 1;
}
void cd_resume(void)
{
- if (!paused)
- return;
+ if (!paused)
+ return;
- if (end_pos[0]) {
- command("play cdaudio from %s to %s", paused_pos, end_pos);
- } else {
- command("play cdaudio from %s", paused_pos);
- }
- paused = 0;
+ if (end_pos[0]) {
+ command("play cdaudio from %s to %s", paused_pos, end_pos);
+ } else {
+ command("play cdaudio from %s", paused_pos);
+ }
+ paused = 0;
}
int cd_is_paused(void)
{
- return paused;
+ return paused;
}
void cd_stop(void)
{
- command("stop cdaudio wait");
- paused = 0;
+ command("stop cdaudio wait");
+ paused = 0;
}
int cd_get_tracks(int *first, int *last)
{
- int i;
-
- if (command("status cdaudio number of tracks") != 0)
- return -1;
-
- i = atoi(ret);
-
- if (first) {
- *first = 1;
- }
- if (last) {
- *last = i;
- }
-
- return (i) ? 0 : -1;
+ int i;
+
+ if (command("status cdaudio number of tracks") != 0)
+ return -1;
+
+ i = atoi(ret);
+
+ if (first) {
+ *first = 1;
+ }
+ if (last) {
+ *last = i;
+ }
+
+ return (i) ? 0 : -1;
}
int cd_is_audio(int track)
{
- if (command("status cdaudio type track %u", track) != 0) {
- return -1;
- }
- return (strcmp(ret, "audio") == 0) ? 1 : 0;
+ if (command("status cdaudio type track %u", track) != 0) {
+ return -1;
+ }
+ return (strcmp(ret, "audio") == 0) ? 1 : 0;
}
void cd_get_volume(int *c0, int *c1)
{
- if (c0) {
- *c0 = 128; /* (shrug) */
- }
- if (c1) {
- *c1 = 128;
- }
+ if (c0) {
+ *c0 = 128; /* (shrug) */
+ }
+ if (c1) {
+ *c1 = 128;
+ }
}
void cd_set_volume(int c0 __attribute__((unused)),
- int c1 __attribute__((unused)))
+ int c1 __attribute__((unused)))
{
}
void cd_eject(void)
{
- command("set cdaudio door open");
- paused = 0;
+ command("set cdaudio door open");
+ paused = 0;
}
void cd_close(void)
{
- command("set cdaudio door closed");
- paused = 0;
+ command("set cdaudio door closed");
+ paused = 0;
}
#endif // WIN32
#endif // USE_LIBCDA
Index: stratagus/src/sound/mad.c
diff -u stratagus/src/sound/mad.c:1.25 stratagus/src/sound/mad.c:1.26
--- stratagus/src/sound/mad.c:1.25 Thu Oct 2 07:01:00 2003
+++ stratagus/src/sound/mad.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,20 +26,20 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: mad.c,v 1.25 2003/10/01 21:01:00 jsalmon3 Exp $
+// $Id: mad.c,v 1.26 2003/12/23 03:48:03 jsalmon3 Exp $
// FIXME: JOHNS: MP3 streaming did not yet work.
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "stratagus.h"
-#if defined(WITH_SOUND) && defined(USE_MAD) // {
+#if defined(WITH_SOUND) && defined(USE_MAD) // {
#include <stdlib.h>
#include <string.h>
@@ -50,497 +50,497 @@
#include "sound_server.h"
/*----------------------------------------------------------------------------
--- Declaration
+-- Declaration
----------------------------------------------------------------------------*/
/**
-** My user data for mad callbacks.
+** My user data for mad callbacks.
*/
typedef struct _mad_user_ {
- CLFile* File; // File handle
- Sample* Sample; // Sample buffer
- unsigned char Buffer[4096]; // Decoded buffer
+ CLFile* File; // File handle
+ Sample* Sample; // Sample buffer
+ unsigned char Buffer[4096]; // Decoded
buffer
} MyUser;
/**
-** Private mp3 data structure to handle mp3 streaming.
+** Private mp3 data structure to handle mp3 streaming.
*/
typedef struct _mp3_data_ {
- char* PointerInBuffer; /// Pointer into buffer
- struct mad_decoder Decoder[1]; /// Mad decoder handle
- MyUser User[1]; /// Decoder user data
+ char* PointerInBuffer; ///
Pointer into buffer
+ struct mad_decoder Decoder[1];
/// Mad decoder handle
+ MyUser User[1];
/// Decoder user data
} Mp3Data;
-#define MP3_BUFFER_SIZE (12 * 1024) /// Buffer size to fill
+#define MP3_BUFFER_SIZE (12 * 1024) /// Buffer size
to fill
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** MAD read callback.
+** MAD read callback.
**
-** @param user Our user pointer.
-** @param stream MP3 stream.
+** @param user Our user pointer.
+** @param stream MP3 stream.
**
-** @return MAP_FLOW_STOP if eof, MAD_FLOW_CONTINUE otherwise.
+** @return MAP_FLOW_STOP if eof,
MAD_FLOW_CONTINUE otherwise.
*/
local enum mad_flow MAD_read(void* user, struct mad_stream* stream)
{
- int i;
- int l;
- CLFile* f;
- MyUser* u;
-
- DebugLevel3Fn("Read callback\n");
-
- u = (MyUser*) user;
- f = u->File;
-
- l = 0;
- // Copy remaining bytes over
- if (stream->next_frame) {
- memmove(u->Buffer, stream->next_frame,
- l = &u->Buffer[sizeof(u->Buffer)] - stream->next_frame);
- }
-
- i = CLread(f, u->Buffer + l, sizeof(u->Buffer) - l);
- //if (!(l + i)) {
- if (!i) {
- return MAD_FLOW_STOP;
- }
- DebugLevel3Fn("%d bytes\n" _C_ l + i);
- mad_stream_buffer(stream, u->Buffer, l + i);
+ int i;
+ int l;
+ CLFile* f;
+ MyUser* u;
+
+ DebugLevel3Fn("Read callback\n");
+
+ u = (MyUser*) user;
+ f = u->File;
+
+ l = 0;
+ // Copy remaining bytes over
+ if (stream->next_frame) {
+ memmove(u->Buffer, stream->next_frame,
+ l = &u->Buffer[sizeof(u->Buffer)] - stream->next_frame);
+ }
+
+ i = CLread(f, u->Buffer + l, sizeof(u->Buffer) - l);
+ //if (!(l + i)) {
+ if (!i) {
+ return MAD_FLOW_STOP;
+ }
+ DebugLevel3Fn("%d bytes\n" _C_ l + i);
+ mad_stream_buffer(stream, u->Buffer, l + i);
- return MAD_FLOW_CONTINUE;
+ return MAD_FLOW_CONTINUE;
}
/**
-** This is the output callback function. It is called after each frame of
-** MPEG audio data has been completely decoded. The purpose of this
-** callback is to output the decoded PCM audio.
-**
-** @param user User argument.
-** @param header MAD header.
-** @param pcm MAD pcm data struture.
+** This is the output callback function. It is called after each
frame of
+** MPEG audio data has been completely decoded. The purpose of this
+** callback is to output the decoded PCM audio.
+**
+** @param user User argument.
+** @param header MAD header.
+** @param pcm MAD pcm data struture.
*/
local enum mad_flow MAD_write(void* user,
- struct mad_header const* header __attribute__((unused)),
- struct mad_pcm* pcm)
+ struct mad_header const* header __attribute__((unused)),
+ struct mad_pcm* pcm)
{
- int i;
- int n;
- int c;
- int channels;
- Sample* sample;
- short* p;
-
- n = pcm->length;
- channels = pcm->channels;
-
- DebugLevel3Fn("%d channels %d samples\n" _C_ channels _C_ n);
-
- sample = ((MyUser*)user)->Sample;
-
- if (!sample->SampleSize) {
- sample->Frequency = pcm->samplerate;
- sample->Channels = channels;
- sample->SampleSize = 16;
- }
-
- i = n * channels * 2;
-
- ((MyUser*)user)->Sample = sample =
- realloc(sample, sizeof(*sample) + sample->Length + i);
- if (!sample) {
- fprintf(stderr, "Out of memory!\n");
- CLclose(((MyUser*) user)->File);
- ExitFatal(-1);
- }
- p = (short*)(sample->Data + sample->Length);
- sample->Length += i;
-
- for (i = 0; i < n; ++i) {
- for (c = 0; c < channels; ++c) {
- mad_fixed_t b;
-
- b = pcm->samples[c][i];
- // round
- b += (1L << (MAD_F_FRACBITS - 16));
- // clip
- if (b >= MAD_F_ONE) {
- b = MAD_F_ONE - 1;
- } else if (b < -MAD_F_ONE) {
- b = -MAD_F_ONE;
- }
- // quantize
- *p++ = b >> (MAD_F_FRACBITS + 1 - 16);
+ int i;
+ int n;
+ int c;
+ int channels;
+ Sample* sample;
+ short* p;
+
+ n = pcm->length;
+ channels = pcm->channels;
+
+ DebugLevel3Fn("%d channels %d samples\n" _C_ channels _C_ n);
+
+ sample = ((MyUser*)user)->Sample;
+
+ if (!sample->SampleSize) {
+ sample->Frequency = pcm->samplerate;
+ sample->Channels = channels;
+ sample->SampleSize = 16;
}
- }
- return MAD_FLOW_CONTINUE;
+ i = n * channels * 2;
+
+ ((MyUser*)user)->Sample = sample =
+ realloc(sample, sizeof(*sample) + sample->Length + i);
+ if (!sample) {
+ fprintf(stderr, "Out of memory!\n");
+ CLclose(((MyUser*) user)->File);
+ ExitFatal(-1);
+ }
+ p = (short*)(sample->Data + sample->Length);
+ sample->Length += i;
+
+ for (i = 0; i < n; ++i) {
+ for (c = 0; c < channels; ++c) {
+ mad_fixed_t b;
+
+ b = pcm->samples[c][i];
+ // round
+ b += (1L << (MAD_F_FRACBITS - 16));
+ // clip
+ if (b >= MAD_F_ONE) {
+ b = MAD_F_ONE - 1;
+ } else if (b < -MAD_F_ONE) {
+ b = -MAD_F_ONE;
+ }
+ // quantize
+ *p++ = b >> (MAD_F_FRACBITS + 1 - 16);
+ }
+ }
+
+ return MAD_FLOW_CONTINUE;
}
/**
-** This is the error callback function. It is called whenever a decoding
-** error occurs. The error is indicated by stream->error; the list of
-** possible MAD_ERROR_* errors can be found in the mad.h (or
-** libmad/stream.h) header file.
+** This is the error callback function. It is called whenever a
decoding
+** error occurs. The error is indicated by stream->error; the list
of
+** possible MAD_ERROR_* errors can be found in the mad.h (or
+** libmad/stream.h) header file.
*/
local enum mad_flow MAD_error(void* user __attribute__((unused)),
- struct mad_stream* stream,
- struct mad_frame* frame __attribute__((unused)))
+ struct mad_stream* stream,
+ struct mad_frame* frame __attribute__((unused)))
{
- fprintf(stderr, "decoding error 0x%04x (%s)\n",
- stream->error, mad_stream_errorstr(stream));
+ fprintf(stderr, "decoding error 0x%04x (%s)\n",
+ stream->error, mad_stream_errorstr(stream));
- return MAD_FLOW_BREAK;
+ return MAD_FLOW_BREAK;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
-** Read one frame from mad decoder.
+** Read one frame from mad decoder.
**
-** @param decoder Decoder
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param decoder Decoder
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int MadRead(struct mad_decoder* decoder, unsigned char* buf, int len)
{
- struct mad_stream* stream;
- struct mad_frame* frame;
- struct mad_synth* synth;
-
- DebugLevel0Fn("%p %p %d\n" _C_ decoder _C_ buf _C_ len);
-
- stream = &decoder->sync->stream;
- frame = &decoder->sync->frame;
- synth = &decoder->sync->synth;
- DebugLevel0Fn("Error: %d\n" _C_ stream->error);
- do {
- DebugLevel0Fn("Read stream\n");
- switch (MAD_read(decoder->cb_data, stream)) {
- case MAD_FLOW_STOP:
- return 0;
- case MAD_FLOW_BREAK:
- return -1;
- case MAD_FLOW_IGNORE:
- continue;
- case MAD_FLOW_CONTINUE:
- break;
- }
-
- while (1) {
- if (mad_frame_decode(frame, stream) == -1) {
- if (!MAD_RECOVERABLE(stream->error)) {
- break;
+ struct mad_stream* stream;
+ struct mad_frame* frame;
+ struct mad_synth* synth;
+
+ DebugLevel0Fn("%p %p %d\n" _C_ decoder _C_ buf _C_ len);
+
+ stream = &decoder->sync->stream;
+ frame = &decoder->sync->frame;
+ synth = &decoder->sync->synth;
+ DebugLevel0Fn("Error: %d\n" _C_ stream->error);
+ do {
+ DebugLevel0Fn("Read stream\n");
+ switch (MAD_read(decoder->cb_data, stream)) {
+ case MAD_FLOW_STOP:
+ return 0;
+ case MAD_FLOW_BREAK:
+ return -1;
+ case MAD_FLOW_IGNORE:
+ continue;
+ case MAD_FLOW_CONTINUE:
+ break;
}
- switch (MAD_error(decoder->cb_data, stream, frame)) {
- case MAD_FLOW_STOP:
- return 0;
- case MAD_FLOW_BREAK:
- return -1;
- case MAD_FLOW_IGNORE:
- break;
- case MAD_FLOW_CONTINUE:
- default:
- continue;
- }
- }
+ while (1) {
+ if (mad_frame_decode(frame, stream) == -1) {
+ if (!MAD_RECOVERABLE(stream->error)) {
+ break;
+ }
+
+ switch (MAD_error(decoder->cb_data, stream,
frame)) {
+ case MAD_FLOW_STOP:
+ return 0;
+ case MAD_FLOW_BREAK:
+ return -1;
+ case MAD_FLOW_IGNORE:
+ break;
+ case MAD_FLOW_CONTINUE:
+ default:
+ continue;
+ }
+ }
- mad_synth_frame(synth, frame);
+ mad_synth_frame(synth, frame);
#if 0
- // FIXME: write out the frame buffer!
- switch (decoder->output_func(decoder->cb_data, &frame->header,
- &synth->pcm)) {
- case MAD_FLOW_STOP:
- return 0;
- case MAD_FLOW_BREAK:
- return -1;
- case MAD_FLOW_IGNORE:
- case MAD_FLOW_CONTINUE:
- break;
- }
+ // FIXME: write out the frame buffer!
+ switch (decoder->output_func(decoder->cb_data,
&frame->header,
+ &synth->pcm)) {
+ case MAD_FLOW_STOP:
+ return 0;
+ case MAD_FLOW_BREAK:
+ return -1;
+ case MAD_FLOW_IGNORE:
+ case MAD_FLOW_CONTINUE:
+ break;
+ }
#endif
- }
- // Should stop here!
- } while (stream->error == MAD_ERROR_BUFLEN);
+ }
+ // Should stop here!
+ } while (stream->error == MAD_ERROR_BUFLEN);
- return -1;
+ return -1;
}
/**
-** Type member function to read from the mp3 file
+** Type member function to read from the mp3 file
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int Mp3ReadStream(Sample* sample, void* buf, int len)
{
- Mp3Data* data;
- int i;
- int n;
-
- DebugLevel0Fn("%p %d\n" _C_ buf _C_ len);
-
- data = sample->User;
-
- // see if we have enough read already
- if (data->PointerInBuffer - sample->Data + len > sample->Length) {
- // not enough in buffer, read more
- n = sample->Length - (data->PointerInBuffer - sample->Data);
- memcpy(sample->Data, data->PointerInBuffer, n);
- sample->Length = n;
- data->PointerInBuffer = sample->Data;
-
- n = MP3_BUFFER_SIZE - n;
- for (;;) {
- i = MadRead(data->Decoder, data->PointerInBuffer + sample->Length,
- n);
- if (i <= 0) {
- break;
- }
- sample->Length += i;
- n -= i;
- if (n < 4096) {
- break;
- }
- }
- if (sample->Length < len) {
- len = sample->Length;
- }
- }
-
- memcpy(buf, data->PointerInBuffer, len);
- data->PointerInBuffer += len;
- return len;
+ Mp3Data* data;
+ int i;
+ int n;
+
+ DebugLevel0Fn("%p %d\n" _C_ buf _C_ len);
+
+ data = sample->User;
+
+ // see if we have enough read already
+ if (data->PointerInBuffer - sample->Data + len > sample->Length) {
+ // not enough in buffer, read more
+ n = sample->Length - (data->PointerInBuffer - sample->Data);
+ memcpy(sample->Data, data->PointerInBuffer, n);
+ sample->Length = n;
+ data->PointerInBuffer = sample->Data;
+
+ n = MP3_BUFFER_SIZE - n;
+ for (;;) {
+ i = MadRead(data->Decoder, data->PointerInBuffer +
sample->Length,
+ n);
+ if (i <= 0) {
+ break;
+ }
+ sample->Length += i;
+ n -= i;
+ if (n < 4096) {
+ break;
+ }
+ }
+ if (sample->Length < len) {
+ len = sample->Length;
+ }
+ }
+
+ memcpy(buf, data->PointerInBuffer, len);
+ data->PointerInBuffer += len;
+ return len;
}
/**
-** Type member function to free an mp3 file
+** Type member function to free an mp3 file
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void Mp3FreeStream(Sample* sample)
{
- Mp3Data* data;
+ Mp3Data* data;
#ifdef DEBUG
- AllocatedSoundMemory -= sizeof(*sample) + MP3_BUFFER_SIZE;
+ AllocatedSoundMemory -= sizeof(*sample) + MP3_BUFFER_SIZE;
#endif
- data = sample->User;
-
- // release the decoder
+ data = sample->User;
- mad_synth_finish(data->Decoder->sync->synth);
- mad_frame_finish(&data->Decoder->sync->frame);
- mad_stream_finish(&data->Decoder->sync->stream);
+ // release the decoder
- free(data->Decoder->sync);
- data->Decoder->sync = NULL;
- mad_decoder_finish(data->Decoder);
+ mad_synth_finish(data->Decoder->sync->synth);
+ mad_frame_finish(&data->Decoder->sync->frame);
+ mad_stream_finish(&data->Decoder->sync->stream);
+
+ free(data->Decoder->sync);
+ data->Decoder->sync = NULL;
+ mad_decoder_finish(data->Decoder);
- CLclose(data->User->File);
+ CLclose(data->User->File);
- free(data);
- free(sample);
+ free(data);
+ free(sample);
}
/**
-** Mp3 object type structure.
+** Mp3 object type structure.
*/
local const SampleType Mp3StreamSampleType = {
- Mp3ReadStream,
- Mp3FreeStream,
+ Mp3ReadStream,
+ Mp3FreeStream,
};
/**
-** Type member function to read from the mp3 file
+** Type member function to read from the mp3 file
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int Mp3Read(Sample* sample, void* buf, int len)
{
- int pos;
+ int pos;
- pos = (int)sample->User;
- if (pos + len > sample->Length) { // Not enough data?
- len = sample->Length - pos;
- }
- memcpy(buf, sample->Data + pos, len);
+ pos = (int)sample->User;
+ if (pos + len > sample->Length) { // Not
enough data?
+ len = sample->Length - pos;
+ }
+ memcpy(buf, sample->Data + pos, len);
- sample->User = (void*)(pos + len);
+ sample->User = (void*)(pos + len);
- return len;
+ return len;
}
/**
-** Type member function to free an mp3 file
+** Type member function to free an mp3 file
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void Mp3Free(Sample* sample)
{
#ifdef DEBUG
- AllocatedSoundMemory -= sample->Length;
+ AllocatedSoundMemory -= sample->Length;
#endif
- free(sample);
+ free(sample);
}
/**
-** Mp3 object type structure.
+** Mp3 object type structure.
*/
local const SampleType Mp3SampleType = {
- Mp3Read,
- Mp3Free,
+ Mp3Read,
+ Mp3Free,
};
/**
-** Load mp3.
+** Load mp3.
**
-** @param name File name.
-** @param flags Load flags.
+** @param name File name.
+** @param flags Load flags.
**
-** @return Returns the loaded sample.
+** @return Returns the loaded sample.
**
-** @todo Support more flags, LoadOnDemand.
+** @todo Support more flags,
LoadOnDemand.
*/
global Sample* LoadMp3(const char* name, int flags)
{
- CLFile* f;
- unsigned char magic[2];
- Sample* sample;
-
- if (!(f = CLopen(name,CL_OPEN_READ))) {
- fprintf(stderr, "Can't open file `%s'\n", name);
- return NULL;
- }
- CLread(f, magic, sizeof(magic));
- // 0xFF 0xE? for mp3 stream
- if (magic[0] != 0xFF || (magic[1]&0xE0) != 0xE0) {
- CLclose(f);
- return NULL;
- }
+ CLFile* f;
+ unsigned char magic[2];
+ Sample* sample;
+
+ if (!(f = CLopen(name,CL_OPEN_READ))) {
+ fprintf(stderr, "Can't open file `%s'\n", name);
+ return NULL;
+ }
+ CLread(f, magic, sizeof(magic));
+ // 0xFF 0xE? for mp3 stream
+ if (magic[0] != 0xFF || (magic[1]&0xE0) != 0xE0) {
+ CLclose(f);
+ return NULL;
+ }
- // FIXME: ugly way to rewind.
- CLclose(f);
- if (!(f = CLopen(name,CL_OPEN_READ))) {
- fprintf(stderr, "Can't open file `%s'\n", name);
- return NULL;
- }
+ // FIXME: ugly way to rewind.
+ CLclose(f);
+ if (!(f = CLopen(name,CL_OPEN_READ))) {
+ fprintf(stderr, "Can't open file `%s'\n", name);
+ return NULL;
+ }
- DebugLevel2Fn("Have mp3 file %s\n" _C_ name);
+ DebugLevel2Fn("Have mp3 file %s\n" _C_ name);
#ifdef MP3_STREAM_WORKS
- if (flags & PlayAudioStream)
+ if (flags & PlayAudioStream)
#else
- if (0 && (flags & PlayAudioStream))
+ if (0 && (flags & PlayAudioStream))
#endif
- {
- Mp3Data* data;
+ {
+ Mp3Data* data;
- sample = malloc(sizeof(*sample) + MP3_BUFFER_SIZE);
- if (!sample) {
- fprintf(stderr, "Out of memory\n");
- CLclose(f);
- return NULL;
- }
- data = malloc(sizeof(*data));
- if (!data) {
- fprintf(stderr, "Out of memory\n");
- free(sample);
- CLclose(f);
- return NULL;
- }
- sample->User = data;
- sample->Channels = 0;
- sample->SampleSize = 0;
- sample->Frequency = 0;
- sample->Length = 0;
- sample->Type = &Mp3StreamSampleType;
-
- data->User->File = f;
- data->User->Sample = sample;
-
- // configure input, output, and error functions
-
- mad_decoder_init(data->Decoder, data->User,
- MAD_read, NULL /* header */, NULL /* filter */, MAD_write,
- MAD_error, NULL /* message */);
-
- data->Decoder->sync = malloc(sizeof(*data->Decoder->sync));
- if (!data->Decoder->sync) {
- fprintf(stderr, "Out of memory\n");
- mad_decoder_finish(data->Decoder);
- free(data);
- free(sample);
- CLclose(f);
- return NULL;
- }
-
- mad_stream_init(&data->Decoder->sync->stream);
- mad_frame_init(&data->Decoder->sync->frame);
- mad_synth_init(&data->Decoder->sync->synth);
- mad_stream_options(&data->Decoder->sync->stream,
- data->Decoder->options);
-
- // Read first frame for channels, ...
- data->PointerInBuffer = sample->Data;
- sample->Length = MadRead(data->Decoder, sample->Data, MP3_BUFFER_SIZE);
+ sample = malloc(sizeof(*sample) + MP3_BUFFER_SIZE);
+ if (!sample) {
+ fprintf(stderr, "Out of memory\n");
+ CLclose(f);
+ return NULL;
+ }
+ data = malloc(sizeof(*data));
+ if (!data) {
+ fprintf(stderr, "Out of memory\n");
+ free(sample);
+ CLclose(f);
+ return NULL;
+ }
+ sample->User = data;
+ sample->Channels = 0;
+ sample->SampleSize = 0;
+ sample->Frequency = 0;
+ sample->Length = 0;
+ sample->Type = &Mp3StreamSampleType;
+
+ data->User->File = f;
+ data->User->Sample = sample;
+
+ // configure input, output, and error functions
+
+ mad_decoder_init(data->Decoder, data->User,
+ MAD_read, NULL /* header */, NULL /* filter */,
MAD_write,
+ MAD_error, NULL /* message */);
+
+ data->Decoder->sync = malloc(sizeof(*data->Decoder->sync));
+ if (!data->Decoder->sync) {
+ fprintf(stderr, "Out of memory\n");
+ mad_decoder_finish(data->Decoder);
+ free(data);
+ free(sample);
+ CLclose(f);
+ return NULL;
+ }
- DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + MP3_BUFFER_SIZE);
+ mad_stream_init(&data->Decoder->sync->stream);
+ mad_frame_init(&data->Decoder->sync->frame);
+ mad_synth_init(&data->Decoder->sync->synth);
+ mad_stream_options(&data->Decoder->sync->stream,
+ data->Decoder->options);
+
+ // Read first frame for channels, ...
+ data->PointerInBuffer = sample->Data;
+ sample->Length = MadRead(data->Decoder, sample->Data,
MP3_BUFFER_SIZE);
+
+ DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + MP3_BUFFER_SIZE);
#ifdef DEBUG
- AllocatedSoundMemory += sizeof(*sample) + MP3_BUFFER_SIZE;
+ AllocatedSoundMemory += sizeof(*sample) + MP3_BUFFER_SIZE;
#endif
- return sample;
- } else {
- MyUser user;
- struct mad_decoder decoder;
-
- sample = calloc(1, sizeof(*sample));
- user.File = f;
- user.Sample = sample;
-
- // configure input, output, and error functions
-
- mad_decoder_init(&decoder, &user,
- MAD_read, NULL /* header */, NULL /* filter */, MAD_write,
- MAD_error, NULL /* message */);
+ return sample;
+ } else {
+ MyUser user;
+ struct mad_decoder decoder;
- mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
+ sample = calloc(1, sizeof(*sample));
+ user.File = f;
+ user.Sample = sample;
- // release the decoder
- mad_decoder_finish(&decoder);
- CLclose(f);
+ // configure input, output, and error functions
+
+ mad_decoder_init(&decoder, &user,
+ MAD_read, NULL /* header */, NULL /* filter */,
MAD_write,
+ MAD_error, NULL /* message */);
+
+ mad_decoder_run(&decoder, MAD_DECODER_MODE_SYNC);
- user.Sample->Type = &Mp3SampleType;
- user.Sample->User = 0;
+ // release the decoder
+ mad_decoder_finish(&decoder);
+ CLclose(f);
- DebugLevel0Fn(" %d\n" _C_ user.Sample->Length);
+ user.Sample->Type = &Mp3SampleType;
+ user.Sample->User = 0;
+
+ DebugLevel0Fn(" %d\n" _C_ user.Sample->Length);
#ifdef DEBUG
- AllocatedSoundMemory += user.Sample->Length;
+ AllocatedSoundMemory += user.Sample->Length;
#endif
- return user.Sample;
- }
+ return user.Sample;
+ }
}
-#endif // } WITH_SOUND && USE_MAD
+#endif // } WITH_SOUND && USE_MAD
//@}
Index: stratagus/src/sound/music.c
diff -u stratagus/src/sound/music.c:1.84 stratagus/src/sound/music.c:1.85
--- stratagus/src/sound/music.c:1.84 Tue Dec 2 04:22:17 2003
+++ stratagus/src/sound/music.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,18 +26,18 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: music.c,v 1.84 2003/12/01 17:22:17 jsalmon3 Exp $
+// $Id: music.c,v 1.85 2003/12/23 03:48:03 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "stratagus.h"
-#if defined(WITH_SOUND) // {
+#if defined(WITH_SOUND) // {
#include <stdlib.h>
#include <string.h>
@@ -60,370 +60,370 @@
#include "cdaudio.h"
/*----------------------------------------------------------------------------
--- Declaration
+-- Declaration
----------------------------------------------------------------------------*/
-#define SoundFrequency 44100 // sample rate of dsp
+#define SoundFrequency 44100 // sample rate
of dsp
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
#if defined(USE_OGG) || defined(USE_FLAC) || defined(USE_MAD) ||
defined(USE_LIBMODPLUG)
-global Sample* MusicSample; /// Music samples
+global Sample* MusicSample; /// Music samples
#endif
global char* CurrentMusicFile;
-global PlaySection* PlaySections; // Play Sections
-global int NumPlaySections; // Number of Play Sections
-global PlaySectionType CurrentPlaySection; // Current Play Section
+global PlaySection* PlaySections; // Play Sections
+global int NumPlaySections; //
Number of Play Sections
+global PlaySectionType CurrentPlaySection; // Current Play Section
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Stop the current playing music.
+** Stop the current playing music.
**
-** @todo FIXME: Stop the CD-PLAYER.
+** @todo FIXME: Stop the CD-PLAYER.
*/
global void StopMusic(void)
{
- if (PlayingMusic) {
- PlayingMusic = 0; // Callback!
+ if (PlayingMusic) {
+ PlayingMusic = 0; // Callback!
#if defined(USE_OGG) || defined(USE_FLAC) || defined(USE_MAD) ||
defined(USE_LIBMODPLUG)
- if (MusicSample) {
+ if (MusicSample) {
#ifdef USE_SDL
- SDL_LockAudio();
+ SDL_LockAudio();
#endif
- SoundFree(MusicSample);
- MusicSample = NULL;
+ SoundFree(MusicSample);
+ MusicSample = NULL;
#ifdef USE_SDL
- SDL_UnlockAudio();
+ SDL_UnlockAudio();
#endif
- return;
- }
+ return;
+ }
#endif
- }
+ }
}
#ifdef USE_LIBMODPLUG
/**
-** Read next samples from libmodplug object.
+** Read next samples from libmodplug object.
**
-** @param o pointer to object.
-** @param buf buffer to fill.
-** @param len length of buffer in bytes.
+** @param o pointer to object.
+** @param buf buffer to fill.
+** @param len length of buffer in bytes.
**
-** @return Number of bytes filled.
+** @return Number of bytes filled.
*/
local int ModRead(Sample* o, void* buf, int len)
{
- return ModPlug_Read(o->User, buf, len);
+ return ModPlug_Read(o->User, buf, len);
}
/**
-** Free the sample of libmodplug object.
+** Free the sample of libmodplug object.
**
-** @param o pointer to object.
+** @param o pointer to object.
*/
local void ModFree(Sample* o)
{
- ModPlug_Unload(o->User);
- free(o);
+ ModPlug_Unload(o->User);
+ free(o);
}
/**
-** Libmodplug object type structure.
+** Libmodplug object type structure.
*/
local const SampleType ModSampleType = {
- ModRead,
- ModFree,
+ ModRead,
+ ModFree,
};
/**
-** Load a mod file.
+** Load a mod file.
**
-** @param name A possible mod file.
-** @param flags Load flags.
+** @param name A possible mod file.
+** @param flags Load flags.
**
-** @return Sample to mix the mod, if the file is a mod.
+** @return Sample to mix the mod, if the
file is a mod.
**
-** @todo If CL supports file size query, loading can be done
-** faster, perhaps we can rewrite modplug to support
-** streaming.
+** @todo If CL supports file size query,
loading can be done
+** faster, perhaps we can rewrite
modplug to support
+** streaming.
*/
local Sample* LoadMod(const char* name,int flags __attribute__((unused)))
{
- ModPlug_Settings settings;
- ModPlugFile* modfile;
- Sample* sample;
- CLFile* f;
- char* buffer;
- int size;
- int i;
- int ticks;
- int n;
-
- ticks = GetTicks();
- DebugLevel0Fn("Trying `%s'\n" _C_ name);
- if (!(f = CLopen(name,CL_OPEN_READ))) {
- printf("Can't open file `%s'\n", name);
- return NULL;
- }
+ ModPlug_Settings settings;
+ ModPlugFile* modfile;
+ Sample* sample;
+ CLFile* f;
+ char* buffer;
+ int size;
+ int i;
+ int ticks;
+ int n;
+
+ ticks = GetTicks();
+ DebugLevel0Fn("Trying `%s'\n" _C_ name);
+ if (!(f = CLopen(name,CL_OPEN_READ))) {
+ printf("Can't open file `%s'\n", name);
+ return NULL;
+ }
- // Load complete file into memory, with realloc = slow
- size = 0;
- n = 16384;
- buffer = malloc(n);
- while ((i = CLread(f, buffer + size, n)) == n) {
- size += n;
- if (n < 1024 * 1024) {
- n <<= 1;
- } else {
- n = 2 * 1024 * 1024;
+ // Load complete file into memory, with realloc = slow
+ size = 0;
+ n = 16384;
+ buffer = malloc(n);
+ while ((i = CLread(f, buffer + size, n)) == n) {
+ size += n;
+ if (n < 1024 * 1024) {
+ n <<= 1;
+ } else {
+ n = 2 * 1024 * 1024;
+ }
+ buffer = realloc(buffer, size + n);
}
- buffer = realloc(buffer, size + n);
- }
- size += i;
- buffer = realloc(buffer, size);
+ size += i;
+ buffer = realloc(buffer, size);
- CLclose(f);
+ CLclose(f);
- StopMusic(); // stop music before new music
+ StopMusic(); // stop music
before new music
- ModPlug_GetSettings(&settings); // Conversion settings
- settings.mFrequency = SoundFrequency;
+ ModPlug_GetSettings(&settings); // Conversion settings
+ settings.mFrequency = SoundFrequency;
#ifdef USE_LIBMODPLUG32
- settings.mBits = 32;
+ settings.mBits = 32;
#else
- settings.mBits = 16;
+ settings.mBits = 16;
#endif
- settings.mLoopCount = 0; // Disable looping
- ModPlug_SetSettings(&settings);
+ settings.mLoopCount = 0; // Disable
looping
+ ModPlug_SetSettings(&settings);
- modfile = ModPlug_Load(buffer, size);
+ modfile = ModPlug_Load(buffer, size);
- free(buffer);
+ free(buffer);
- if (modfile) {
- DebugLevel0Fn("Started ticks %ld\n" _C_ GetTicks() - ticks);
- sample = malloc(sizeof(*sample));
- sample->Type = &ModSampleType;
- sample->User = modfile;
- sample->Channels = 2;
+ if (modfile) {
+ DebugLevel0Fn("Started ticks %ld\n" _C_ GetTicks() - ticks);
+ sample = malloc(sizeof(*sample));
+ sample->Type = &ModSampleType;
+ sample->User = modfile;
+ sample->Channels = 2;
#ifdef USE_LIBMODPLUG32
- sample->SampleSize = 32;
+ sample->SampleSize = 32;
#else
- sample->SampleSize = 16;
+ sample->SampleSize = 16;
#endif
- sample->Frequency = SoundFrequency;
- sample->Length = 0;
- return sample;
- }
+ sample->Frequency = SoundFrequency;
+ sample->Length = 0;
+ return sample;
+ }
- return NULL;
+ return NULL;
}
#endif
/**
-** FIXME: docu
+** FIXME: docu
*/
global void PlaySectionMusic(PlaySectionType section)
{
#ifdef USE_CDAUDIO
- int track;
- int newtrack;
+ int track;
+ int newtrack;
#endif
- int i;
- int j;
- int found;
- int numfiles;
-
- if (NumPlaySections == 0) {
- return;
- }
-
- if (section == PlaySectionUnknown) {
- section = CurrentPlaySection;
- }
-
- if (section == PlaySectionStats) {
- if (GameResult == GameVictory) {
- section = PlaySectionStatsVictory;
- } else {
- section = PlaySectionStatsDefeat;
+ int i;
+ int j;
+ int found;
+ int numfiles;
+
+ if (NumPlaySections == 0) {
+ return;
}
- }
- for (i = 0; i < NumPlaySections; ++i) {
- if (PlaySections[i].Type == section && (!PlaySections[i].Race ||
- !(strcmp(PlaySections[i].Race, ThisPlayer->RaceName)))) {
- break;
+ if (section == PlaySectionUnknown) {
+ section = CurrentPlaySection;
}
- }
- CurrentPlaySection = PlaySections[i].Type;
-#ifdef USE_CDAUDIO
- if (CDMode == CDModeDefined) {
- track = CDTrack;
- newtrack = 0;
- if ((1 << track) & PlaySections[i].CDTracks) {
- newtrack = 0;
- } else {
- if (!((1 << CDTrack) & PlaySections[i].CDTracks)) {
- CDTrack = 0;
- }
- if (PlaySections[i].CDOrder == PlaySectionOrderAll) {
- for (j = CDTrack + 1; j != CDTrack; ++j) {
- if ((1 << j) & PlaySections[i].CDTracks) {
- newtrack = j;
+ if (section == PlaySectionStats) {
+ if (GameResult == GameVictory) {
+ section = PlaySectionStatsVictory;
+ } else {
+ section = PlaySectionStatsDefeat;
+ }
+ }
+
+ for (i = 0; i < NumPlaySections; ++i) {
+ if (PlaySections[i].Type == section && (!PlaySections[i].Race ||
+ !(strcmp(PlaySections[i].Race,
ThisPlayer->RaceName)))) {
break;
- } else if (j == 31) {
- j = 0;
- }
}
- } else if (PlaySections[i].CDOrder == PlaySectionOrderRandom) {
- do {
- newtrack = MyRand() % NumCDTracks;
- } while (!((1 << newtrack) & PlaySections[i].CDTracks) ||
- (!IsAudioTrack(newtrack)));
- }
- }
- if (newtrack) {
- PlayCDTrack(newtrack);
- CDTrack = newtrack;
}
- } else if (PlaySections[i].Files && (CDMode == CDModeOff || CDMode ==
CDModeStopped)) {
+ CurrentPlaySection = PlaySections[i].Type;
+
+#ifdef USE_CDAUDIO
+ if (CDMode == CDModeDefined) {
+ track = CDTrack;
+ newtrack = 0;
+ if ((1 << track) & PlaySections[i].CDTracks) {
+ newtrack = 0;
+ } else {
+ if (!((1 << CDTrack) & PlaySections[i].CDTracks)) {
+ CDTrack = 0;
+ }
+ if (PlaySections[i].CDOrder == PlaySectionOrderAll) {
+ for (j = CDTrack + 1; j != CDTrack; ++j) {
+ if ((1 << j) &
PlaySections[i].CDTracks) {
+ newtrack = j;
+ break;
+ } else if (j == 31) {
+ j = 0;
+ }
+ }
+ } else if (PlaySections[i].CDOrder ==
PlaySectionOrderRandom) {
+ do {
+ newtrack = MyRand() % NumCDTracks;
+ } while (!((1 << newtrack) &
PlaySections[i].CDTracks) ||
+ (!IsAudioTrack(newtrack)));
+ }
+ }
+ if (newtrack) {
+ PlayCDTrack(newtrack);
+ CDTrack = newtrack;
+ }
+ } else if (PlaySections[i].Files && (CDMode == CDModeOff || CDMode ==
CDModeStopped)) {
#else
- if (PlaySections[i].Files) {
+ if (PlaySections[i].Files) {
#endif
- found = 0;
- numfiles = 0;
- for (j = 0; PlaySections[i].Files[j] && !found; ++j) {
- if (!strcmp(PlaySections[i].Files[j], CurrentMusicFile)) {
- found = 1;
- ++numfiles;
- }
- }
- if (!found) {
- if (PlaySections[i].FileOrder == PlaySectionOrderAll) {
- PlayMusic(PlaySections[i].Files[0]);
- } else if (PlaySections[i].FileOrder == PlaySectionOrderRandom) {
- j = MyRand() % numfiles;
- PlayMusic(PlaySections[i].Files[j]);
- }
+ found = 0;
+ numfiles = 0;
+ for (j = 0; PlaySections[i].Files[j] && !found; ++j) {
+ if (!strcmp(PlaySections[i].Files[j],
CurrentMusicFile)) {
+ found = 1;
+ ++numfiles;
+ }
+ }
+ if (!found) {
+ if (PlaySections[i].FileOrder == PlaySectionOrderAll) {
+ PlayMusic(PlaySections[i].Files[0]);
+ } else if (PlaySections[i].FileOrder ==
PlaySectionOrderRandom) {
+ j = MyRand() % numfiles;
+ PlayMusic(PlaySections[i].Files[j]);
+ }
+ }
}
- }
}
/**
-** Play a music file.
+** Play a music file.
**
-** Currently supported are .mod, .it, .s3m, .wav, .xm.
-** Optional .ogg, .mp3, .flac and cdrom.
+** Currently supported are .mod, .it, .s3m, .wav, .xm.
+** Optional .ogg, .mp3, .flac and cdrom.
**
-** @param name Name of sound file, format is automatic detected.
-** Names starting with ':' control the cdrom.
+** @param name Name of sound file, format is automatic
detected.
+** Names starting with ':' control
the cdrom.
**
-** @return 1 if music is playing, 0 if not.
+** @return 1 if music is playing, 0 if not.
*/
global int PlayMusic(const char* name)
{
- char buffer[PATH_MAX];
+ char buffer[PATH_MAX];
#if defined(USE_OGG) || defined(USE_FLAC) || defined(USE_MAD) ||
defined(USE_LIBMODPLUG)
- Sample* sample;
+ Sample* sample;
#endif
- if (MusicOff) {
- return 0;
- }
+ if (MusicOff) {
+ return 0;
+ }
- if (CurrentMusicFile) {
- free(CurrentMusicFile);
- }
- CurrentMusicFile = strdup(name);
-
- name = LibraryFileName(name, buffer);
-
- if ((sample = LoadWav(name, PlayAudioStream))) {
- StopMusic();
- MusicSample = sample;
- PlayingMusic = 1;
- return 1;
- }
+ if (CurrentMusicFile) {
+ free(CurrentMusicFile);
+ }
+ CurrentMusicFile = strdup(name);
+
+ name = LibraryFileName(name, buffer);
+
+ if ((sample = LoadWav(name, PlayAudioStream))) {
+ StopMusic();
+ MusicSample = sample;
+ PlayingMusic = 1;
+ return 1;
+ }
#ifdef USE_OGG
- if ((sample = LoadOgg(name, PlayAudioStream))) {
- if ((sample->Channels != 1 && sample->Channels != 2) ||
- sample->SampleSize != 16) {
- DebugLevel0Fn("Not supported music format\n");
- SoundFree(sample);
- return 0;
- }
- StopMusic();
- MusicSample = sample;
- PlayingMusic = 1;
- return 1;
- }
+ if ((sample = LoadOgg(name, PlayAudioStream))) {
+ if ((sample->Channels != 1 && sample->Channels != 2) ||
+ sample->SampleSize != 16) {
+ DebugLevel0Fn("Not supported music format\n");
+ SoundFree(sample);
+ return 0;
+ }
+ StopMusic();
+ MusicSample = sample;
+ PlayingMusic = 1;
+ return 1;
+ }
#endif
#ifdef USE_MAD
- if ((sample = LoadMp3(name, PlayAudioStream))) {
-// if (sample->Channels != 2 || sample->SampleSize != 16
-// || sample->Frequency != SoundFrequency) {
-// DebugLevel0Fn("Not supported music format\n");
-// SoundFree(sample);
-// return;
-// }
- StopMusic();
- MusicSample = sample;
- PlayingMusic = 1;
- return 1;
- }
+ if ((sample = LoadMp3(name, PlayAudioStream))) {
+// if (sample->Channels != 2 || sample->SampleSize != 16
+// || sample->Frequency != SoundFrequency) {
+// DebugLevel0Fn("Not supported music format\n");
+// SoundFree(sample);
+// return;
+// }
+ StopMusic();
+ MusicSample = sample;
+ PlayingMusic = 1;
+ return 1;
+ }
#endif
#ifdef USE_FLAC
- if ((sample = LoadFlac(name, PlayAudioStream))) {
+ if ((sample = LoadFlac(name, PlayAudioStream))) {
/*
- if (sample->Channels != 2 || sample->SampleSize != 16
- || sample->Frequency != SoundFrequency) {
- DebugLevel0Fn("Not supported music format\n");
- SoundFree(sample);
- return;
- }
+ if (sample->Channels != 2 || sample->SampleSize != 16
+ || sample->Frequency != SoundFrequency) {
+ DebugLevel0Fn("Not supported music format\n");
+ SoundFree(sample);
+ return;
+ }
*/
- StopMusic();
- MusicSample = sample;
- PlayingMusic = 1;
- return 1;
- }
+ StopMusic();
+ MusicSample = sample;
+ PlayingMusic = 1;
+ return 1;
+ }
#endif
#ifdef USE_LIBMODPLUG
- if ((sample = LoadMod(name, PlayAudioStream))) {
- MusicSample = sample;
- PlayingMusic = 1;
- return 1;
- }
+ if ((sample = LoadMod(name, PlayAudioStream))) {
+ MusicSample = sample;
+ PlayingMusic = 1;
+ return 1;
+ }
#endif
- return 0;
+ return 0;
}
/**
-** Play a sound file.
+** Play a sound file.
**
-** @param name Name of sound file
+** @param name Name of sound file
*/
global void PlayFile(const char* name)
{
- SoundId id;
- if (SoundIdForName("dynamic-sound")) {
- id = RegisterSound(&name, 1);
- } else {
- id = MakeSound("dynamic-sound", &name, 1);
- }
- PlayGameSound(id, GlobalVolume);
+ SoundId id;
+ if (SoundIdForName("dynamic-sound")) {
+ id = RegisterSound(&name, 1);
+ } else {
+ id = MakeSound("dynamic-sound", &name, 1);
+ }
+ PlayGameSound(id, GlobalVolume);
}
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
//@}
Index: stratagus/src/sound/ogg.c
diff -u stratagus/src/sound/ogg.c:1.35 stratagus/src/sound/ogg.c:1.36
--- stratagus/src/sound/ogg.c:1.35 Thu Oct 16 21:27:28 2003
+++ stratagus/src/sound/ogg.c Tue Dec 23 14:48:03 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,18 +26,18 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: ogg.c,v 1.35 2003/10/16 11:27:28 mr-russ Exp $
+// $Id: ogg.c,v 1.36 2003/12/23 03:48:03 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "stratagus.h"
-#if defined(WITH_SOUND) && defined(USE_OGG) // {
+#if defined(WITH_SOUND) && defined(USE_OGG) // {
#include <stdlib.h>
#include <string.h>
@@ -61,485 +61,485 @@
#include "avi.h"
/*----------------------------------------------------------------------------
--- Declaration
+-- Declaration
----------------------------------------------------------------------------*/
/**
-** Private ogg data structure to handle ogg streaming.
+** Private ogg data structure to handle ogg streaming.
*/
typedef struct _ogg_data_ {
- char* PointerInBuffer; /// Pointer into buffer
- OggVorbis_File VorbisFile[1]; /// Vorbis file handle
+ char* PointerInBuffer; ///
Pointer into buffer
+ OggVorbis_File VorbisFile[1]; ///
Vorbis file handle
} OggData;
-#define OGG_BUFFER_SIZE (12 * 1024) /// Buffer size to fill
+#define OGG_BUFFER_SIZE (12 * 1024) /// Buffer size
to fill
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** OGG vorbis read callback.
+** OGG vorbis read callback.
**
-** @param ptr Pointer to memory to fill.
-** @param size Size of the element.
-** @param nmemb Number of elements to fill.
-** @param user User argument.
+** @param ptr Pointer to memory to
fill.
+** @param size Size of the element.
+** @param nmemb Number of elements to
fill.
+** @param user User argument.
**
-** @return The number of elements loaded.
+** @return The number of
elements loaded.
*/
local size_t OGG_read(void* ptr, size_t size, size_t nmemb, void* user)
{
- return CLread(user, ptr, size * nmemb) / size;
+ return CLread(user, ptr, size * nmemb) / size;
}
/**
-** OGG vorbis seek callback.
+** OGG vorbis seek callback.
**
-** @param user User argument.
-** @param offset Seek offset.
-** @param whence How to seek.
+** @param user User argument.
+** @param offset Seek offset.
+** @param whence How to seek.
**
-** @return Seek position, -1 if failure.
+** @return Seek position,
-1 if failure.
*/
local int OGG_seek(void* user __attribute__((unused)),
- int64_t offset __attribute__((unused)),
- int whence __attribute__((unused)))
+ int64_t offset __attribute__((unused)),
+ int whence __attribute__((unused)))
{
- return -1;
+ return -1;
}
/**
-** OGG vorbis tell callback.
+** OGG vorbis tell callback.
**
-** @param user User argument.
+** @param user User argument.
**
-** @return Current seek postition.
+** @return Current seek
postition.
local long OGG_tell(void* user __attribute__((unused)))
{
- return -1;
+ return -1;
}
*/
/**
-** OGG vorbis close callback.
+** OGG vorbis close callback.
**
-** @param user User argument.
+** @param user User argument.
**
-** @return Success status.
+** @return Success status.
*/
local int OGG_close(void* user)
{
- return CLclose(user);
+ return CLclose(user);
}
/**
-** Type member function to read from the ogg file
+** Type member function to read from the ogg file
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int OggReadStream(Sample* sample, void* buf, int len)
{
- OggData* data;
- int i;
- int n;
- int bitstream;
-
- int freqratio;
- int chanratio;
- int brratio;
- int divide;
- char sndbuf[OGG_BUFFER_SIZE];
-
- data = (OggData*)sample->User;
-
- // see if we have enough read already
- if (data->PointerInBuffer - sample->Data + len > sample->Length) {
- // not enough in buffer, read more
- sample->Length -= (data->PointerInBuffer - sample->Data);
- memcpy(sample->Data, data->PointerInBuffer, sample->Length);
- data->PointerInBuffer = sample->Data;
-
- n = OGG_BUFFER_SIZE - sample->Length;
+ OggData* data;
+ int i;
+ int n;
+ int bitstream;
- freqratio = 44100 / sample->Frequency;
- brratio = 4 / ((sample->SampleSize/8) * sample->Channels);
- chanratio = 2 / sample->Channels;
- divide = freqratio * brratio / chanratio;
+ int freqratio;
+ int chanratio;
+ int brratio;
+ int divide;
+ char sndbuf[OGG_BUFFER_SIZE];
+
+ data = (OggData*)sample->User;
+
+ // see if we have enough read already
+ if (data->PointerInBuffer - sample->Data + len > sample->Length) {
+ // not enough in buffer, read more
+ sample->Length -= (data->PointerInBuffer - sample->Data);
+ memcpy(sample->Data, data->PointerInBuffer, sample->Length);
+ data->PointerInBuffer = sample->Data;
+
+ n = OGG_BUFFER_SIZE - sample->Length;
+
+ freqratio = 44100 / sample->Frequency;
+ brratio = 4 / ((sample->SampleSize/8) * sample->Channels);
+ chanratio = 2 / sample->Channels;
+ divide = freqratio * brratio / chanratio;
- for (;;) {
+ for (;;) {
#ifdef WORDS_BIGENDIAN
- i = ov_read(data->VorbisFile, sndbuf, n / divide, 1, 2, 1,
- &bitstream);
+ i = ov_read(data->VorbisFile, sndbuf, n / divide, 1, 2,
1,
+ &bitstream);
#else
- i = ov_read(data->VorbisFile, sndbuf, n / divide, 0, 2, 1,
- &bitstream);
+ i = ov_read(data->VorbisFile, sndbuf, n / divide, 0, 2,
1,
+ &bitstream);
#endif
- if (i <= 0) {
- break;
- }
-
- i = ConvertToStereo32(sndbuf,
&data->PointerInBuffer[sample->Length],
- sample->Frequency, sample->SampleSize / 8, sample->Channels, i);
-
- sample->Length += i;
- n -= i;
- if (n < 4096) {
- break;
- }
- }
- if (sample->Length < len) {
- len = sample->Length;
+ if (i <= 0) {
+ break;
+ }
+
+ i = ConvertToStereo32(sndbuf,
&data->PointerInBuffer[sample->Length],
+ sample->Frequency, sample->SampleSize / 8,
sample->Channels, i);
+
+ sample->Length += i;
+ n -= i;
+ if (n < 4096) {
+ break;
+ }
+ }
+ if (sample->Length < len) {
+ len = sample->Length;
+ }
}
- }
- memcpy(buf, data->PointerInBuffer, len);
- data->PointerInBuffer += len;
- return len;
+ memcpy(buf, data->PointerInBuffer, len);
+ data->PointerInBuffer += len;
+ return len;
}
/**
-** Type member function to free an ogg file
+** Type member function to free an ogg file
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void OggFreeStream(Sample* sample)
{
- OggData* data;
+ OggData* data;
#ifdef DEBUG
- AllocatedSoundMemory -= sizeof(*sample) + OGG_BUFFER_SIZE;
+ AllocatedSoundMemory -= sizeof(*sample) + OGG_BUFFER_SIZE;
#endif
- data = (OggData*)sample->User;
- ov_clear(data->VorbisFile);
- free(data);
- free(sample);
+ data = (OggData*)sample->User;
+ ov_clear(data->VorbisFile);
+ free(data);
+ free(sample);
}
/**
-** Ogg object type structure.
+** Ogg object type structure.
*/
local const SampleType OggStreamSampleType = {
- OggReadStream,
- OggFreeStream,
+ OggReadStream,
+ OggFreeStream,
};
/**
-** Type member function to read from the ogg file
+** Type member function to read from the ogg file
**
-** @param sample Sample reading from
-** @param buf Buffer to write data to
-** @param len Length of the buffer
+** @param sample Sample reading from
+** @param buf Buffer to write data to
+** @param len Length of the buffer
**
-** @return Number of bytes read
+** @return Number of bytes read
*/
local int OggRead(Sample* sample, void* buf, int len)
{
- int pos;
+ int pos;
- pos = (int)sample->User;
- if (pos + len > sample->Length) { // Not enough data?
- len = sample->Length - pos;
- }
- memcpy(buf, sample->Data + pos, len);
+ pos = (int)sample->User;
+ if (pos + len > sample->Length) { // Not
enough data?
+ len = sample->Length - pos;
+ }
+ memcpy(buf, sample->Data + pos, len);
- sample->User = (void*)(pos + len);
+ sample->User = (void*)(pos + len);
- return len;
+ return len;
}
/**
-** Type member function to free an ogg file
+** Type member function to free an ogg file
**
-** @param sample Sample to free
+** @param sample Sample to free
*/
local void OggFree(Sample* sample)
{
#ifdef DEBUG
- AllocatedSoundMemory -= sample->Length;
+ AllocatedSoundMemory -= sample->Length;
#endif
- free(sample);
+ free(sample);
}
/**
-** Ogg object type structure.
+** Ogg object type structure.
*/
local const SampleType OggSampleType = {
- OggRead,
- OggFree,
+ OggRead,
+ OggFree,
};
/**
-** Load ogg.
+** Load ogg.
**
-** @param name File name.
-** @param flags Load flags.
+** @param name File name.
+** @param flags Load flags.
**
-** @return Returns the loaded sample.
+** @return Returns the loaded sample.
**
-** @todo Support more flags, LoadOnDemand.
+** @todo Support more flags,
LoadOnDemand.
*/
global Sample* LoadOgg(const char* name,int flags)
{
- static const ov_callbacks vc = { OGG_read, OGG_seek, OGG_close, NULL };
- CLFile* f;
- Sample* sample;
- OggVorbis_File vf[1];
- unsigned int magic[1];
- vorbis_info* info;
-
- if (!(f = CLopen(name,CL_OPEN_READ))) {
- fprintf(stderr, "Can't open file `%s'\n", name);
- return NULL;
- }
- CLread(f, magic, sizeof(magic));
- if (AccessLE32(magic) != 0x5367674F) { // "OggS" in ASCII
- CLclose(f);
- return NULL;
- }
-
- DebugLevel2Fn("Loading ogg file: %s\n" _C_ name);
-
- if (ov_open_callbacks(f, vf, (char*)&magic, sizeof(magic), vc)) {
- fprintf(stderr, "Can't initialize ogg decoder\n");
- CLclose(f);
- return NULL;
- }
- /* JOHNS: ov_test_callbacks didn't worked for me 1.0 RC3
- if (ov_test_open(vf)) {
- ov_clear(vf);
- return NULL;
- }
- */
- info = ov_info(vf, -1);
- if (!info) {
- fprintf(stderr, "no ogg stream\n");
- ov_clear(vf);
- return NULL;
- }
-
- //
- // We have now a correct OGG stream
- //
-
- sample = malloc(sizeof(*sample) + OGG_BUFFER_SIZE);
- if (!sample) {
- fprintf(stderr, "Out of memory\n");
- ov_clear(vf);
- return NULL;
- }
- sample->Channels = info->channels;
- sample->SampleSize = 16;
- sample->Frequency = info->rate;
- sample->Length = 0;
+ static const ov_callbacks vc = { OGG_read, OGG_seek, OGG_close, NULL };
+ CLFile* f;
+ Sample* sample;
+ OggVorbis_File vf[1];
+ unsigned int magic[1];
+ vorbis_info* info;
+
+ if (!(f = CLopen(name,CL_OPEN_READ))) {
+ fprintf(stderr, "Can't open file `%s'\n", name);
+ return NULL;
+ }
+ CLread(f, magic, sizeof(magic));
+ if (AccessLE32(magic) != 0x5367674F) { // "OggS" in ASCII
+ CLclose(f);
+ return NULL;
+ }
- if (flags & PlayAudioStream) {
- OggData* data;
+ DebugLevel2Fn("Loading ogg file: %s\n" _C_ name);
- data = malloc(sizeof(OggData));
- if (!data) {
- fprintf(stderr, "Out of memory\n");
- free(sample);
- ov_clear(vf);
- return NULL;
+ if (ov_open_callbacks(f, vf, (char*)&magic, sizeof(magic), vc)) {
+ fprintf(stderr, "Can't initialize ogg decoder\n");
+ CLclose(f);
+ return NULL;
+ }
+ /* JOHNS: ov_test_callbacks didn't worked for me 1.0 RC3
+ if (ov_test_open(vf)) {
+ ov_clear(vf);
+ return NULL;
+ }
+ */
+ info = ov_info(vf, -1);
+ if (!info) {
+ fprintf(stderr, "no ogg stream\n");
+ ov_clear(vf);
+ return NULL;
}
- data->VorbisFile[0] = vf[0];
- data->PointerInBuffer = sample->Data;
- sample->Type = &OggStreamSampleType;
- sample->User = data;
+ //
+ // We have now a correct OGG stream
+ //
+
+ sample = malloc(sizeof(*sample) + OGG_BUFFER_SIZE);
+ if (!sample) {
+ fprintf(stderr, "Out of memory\n");
+ ov_clear(vf);
+ return NULL;
+ }
+ sample->Channels = info->channels;
+ sample->SampleSize = 16;
+ sample->Frequency = info->rate;
+ sample->Length = 0;
+
+ if (flags & PlayAudioStream) {
+ OggData* data;
+
+ data = malloc(sizeof(OggData));
+ if (!data) {
+ fprintf(stderr, "Out of memory\n");
+ free(sample);
+ ov_clear(vf);
+ return NULL;
+ }
+ data->VorbisFile[0] = vf[0];
+ data->PointerInBuffer = sample->Data;
- DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + OGG_BUFFER_SIZE);
+ sample->Type = &OggStreamSampleType;
+ sample->User = data;
+
+ DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + OGG_BUFFER_SIZE);
#ifdef DEBUG
- AllocatedSoundMemory += sizeof(*sample) + OGG_BUFFER_SIZE;
+ AllocatedSoundMemory += sizeof(*sample) + OGG_BUFFER_SIZE;
#endif
- } else {
- int n;
- char* p;
-
- sample->Type = &OggSampleType;
- sample->User = 0;
-
- n = OGG_BUFFER_SIZE;
- p = sample->Data;
-
- // CLread is not seekable and ov_pcm_total(vf,-1) not supported :(
-
- for (;;) {
- int bitstream;
- int i;
-
- if (n < 4096) {
- Sample* s;
-
- if( sample->Length < 1024 * 1024 ) {
- n = sample->Length << 1;
- } else {
- n = 2 * 1024 * 1024; // Big junks needed for windows
- }
- s = realloc(sample, sizeof(*sample) + sample->Length + n);
- if (!s) {
- fprintf(stderr, "out of memory\n");
- free(sample);
- ov_clear(vf);
- return NULL;
+ } else {
+ int n;
+ char* p;
+
+ sample->Type = &OggSampleType;
+ sample->User = 0;
+
+ n = OGG_BUFFER_SIZE;
+ p = sample->Data;
+
+ // CLread is not seekable and ov_pcm_total(vf,-1) not supported
:(
+
+ for (;;) {
+ int bitstream;
+ int i;
+
+ if (n < 4096) {
+ Sample* s;
+
+ if( sample->Length < 1024 * 1024 ) {
+ n = sample->Length << 1;
+ } else {
+ n = 2 * 1024 * 1024; // Big
junks needed for windows
+ }
+ s = realloc(sample, sizeof(*sample) +
sample->Length + n);
+ if (!s) {
+ fprintf(stderr, "out of memory\n");
+ free(sample);
+ ov_clear(vf);
+ return NULL;
+ }
+ sample = s;
+ p = sample->Data + sample->Length;
+ }
+
+ #ifdef WORDS_BIGENDIAN
+ i = ov_read(vf, p, 4096, 1, 2, 1, &bitstream);
+ #else
+ i = ov_read(vf, p, 4096, 0, 2, 1, &bitstream);
+ #endif
+ if (i <= 0) {
+ break;
+ }
+ p += i;
+ sample->Length += i;
+ n -= i;
}
- sample = s;
- p = sample->Data + sample->Length;
- }
-
- #ifdef WORDS_BIGENDIAN
- i = ov_read(vf, p, 4096, 1, 2, 1, &bitstream);
- #else
- i = ov_read(vf, p, 4096, 0, 2, 1, &bitstream);
- #endif
- if (i <= 0) {
- break;
- }
- p += i;
- sample->Length += i;
- n -= i;
- }
- // Shrink to real size
- sample = realloc(sample, sizeof(*sample) + sample->Length);
+ // Shrink to real size
+ sample = realloc(sample, sizeof(*sample) + sample->Length);
- ov_clear(vf);
+ ov_clear(vf);
- DebugLevel0Fn(" %d\n" _C_ sample->Length);
+ DebugLevel0Fn(" %d\n" _C_ sample->Length);
#ifdef DEBUG
- AllocatedSoundMemory += sample->Length;
+ AllocatedSoundMemory += sample->Length;
#endif
- }
+ }
- return sample;
+ return sample;
}
/*----------------------------------------------------------------------------
--- Avi support
+-- Avi support
----------------------------------------------------------------------------*/
/**
-** OGG vorbis read callback.
+** OGG vorbis read callback.
**
-** @param ptr Pointer to memory to fill.
-** @param size Size of the element.
-** @param nmemb Number of elements to fill.
-** @param user User argument.
+** @param ptr Pointer to memory to
fill.
+** @param size Size of the element.
+** @param nmemb Number of elements to
fill.
+** @param user User argument.
**
-** @return The number of elements loaded.
+** @return The number of
elements loaded.
*/
local size_t AVI_OGG_read(void* ptr, size_t size, size_t nmemb, void* user)
{
- AviFile* avi;
- size_t length;
- unsigned char* frame;
-
- DebugLevel3Fn("%p: %p %d*%d\n" _C_ user _C_ ptr _C_ size _C_ nmemb);
-
- avi = user;
- if (avi->AudioRemain) { // Bytes remaining
- DebugLevel3Fn("Remain %d %d\n" _C_ avi->AudioRemain _C_
- avi->AudioBuffer->Length - avi->AudioRemain);
- length = avi->AudioRemain;
- if (length > nmemb * size) {
- length = nmemb * size;
+ AviFile* avi;
+ size_t length;
+ unsigned char* frame;
+
+ DebugLevel3Fn("%p: %p %d*%d\n" _C_ user _C_ ptr _C_ size _C_ nmemb);
+
+ avi = user;
+ if (avi->AudioRemain) { // Bytes remaining
+ DebugLevel3Fn("Remain %d %d\n" _C_ avi->AudioRemain _C_
+ avi->AudioBuffer->Length - avi->AudioRemain);
+ length = avi->AudioRemain;
+ if (length > nmemb * size) {
+ length = nmemb * size;
+ }
+ memcpy(ptr,
+ avi->AudioBuffer->Data + avi->AudioBuffer->Length -
+ avi->AudioRemain, length);
+ avi->AudioRemain -= length;
+ return length / size;
}
- memcpy(ptr,
- avi->AudioBuffer->Data + avi->AudioBuffer->Length -
- avi->AudioRemain, length);
- avi->AudioRemain -= length;
- return length / size;
- }
- length = AviReadNextAudioFrame(avi, &frame);
- DebugLevel3Fn("Bytes %d - %d\n" _C_ length _C_ avi->AudioBuffer->Length);
- if ((int)length < 0) {
- return 0;
- }
- if (length > nmemb * size) {
- avi->AudioRemain = length - nmemb * size;
- length = nmemb * size;
- }
- memcpy(ptr, frame, length);
+ length = AviReadNextAudioFrame(avi, &frame);
+ DebugLevel3Fn("Bytes %d - %d\n" _C_ length _C_
avi->AudioBuffer->Length);
+ if ((int)length < 0) {
+ return 0;
+ }
+ if (length > nmemb * size) {
+ avi->AudioRemain = length - nmemb * size;
+ length = nmemb * size;
+ }
+ memcpy(ptr, frame, length);
- return length / size;
+ return length / size;
}
/**
-** OGG vorbis close callback.
+** OGG vorbis close callback.
**
-** @param user User argument.
+** @param user User argument.
**
-** @return Success status.
+** @return Success status.
*/
local int AVI_OGG_close(void* user __attribute__((unused)))
{
- return 0;
+ return 0;
}
/**
-** Play the ogg stream of an avi movie.
+** Play the ogg stream of an avi movie.
**
-** @param avi Avi file handle
+** @param avi Avi file handle
*/
global void PlayAviOgg(AviFile* avi)
{
- static const ov_callbacks vc = { AVI_OGG_read, OGG_seek, AVI_OGG_close,
- NULL };
- Sample* sample;
- OggVorbis_File vf[1];
- vorbis_info* info;
- OggData* data;
-
- if (ov_open_callbacks(avi, vf, 0, 0, vc)) {
- fprintf(stderr, "Can't initialize ogg decoder\n");
- return;
- }
- info = ov_info(vf, -1);
- if (!info) {
- fprintf(stderr, "no ogg stream\n");
- ov_clear(vf);
- return;
- }
-
- //
- // We have now a correct OGG stream
- //
-
- sample = malloc(sizeof(*sample) + OGG_BUFFER_SIZE);
- if (!sample) {
- fprintf(stderr, "Out of memory\n");
- ov_clear(vf);
- return;
- }
- sample->Channels = info->channels;
- sample->SampleSize = 16;
- sample->Frequency = info->rate;
- sample->Length = 0;
-
- data = malloc(sizeof(OggData));
- if (!data) {
- fprintf(stderr, "Out of memory\n");
- free(sample);
- ov_clear(vf);
- return;
- }
- data->VorbisFile[0] = vf[0];
- data->PointerInBuffer = sample->Data;
+ static const ov_callbacks vc = { AVI_OGG_read, OGG_seek, AVI_OGG_close,
+ NULL };
+ Sample* sample;
+ OggVorbis_File vf[1];
+ vorbis_info* info;
+ OggData* data;
+
+ if (ov_open_callbacks(avi, vf, 0, 0, vc)) {
+ fprintf(stderr, "Can't initialize ogg decoder\n");
+ return;
+ }
+ info = ov_info(vf, -1);
+ if (!info) {
+ fprintf(stderr, "no ogg stream\n");
+ ov_clear(vf);
+ return;
+ }
+
+ //
+ // We have now a correct OGG stream
+ //
+
+ sample = malloc(sizeof(*sample) + OGG_BUFFER_SIZE);
+ if (!sample) {
+ fprintf(stderr, "Out of memory\n");
+ ov_clear(vf);
+ return;
+ }
+ sample->Channels = info->channels;
+ sample->SampleSize = 16;
+ sample->Frequency = info->rate;
+ sample->Length = 0;
- sample->Type = &OggStreamSampleType;
- sample->User = data;
+ data = malloc(sizeof(OggData));
+ if (!data) {
+ fprintf(stderr, "Out of memory\n");
+ free(sample);
+ ov_clear(vf);
+ return;
+ }
+ data->VorbisFile[0] = vf[0];
+ data->PointerInBuffer = sample->Data;
+
+ sample->Type = &OggStreamSampleType;
+ sample->User = data;
- MusicSample = sample;
- PlayingMusic = 1;
+ MusicSample = sample;
+ PlayingMusic = 1;
}
-#endif // } WITH_SOUND && USE_OGG
+#endif // } WITH_SOUND && USE_OGG
//@}
Index: stratagus/src/sound/oss_audio.c
diff -u stratagus/src/sound/oss_audio.c:1.11
stratagus/src/sound/oss_audio.c:1.12
--- stratagus/src/sound/oss_audio.c:1.11 Thu Oct 2 09:56:21 2003
+++ stratagus/src/sound/oss_audio.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,19 +26,19 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: oss_audio.c,v 1.11 2003/10/01 23:56:21 jsalmon3 Exp $
+// $Id: oss_audio.c,v 1.12 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "stratagus.h"
-#if defined(WITH_SOUND) && !defined(USE_SDLA) // {
+#if defined(WITH_SOUND) && !defined(USE_SDLA) // {
#include <unistd.h>
#include <fcntl.h>
@@ -55,120 +55,120 @@
#endif
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Initialize sound card hardware part for oss compatible drivers.
+** Initialize sound card hardware part for oss compatible drivers.
**
-** @param dev Device name ("/dev/dsp").
-** @param freq Sample frequenz (44100,22050,11025 hz).
-** @param size Sample size (8bit, 16bit)
-** @param wait Flag, if true wait for sound device to open.
+** @param dev Device name ("/dev/dsp").
+** @param freq Sample frequenz (44100,22050,11025 hz).
+** @param size Sample size (8bit, 16bit)
+** @param wait Flag, if true wait for sound device to
open.
**
-** @return True if failure, false if everything ok.
+** @return True if failure, false if
everything ok.
*/
global int InitOssSound(const char* dev, int freq, int size, int wait)
{
- int dummy;
+ int dummy;
- //
- // Open dsp device, 8bit samples, stereo.
- //
- if (wait) {
- SoundFildes = open(dev, O_WRONLY);
- } else {
- SoundFildes = open(dev, O_WRONLY | O_NDELAY);
- }
- if (SoundFildes == -1) {
- fprintf(stderr, "Can't open audio device `%s'\n", dev);
- return 1;
- }
- dummy = size;
- if (ioctl(SoundFildes, SNDCTL_DSP_SAMPLESIZE, &dummy) == -1) {
- PrintFunction();
- fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SAMPLESIZE)", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
- dummy = 1;
- if (ioctl(SoundFildes, SNDCTL_DSP_STEREO, &dummy) == -1) {
- PrintFunction();
- fprintf(stdout, "%s - ioctl(SNDCTL_DSP_STEREO)", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
- dummy = freq;
- if (ioctl(SoundFildes, SNDCTL_DSP_SPEED, &dummy) == -1) {
- PrintFunction();
- fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SPEED)", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
- //
- // 33ms buffer minimum.
- //
- // FIXME: higher speed more buffers!!
-
- switch (freq) {
- case 11025:
- dummy=((8 << 16) | 8); // 8 Buffers of 256 Bytes
- break;
- case 22050:
- dummy=((8 << 16) | 9); // 8 Buffers of 512 Bytes
- break;
- default:
- DebugLevel0Fn("Unexpected sample frequency %d\n" _C_ freq);
- // FALL THROUGH
- case 44100:
- dummy=((8 << 16) | 10); // 8 Buffers of 1024 Bytes
- break;
- }
- if (size == 16) { // 8 bit
- ++dummy; // double buffer size
- }
-
- DebugLevel0Fn("%d bytes %d ms buffer\n" _C_ freq*size/8 _C_
- ((dummy >> 16) * (1 << (dummy & 0xFFFF)) * 1000) / (freq * size / 8));
-
- if (ioctl(SoundFildes, SNDCTL_DSP_SETFRAGMENT, &dummy) == -1) {
- PrintFunction();
- fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SETFRAGMENT)", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
+ //
+ // Open dsp device, 8bit samples, stereo.
+ //
+ if (wait) {
+ SoundFildes = open(dev, O_WRONLY);
+ } else {
+ SoundFildes = open(dev, O_WRONLY | O_NDELAY);
+ }
+ if (SoundFildes == -1) {
+ fprintf(stderr, "Can't open audio device `%s'\n", dev);
+ return 1;
+ }
+ dummy = size;
+ if (ioctl(SoundFildes, SNDCTL_DSP_SAMPLESIZE, &dummy) == -1) {
+ PrintFunction();
+ fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SAMPLESIZE)",
strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
+ dummy = 1;
+ if (ioctl(SoundFildes, SNDCTL_DSP_STEREO, &dummy) == -1) {
+ PrintFunction();
+ fprintf(stdout, "%s - ioctl(SNDCTL_DSP_STEREO)",
strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
+ dummy = freq;
+ if (ioctl(SoundFildes, SNDCTL_DSP_SPEED, &dummy) == -1) {
+ PrintFunction();
+ fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SPEED)",
strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
+ //
+ // 33ms buffer minimum.
+ //
+ // FIXME: higher speed more buffers!!
+
+ switch (freq) {
+ case 11025:
+ dummy=((8 << 16) | 8); // 8 Buffers of 256 Bytes
+ break;
+ case 22050:
+ dummy=((8 << 16) | 9); // 8 Buffers of 512 Bytes
+ break;
+ default:
+ DebugLevel0Fn("Unexpected sample frequency %d\n" _C_
freq);
+ // FALL THROUGH
+ case 44100:
+ dummy=((8 << 16) | 10); // 8 Buffers of 1024 Bytes
+ break;
+ }
+ if (size == 16) { // 8
bit
+ ++dummy; //
double buffer size
+ }
+
+ DebugLevel0Fn("%d bytes %d ms buffer\n" _C_ freq*size/8 _C_
+ ((dummy >> 16) * (1 << (dummy & 0xFFFF)) * 1000) / (freq * size
/ 8));
+
+ if (ioctl(SoundFildes, SNDCTL_DSP_SETFRAGMENT, &dummy) == -1) {
+ PrintFunction();
+ fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SETFRAGMENT)",
strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
#if 0
- dummy = 4;
- if (ioctl(SoundFildes, SNDCTL_DSP_SUBDIVIDE, &dummy) == -1) {
- PrintFunction();
- fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SUBDIVIDE)", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return;
- }
+ dummy = 4;
+ if (ioctl(SoundFildes, SNDCTL_DSP_SUBDIVIDE, &dummy) == -1) {
+ PrintFunction();
+ fprintf(stdout, "%s - ioctl(SNDCTL_DSP_SUBDIVIDE)",
strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return;
+ }
#endif
#ifdef DEBUG
- if (ioctl(SoundFildes, SNDCTL_DSP_GETBLKSIZE, &dummy) == -1) {
- PrintFunction();
- fprintf(stdout, "%s - ioctl(SNDCTL_DSP_GETBLKSIZE)", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
+ if (ioctl(SoundFildes, SNDCTL_DSP_GETBLKSIZE, &dummy) == -1) {
+ PrintFunction();
+ fprintf(stdout, "%s - ioctl(SNDCTL_DSP_GETBLKSIZE)",
strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
- DebugLevel2Fn("DSP block size %d\n" _C_ dummy);
- DebugLevel2Fn("DSP sample speed %d\n" _C_ freq);
+ DebugLevel2Fn("DSP block size %d\n" _C_ dummy);
+ DebugLevel2Fn("DSP sample speed %d\n" _C_ freq);
#endif
- return 0;
+ return 0;
}
-#endif // } WITH_SOUND && !USE_SDLA
+#endif // } WITH_SOUND && !USE_SDLA
//@}
Index: stratagus/src/sound/sdl_audio.c
diff -u stratagus/src/sound/sdl_audio.c:1.10
stratagus/src/sound/sdl_audio.c:1.11
--- stratagus/src/sound/sdl_audio.c:1.10 Thu Oct 2 09:56:21 2003
+++ stratagus/src/sound/sdl_audio.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,72 +26,72 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: sdl_audio.c,v 1.10 2003/10/01 23:56:21 jsalmon3 Exp $
+// $Id: sdl_audio.c,v 1.11 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "stratagus.h"
-#ifdef WITH_SOUND // {
+#ifdef WITH_SOUND // {
#ifdef USE_SDLA
#include "SDL.h"
#include "sound_server.h"
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
- /// FIXME: move function to here.
+ /// FIXME: move function to here.
extern void FillAudio(void* udata __attribute__((unused)), Uint8* stream,
- int len);
+ int len);
/**
-** Initialize sound card hardware part with SDL.
+** Initialize sound card hardware part with SDL.
**
-** @param dev Device name ("/dev/dsp").
-** @param freq Sample frequenz (44100,22050,11025 hz).
-** @param size Sampe size (8bit, 16bit)
-** @param wait Flag, if true wait for sound device to open.
+** @param dev Device name ("/dev/dsp").
+** @param freq Sample frequenz (44100,22050,11025 hz).
+** @param size Sampe size (8bit, 16bit)
+** @param wait Flag, if true wait for sound device to
open.
**
-** @return True if failure, false if everything ok.
+** @return True if failure, false if
everything ok.
*/
global int InitSdlSound(const char* dev __attribute__((unused)), int freq,
- int size, int wait __attribute__((unused)))
+ int size, int wait __attribute__((unused)))
{
- SDL_AudioSpec wanted;
+ SDL_AudioSpec wanted;
- wanted.freq = freq;
- if (size == 8) {
- wanted.format = AUDIO_U8;
- } else if (size == 16) {
- wanted.format = AUDIO_S16SYS;
- } else {
- DebugLevel0Fn("Unexpected sample size %d\n" _C_ size);
- wanted.format = AUDIO_S16SYS;
- }
- wanted.channels = 2;
- wanted.samples = 2048;
- wanted.callback = FillAudio;
- wanted.userdata = NULL;
-
- // Open the audio device, forcing the desired format
- if (SDL_OpenAudio(&wanted, NULL) < 0) {
- fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
- return -1;
- }
- SoundFildes = 0;
- SDL_PauseAudio(0);
+ wanted.freq = freq;
+ if (size == 8) {
+ wanted.format = AUDIO_U8;
+ } else if (size == 16) {
+ wanted.format = AUDIO_S16SYS;
+ } else {
+ DebugLevel0Fn("Unexpected sample size %d\n" _C_ size);
+ wanted.format = AUDIO_S16SYS;
+ }
+ wanted.channels = 2;
+ wanted.samples = 2048;
+ wanted.callback = FillAudio;
+ wanted.userdata = NULL;
+
+ // Open the audio device, forcing the desired format
+ if (SDL_OpenAudio(&wanted, NULL) < 0) {
+ fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
+ return -1;
+ }
+ SoundFildes = 0;
+ SDL_PauseAudio(0);
- return 0;
+ return 0;
}
#endif
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
//@}
Index: stratagus/src/sound/sound.c
diff -u stratagus/src/sound/sound.c:1.45 stratagus/src/sound/sound.c:1.46
--- stratagus/src/sound/sound.c:1.45 Sun Nov 2 15:20:38 2003
+++ stratagus/src/sound/sound.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: sound.c,v 1.45 2003/11/02 04:20:38 jsalmon3 Exp $
+// $Id: sound.c,v 1.46 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
@@ -40,7 +40,7 @@
#include "stratagus.h"
-#ifdef WITH_SOUND // {
+#ifdef WITH_SOUND // {
#ifdef USE_SDLA
#include "SDL_audio.h"
@@ -60,282 +60,282 @@
#include "sound.h"
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
-global int SoundOff; /// True quiet, sound turned off
-global int MusicOff; /// Music turned off
+global int SoundOff; /// True quiet,
sound turned off
+global int MusicOff; /// Music
turned off
/**
-** Various sounds used in game.
+** Various sounds used in game.
**
-** FIXME: @todo support more races. Must remove static config.
+** FIXME: @todo support more races. Must remove static config.
*/
global GameSound GameSounds
#ifndef laterUSE_CCL
// FIXME: Removing this crashes?
={
- { "placement error", NULL },
- { "placement success", NULL },
- { "click", NULL },
- { "transport docking", NULL },
- { "building construction", NULL },
- { { "basic human voices work complete", NULL },
- { "basic orc voices work complete", NULL },
- },
- { { "rescue (human) UNUSED", NULL },
- { "rescue (orc) UNUSED", NULL },
- },
+ { "placement error", NULL },
+ { "placement success", NULL },
+ { "click", NULL },
+ { "transport docking", NULL },
+ { "building construction", NULL },
+ { { "basic human voices work complete", NULL },
+ { "basic orc voices work complete", NULL },
+ },
+ { { "rescue (human) UNUSED", NULL },
+ { "rescue (orc) UNUSED", NULL },
+ },
}
#endif
- ;
+ ;
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Helper function: insert a sound request in the server side sound FIFO.
+** Helper function: insert a sound request in the server side
sound FIFO.
**
-** @param unit Pointer to unit.
-** @param id Unit identifier, for pointer reuse detection.
-** @param power How loud to play the sound.
-** @param sound FIXME: docu
-** @param fight FIXME: docu
-** @param selection FIXME: docu
-** @param volume FIXME: docu
-** @param stereo FIXME: docu
+** @param unit Pointer to unit.
+** @param id Unit identifier, for pointer reuse
detection.
+** @param power How loud to play the sound.
+** @param sound FIXME: docu
+** @param fight FIXME: docu
+** @param selection FIXME: docu
+** @param volume FIXME: docu
+** @param stereo FIXME: docu
*/
local void InsertSoundRequest(const Unit* unit, unsigned id,
- unsigned char power, SoundId sound, unsigned char fight,
- unsigned char selection, unsigned char volume, char stereo)
+ unsigned char power, SoundId sound, unsigned char fight,
+ unsigned char selection, unsigned char volume, char stereo)
{
#ifdef USE_SDLA
- SDL_LockAudio();
+ SDL_LockAudio();
#endif
- //FIXME: valid only in a shared memory context...
- if (!SoundOff && sound != NO_SOUND) {
- if (SoundRequests[NextSoundRequestIn].Used) {
- DebugLevel0("***** NO FREE SLOT IN SOUND FIFO *****\n");
- } else {
- SoundRequests[NextSoundRequestIn].Used = 1;
- SoundRequests[NextSoundRequestIn].Source.Base = unit;
- SoundRequests[NextSoundRequestIn].Source.Id = id;
- SoundRequests[NextSoundRequestIn].Sound = sound;
- SoundRequests[NextSoundRequestIn].Power = power;
- SoundRequests[NextSoundRequestIn].Fight = fight ? 1 : 0;
- SoundRequests[NextSoundRequestIn].Selection = selection ? 1 : 0;
- SoundRequests[NextSoundRequestIn].IsVolume = volume ? 1 : 0;
- SoundRequests[NextSoundRequestIn].Stereo = stereo;
- DebugLevel3("Source[%p,%s]: registering request %p at slot %d=%d\n"
_C_
- unit _C_ unit ? unit->Type->Ident : "" _C_
- sound _C_ NextSoundRequestIn _C_ power);
+ //FIXME: valid only in a shared memory context...
+ if (!SoundOff && sound != NO_SOUND) {
+ if (SoundRequests[NextSoundRequestIn].Used) {
+ DebugLevel0("***** NO FREE SLOT IN SOUND FIFO *****\n");
+ } else {
+ SoundRequests[NextSoundRequestIn].Used = 1;
+ SoundRequests[NextSoundRequestIn].Source.Base = unit;
+ SoundRequests[NextSoundRequestIn].Source.Id = id;
+ SoundRequests[NextSoundRequestIn].Sound = sound;
+ SoundRequests[NextSoundRequestIn].Power = power;
+ SoundRequests[NextSoundRequestIn].Fight = fight ? 1 : 0;
+ SoundRequests[NextSoundRequestIn].Selection = selection
? 1 : 0;
+ SoundRequests[NextSoundRequestIn].IsVolume = volume ? 1
: 0;
+ SoundRequests[NextSoundRequestIn].Stereo = stereo;
+ DebugLevel3("Source[%p,%s]: registering request %p at
slot %d=%d\n" _C_
+ unit _C_ unit ? unit->Type->Ident : "" _C_
+ sound _C_ NextSoundRequestIn _C_ power);
#ifdef USE_THREAD
- // increment semaphore
- if (SoundThreadRunning) {
- if (sem_post(&SoundThreadChannelSemaphore)) {
- DebugLevel0("Cannot increment semaphore!\n");
- //FIXME: need to quit?
- }
- }
+ // increment semaphore
+ if (SoundThreadRunning) {
+ if (sem_post(&SoundThreadChannelSemaphore)) {
+ DebugLevel0("Cannot increment
semaphore!\n");
+ //FIXME: need to quit?
+ }
+ }
#endif
- ++NextSoundRequestIn;
- if (NextSoundRequestIn >= MAX_SOUND_REQUESTS) {
- NextSoundRequestIn = 0;
- }
+ ++NextSoundRequestIn;
+ if (NextSoundRequestIn >= MAX_SOUND_REQUESTS) {
+ NextSoundRequestIn = 0;
+ }
+ }
}
- }
#ifdef USE_SDLA
- SDL_UnlockAudio();
+ SDL_UnlockAudio();
#endif
}
/**
-** Maps a UnitVoiceGroup to a SoundId.
+** Maps a UnitVoiceGroup to a SoundId.
**
-** @param unit Sound initiator
-** @param voice Type of sound wanted
+** @param unit Sound initiator
+** @param voice Type of sound wanted
**
-** @return Sound identifier
+** @return Sound identifier
**
-** @todo FIXME: The work completed sounds only supports two races.
+** @todo FIXME: The work completed sounds only supports two races.
*/
local SoundId ChooseUnitVoiceSoundId(const Unit* unit, UnitVoiceGroup voice)
{
- switch (voice) {
- case VoiceAcknowledging:
- return unit->Type->Sound.Acknowledgement.Sound;
- case VoiceReady:
- return unit->Type->Sound.Ready.Sound;
- case VoiceSelected:
- return unit->Type->Sound.Selected.Sound;
- case VoiceAttacking:
- return unit->Type->Weapon.Attack.Sound;
- case VoiceHelpMe:
- return unit->Type->Sound.Help.Sound;
- case VoiceDying:
- return unit->Type->Sound.Dead.Sound;
- case VoiceWorkCompleted:
- return GameSounds.WorkComplete[ThisPlayer->Race].Sound;
- case VoiceBuilding:
- return GameSounds.BuildingConstruction.Sound;
- case VoiceDocking:
- return GameSounds.Docking.Sound;
- case VoiceRepairing:
- return unit->Type->Sound.Repair.Sound;
- case VoiceHarvesting:
- return unit->Type->Sound.Harvest[unit->CurrentResource].Sound;
- }
- return NULL;
+ switch (voice) {
+ case VoiceAcknowledging:
+ return unit->Type->Sound.Acknowledgement.Sound;
+ case VoiceReady:
+ return unit->Type->Sound.Ready.Sound;
+ case VoiceSelected:
+ return unit->Type->Sound.Selected.Sound;
+ case VoiceAttacking:
+ return unit->Type->Weapon.Attack.Sound;
+ case VoiceHelpMe:
+ return unit->Type->Sound.Help.Sound;
+ case VoiceDying:
+ return unit->Type->Sound.Dead.Sound;
+ case VoiceWorkCompleted:
+ return GameSounds.WorkComplete[ThisPlayer->Race].Sound;
+ case VoiceBuilding:
+ return GameSounds.BuildingConstruction.Sound;
+ case VoiceDocking:
+ return GameSounds.Docking.Sound;
+ case VoiceRepairing:
+ return unit->Type->Sound.Repair.Sound;
+ case VoiceHarvesting:
+ return
unit->Type->Sound.Harvest[unit->CurrentResource].Sound;
+ }
+ return NULL;
}
/**
-** Ask to the sound server to play a sound attached to an unit. The
-** sound server may discard the sound if needed (e.g., when the same
-** unit is already speaking).
+** Ask to the sound server to play a sound attached to an unit. The
+** sound server may discard the sound if needed (e.g., when the
same
+** unit is already speaking).
**
-** @param unit Sound initiator, unit speaking
-** @param voice Type of sound wanted (Ready,Die,Yes,...)
+** @param unit Sound initiator, unit speaking
+** @param voice Type of sound wanted (Ready,Die,Yes,...)
*/
global void PlayUnitSound(const Unit* unit, UnitVoiceGroup voice)
{
- int stereo;
+ int stereo;
+
+ stereo = ((unit->X * TileSizeX + unit->Type->TileWidth * TileSizeX / 2 +
+ unit->IX - TheUI.SelectedViewport->MapX * TileSizeX) * 256 /
+ ((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
+ if (stereo < -128) {
+ stereo = -128;
+ } else if (stereo > 127) {
+ stereo = 127;
+ }
- stereo = ((unit->X * TileSizeX + unit->Type->TileWidth * TileSizeX / 2 +
- unit->IX - TheUI.SelectedViewport->MapX * TileSizeX) * 256 /
- ((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
- if (stereo < -128) {
- stereo = -128;
- } else if (stereo > 127) {
- stereo = 127;
- }
-
- InsertSoundRequest(unit, unit->Slot, ViewPointDistanceToUnit(unit),
- ChooseUnitVoiceSoundId(unit, voice), voice == VoiceAttacking,
- (voice == VoiceSelected || voice == VoiceBuilding), 0, stereo);
+ InsertSoundRequest(unit, unit->Slot, ViewPointDistanceToUnit(unit),
+ ChooseUnitVoiceSoundId(unit, voice), voice == VoiceAttacking,
+ (voice == VoiceSelected || voice == VoiceBuilding), 0, stereo);
}
/**
-** Ask the sound server to play a sound for a missile.
+** Ask the sound server to play a sound for a missile.
**
-** @param missile Sound initiator, missile exploding
-** @param sound Sound to be generated
+** @param missile Sound initiator, missile exploding
+** @param sound Sound to be generated
*/
global void PlayMissileSound(const Missile* missile, SoundId sound)
{
- int stereo;
+ int stereo;
- stereo = ((missile->X + missile->Type->Width / 2 -
- TheUI.SelectedViewport->MapX * TileSizeX) * 256 /
- ((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
- if (stereo < -128) {
- stereo = -128;
- } else if (stereo > 127) {
- stereo = 127;
- }
+ stereo = ((missile->X + missile->Type->Width / 2 -
+ TheUI.SelectedViewport->MapX * TileSizeX) * 256 /
+ ((TheUI.SelectedViewport->MapWidth - 1) * TileSizeX)) - 128;
+ if (stereo < -128) {
+ stereo = -128;
+ } else if (stereo > 127) {
+ stereo = 127;
+ }
- InsertSoundRequest(NULL, 0, ViewPointDistanceToMissile(missile), sound, 1,
- 0, 0, stereo);
+ InsertSoundRequest(NULL, 0, ViewPointDistanceToMissile(missile), sound,
1,
+ 0, 0, stereo);
}
/**
-** FIXME: docu
+** FIXME: docu
*/
global void PlayGameSound(SoundId sound, unsigned char volume)
{
- DebugLevel3("Playing %p at volume %u\n" _C_ sound _C_ volume);
- InsertSoundRequest(NULL, 0, volume, sound, 0, 0, 1, 0);
+ DebugLevel3("Playing %p at volume %u\n" _C_ sound _C_ volume);
+ InsertSoundRequest(NULL, 0, volume, sound, 0, 0, 1, 0);
}
/**
-** Ask to the sound server to set the global volume of the sound.
+** Ask to the sound server to set the global volume of the sound.
**
-** @param volume the sound volume (positive number) 0-255
+** @param volume the sound volume (positive number) 0-255
**
-** @see MaxVolume
+** @see MaxVolume
*/
global void SetGlobalVolume(int volume)
{
- //FIXME: we use here the fact that we are in a shared memory context. This
- // should send a message to the sound server
- // silently discard out of range values
- if (volume < 0) {
- GlobalVolume = 0;
- } else if (volume > MaxVolume) {
- GlobalVolume = MaxVolume;
- } else {
- GlobalVolume = volume;
- }
+ //FIXME: we use here the fact that we are in a shared memory context.
This
+ // should send a message to the sound server
+ // silently discard out of range values
+ if (volume < 0) {
+ GlobalVolume = 0;
+ } else if (volume > MaxVolume) {
+ GlobalVolume = MaxVolume;
+ } else {
+ GlobalVolume = volume;
+ }
}
/**
-** Ask to the sound server to set the volume of the music.
+** Ask to the sound server to set the volume of the music.
**
-** @param volume the music volume (positive number) 0-255
+** @param volume the music volume (positive number) 0-255
**
-** @see MaxVolume
+** @see MaxVolume
*/
global void SetMusicVolume(int volume)
{
- //FIXME: we use here the fact that we are in a shared memory context. This
- // should send a message to the sound server
+ //FIXME: we use here the fact that we are in a shared memory context.
This
+ // should send a message to the sound server
- // silently discard out of range values
- if (volume < 0) {
- MusicVolume = 0;
- } else if (volume > MaxVolume) {
- MusicVolume = MaxVolume;
- } else {
- MusicVolume = volume;
- }
+ // silently discard out of range values
+ if (volume < 0) {
+ MusicVolume = 0;
+ } else if (volume > MaxVolume) {
+ MusicVolume = MaxVolume;
+ } else {
+ MusicVolume = volume;
+ }
}
/**
-** Lookup the sound id's for the game sounds.
+** Lookup the sound id's for the game sounds.
*/
global void InitSoundClient(void)
{
- int i;
+ int i;
- if (SoundFildes == -1) { // No sound enabled
- return;
- }
- // let's map game sounds, look if already setup in ccl.
-
- if (!GameSounds.PlacementError.Sound) {
- GameSounds.PlacementError.Sound =
- SoundIdForName(GameSounds.PlacementError.Name);
- }
- if (!GameSounds.PlacementSuccess.Sound) {
- GameSounds.PlacementSuccess.Sound =
- SoundIdForName(GameSounds.PlacementSuccess.Name);
- }
- if (!GameSounds.Click.Sound) {
- GameSounds.Click.Sound = SoundIdForName(GameSounds.Click.Name);
- }
- if (!GameSounds.Docking.Sound) {
- GameSounds.Docking.Sound =
- SoundIdForName(GameSounds.Docking.Name);
- }
- if (!GameSounds.BuildingConstruction.Sound) {
- GameSounds.BuildingConstruction.Sound =
- SoundIdForName(GameSounds.BuildingConstruction.Name);
- }
- for (i = 0; i < PlayerRaces.Count; ++i) {
- if (!GameSounds.WorkComplete[i].Sound &&
- GameSounds.WorkComplete[i].Name) {
- GameSounds.WorkComplete[i].Sound =
- SoundIdForName(GameSounds.WorkComplete[i].Name);
- }
- }
- for (i = 0; i < PlayerRaces.Count; ++i) {
- if (!GameSounds.Rescue[i].Sound && GameSounds.Rescue[i].Name) {
- GameSounds.Rescue[i].Sound =
- SoundIdForName(GameSounds.Rescue[i].Name);
+ if (SoundFildes == -1) { // No sound
enabled
+ return;
+ }
+ // let's map game sounds, look if already setup in ccl.
+
+ if (!GameSounds.PlacementError.Sound) {
+ GameSounds.PlacementError.Sound =
+ SoundIdForName(GameSounds.PlacementError.Name);
+ }
+ if (!GameSounds.PlacementSuccess.Sound) {
+ GameSounds.PlacementSuccess.Sound =
+ SoundIdForName(GameSounds.PlacementSuccess.Name);
+ }
+ if (!GameSounds.Click.Sound) {
+ GameSounds.Click.Sound = SoundIdForName(GameSounds.Click.Name);
+ }
+ if (!GameSounds.Docking.Sound) {
+ GameSounds.Docking.Sound =
+ SoundIdForName(GameSounds.Docking.Name);
+ }
+ if (!GameSounds.BuildingConstruction.Sound) {
+ GameSounds.BuildingConstruction.Sound =
+ SoundIdForName(GameSounds.BuildingConstruction.Name);
+ }
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!GameSounds.WorkComplete[i].Sound &&
+ GameSounds.WorkComplete[i].Name) {
+ GameSounds.WorkComplete[i].Sound =
+ SoundIdForName(GameSounds.WorkComplete[i].Name);
+ }
+ }
+ for (i = 0; i < PlayerRaces.Count; ++i) {
+ if (!GameSounds.Rescue[i].Sound && GameSounds.Rescue[i].Name) {
+ GameSounds.Rescue[i].Sound =
+ SoundIdForName(GameSounds.Rescue[i].Name);
+ }
}
- }
}
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
//@}
Index: stratagus/src/sound/sound_id.c
diff -u stratagus/src/sound/sound_id.c:1.22 stratagus/src/sound/sound_id.c:1.23
--- stratagus/src/sound/sound_id.c:1.22 Wed Dec 3 11:31:36 2003
+++ stratagus/src/sound/sound_id.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -20,7 +20,7 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
-// $Id: sound_id.c,v 1.22 2003/12/03 00:31:36 jsalmon3 Exp $
+// $Id: sound_id.c,v 1.23 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
@@ -31,7 +31,7 @@
#include <stdio.h>
#include "stratagus.h"
-#ifdef WITH_SOUND // {
+#ifdef WITH_SOUND // {
#include <stdlib.h>
#include <string.h>
@@ -47,141 +47,141 @@
#include "etlib/hash.h"
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
-#ifdef DOXYGEN // no real code, only for document
+#ifdef DOXYGEN // no
real code, only for document
/**
-** hash table used to store the mapping between sound name and sound id
+** hash table used to store the mapping between sound name and
sound id
*/
local int SoundIdHash[61];
#else
/**
-** hash table used to store the mapping between sound name and sound id
+** hash table used to store the mapping between sound name and
sound id
*/
local hashtable(int, 61) SoundIdHash;
#endif
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Display the sound name hash table.
+** Display the sound name hash table.
*/
global void DisplaySoundHashTable(void)
{
- struct hash_st st;
+ struct hash_st st;
- fprintf(stdout,"Sound HashTable Begin\n");
- PrintFunction();
- fprintf(stdout,"FIXME: not written\n");
- fprintf(stdout,"Sound HashTable End\n");
-
- hash_stat(SoundIdHash, &st);
- printf("nelem : %d\n", st.nelem);
- printf("hashsize: %d\n", st.hashsize);
- printf("maxdepth: %d\n", st.maxdepth);
- printf("middepth: %d.%03d\n", st.middepth / 1000, st.middepth % 1000);
+ fprintf(stdout,"Sound HashTable Begin\n");
+ PrintFunction();
+ fprintf(stdout,"FIXME: not written\n");
+ fprintf(stdout,"Sound HashTable End\n");
+
+ hash_stat(SoundIdHash, &st);
+ printf("nelem : %d\n", st.nelem);
+ printf("hashsize: %d\n", st.hashsize);
+ printf("maxdepth: %d\n", st.maxdepth);
+ printf("middepth: %d.%03d\n", st.middepth / 1000, st.middepth % 1000);
}
/**
-** Add a new mapping (sound name to sound id) in the hash table
-** Create a new mapping between a name and an already valid sound id.
+** Add a new mapping (sound name to sound id) in the hash table
+** Create a new mapping between a name and an already valid sound
id.
**
-** @param name Name of the sound (now freed by caller!).
-** @param id Sound identifier.
+** @param name Name of the sound (now freed by
caller!).
+** @param id Sound identifier.
*/
global void MapSound(const char* name, const SoundId id)
{
- *((SoundId*)hash_add(SoundIdHash, (char*)name)) = id;
+ *((SoundId*)hash_add(SoundIdHash, (char*)name)) = id;
}
/**
-** Maps a sound name to its id
+** Maps a sound name to its id
**
-** @param name Sound name.
+** @param name Sound name.
**
-** @return Sound idenfier for this name.
+** @return Sound idenfier for this name.
*/
global SoundId SoundIdForName(const char* name)
{
- const SoundId* result;
+ const SoundId* result;
- DebugCheck(!name);
+ DebugCheck(!name);
- if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
- return *result;
- }
- DebugLevel0("Can't find sound `%s' in sound table\n" _C_ name);
- return NULL;
+ if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
+ return *result;
+ }
+ DebugLevel0("Can't find sound `%s' in sound table\n" _C_ name);
+ return NULL;
}
/**
-** Ask the sound server to register a sound and store the mapping
-** between its name and its id.
-** Register a sound group (or an unique sound if nb==1) and get the
-** corresponding sound id.
-**
-** @param name name of this sound group (Freed by caller).
-** @param file list of sound file names
-** @param nb number of sounds
+** Ask the sound server to register a sound and store the mapping
+** between its name and its id.
+** Register a sound group (or an unique sound if nb==1) and get the
+** corresponding sound id.
+**
+** @param name name of this sound group (Freed by
caller).
+** @param file list of sound file names
+** @param nb number of sounds
**
-** @return the sound id of the created group
+** @return the sound id of the created group
*/
global SoundId MakeSound(const char* name, const char* file[], int nb)
{
- SoundId id;
- const SoundId* result;
+ SoundId id;
+ const SoundId* result;
- DebugCheck(nb > 255);
+ DebugCheck(nb > 255);
- if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
- DebugLevel0Fn("re-register sound `%s'\n" _C_ name);
- return *result;
- }
-
- // ask the server to register the sound
- id = RegisterSound(file, nb);
- // save the mapping from name to id in the hash table.
- MapSound(name, id);
- return id;
+ if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
+ DebugLevel0Fn("re-register sound `%s'\n" _C_ name);
+ return *result;
+ }
+
+ // ask the server to register the sound
+ id = RegisterSound(file, nb);
+ // save the mapping from name to id in the hash table.
+ MapSound(name, id);
+ return id;
}
/**
-** Ask the sound server to build a special sound group.
+** Ask the sound server to build a special sound group.
**
-** Register two sound groups together to make a special sound (for
-** selection). Return the corresponding id after registering it under a
-** given name.
+** Register two sound groups together to make a special sound (for
+** selection). Return the corresponding id after registering it
under a
+** given name.
**
-** @param name the name of the group (handled by caller).
-** @param first id of the first group
-** @param second id of the second group
+** @param name the name of the group (handled by
caller).
+** @param first id of the first group
+** @param second id of the second group
**
-** @return Registered sound identifier.
+** @return Registered sound identifier.
*/
global SoundId MakeSoundGroup(const char* name, SoundId first, SoundId second)
{
- SoundId sound;
- const SoundId* result;
+ SoundId sound;
+ const SoundId* result;
- if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
- DebugLevel0Fn("re-register sound `%s'\n" _C_ name);
- return *result;
- }
+ if ((result = (const SoundId*)hash_find(SoundIdHash, (char*)name))) {
+ DebugLevel0Fn("re-register sound `%s'\n" _C_ name);
+ return *result;
+ }
- sound = RegisterTwoGroups(first, second);
- MapSound(name, sound);
+ sound = RegisterTwoGroups(first, second);
+ MapSound(name, sound);
- return sound;
+ return sound;
}
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
//@}
Index: stratagus/src/sound/sound_server.c
diff -u stratagus/src/sound/sound_server.c:1.127
stratagus/src/sound/sound_server.c:1.128
--- stratagus/src/sound/sound_server.c:1.127 Tue Dec 2 04:22:18 2003
+++ stratagus/src/sound/sound_server.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -27,23 +27,23 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: sound_server.c,v 1.127 2003/12/01 17:22:18 jsalmon3 Exp $
+// $Id: sound_server.c,v 1.128 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "stratagus.h"
-#ifdef WITH_SOUND // {
+#ifdef WITH_SOUND // {
#if !defined(USE_LIBMODPLUG) && !defined(noUSE_LIBMODPLUG)
-#define USE_LIBMODPLUG /// Include lib modplug support
+#define USE_LIBMODPLUG /// Include lib
modplug support
#endif
-#define _USE_LIBMODPLUG32 /// Test with 32bit resolution
+#define _USE_LIBMODPLUG32 /// Test with 32bit
resolution
#include <stdlib.h>
#include <string.h>
@@ -93,32 +93,32 @@
#endif
/*----------------------------------------------------------------------------
--- Defines
+-- Defines
----------------------------------------------------------------------------*/
-//#define SoundSampleSize 8 /// sample size of dsp in bit
-#define SoundSampleSize 16 // sample size of dsp in bit
-#define SoundFrequency 44100 // sample rate of dsp
-//#define SoundFrequency 22050 // sample rate of dsp
-//#define SoundFrequency 11025 /// sample rate of dsp
-#define SoundDeviceName "/dev/dsp" /// dsp device
+//#define SoundSampleSize 8 ///
sample size of dsp in bit
+#define SoundSampleSize 16 //
sample size of dsp in bit
+#define SoundFrequency 44100 // sample rate
of dsp
+//#define SoundFrequency 22050 //
sample rate of dsp
+//#define SoundFrequency 11025 ///
sample rate of dsp
+#define SoundDeviceName "/dev/dsp" /// dsp device
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
-global int SoundFildes = -1; /// audio file descriptor
-global int PlayingMusic; /// flag true if playing music
-global int CallbackMusic; /// flag true callback ccl if stops
+global int SoundFildes = -1; /// audio file
descriptor
+global int PlayingMusic; /// flag true if
playing music
+global int CallbackMusic; /// flag true callback
ccl if stops
#ifdef DEBUG
-global unsigned AllocatedSoundMemory; /// memory used by sound
+global unsigned AllocatedSoundMemory; /// memory used by sound
#endif
-global int GlobalVolume = 128; /// global sound volume
-global int MusicVolume = 128; /// music volume
+global int GlobalVolume = 128; /// global sound volume
+global int MusicVolume = 128; /// music volume
-global int DistanceSilent; /// silent distance
+global int DistanceSilent; /// silent distance
// the sound FIFO
global SoundRequest SoundRequests[MAX_SOUND_REQUESTS];
@@ -127,11 +127,11 @@
#ifdef USE_THREAD
global sem_t SoundThreadChannelSemaphore;/// FIXME: docu
-local pthread_t SoundThread; /// FIXME: docu
-global int WithSoundThread; /// FIXME: docu
+local pthread_t SoundThread; /// FIXME: docu
+global int WithSoundThread; /// FIXME: docu
#endif
-global int SoundThreadRunning; /// FIXME: docu
+global int SoundThreadRunning; /// FIXME: docu
local int MusicTerminated;
@@ -140,104 +140,104 @@
#endif
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
#if defined(USE_OGG) || defined(USE_FLAC) || defined(USE_MAD) ||
defined(USE_LIBMODPLUG) || defined(USE_CDDA)
/**
-** Check if the playlist need to be advanced,
-** and invoque music-stopped if necessary
+** Check if the playlist need to be advanced,
+** and invoque music-stopped if necessary
*/
global void PlayListAdvance(void)
{
#if defined(USE_GUILE) || defined(USE_SIOD)
- int proceed;
- SCM cb;
- SCM value;
-
+ int proceed;
+ SCM cb;
+ SCM value;
+
#ifdef USE_SDLA
- SDL_LockMutex(MusicTerminatedMutex);
+ SDL_LockMutex(MusicTerminatedMutex);
#endif
- proceed = MusicTerminated;
- MusicTerminated = 0;
+ proceed = MusicTerminated;
+ MusicTerminated = 0;
#ifdef USE_SDLA
- SDL_UnlockMutex(MusicTerminatedMutex);
+ SDL_UnlockMutex(MusicTerminatedMutex);
#endif
-
- if (proceed) {
- cb = gh_symbol2scm("music-stopped");
- if (symbol_boundp(cb, NIL)) {
-
- value = symbol_value(cb, NIL);
- if (!gh_null_p(value)) {
- gh_apply(value, NIL);
- }
+
+ if (proceed) {
+ cb = gh_symbol2scm("music-stopped");
+ if (symbol_boundp(cb, NIL)) {
+
+ value = symbol_value(cb, NIL);
+ if (!gh_null_p(value)) {
+ gh_apply(value, NIL);
+ }
+ }
}
- }
#elif defined(USE_LUA)
#endif
}
/**
-** Mix music to stereo 32 bit.
+** Mix music to stereo 32 bit.
**
-** @param buffer Buffer for mixed samples.
-** @param size Number of samples that fits into buffer.
+** @param buffer Buffer for mixed samples.
+** @param size Number of samples that fits into buffer.
**
-** @todo this functions can be called from inside the SDL audio callback,
-** which is bad, the buffer should be precalculated.
+** @todo this functions can be called from inside the SDL audio
callback,
+** which is bad, the buffer should be
precalculated.
*/
local void MixMusicToStereo32(int* buffer, int size)
{
- int i;
- int n;
- int len;
- short* buf;
-
- if (PlayingMusic) {
- DebugCheck(!MusicSample && !MusicSample->Type);
-
- // FIXME: if samples are shared this fails
- if (MusicSample->Channels == 2) {
- len = size * sizeof(*buf);
- buf = alloca(len);
- n = MusicSample->Type->Read(MusicSample, buf, len);
-
- for (i = 0; i < n / (int)sizeof(*buf); ++i) {
- // Add to our samples
- buffer[i] += (buf[i] * MusicVolume) / 256;
- }
- } else {
- len = size * sizeof(*buf) / 2;
- buf = alloca(len);
- n = MusicSample->Type->Read(MusicSample, buf, len);
-
- for (i = 0; i < n / (int)sizeof(*buf); ++i) {
- // Add to our samples
- buffer[i * 2 + 0] += (buf[i] * MusicVolume) / 256;
- buffer[i * 2 + 1] += (buf[i] * MusicVolume) / 256;
- }
- }
-
- if (n != len) { // End reached
- PlayingMusic = 0;
- SoundFree(MusicSample);
- MusicSample = NULL;
+ int i;
+ int n;
+ int len;
+ short* buf;
+
+ if (PlayingMusic) {
+ DebugCheck(!MusicSample && !MusicSample->Type);
+
+ // FIXME: if samples are shared this fails
+ if (MusicSample->Channels == 2) {
+ len = size * sizeof(*buf);
+ buf = alloca(len);
+ n = MusicSample->Type->Read(MusicSample, buf, len);
+
+ for (i = 0; i < n / (int)sizeof(*buf); ++i) {
+ // Add to our samples
+ buffer[i] += (buf[i] * MusicVolume) / 256;
+ }
+ } else {
+ len = size * sizeof(*buf) / 2;
+ buf = alloca(len);
+ n = MusicSample->Type->Read(MusicSample, buf, len);
+
+ for (i = 0; i < n / (int)sizeof(*buf); ++i) {
+ // Add to our samples
+ buffer[i * 2 + 0] += (buf[i] * MusicVolume) /
256;
+ buffer[i * 2 + 1] += (buf[i] * MusicVolume) /
256;
+ }
+ }
- // we are inside the SDL callback!
- if (CallbackMusic) {
+ if (n != len) { // End
reached
+ PlayingMusic = 0;
+ SoundFree(MusicSample);
+ MusicSample = NULL;
+
+ // we are inside the SDL callback!
+ if (CallbackMusic) {
#ifdef USE_SDLA
- SDL_LockMutex(MusicTerminatedMutex);
+ SDL_LockMutex(MusicTerminatedMutex);
#endif
- MusicTerminated = 1;
+ MusicTerminated = 1;
#ifdef USE_SDLA
- SDL_UnlockMutex(MusicTerminatedMutex);
+ SDL_UnlockMutex(MusicTerminatedMutex);
#endif
- }
+ }
+ }
}
- }
}
#else
@@ -245,7 +245,7 @@
/// Dummy functions if no music support is enabled
global int PlayMusic(const char* name __attribute__((unused)))
{
- return 0;
+ return 0;
}
/// Dummy functions if no music support is enabled
@@ -259,147 +259,147 @@
#endif
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Mix sample to buffer.
+** Mix sample to buffer.
+**
+** The input samples are adjusted by the local volume and resampled
+** to the output frequence.
**
-** The input samples are adjusted by the local volume and resampled
-** to the output frequence.
+** @param sample Input sample
+** @param index Position into input sample
+** @param volume Volume of the input sample
+** @param stereo Stereo (left/right) position of sample
+** @param buffer Output buffer
+** @param size Size of the output buffer to be filled
**
-** @param sample Input sample
-** @param index Position into input sample
-** @param volume Volume of the input sample
-** @param stereo Stereo (left/right) position of sample
-** @param buffer Output buffer
-** @param size Size of the output buffer to be filled
-**
-** @return the number of bytes used to fill buffer
+** @return the number of bytes used to
fill buffer
**
-** @todo Can mix faster if signed 8 bit buffers are used.
-** @todo Can combine stereo and volume for faster operation.
+** @todo Can mix faster if signed 8 bit
buffers are used.
+** @todo Can combine stereo and volume
for faster operation.
*/
local int MixSampleToStereo32(Sample* sample,int index,unsigned char volume,
- char stereo, int* buffer, int size)
+ char stereo, int* buffer, int size)
{
- int ri; // read index
- int wi; // write index
- unsigned length;
- int v;
- int local_volume;
- unsigned char left;
- unsigned char right;
-
- local_volume = ((int)volume + 1) * 2 * GlobalVolume / MaxVolume;
- length = sample->Length - index;
- if (stereo < 0) {
- left = 128;
- right = 128 + stereo;
- }
- else {
- left = 128 - stereo;
- right = 128;
- }
- DebugLevel3("Length %d\n" _C_ length);
-
- // FIXME: support other formats, stereo or 32 bit ...
-
- if (sample->SampleSize == 8) {
- unsigned char* rp;
-
- rp = sample->Data + index;
- if ((size * sample->Frequency) / SoundFrequency / 2 > length) {
- size = (length * SoundFrequency / sample->Frequency) * 2;
- }
-
- // mix mono, 8 bit sound to stereo, 32 bit
- for (ri = wi = 0; wi < size;) {
- ri = (wi * sample->Frequency) / SoundFrequency;
- ri /= 2; // adjust for mono
-
- // FIXME: must interpolate samples!
- v = (rp[ri] - 127) * local_volume;
-
- buffer[wi++] += v * left / 128;
- buffer[wi++] += v * right / 128; // left+right channel
- }
- ri = (wi * sample->Frequency) / SoundFrequency;
- ri /= 2; // adjust for mono
- DebugLevel3("Mixed %d bytes to %d\n" _C_ ri _C_ wi);
- } else {
- short* rp;
-
- DebugCheck(index & 1);
-
- rp = (short*)(sample->Data + index);
- if ((size * sample->Frequency) / SoundFrequency > length) {
- size = (length * SoundFrequency / sample->Frequency);
- }
-
- // mix mono, 16 bit sound to stereo, 32 bit
- for (ri = wi = 0; wi < size;) {
- ri = (wi * sample->Frequency) / SoundFrequency;
- ri /= 2; // adjust for mono
-
- // FIXME: must interpolate samples!
- v = rp[ri] * local_volume / 256;
-
- buffer[wi++] += v * left / 128;
- buffer[wi++] += v * right / 128;
- }
- ri = (wi * sample->Frequency) / SoundFrequency;
- }
-
- return ri;
-}
-
-/**
-** Convert RAW sound data to 44100 hz, Stereo, 16 bits per channel
-**
-** // FIXME
-** @param src Source buffer
-** @param dest Destination buffer
-** @param frequency Frequency of source
-** @param chansize Bitrate in bytes per channel of source
-** @param channels Number of channels of source
-** @param bytes Number of compressed bytes to read
-**
-** @return Number of bytes written in 'dest'
-*/
-global int ConvertToStereo32(const char* src, char* dest, int frequency,
- int chansize, int channels, int bytes)
-{
- int s; // sample index
- int c; // channel index
- int freqratio;
- int chanratio;
- int brratio;
- int samplesize; // number of bytes per sample
- int divide;
- int offset;
-
- freqratio = 44100 / frequency;
- samplesize = chansize * channels;
- brratio = 4 / samplesize;
- chanratio = 2 / channels;
- divide = freqratio * brratio;
-
- // s is the sample
- for (s = 0; s < bytes * divide; s += 4) {
- // c is the channel in the sample
- for (c = 0; c < 2; ++c) {
- offset = (((s / 4) / freqratio) * samplesize + (c / chanratio) *
chansize);
- if (chansize == 2) {
- *(short*)(dest + s + c * 2) = *(short*)(src + offset);
- } else {
- *(dest + s + c * 2) = *(src + offset) + 128;
- *(dest + s + c * 2 + 1) = *(src + offset) + 128;
- }
+ int ri; // read
index
+ int wi; //
write index
+ unsigned length;
+ int v;
+ int local_volume;
+ unsigned char left;
+ unsigned char right;
+
+ local_volume = ((int)volume + 1) * 2 * GlobalVolume / MaxVolume;
+ length = sample->Length - index;
+ if (stereo < 0) {
+ left = 128;
+ right = 128 + stereo;
+ }
+ else {
+ left = 128 - stereo;
+ right = 128;
+ }
+ DebugLevel3("Length %d\n" _C_ length);
+
+ // FIXME: support other formats, stereo or 32 bit ...
+
+ if (sample->SampleSize == 8) {
+ unsigned char* rp;
+
+ rp = sample->Data + index;
+ if ((size * sample->Frequency) / SoundFrequency / 2 > length) {
+ size = (length * SoundFrequency / sample->Frequency) *
2;
+ }
+
+ // mix mono, 8 bit sound to stereo, 32 bit
+ for (ri = wi = 0; wi < size;) {
+ ri = (wi * sample->Frequency) / SoundFrequency;
+ ri /= 2;
// adjust for mono
+
+ // FIXME: must interpolate samples!
+ v = (rp[ri] - 127) * local_volume;
+
+ buffer[wi++] += v * left / 128;
+ buffer[wi++] += v * right / 128; //
left+right channel
+ }
+ ri = (wi * sample->Frequency) / SoundFrequency;
+ ri /= 2;
// adjust for mono
+ DebugLevel3("Mixed %d bytes to %d\n" _C_ ri _C_ wi);
+ } else {
+ short* rp;
+
+ DebugCheck(index & 1);
+
+ rp = (short*)(sample->Data + index);
+ if ((size * sample->Frequency) / SoundFrequency > length) {
+ size = (length * SoundFrequency / sample->Frequency);
+ }
+
+ // mix mono, 16 bit sound to stereo, 32 bit
+ for (ri = wi = 0; wi < size;) {
+ ri = (wi * sample->Frequency) / SoundFrequency;
+ ri /= 2;
// adjust for mono
+
+ // FIXME: must interpolate samples!
+ v = rp[ri] * local_volume / 256;
+
+ buffer[wi++] += v * left / 128;
+ buffer[wi++] += v * right / 128;
+ }
+ ri = (wi * sample->Frequency) / SoundFrequency;
}
- }
- return bytes * divide;
+ return ri;
+}
+
+/**
+** Convert RAW sound data to 44100 hz, Stereo, 16 bits per channel
+**
+** // FIXME
+** @param src Source buffer
+** @param dest Destination buffer
+** @param frequency Frequency of source
+** @param chansize Bitrate in bytes per
channel of source
+** @param channels Number of channels of
source
+** @param bytes Number of compressed
bytes to read
+**
+** @return Number of bytes written in
'dest'
+*/
+global int ConvertToStereo32(const char* src, char* dest, int frequency,
+ int chansize, int channels, int bytes)
+{
+ int s; // sample index
+ int c; // channel index
+ int freqratio;
+ int chanratio;
+ int brratio;
+ int samplesize; // number of bytes per sample
+ int divide;
+ int offset;
+
+ freqratio = 44100 / frequency;
+ samplesize = chansize * channels;
+ brratio = 4 / samplesize;
+ chanratio = 2 / channels;
+ divide = freqratio * brratio;
+
+ // s is the sample
+ for (s = 0; s < bytes * divide; s += 4) {
+ // c is the channel in the sample
+ for (c = 0; c < 2; ++c) {
+ offset = (((s / 4) / freqratio) * samplesize + (c /
chanratio) * chansize);
+ if (chansize == 2) {
+ *(short*)(dest + s + c * 2) = *(short*)(src +
offset);
+ } else {
+ *(dest + s + c * 2) = *(src + offset) + 128;
+ *(dest + s + c * 2 + 1) = *(src + offset) + 128;
+ }
+ }
+ }
+
+ return bytes * divide;
}
global SoundChannel Channels[MaxChannels];
@@ -409,16 +409,16 @@
** Selection handling
*/
typedef struct _selection_handling_ {
- Origin Source; // origin of the sound
- ServerSoundId Sound; // last sound played by this unit
- unsigned char HowMany; // number of sound played in this group
+ Origin Source; // origin of the sound
+ ServerSoundId Sound; // last sound played by this unit
+ unsigned char HowMany; // number of sound played in this group
} SelectionHandling;
/// FIXME: docu
SelectionHandling SelectionHandler;
/**
-** Source registration
+** Source registration
*/
/// hash table used to store unit to channel mapping
#ifdef USE_GLIB
@@ -428,7 +428,7 @@
#endif
/**
-** Distance to Volume Mapping
+** Distance to Volume Mapping
*/
local int ViewPointOffset;
@@ -437,57 +437,57 @@
*/
local int HowManyFree(void)
{
- int channel;
- int nb;
+ int channel;
+ int nb;
- nb = 0;
- channel = NextFreeChannel;
- while(channel < MaxChannels) {
- ++nb;
- channel = Channels[channel].Point;
- }
- return nb;
+ nb = 0;
+ channel = NextFreeChannel;
+ while(channel < MaxChannels) {
+ ++nb;
+ channel = Channels[channel].Point;
+ }
+ return nb;
}
/*
** Check whether to discard or not a sound request
*/
local int KeepRequest(SoundRequest* sr) {
- //FIXME: take fight flag into account
- int channel;
+ //FIXME: take fight flag into account
+ int channel;
- if (sr->Sound == NO_SOUND) {
- return 0;
- }
+ if (sr->Sound == NO_SOUND) {
+ return 0;
+ }
#ifdef USE_GLIB
- if ((channel = (int)(long)g_hash_table_lookup(UnitToChannel,
- (gpointer)(sr->Source.Base)))) {
- --channel;
- if (Channels[channel].Source.Id == sr->Source.Id) {
- //FIXME: decision should take into account the sound
- return 0;
+ if ((channel = (int)(long)g_hash_table_lookup(UnitToChannel,
+ (gpointer)(sr->Source.Base)))) {
+ --channel;
+ if (Channels[channel].Source.Id == sr->Source.Id) {
+ //FIXME: decision should take into account the sound
+ return 0;
+ }
+ return 1;
}
- return 1;
- }
#else
- {
- const SoundChannel* theChannel;
+ {
+ const SoundChannel* theChannel;
- // slow but working solution: we look for the source in the channels
- theChannel = Channels;
- for (channel = 0; channel < MaxChannels; ++channel) {
- if ((*theChannel).Command == ChannelPlay &&
- (*theChannel).Source.Base == sr->Source.Base &&
- (*theChannel).Sound == sr->Sound &&
- (*theChannel).Source.Id == sr->Source.Id) {
- //FIXME: decision should take into account the sound
- return 0;
- }
- ++theChannel;
+ // slow but working solution: we look for the source in the
channels
+ theChannel = Channels;
+ for (channel = 0; channel < MaxChannels; ++channel) {
+ if ((*theChannel).Command == ChannelPlay &&
+ (*theChannel).Source.Base ==
sr->Source.Base &&
+ (*theChannel).Sound == sr->Sound &&
+ (*theChannel).Source.Id ==
sr->Source.Id) {
+ //FIXME: decision should take into account the
sound
+ return 0;
+ }
+ ++theChannel;
+ }
}
- }
#endif
- return 1;
+ return 1;
}
/*
@@ -495,22 +495,22 @@
*/
local void RegisterSource(SoundRequest* sr, int channel)
{
- // always keep the last registered channel
- // use channel+1 to avoid inserting null values
- //FIXME: we should use here the unique identifier of the source, not only
- // the pointer
+ // always keep the last registered channel
+ // use channel+1 to avoid inserting null values
+ //FIXME: we should use here the unique identifier of the source, not
only
+ // the pointer
#ifdef USE_GLIB
- g_hash_table_insert(UnitToChannel, (gpointer)(long)(sr->Source.Base),
- (gpointer)(channel+1));
+ g_hash_table_insert(UnitToChannel, (gpointer)(long)(sr->Source.Base),
+ (gpointer)(channel+1));
#else
- int i;
- void* p;
+ int i;
+ void* p;
- i = channel;
- p = sr;
- DebugLevel3Fn("FIXME: must write %p -> %d\n" _C_ sr _C_ channel);
+ i = channel;
+ p = sr;
+ DebugLevel3Fn("FIXME: must write %p -> %d\n" _C_ sr _C_ channel);
#endif
- DebugLevel3("Registering %p (channel %d)\n" _C_ sr->Source.Base _C_
channel);
+ DebugLevel3("Registering %p (channel %d)\n" _C_ sr->Source.Base _C_
channel);
}
/*
@@ -518,52 +518,52 @@
*/
local void UnRegisterSource(int channel) {
#ifdef USE_GLIB
- if ((int)(long)g_hash_table_lookup(UnitToChannel,
- (gpointer)(Channels[channel].Source.Base)) == channel + 1) {
- g_hash_table_remove(UnitToChannel,
- (gpointer)(long)(Channels[channel].Source.Base));
- }
+ if ((int)(long)g_hash_table_lookup(UnitToChannel,
+ (gpointer)(Channels[channel].Source.Base)) == channel +
1) {
+ g_hash_table_remove(UnitToChannel,
+ (gpointer)(long)(Channels[channel].Source.Base));
+ }
#else
- int i;
+ int i;
- i = channel;
- DebugLevel3Fn("FIXME: must write %d\n" _C_ channel);
+ i = channel;
+ DebugLevel3Fn("FIXME: must write %d\n" _C_ channel);
#endif
- DebugLevel3("Removing %p (channel %d)\n" _C_
- Channels[channel].Source.Base _C_ channel);
+ DebugLevel3("Removing %p (channel %d)\n" _C_
+ Channels[channel].Source.Base _C_ channel);
}
/**
-** Compute a suitable volume for something taking place at a given
-** distance from the current view point.
+** Compute a suitable volume for something taking place at a given
+** distance from the current view point.
**
-** @param d distance
-** @param range range
+** @param d distance
+** @param range range
**
-** @return volume for given distance (0..??)
+** @return volume for given distance
(0..??)
*/
local unsigned char VolumeForDistance(unsigned short d, unsigned char range) {
- int d_tmp;
- int range_tmp;
+ int d_tmp;
+ int range_tmp;
- //FIXME: THIS IS SLOW!!!!!!!
- if (d <= ViewPointOffset || range==INFINITE_SOUND_RANGE) {
- return MaxVolume;
- } else {
- if (range) {
- d -= ViewPointOffset;
- d_tmp = d * MAX_SOUND_RANGE;
- range_tmp = DistanceSilent * range;
- DebugLevel3("Distance: %d, Range: %d\n" _C_ d_tmp _C_ range_tmp);
- if (d_tmp > range_tmp) {
- return 0;
- } else {
- return (unsigned char)((range_tmp - d_tmp) * MAX_SOUND_RANGE /
range_tmp);
- }
+ //FIXME: THIS IS SLOW!!!!!!!
+ if (d <= ViewPointOffset || range==INFINITE_SOUND_RANGE) {
+ return MaxVolume;
} else {
- return 0;
+ if (range) {
+ d -= ViewPointOffset;
+ d_tmp = d * MAX_SOUND_RANGE;
+ range_tmp = DistanceSilent * range;
+ DebugLevel3("Distance: %d, Range: %d\n" _C_ d_tmp _C_
range_tmp);
+ if (d_tmp > range_tmp) {
+ return 0;
+ } else {
+ return (unsigned char)((range_tmp - d_tmp) *
MAX_SOUND_RANGE / range_tmp);
+ }
+ } else {
+ return 0;
+ }
}
- }
}
/*
@@ -571,29 +571,29 @@
** parameter of this request, or by mapping this range to a volume.
*/
local unsigned char ComputeVolume(SoundRequest* sr) {
- if (sr->IsVolume) {
- if (sr->Power > MaxVolume) {
- return MaxVolume;
+ if (sr->IsVolume) {
+ if (sr->Power > MaxVolume) {
+ return MaxVolume;
+ } else {
+ return (unsigned char)sr->Power;
+ }
} else {
- return (unsigned char)sr->Power;
+ // map distance to volume
+ return VolumeForDistance(sr->Power,
((ServerSoundId)(sr->Sound))->Range);
}
- } else {
- // map distance to volume
- return VolumeForDistance(sr->Power,
((ServerSoundId)(sr->Sound))->Range);
- }
}
/*
** "Randomly" choose a sample from a sound group.
*/
local Sample* SimpleChooseSample(ServerSoundId sound) {
- if (sound->Number == ONE_SOUND) {
- return sound->Sound.OneSound;
- } else {
- //FIXME: check for errors
- //FIXME: valid only in shared memory context (FrameCounter)
- return sound->Sound.OneGroup[FrameCounter % sound->Number];
- }
+ if (sound->Number == ONE_SOUND) {
+ return sound->Sound.OneSound;
+ } else {
+ //FIXME: check for errors
+ //FIXME: valid only in shared memory context (FrameCounter)
+ return sound->Sound.OneGroup[FrameCounter % sound->Number];
+ }
}
/*
@@ -602,60 +602,60 @@
*/
local Sample* ChooseSample(SoundRequest* sr)
{
- ServerSoundId theSound;
- Sample* result;
-
- result = NO_SOUND;
-
- if (sr->Sound != NO_SOUND) {
- theSound = (ServerSoundId)(sr->Sound);
- if (theSound->Number == TWO_GROUPS) {
- // handle a special sound (selection)
- if (SelectionHandler.Source.Base == sr->Source.Base
- && SelectionHandler.Source.Id == sr->Source.Id) {
- if (SelectionHandler.Sound == theSound->Sound.TwoGroups->First)
{
- DebugLevel3("First group\n");
- result = SimpleChooseSample(SelectionHandler.Sound);
- SelectionHandler.HowMany++;
- if (SelectionHandler.HowMany >= 3) {
- SelectionHandler.HowMany = 0;
- SelectionHandler.Sound =
(ServerSoundId)theSound->Sound.TwoGroups->Second;
- DebugLevel3("Switching to second group\n");
- }
+ ServerSoundId theSound;
+ Sample* result;
+
+ result = NO_SOUND;
+
+ if (sr->Sound != NO_SOUND) {
+ theSound = (ServerSoundId)(sr->Sound);
+ if (theSound->Number == TWO_GROUPS) {
+ // handle a special sound (selection)
+ if (SelectionHandler.Source.Base == sr->Source.Base
+ && SelectionHandler.Source.Id == sr->Source.Id)
{
+ if (SelectionHandler.Sound ==
theSound->Sound.TwoGroups->First) {
+ DebugLevel3("First group\n");
+ result =
SimpleChooseSample(SelectionHandler.Sound);
+ SelectionHandler.HowMany++;
+ if (SelectionHandler.HowMany >= 3) {
+ SelectionHandler.HowMany = 0;
+ SelectionHandler.Sound =
(ServerSoundId)theSound->Sound.TwoGroups->Second;
+ DebugLevel3("Switching to
second group\n");
+ }
+ } else {
+ //FIXME: checks for error
+ DebugLevel3("Second group\n");
+ // check wether the second group is
really a group
+ if (SelectionHandler.Sound->Number > 1)
{
+ result =
SelectionHandler.Sound->Sound.OneGroup[SelectionHandler.HowMany];
+ SelectionHandler.HowMany++;
+ if(SelectionHandler.HowMany >=
SelectionHandler.Sound->Number) {
+
SelectionHandler.HowMany = 0;
+ SelectionHandler.Sound
= (ServerSoundId)theSound->Sound.TwoGroups->First;
+ DebugLevel3("Switching
to first group\n");
+ }
+ } else {
+ result =
SelectionHandler.Sound->Sound.OneSound;
+ SelectionHandler.HowMany = 0;
+ SelectionHandler.Sound =
(ServerSoundId)theSound->Sound.TwoGroups->First;
+ DebugLevel3("Switching to first
group\n");
+ }
+ }
+ } else {
+ SelectionHandler.Source = sr->Source;
+ SelectionHandler.Sound =
theSound->Sound.TwoGroups->First;
+ result =
SimpleChooseSample(SelectionHandler.Sound);
+ SelectionHandler.HowMany = 1;
+ }
} else {
- //FIXME: checks for error
- DebugLevel3("Second group\n");
- // check wether the second group is really a group
- if (SelectionHandler.Sound->Number > 1) {
- result =
SelectionHandler.Sound->Sound.OneGroup[SelectionHandler.HowMany];
- SelectionHandler.HowMany++;
- if(SelectionHandler.HowMany >=
SelectionHandler.Sound->Number) {
- SelectionHandler.HowMany = 0;
- SelectionHandler.Sound =
(ServerSoundId)theSound->Sound.TwoGroups->First;
- DebugLevel3("Switching to first group\n");
+ // normal sound/sound group handling
+ result = SimpleChooseSample(theSound);
+ if (sr->Selection) {
+ SelectionHandler.Source = sr->Source;
}
- } else {
- result = SelectionHandler.Sound->Sound.OneSound;
- SelectionHandler.HowMany = 0;
- SelectionHandler.Sound =
(ServerSoundId)theSound->Sound.TwoGroups->First;
- DebugLevel3("Switching to first group\n");
- }
- }
- } else {
- SelectionHandler.Source = sr->Source;
- SelectionHandler.Sound = theSound->Sound.TwoGroups->First;
- result = SimpleChooseSample(SelectionHandler.Sound);
- SelectionHandler.HowMany = 1;
- }
- } else {
- // normal sound/sound group handling
- result = SimpleChooseSample(theSound);
- if (sr->Selection) {
- SelectionHandler.Source = sr->Source;
- }
+ }
}
- }
- return result;
+ return result;
}
/*
@@ -663,13 +663,13 @@
*/
global void FreeOneChannel(int channel)
{
- Channels[channel].Command = ChannelFree;
- Channels[channel].Point = NextFreeChannel;
- NextFreeChannel = channel;
- if (Channels[channel].Source.Base) {
- // unregister only valid sources
- UnRegisterSource(channel);
- }
+ Channels[channel].Command = ChannelFree;
+ Channels[channel].Point = NextFreeChannel;
+ NextFreeChannel = channel;
+ if (Channels[channel].Source.Base) {
+ // unregister only valid sources
+ UnRegisterSource(channel);
+ }
}
/*
@@ -678,25 +678,25 @@
*/
local int FillOneChannel(SoundRequest* sr)
{
- int next_free;
- int old_free;
+ int next_free;
+ int old_free;
- old_free = NextFreeChannel;
- if (NextFreeChannel < MaxChannels) {
- next_free = Channels[NextFreeChannel].Point;
- Channels[NextFreeChannel].Source = sr->Source;
- Channels[NextFreeChannel].Point = 0;
- Channels[NextFreeChannel].Volume = ComputeVolume(sr);
- Channels[NextFreeChannel].Command = ChannelPlay;
- Channels[NextFreeChannel].Sound = sr->Sound;
- Channels[NextFreeChannel].Sample = ChooseSample(sr);
- Channels[NextFreeChannel].Stereo = sr->Stereo;
- NextFreeChannel = next_free;
- } else {
- // should not happen
- DebugLevel0("***** NO FREE CHANNEL *****\n");
- }
- return old_free;
+ old_free = NextFreeChannel;
+ if (NextFreeChannel < MaxChannels) {
+ next_free = Channels[NextFreeChannel].Point;
+ Channels[NextFreeChannel].Source = sr->Source;
+ Channels[NextFreeChannel].Point = 0;
+ Channels[NextFreeChannel].Volume = ComputeVolume(sr);
+ Channels[NextFreeChannel].Command = ChannelPlay;
+ Channels[NextFreeChannel].Sound = sr->Sound;
+ Channels[NextFreeChannel].Sample = ChooseSample(sr);
+ Channels[NextFreeChannel].Stereo = sr->Stereo;
+ NextFreeChannel = next_free;
+ } else {
+ // should not happen
+ DebugLevel0("***** NO FREE CHANNEL *****\n");
+ }
+ return old_free;
}
/**
@@ -706,596 +706,596 @@
*/
local void FillChannels(int free_channels,int* discarded,int* started)
{
- int channel;
- SoundRequest* sr;
+ int channel;
+ SoundRequest* sr;
- sr = SoundRequests+NextSoundRequestOut;
- *discarded = 0;
- *started = 0;
- while (free_channels && sr->Used) {
- if (KeepRequest(sr)) {
- DebugLevel3("Source [%p]: start playing request %p at slot %d\n" _C_
- sr->Source.Base _C_ sr->Sound _C_ NextSoundRequestOut);
- channel = FillOneChannel(sr);
- if (sr->Source.Base) {
- //Register only sound with a valid origin
- RegisterSource(sr, channel);
- }
- --free_channels;
- DebugLevel3("Free channels: %d\n" _C_ free_channels);
- sr->Used = 0;
- ++NextSoundRequestOut;
- (*started)++;
- } else {
- // Discarding request (for whatever reason)
- DebugLevel3("Discarding resquest %p from %p at slot %d\n" _C_
- sr->Sound _C_ sr->Source.Base _C_ NextSoundRequestOut);
- sr->Used = 0;
- ++NextSoundRequestOut;
- (*discarded)++;
- }
- if(NextSoundRequestOut >= MAX_SOUND_REQUESTS) {
- NextSoundRequestOut = 0;
+ sr = SoundRequests+NextSoundRequestOut;
+ *discarded = 0;
+ *started = 0;
+ while (free_channels && sr->Used) {
+ if (KeepRequest(sr)) {
+ DebugLevel3("Source [%p]: start playing request %p at
slot %d\n" _C_
+ sr->Source.Base _C_ sr->Sound _C_
NextSoundRequestOut);
+ channel = FillOneChannel(sr);
+ if (sr->Source.Base) {
+ //Register only sound with a valid origin
+ RegisterSource(sr, channel);
+ }
+ --free_channels;
+ DebugLevel3("Free channels: %d\n" _C_ free_channels);
+ sr->Used = 0;
+ ++NextSoundRequestOut;
+ (*started)++;
+ } else {
+ // Discarding request (for whatever reason)
+ DebugLevel3("Discarding resquest %p from %p at slot %d\n" _C_
+ sr->Sound _C_ sr->Source.Base _C_
NextSoundRequestOut);
+ sr->Used = 0;
+ ++NextSoundRequestOut;
+ (*discarded)++;
+ }
+ if(NextSoundRequestOut >= MAX_SOUND_REQUESTS) {
+ NextSoundRequestOut = 0;
+ }
+ sr = SoundRequests + NextSoundRequestOut;
}
- sr = SoundRequests + NextSoundRequestOut;
- }
}
/**
-** Mix channels to stereo 32 bit.
+** Mix channels to stereo 32 bit.
**
-** @param buffer Buffer for mixed samples.
-** @param size Number of samples that fits into buffer.
+** @param buffer Buffer for mixed samples.
+** @param size Number of samples that fits into buffer.
**
-** @return How many channels become free after mixing them.
+** @return How many channels become free
after mixing them.
*/
local int MixChannelsToStereo32(int* buffer,int size)
{
- int channel;
- int i;
- int new_free_channels;
-
- new_free_channels = 0;
- for (channel = 0; channel < MaxChannels; ++channel) {
- if (Channels[channel].Command == ChannelPlay &&
- Channels[channel].Sample) {
- i = MixSampleToStereo32(Channels[channel].Sample,
- Channels[channel].Point, Channels[channel].Volume,
- Channels[channel].Stereo, buffer, size);
- Channels[channel].Point += i;
-
- if (Channels[channel].Point >= Channels[channel].Sample->Length) {
- // free channel as soon as possible (before playing)
- // useful in multithreading
- DebugLevel3("End playing request from %p\n" _C_
- Channels[channel].Source.Base);
- FreeOneChannel(channel);
- ++new_free_channels;
- }
+ int channel;
+ int i;
+ int new_free_channels;
+
+ new_free_channels = 0;
+ for (channel = 0; channel < MaxChannels; ++channel) {
+ if (Channels[channel].Command == ChannelPlay &&
+ Channels[channel].Sample) {
+ i = MixSampleToStereo32(Channels[channel].Sample,
+ Channels[channel].Point,
Channels[channel].Volume,
+ Channels[channel].Stereo, buffer, size);
+ Channels[channel].Point += i;
+
+ if (Channels[channel].Point >=
Channels[channel].Sample->Length) {
+ // free channel as soon as possible (before
playing)
+ // useful in multithreading
+ DebugLevel3("End playing request from %p\n" _C_
+ Channels[channel].Source.Base);
+ FreeOneChannel(channel);
+ ++new_free_channels;
+ }
+ }
}
- }
- return new_free_channels;
+ return new_free_channels;
}
#if SoundSampleSize == 8
/**
-** Clip mix to output stereo 8 unsigned bit.
+** Clip mix to output stereo 8 unsigned bit.
**
-** @param mix signed 32 bit input.
-** @param size number of samples in input.
-** @param output clipped 8 unsigned bit output buffer.
+** @param mix signed 32 bit input.
+** @param size number of samples in input.
+** @param output clipped 8 unsigned bit output buffer.
*/
local void ClipMixToStereo8(const int* mix, int size, unsigned char* output)
{
- int s;
+ int s;
- while (size--) {
- s = (*mix++) / 256;
- if (s > 127) {
- *output++ = 255;
- } else if (s < -127) {
- *output++ = 0;
- } else {
- *output++ = s + 127;
+ while (size--) {
+ s = (*mix++) / 256;
+ if (s > 127) {
+ *output++ = 255;
+ } else if (s < -127) {
+ *output++ = 0;
+ } else {
+ *output++ = s + 127;
+ }
}
- }
}
#endif
#if SoundSampleSize == 16
/**
-** Clip mix to output stereo 16 signed bit.
+** Clip mix to output stereo 16 signed bit.
**
-** @param mix signed 32 bit input.
-** @param size number of samples in input.
-** @param output clipped 16 signed bit output buffer.
+** @param mix signed 32 bit input.
+** @param size number of samples in input.
+** @param output clipped 16 signed bit output buffer.
*/
local void ClipMixToStereo16(const int* mix, int size, short* output)
{
- int s;
- const int* end;
+ int s;
+ const int* end;
- end = mix + size;
- while (mix < end) {
- s = (*mix++);
- if (s > SHRT_MAX) {
- *output++ = SHRT_MAX;
- } else if (s < SHRT_MIN) {
- *output++ = SHRT_MIN;
- } else {
- *output++ = s;
+ end = mix + size;
+ while (mix < end) {
+ s = (*mix++);
+ if (s > SHRT_MAX) {
+ *output++ = SHRT_MAX;
+ } else if (s < SHRT_MIN) {
+ *output++ = SHRT_MIN;
+ } else {
+ *output++ = s;
+ }
}
- }
}
#endif
/*----------------------------------------------------------------------------
--- Other
+-- Other
----------------------------------------------------------------------------*/
/**
-** Load one sample
+** Load one sample
**
-** @param name File name of sample (short version).
+** @param name File name of sample (short version).
**
-** @return General sample loaded from file into memory.
+** @return General sample loaded from file
into memory.
**
-** @todo Add streaming, cashing support.
+** @todo Add streaming, cashing support.
*/
local Sample* LoadSample(const char* name)
{
- Sample* sample;
- char* buf;
+ Sample* sample;
+ char* buf;
- // FIXME: find a better way to detect sound not in sound dir
- if (strstr(name, "campaign")) {
- buf = strdcat3(StratagusLibPath, "/", name);
- } else {
- buf = strdcat3(StratagusLibPath, "/sounds/", name);
- }
+ // FIXME: find a better way to detect sound not in sound dir
+ if (strstr(name, "campaign")) {
+ buf = strdcat3(StratagusLibPath, "/", name);
+ } else {
+ buf = strdcat3(StratagusLibPath, "/sounds/", name);
+ }
- if ((sample = LoadWav(buf, PlayAudioLoadInMemory))) {
- free(buf);
- return sample;
- }
+ if ((sample = LoadWav(buf, PlayAudioLoadInMemory))) {
+ free(buf);
+ return sample;
+ }
#ifdef USE_OGG
- if ((sample = LoadOgg(buf, PlayAudioLoadInMemory))) {
- free(buf);
- return sample;
- }
+ if ((sample = LoadOgg(buf, PlayAudioLoadInMemory))) {
+ free(buf);
+ return sample;
+ }
#endif
#ifdef USE_FLAC
- if ((sample = LoadFlac(buf, PlayAudioLoadInMemory))) {
- free(buf);
- return sample;
- }
+ if ((sample = LoadFlac(buf, PlayAudioLoadInMemory))) {
+ free(buf);
+ return sample;
+ }
#endif
#ifdef USE_MAD
- if ((sample = LoadMp3(buf, PlayAudioLoadInMemory))) {
- free(buf);
- return sample;
- }
+ if ((sample = LoadMp3(buf, PlayAudioLoadInMemory))) {
+ free(buf);
+ return sample;
+ }
#endif
- fprintf(stderr, "Can't load the sound `%s'\n", name);
+ fprintf(stderr, "Can't load the sound `%s'\n", name);
- // FIXME: should support more sample formats.
- free(buf);
- return sample;
+ // FIXME: should support more sample formats.
+ free(buf);
+ return sample;
}
/**
-** Ask the sound server to register a sound (and currently to load it)
-** and to return an unique identifier for it. The unique identifier is
-** memory pointer of the server.
+** Ask the sound server to register a sound (and currently to load
it)
+** and to return an unique identifier for it. The unique
identifier is
+** memory pointer of the server.
**
-** @param files An array of wav files.
-** @param number Number of files belonging together.
+** @param files An array of wav files.
+** @param number Number of files belonging together.
**
-** @return the sound unique identifier
+** @return the sound unique identifier
**
-** @todo FIXME: Must handle the errors better.
-** FIXME: Support for more sample files (ogg/flac/mp3).
+** @todo FIXME: Must handle the errors better.
+** FIXME: Support for more sample files
(ogg/flac/mp3).
*/
global SoundId RegisterSound(const char* files[], unsigned number)
{
- unsigned i;
- ServerSoundId id;
+ unsigned i;
+ ServerSoundId id;
- id = malloc(sizeof(*id));
- if (number > 1) { // load a sound group
- id->Sound.OneGroup = malloc(sizeof(Sample*) * number);
- for (i = 0; i < number; ++i) {
- DebugLevel3("Registering `%s'\n" _C_ files[i]);
- id->Sound.OneGroup[i] = LoadSample(files[i]);
- if (!id->Sound.OneGroup[i]) {
- free(id->Sound.OneGroup);
- free(id);
- return NO_SOUND;
- }
- }
- id->Number = number;
- } else { // load an unique sound
- DebugLevel3("Registering `%s'\n" _C_ files[0]);
- id->Sound.OneSound = LoadSample(files[0]);
- if (!id->Sound.OneSound) {
- free(id);
- return NO_SOUND;
+ id = malloc(sizeof(*id));
+ if (number > 1) { // load
a sound group
+ id->Sound.OneGroup = malloc(sizeof(Sample*) * number);
+ for (i = 0; i < number; ++i) {
+ DebugLevel3("Registering `%s'\n" _C_ files[i]);
+ id->Sound.OneGroup[i] = LoadSample(files[i]);
+ if (!id->Sound.OneGroup[i]) {
+ free(id->Sound.OneGroup);
+ free(id);
+ return NO_SOUND;
+ }
+ }
+ id->Number = number;
+ } else {
// load an unique sound
+ DebugLevel3("Registering `%s'\n" _C_ files[0]);
+ id->Sound.OneSound = LoadSample(files[0]);
+ if (!id->Sound.OneSound) {
+ free(id);
+ return NO_SOUND;
+ }
+ id->Number = ONE_SOUND;
}
- id->Number = ONE_SOUND;
- }
- id->Range = MAX_SOUND_RANGE;
- return (SoundId)id;
+ id->Range = MAX_SOUND_RANGE;
+ return (SoundId)id;
}
/**
-** Ask the sound server to put together two sounds to form a special sound.
+** Ask the sound server to put together two sounds to form a
special sound.
**
-** @param first first part of the group
-** @param second second part of the group
+** @param first first part of the group
+** @param second second part of the group
**
-** @return the special sound unique identifier
+** @return the special sound unique
identifier
*/
global SoundId RegisterTwoGroups(SoundId first, SoundId second)
{
- ServerSoundId id;
+ ServerSoundId id;
- if (first == NO_SOUND || second == NO_SOUND) {
- return NO_SOUND;
- }
- id = (ServerSoundId)malloc(sizeof(*id));
- id->Number = TWO_GROUPS;
- id->Sound.TwoGroups = (TwoGroups*)malloc(sizeof(TwoGroups));
- id->Sound.TwoGroups->First = first;
- id->Sound.TwoGroups->Second = second;
- id->Range = MAX_SOUND_RANGE;
+ if (first == NO_SOUND || second == NO_SOUND) {
+ return NO_SOUND;
+ }
+ id = (ServerSoundId)malloc(sizeof(*id));
+ id->Number = TWO_GROUPS;
+ id->Sound.TwoGroups = (TwoGroups*)malloc(sizeof(TwoGroups));
+ id->Sound.TwoGroups->First = first;
+ id->Sound.TwoGroups->Second = second;
+ id->Range = MAX_SOUND_RANGE;
- return (SoundId) id;
+ return (SoundId) id;
}
/**
-** Ask the sound server to change the range of a sound.
+** Ask the sound server to change the range of a sound.
**
-** @param sound the id of the sound to modify.
-** @param range the new range for this sound.
+** @param sound the id of the sound to modify.
+** @param range the new range for this sound.
*/
global void SetSoundRange(SoundId sound, unsigned char range)
{
- if (sound != NO_SOUND) {
- ((ServerSoundId) sound)->Range = range;
- DebugLevel3("Setting sound <%p> to range %u\n" _C_ sound _C_ range);
- }
+ if (sound != NO_SOUND) {
+ ((ServerSoundId) sound)->Range = range;
+ DebugLevel3("Setting sound <%p> to range %u\n" _C_ sound _C_
range);
+ }
}
/**
-** Mix into buffer.
+** Mix into buffer.
**
-** @param buffer Buffer to be filled with samples. Buffer must be big
-** enough.
-** @param samples Number of samples.
+** @param buffer Buffer to be filled with samples.
Buffer must be big
+** enough.
+** @param samples Number of samples.
*/
global void MixIntoBuffer(void* buffer, int samples)
{
- int* mixer_buffer;
- int free_channels;
- int dummy1;
- int dummy2;
-
- free_channels = HowManyFree();
- FillChannels(free_channels, &dummy1, &dummy2);
-
- // Create empty mixer buffer
- mixer_buffer = alloca(samples * sizeof(*mixer_buffer));
- // FIXME: can save the memset here, if first channel sets the values
- memset(mixer_buffer, 0, samples * sizeof(*mixer_buffer));
-
- // Add channels to mixer buffer
- MixChannelsToStereo32(mixer_buffer, samples);
- // Add music to mixer buffer
- MixMusicToStereo32(mixer_buffer, samples);
+ int* mixer_buffer;
+ int free_channels;
+ int dummy1;
+ int dummy2;
+
+ free_channels = HowManyFree();
+ FillChannels(free_channels, &dummy1, &dummy2);
+
+ // Create empty mixer buffer
+ mixer_buffer = alloca(samples * sizeof(*mixer_buffer));
+ // FIXME: can save the memset here, if first channel sets the values
+ memset(mixer_buffer, 0, samples * sizeof(*mixer_buffer));
+
+ // Add channels to mixer buffer
+ MixChannelsToStereo32(mixer_buffer, samples);
+ // Add music to mixer buffer
+ MixMusicToStereo32(mixer_buffer, samples);
#if SoundSampleSize == 8
- ClipMixToStereo8(mixer_buffer, samples, buffer);
+ ClipMixToStereo8(mixer_buffer, samples, buffer);
#endif
#if SoundSampleSize==16
- ClipMixToStereo16(mixer_buffer, samples, buffer);
+ ClipMixToStereo16(mixer_buffer, samples, buffer);
#endif
}
#ifndef USE_SDLA
/**
-** Write buffer to sound card.
+** Write buffer to sound card.
*/
global void WriteSound(void)
{
#if SoundSampleSize == 8
- char buffer[1024];
+ char buffer[1024];
#endif
#if SoundSampleSize == 16
- short buffer[1024];
+ short buffer[1024];
#endif
- // ARI: If DSP open had failed: No soundcard, other user, etc..
- if (SoundFildes == -1) {
- DebugLevel0Fn("Shouldn't be reached\n");
- return;
- }
+ // ARI: If DSP open had failed: No soundcard, other user, etc..
+ if (SoundFildes == -1) {
+ DebugLevel0Fn("Shouldn't be reached\n");
+ return;
+ }
- DebugLevel3Fn("\n");
+ DebugLevel3Fn("\n");
- if (0) {
- audio_buf_info info;
+ if (0) {
+ audio_buf_info info;
- ioctl(SoundFildes, SNDCTL_DSP_GETOSPACE, &info);
- DebugLevel0("%lu Free bytes %d\n" _C_ GameCycle _C_ info.bytes);
- if (info.bytes < (int)sizeof(buffer)) {
- return;
+ ioctl(SoundFildes, SNDCTL_DSP_GETOSPACE, &info);
+ DebugLevel0("%lu Free bytes %d\n" _C_ GameCycle _C_ info.bytes);
+ if (info.bytes < (int)sizeof(buffer)) {
+ return;
+ }
}
- }
- MixIntoBuffer(buffer, sizeof(buffer) / sizeof(*buffer));
+ MixIntoBuffer(buffer, sizeof(buffer) / sizeof(*buffer));
#ifdef WITH_ARTSC
- if (WriteArtsSound(buffer, sizeof(buffer)) < 0) {
- DebugLevel0Fn("ARTSD: Write error - Shouldn't happen!\n");
-
- }
+ if (WriteArtsSound(buffer, sizeof(buffer)) < 0) {
+ DebugLevel0Fn("ARTSD: Write error - Shouldn't happen!\n");
+
+ }
#else
- while (write(SoundFildes, buffer, sizeof(buffer)) == -1) {
- switch (errno) {
- case EAGAIN:
- case EINTR:
- continue;
+ while (write(SoundFildes, buffer, sizeof(buffer)) == -1) {
+ switch (errno) {
+ case EAGAIN:
+ case EINTR:
+ continue;
+ }
+ perror("write");
+ break;
}
- perror("write");
- break;
- }
#endif
}
#endif
-#ifdef USE_SDLA // {
+#ifdef USE_SDLA // {
global void WriteSound(void)
{
}
/**
-** Fill buffer for the sound card.
+** Fill buffer for the sound card.
**
-** @see SDL_OpenAudio
+** @see SDL_OpenAudio
**
-** @param udata the pointer stored in userdata field of SDL_AudioSpec.
-** @param stream pointer to buffer you want to fill with information.
-** @param len is length of audio buffer in bytes.
+** @param udata the pointer stored in userdata field of
SDL_AudioSpec.
+** @param stream pointer to buffer you want to fill with
information.
+** @param len is length of audio buffer in bytes.
*/
global void FillAudio(void* udata __attribute__((unused)), Uint8* stream, int
len)
{
#if SoundSampleSize == 16
- len >>= 1;
+ len >>= 1;
#endif
- DebugLevel3Fn("%d\n" _C_ len);
+ DebugLevel3Fn("%d\n" _C_ len);
- MixIntoBuffer(stream, len);
+ MixIntoBuffer(stream, len);
}
-#endif // } USE_SDLA
+#endif // } USE_SDLA
-#ifdef USE_THREAD // {
+#ifdef USE_THREAD // {
/**
-** FIXME: docu
+** FIXME: docu
*/
global void WriteSoundThreaded(void)
{
- int mixer_buffer[1024];
+ int mixer_buffer[1024];
#if SoundSampleSize == 8
- char buffer[1024];
+ char buffer[1024];
#endif
#if SoundSampleSize == 16
- short buffer[1024];
+ short buffer[1024];
#endif
- int new_free_channels;
- int free_channels;
- int how_many_playing;
- int discarded_request;
- int started_request;
-
- DebugLevel3Fn("\n");
-
- free_channels = MaxChannels;
- how_many_playing = 0;
- // wait for the first sound to come
- sem_wait(&SoundThreadChannelSemaphore);
- for (;;) {
- if (0) {
- audio_buf_info info;
-
- ioctl(SoundFildes, SNDCTL_DSP_GETOSPACE, &info);
- DebugLevel0("Free bytes %d\n" _C_ info.bytes);
- }
- FillChannels(free_channels, &discarded_request, &started_request);
- how_many_playing += started_request;
- new_free_channels = 0;
- if (how_many_playing || PlayingMusic) {
-
- memset(mixer_buffer, 0, sizeof(mixer_buffer));
+ int new_free_channels;
+ int free_channels;
+ int how_many_playing;
+ int discarded_request;
+ int started_request;
+
+ DebugLevel3Fn("\n");
+
+ free_channels = MaxChannels;
+ how_many_playing = 0;
+ // wait for the first sound to come
+ sem_wait(&SoundThreadChannelSemaphore);
+ for (;;) {
+ if (0) {
+ audio_buf_info info;
- if (how_many_playing) {
- new_free_channels = MixChannelsToStereo32(mixer_buffer,
- sizeof(mixer_buffer) / sizeof(int));
- }
- MixMusicToStereo32(mixer_buffer,
- sizeof(mixer_buffer) / sizeof(int));
+ ioctl(SoundFildes, SNDCTL_DSP_GETOSPACE, &info);
+ DebugLevel0("Free bytes %d\n" _C_ info.bytes);
+ }
+ FillChannels(free_channels, &discarded_request,
&started_request);
+ how_many_playing += started_request;
+ new_free_channels = 0;
+ if (how_many_playing || PlayingMusic) {
+
+ memset(mixer_buffer, 0, sizeof(mixer_buffer));
+
+ if (how_many_playing) {
+ new_free_channels =
MixChannelsToStereo32(mixer_buffer,
+ sizeof(mixer_buffer) / sizeof(int));
+ }
+ MixMusicToStereo32(mixer_buffer,
+ sizeof(mixer_buffer) / sizeof(int));
#if SoundSampleSize == 8
- ClipMixToStereo8(mixer_buffer, sizeof(mixer_buffer) / sizeof(int),
- buffer);
+ ClipMixToStereo8(mixer_buffer, sizeof(mixer_buffer) /
sizeof(int),
+ buffer);
#endif
#if SoundSampleSize == 16
- ClipMixToStereo16(mixer_buffer, sizeof(mixer_buffer) / sizeof(int),
- buffer);
+ ClipMixToStereo16(mixer_buffer, sizeof(mixer_buffer) /
sizeof(int),
+ buffer);
#endif
#ifdef WITH_ARTSC
- if (WriteArtsSound(buffer, sizeof(buffer)) < 0) {
- DebugLevel0Fn("ARTSD: Write error - Shouldn't happen!\n");
-
- }
+ if (WriteArtsSound(buffer, sizeof(buffer)) < 0) {
+ DebugLevel0Fn("ARTSD: Write error - Shouldn't
happen!\n");
+
+ }
#else
- while (write(SoundFildes, buffer, sizeof(buffer)) == -1) {
- switch (errno) {
- case EAGAIN:
- case EINTR:
- continue;
- }
- perror("write");
- break;
- }
+ while (write(SoundFildes, buffer, sizeof(buffer)) ==
-1) {
+ switch (errno) {
+ case EAGAIN:
+ case EINTR:
+ continue;
+ }
+ perror("write");
+ break;
+ }
#endif
- how_many_playing -= new_free_channels;
- }
- free_channels = MaxChannels - how_many_playing;
- DebugLevel3("Channels: %d %d %d\n" _C_ free_channels _C_
how_many_playing _C_
- new_free_channels);
- new_free_channels += discarded_request;
- // decrement semaphore by the number of stopped channels
- for (; new_free_channels > 0; --new_free_channels) {
- // sem_getvalue(&SoundThreadChannelSemaphore,&tmp);
- // DebugLevel3("SoundSemaphore: %d\n" _C_ tmp);
- sem_wait(&SoundThreadChannelSemaphore);
- // sem_getvalue(&SoundThreadChannelSemaphore,&tmp);
- // DebugLevel3("SoundSemaphore: %d\n" _C_ tmp);
+ how_many_playing -= new_free_channels;
+ }
+ free_channels = MaxChannels - how_many_playing;
+ DebugLevel3("Channels: %d %d %d\n" _C_ free_channels _C_
how_many_playing _C_
+ new_free_channels);
+ new_free_channels += discarded_request;
+ // decrement semaphore by the number of stopped channels
+ for (; new_free_channels > 0; --new_free_channels) {
+ //
sem_getvalue(&SoundThreadChannelSemaphore,&tmp);
+ // DebugLevel3("SoundSemaphore: %d\n" _C_
tmp);
+ sem_wait(&SoundThreadChannelSemaphore);
+ //
sem_getvalue(&SoundThreadChannelSemaphore,&tmp);
+ // DebugLevel3("SoundSemaphore: %d\n" _C_
tmp);
+ }
}
- }
}
-#endif // } USE_THREAD
+#endif // } USE_THREAD
/**
-** Initialize sound card.
+** Initialize sound card.
*/
global int InitSound(void)
{
- int dummy;
+ int dummy;
- MusicTerminated = 0;
+ MusicTerminated = 0;
#ifdef USE_SDLA
- MusicTerminatedMutex = SDL_CreateMutex();
+ MusicTerminatedMutex = SDL_CreateMutex();
#endif
#ifdef USE_SDLA
- //
- // Open sound device, 8bit samples, stereo.
- //
- if (InitSdlSound(SoundDeviceName, SoundFrequency, SoundSampleSize,
- WaitForSoundDevice)) {
- return 1;
- }
+ //
+ // Open sound device, 8bit samples, stereo.
+ //
+ if (InitSdlSound(SoundDeviceName, SoundFrequency, SoundSampleSize,
+ WaitForSoundDevice)) {
+ return 1;
+ }
#else
#ifdef WITH_ARTSC
- //
- // Connect to artsd, 8bit samples, stereo.
- //
- if (InitArtsSound(SoundFrequency, SoundSampleSize)) {
- return 1;
- }
+ //
+ // Connect to artsd, 8bit samples, stereo.
+ //
+ if (InitArtsSound(SoundFrequency, SoundSampleSize)) {
+ return 1;
+ }
#else
- //
- // Open dsp device, 8bit samples, stereo.
- //
- if (InitOssSound(SoundDeviceName, SoundFrequency, SoundSampleSize,
- WaitForSoundDevice)) {
- return 1;
- }
-#endif // WITH_ARTSC
-#endif // USE_SDLA
-
- // ARI: The following must be done here to allow sound to work in
- // pre-start menus!
- // initialize channels
- for (dummy = 0; dummy < MaxChannels; ++dummy) {
- Channels[dummy].Point = dummy + 1;
- }
+ //
+ // Open dsp device, 8bit samples, stereo.
+ //
+ if (InitOssSound(SoundDeviceName, SoundFrequency, SoundSampleSize,
+ WaitForSoundDevice)) {
+ return 1;
+ }
+#endif // WITH_ARTSC
+#endif // USE_SDLA
+
+ // ARI: The following must be done here to
allow sound to work in
+ // pre-start menus!
+ // initialize channels
+ for (dummy = 0; dummy < MaxChannels; ++dummy) {
+ Channels[dummy].Point = dummy + 1;
+ }
- // initialize unit to channel hash table
- // WARNING: creation is only valid for a hash table using pointers as key
+ // initialize unit to channel hash table
+ // WARNING: creation is only valid for a hash table using pointers as
key
#ifdef USE_GLIB
- UnitToChannel = g_hash_table_new(g_direct_hash, NULL);
+ UnitToChannel = g_hash_table_new(g_direct_hash, NULL);
#else
- DebugLevel0Fn("FIXME: must write non GLIB hash functions\n");
+ DebugLevel0Fn("FIXME: must write non GLIB hash functions\n");
#endif
- return 0;
+ return 0;
}
/**
-** Initialize sound server structures (and thread)
+** Initialize sound server structures (and thread)
*/
global int InitSoundServer(void)
{
- int MapWidth;
- int MapHeight;
+ int MapWidth;
+ int MapHeight;
- MapWidth = (TheUI.MapArea.EndX - TheUI.MapArea.X + TileSizeX) / TileSizeX;
- MapHeight = (TheUI.MapArea.EndY - TheUI.MapArea.Y + TileSizeY) / TileSizeY;
- //FIXME: Valid only in shared memory context!
- DistanceSilent = 3 * max(MapWidth, MapHeight);
- DebugLevel2("Distance Silent: %d\n" _C_ DistanceSilent);
- ViewPointOffset = max(MapWidth / 2, MapHeight / 2);
- DebugLevel2("ViewPointOffset: %d\n" _C_ ViewPointOffset);
+ MapWidth = (TheUI.MapArea.EndX - TheUI.MapArea.X + TileSizeX) /
TileSizeX;
+ MapHeight = (TheUI.MapArea.EndY - TheUI.MapArea.Y + TileSizeY) /
TileSizeY;
+ //FIXME: Valid only in shared memory context!
+ DistanceSilent = 3 * max(MapWidth, MapHeight);
+ DebugLevel2("Distance Silent: %d\n" _C_ DistanceSilent);
+ ViewPointOffset = max(MapWidth / 2, MapHeight / 2);
+ DebugLevel2("ViewPointOffset: %d\n" _C_ ViewPointOffset);
#ifdef USE_THREAD
- if (WithSoundThread) {
- //prepare for the sound thread
- if (sem_init(&SoundThreadChannelSemaphore, 0, 0)) {
- //FIXME: better error handling
- PrintFunction();
- // FIXME: ARI: strerror_r() is better here, but not compatible
- fprintf(stdout, "%s\n", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
- if (pthread_create(&SoundThread, NULL, (void*)&WriteSoundThreaded,
NULL)) {
- //FIXME: better error handling
- PrintFunction();
- fprintf(stdout, "%s\n", strerror(errno));
- close(SoundFildes);
- SoundFildes = -1;
- return 1;
- }
- SoundThreadRunning = 1;
- }
+ if (WithSoundThread) {
+ //prepare for the sound thread
+ if (sem_init(&SoundThreadChannelSemaphore, 0, 0)) {
+ //FIXME: better error handling
+ PrintFunction();
+ // FIXME: ARI: strerror_r() is better here, but not compatible
+ fprintf(stdout, "%s\n", strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
+ if (pthread_create(&SoundThread, NULL, (void*)&WriteSoundThreaded,
NULL)) {
+ //FIXME: better error handling
+ PrintFunction();
+ fprintf(stdout, "%s\n", strerror(errno));
+ close(SoundFildes);
+ SoundFildes = -1;
+ return 1;
+ }
+ SoundThreadRunning = 1;
+ }
#endif
-
- return 0;
+
+ return 0;
}
/**
-** Cleanup sound server.
+** Cleanup sound server.
*/
global void QuitSound(void)
{
#ifdef USE_SDLA
- SDL_CloseAudio();
- SoundFildes = -1;
+ SDL_CloseAudio();
+ SoundFildes = -1;
#else
#ifdef WITH_ARTSC
- ExitArtsSound();
+ ExitArtsSound();
#else // ! WITH_ARTSC
- if (SoundFildes != -1) {
- close(SoundFildes);
- SoundFildes = -1;
- }
+ if (SoundFildes != -1) {
+ close(SoundFildes);
+ SoundFildes = -1;
+ }
#endif // WITH_ARTSC
#endif // USE_SDLA
}
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
-global int WaitForSoundDevice; /// Block until sound device available
+global int WaitForSoundDevice; /// Block until sound
device available
//@}
Index: stratagus/src/sound/unitsound.c
diff -u stratagus/src/sound/unitsound.c:1.26
stratagus/src/sound/unitsound.c:1.27
--- stratagus/src/sound/unitsound.c:1.26 Tue Dec 2 06:44:19 2003
+++ stratagus/src/sound/unitsound.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: unitsound.c,v 1.26 2003/12/01 19:44:19 nehalmistry Exp $
+// $Id: unitsound.c,v 1.27 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Include
+-- Include
----------------------------------------------------------------------------*/
#include <stdio.h>
@@ -40,7 +40,7 @@
#include "stratagus.h"
-#ifdef WITH_SOUND // {
+#ifdef WITH_SOUND // {
#include "video.h"
#include "sound_id.h"
@@ -53,270 +53,270 @@
#include "map.h"
/*----------------------------------------------------------------------------
--- Declarations
+-- Declarations
----------------------------------------------------------------------------*/
/**
-** Simple sound definition:
-** There is only one sound/voice that could be used for this
-** sound identifier.
+** Simple sound definition:
+** There is only one sound/voice that could be
used for this
+** sound identifier.
*/
typedef struct _simple_sound_ {
- char* Name; /// name of the sound
- char* File; /// corresponding sound file
+ char* Name;
/// name of the sound
+ char* File;
/// corresponding sound file
} SimpleSound;
/**
-** Structure for remaping a sound to a new name.
+** Structure for remaping a sound to a new name.
*/
typedef struct _sound_remap_ {
- char* NewName; /// Name in unit-type definition
- char* BaseName; /// Name used in sound definition
+ char* NewName; /// Name in
unit-type definition
+ char* BaseName; /// Name used
in sound definition
} SoundRemap;
-#define MaxSimpleGroups 7 /// maximal number of sounds pro group
+#define MaxSimpleGroups 7 /// maximal number of
sounds pro group
/**
-** Sound group definition:
-** There is a collection of sounds/voices that could be randomly
-** be used fot this sound identifier.
+** Sound group definition:
+** There is a collection of sounds/voices that
could be randomly
+** be used fot this sound identifier.
*/
typedef struct _sound_group_ {
- char* Name; /// name of the group
- char* Sounds[MaxSimpleGroups]; /// list of sound files
+ char* Name;
/// name of the group
+ char* Sounds[MaxSimpleGroups]; /// list of sound files
} SoundGroup;
/**
-** Selection structure:
+** Selection structure:
**
-** Special sound structure currently used for the selection of an unit.
-** For a special number of the uses the first group is used, after this
-** the second groups is played.
+** Special sound structure currently used for the selection of an
unit.
+** For a special number of the uses the first group is used, after
this
+** the second groups is played.
*/
typedef struct _selection_group_ {
- char* Name; /// name of the selection sound
- char* First; /// name of the sound
- char* Second; /// name of the annoyed sound
+ char* Name;
/// name of the selection sound
+ char* First; /// name of the
sound
+ char* Second; /// name of the
annoyed sound
} SelectionGroup;
/*----------------------------------------------------------------------------
--- Variables
+-- Variables
----------------------------------------------------------------------------*/
/**
-** Simple sounds currently available.
+** Simple sounds currently available.
*/
local SimpleSound* SimpleSounds;
/**
-** Sound remaping currently available.
+** Sound remaping currently available.
*/
local SoundRemap* SoundRemaps;
/**
-** Sound-groups currently available
+** Sound-groups currently available
*/
local SoundGroup* SoundGroups;
/**
-** Selection-groups currently available
+** Selection-groups currently available
*/
local SelectionGroup* SelectionGroups;
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
/**
-** Computes the number of sounds in a sound group
+** Computes the number of sounds in a sound group
**
-** @param group list of file names
+** @param group list of file names
**
-** @return number of sounds in group
+** @return number of sounds in group
*/
local int NbSoundsInGroup(char* const* const group)
{
- int i;
+ int i;
- for (i = 0;i < MaxSimpleGroups; ++i) {
- if (!group[i]) {
- return i;
+ for (i = 0;i < MaxSimpleGroups; ++i) {
+ if (!group[i]) {
+ return i;
+ }
}
- }
- return i;
+ return i;
}
/**
-** Loads all simple sounds (listed in the SimpleSounds array).
+** Loads all simple sounds (listed in the SimpleSounds array).
*/
local void LoadSimpleSounds(void)
{
- int i;
+ int i;
- if (SimpleSounds) {
- for (i = 0; SimpleSounds[i].Name; ++i) {
- MakeSound(SimpleSounds[i].Name, (const
char**)&(SimpleSounds[i].File), 1);
+ if (SimpleSounds) {
+ for (i = 0; SimpleSounds[i].Name; ++i) {
+ MakeSound(SimpleSounds[i].Name, (const
char**)&(SimpleSounds[i].File), 1);
+ }
}
- }
}
/**
-** Loads all sound groups.
-** Special groups are created.
+** Loads all sound groups.
+** Special groups are created.
*/
local void LoadSoundGroups(void)
{
- int i;
+ int i;
- if (SoundGroups) {
- for (i = 0; SoundGroups[i].Name; ++i) {
- MakeSound(SoundGroups[i].Name, (const char**)SoundGroups[i].Sounds,
- NbSoundsInGroup(SoundGroups[i].Sounds));
+ if (SoundGroups) {
+ for (i = 0; SoundGroups[i].Name; ++i) {
+ MakeSound(SoundGroups[i].Name, (const
char**)SoundGroups[i].Sounds,
+ NbSoundsInGroup(SoundGroups[i].Sounds));
+ }
}
- }
- if (SelectionGroups) {
- for (i = 0; SelectionGroups[i].Name; ++i) {
- //FIXME: might be more efficient
- MakeSoundGroup(SelectionGroups[i].Name,
- SoundIdForName(SelectionGroups[i].First),
- SoundIdForName(SelectionGroups[i].Second));
+ if (SelectionGroups) {
+ for (i = 0; SelectionGroups[i].Name; ++i) {
+ //FIXME: might be more efficient
+ MakeSoundGroup(SelectionGroups[i].Name,
+ SoundIdForName(SelectionGroups[i].First),
+ SoundIdForName(SelectionGroups[i].Second));
+ }
}
- }
}
/**
-** Performs remaping listed in the Remaps array. Maps also critter
-** sounds to their correct values.
+** Performs remaping listed in the Remaps array. Maps also critter
+** sounds to their correct values.
*/
local void RemapSounds(void)
{
- int i;
+ int i;
- if (SoundRemaps) {
- for (i = 0; SoundRemaps[i].NewName; ++i) {
- //FIXME: should be more efficient
- MapSound(SoundRemaps[i].NewName,
- SoundIdForName(SoundRemaps[i].BaseName));
+ if (SoundRemaps) {
+ for (i = 0; SoundRemaps[i].NewName; ++i) {
+ //FIXME: should be more efficient
+ MapSound(SoundRemaps[i].NewName,
+ SoundIdForName(SoundRemaps[i].BaseName));
+ }
}
- }
- //
- // Make some general sounds.
- //
- // FIXME: move to config CCL
- MapSound("gold-mine-help", SoundIdForName("basic orc voices help 1"));
-
- // critter mapping FIXME: must support more terrains.
-
- switch (TheMap.Terrain) {
- case TilesetSummer:
- MakeSoundGroup("critter-selected",
- SoundIdForName("sheep selected"),
- SoundIdForName("sheep annoyed"));
- break;
- case TilesetWinter:
- MakeSoundGroup("critter-selected",
- SoundIdForName("seal selected"),
- SoundIdForName("seal annoyed"));
- break;
- case TilesetWasteland:
- MakeSoundGroup("critter-selected",
- SoundIdForName("pig selected"),
- SoundIdForName("pig annoyed"));
- break;
- case TilesetSwamp:
- MakeSoundGroup("critter-selected",
- SoundIdForName("warthog selected"),
- SoundIdForName("warthog annoyed"));
- break;
- default:
- DebugLevel2("Unknown Terrain %d\n" _C_ TheMap.Terrain);
- }
+ //
+ // Make some general sounds.
+ //
+ // FIXME: move to config CCL
+ MapSound("gold-mine-help", SoundIdForName("basic orc voices help 1"));
+
+ // critter mapping FIXME: must support more terrains.
+
+ switch (TheMap.Terrain) {
+ case TilesetSummer:
+ MakeSoundGroup("critter-selected",
+ SoundIdForName("sheep selected"),
+ SoundIdForName("sheep annoyed"));
+ break;
+ case TilesetWinter:
+ MakeSoundGroup("critter-selected",
+ SoundIdForName("seal selected"),
+ SoundIdForName("seal annoyed"));
+ break;
+ case TilesetWasteland:
+ MakeSoundGroup("critter-selected",
+ SoundIdForName("pig selected"),
+ SoundIdForName("pig annoyed"));
+ break;
+ case TilesetSwamp:
+ MakeSoundGroup("critter-selected",
+ SoundIdForName("warthog selected"),
+ SoundIdForName("warthog annoyed"));
+ break;
+ default:
+ DebugLevel2("Unknown Terrain %d\n" _C_ TheMap.Terrain);
+ }
}
/**
-** Load all sounds for units.
+** Load all sounds for units.
*/
global void LoadUnitSounds(void)
{
- if (SoundFildes != -1) {
- LoadSimpleSounds();
- LoadSoundGroups();
- RemapSounds();
- }
+ if (SoundFildes != -1) {
+ LoadSimpleSounds();
+ LoadSoundGroups();
+ RemapSounds();
+ }
}
/**
-** Map the sounds of all unit-types to the correct sound id.
-** And overwrite the sound ranges. @todo the sound ranges should be
-** configurable by user with CCL.
+** Map the sounds of all unit-types to the correct sound id.
+** And overwrite the sound ranges. @todo the sound ranges should be
+** configurable by user with CCL.
*/
global void MapUnitSounds(void)
{
- UnitType* type;
- int i;
- int j;
-
- if (SoundFildes != -1) {
- SetSoundRange(SoundIdForName("tree chopping"), 32);
-
- //
- // Parse all units sounds.
- //
- for (i = 0; i < NumUnitTypes; ++i) {
- type = UnitTypes[i];
- if (type->Sound.Selected.Name) {
- type->Sound.Selected.Sound =
- SoundIdForName(type->Sound.Selected.Name);
- }
- if (type->Sound.Acknowledgement.Name) {
- type->Sound.Acknowledgement.Sound =
- SoundIdForName(type->Sound.Acknowledgement.Name);
- /*
- // Acknowledge sounds have infinite range
- SetSoundRange(type->Sound.Acknowledgement.Sound,
- INFINITE_SOUND_RANGE);
- */
- }
- if (type->Sound.Ready.Name) {
- type->Sound.Ready.Sound =
- SoundIdForName(type->Sound.Ready.Name);
- // Ready sounds have infinite range
- SetSoundRange(type->Sound.Ready.Sound,
- INFINITE_SOUND_RANGE);
- }
- if (type->Sound.Repair.Name) {
- type->Sound.Repair.Sound =
- SoundIdForName(type->Sound.Repair.Name);
- }
- for (j = 0; j < MaxCosts; ++j) {
- if (type->Sound.Harvest[j].Name) {
- type->Sound.Harvest[j].Sound =
- SoundIdForName(type->Sound.Harvest[j].Name);
+ UnitType* type;
+ int i;
+ int j;
+
+ if (SoundFildes != -1) {
+ SetSoundRange(SoundIdForName("tree chopping"), 32);
+
+ //
+ // Parse all units sounds.
+ //
+ for (i = 0; i < NumUnitTypes; ++i) {
+ type = UnitTypes[i];
+ if (type->Sound.Selected.Name) {
+ type->Sound.Selected.Sound =
+
SoundIdForName(type->Sound.Selected.Name);
+ }
+ if (type->Sound.Acknowledgement.Name) {
+ type->Sound.Acknowledgement.Sound =
+
SoundIdForName(type->Sound.Acknowledgement.Name);
+ /*
+ // Acknowledge sounds have infinite range
+ SetSoundRange(type->Sound.Acknowledgement.Sound,
+ INFINITE_SOUND_RANGE);
+ */
+ }
+ if (type->Sound.Ready.Name) {
+ type->Sound.Ready.Sound =
+ SoundIdForName(type->Sound.Ready.Name);
+ // Ready sounds have infinite range
+ SetSoundRange(type->Sound.Ready.Sound,
+ INFINITE_SOUND_RANGE);
+ }
+ if (type->Sound.Repair.Name) {
+ type->Sound.Repair.Sound =
+ SoundIdForName(type->Sound.Repair.Name);
+ }
+ for (j = 0; j < MaxCosts; ++j) {
+ if (type->Sound.Harvest[j].Name) {
+ type->Sound.Harvest[j].Sound =
+
SoundIdForName(type->Sound.Harvest[j].Name);
+ }
+ }
+ // FIXME: will be modified, attack sound be moved to
missile/weapon
+ if (type->Weapon.Attack.Name) {
+ type->Weapon.Attack.Sound =
+
SoundIdForName(type->Weapon.Attack.Name);
+ }
+ if (type->Sound.Help.Name) {
+ type->Sound.Help.Sound =
+ SoundIdForName(type->Sound.Help.Name);
+ // Help sounds have infinite range
+ SetSoundRange(type->Sound.Help.Sound,
+ INFINITE_SOUND_RANGE);
+ }
+ if (type->Sound.Dead.Name) {
+ type->Sound.Dead.Sound =
+ SoundIdForName(type->Sound.Dead.Name);
+ }
}
- }
- // FIXME: will be modified, attack sound be moved to missile/weapon
- if (type->Weapon.Attack.Name) {
- type->Weapon.Attack.Sound =
- SoundIdForName(type->Weapon.Attack.Name);
- }
- if (type->Sound.Help.Name) {
- type->Sound.Help.Sound =
- SoundIdForName(type->Sound.Help.Name);
- // Help sounds have infinite range
- SetSoundRange(type->Sound.Help.Sound,
- INFINITE_SOUND_RANGE);
- }
- if (type->Sound.Dead.Name) {
- type->Sound.Dead.Sound =
- SoundIdForName(type->Sound.Dead.Name);
- }
}
- }
}
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
//@}
Index: stratagus/src/sound/wav.c
diff -u stratagus/src/sound/wav.c:1.35 stratagus/src/sound/wav.c:1.36
--- stratagus/src/sound/wav.c:1.35 Fri Nov 14 18:23:42 2003
+++ stratagus/src/sound/wav.c Tue Dec 23 14:48:04 2003
@@ -1,9 +1,9 @@
-// _________ __ __
+// _________ __ __
// / _____// |_____________ _/ |______ ____ __ __ ______
// \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
// / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
// /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
-// \/ \/ \//_____/ \/
+// \/ \/ \//_____/ \/
// ______________________ ______________________
// T H E W A R B E G I N S
// Stratagus - A free fantasy real time strategy game engine
@@ -26,12 +26,12 @@
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//
-// $Id: wav.c,v 1.35 2003/11/14 07:23:42 mr-russ Exp $
+// $Id: wav.c,v 1.36 2003/12/23 03:48:04 jsalmon3 Exp $
//@{
/*----------------------------------------------------------------------------
--- Includes
+-- Includes
----------------------------------------------------------------------------*/
#include <stdio.h>
@@ -49,296 +49,296 @@
#include "wav.h"
/*----------------------------------------------------------------------------
--- Declaration
+-- Declaration
----------------------------------------------------------------------------*/
-/**
-** Private wav data structure to handle wav streaming.
+/**
+** Private wav data structure to handle wav streaming.
*/
typedef struct _wav_data_ {
- char* PointerInBuffer; /// Pointer into buffer
- CLFile* WavFile; /// Vorbis file handle
+ char* PointerInBuffer; /// Pointer into buffer
+ CLFile* WavFile; /// Vorbis file handle
} WavData;
-#define WAV_BUFFER_SIZE (12 * 1024) /// Buffer size to fill
+#define WAV_BUFFER_SIZE (12 * 1024) /// Buffer size to fill
/*----------------------------------------------------------------------------
--- Functions
+-- Functions
----------------------------------------------------------------------------*/
local int WavReadStream(Sample* sample, void* buf, int len)
{
- WavData* data;
- char sndbuf[WAV_BUFFER_SIZE];
- int unc; // number of uncompressed bytes to read
- int comp; // number of compressed bytes actually read
- int freqratio;
- int chanratio;
- int brratio;
- int samplesize; // number of bytes per sample
- int divide;
- int i;
-
- data = (WavData*)sample->User;
-
- if (data->PointerInBuffer - sample->Data + len > sample->Length) {
- // need to read new data
- sample->Length -= data->PointerInBuffer - sample->Data;
- memcpy(sample->Data, data->PointerInBuffer, sample->Length);
- data->PointerInBuffer = sample->Data;
-
- unc = WAV_BUFFER_SIZE - sample->Length;
-
- freqratio = (44100 / sample->Frequency);
- samplesize = sample->SampleSize / 8;
- brratio = 4 / (samplesize * sample->Channels);
- chanratio = 2 / sample->Channels;
- divide = freqratio * brratio / chanratio;
-
- comp = CLread(data->WavFile, sndbuf, unc/divide);
-
- if (sample->BitsPerSample == 16) {
- for (i = 0; i < (unc / divide) >> 1; ++i) {
- ((unsigned short*)sndbuf)[i] = ConvertLE16(((unsigned
short*)sndbuf)[i]);
- }
- }
-
- sample->Length += ConvertToStereo32(sndbuf,
- &data->PointerInBuffer[sample->Length],
- sample->Frequency, sample->SampleSize / 8,
- sample->Channels, comp);
-
- if (sample->Length < len) {
- len = sample->Length;
- }
- }
-
- memcpy(buf, data->PointerInBuffer, len);
- data->PointerInBuffer += len;
- return len;
+ WavData* data;
+ char sndbuf[WAV_BUFFER_SIZE];
+ int unc; // number of uncompressed bytes
to read
+ int comp; // number of compressed bytes
actually read
+ int freqratio;
+ int chanratio;
+ int brratio;
+ int samplesize; // number of bytes per sample
+ int divide;
+ int i;
+
+ data = (WavData*)sample->User;
+
+ if (data->PointerInBuffer - sample->Data + len > sample->Length) {
+ // need to read new data
+ sample->Length -= data->PointerInBuffer - sample->Data;
+ memcpy(sample->Data, data->PointerInBuffer, sample->Length);
+ data->PointerInBuffer = sample->Data;
+
+ unc = WAV_BUFFER_SIZE - sample->Length;
+
+ freqratio = (44100 / sample->Frequency);
+ samplesize = sample->SampleSize / 8;
+ brratio = 4 / (samplesize * sample->Channels);
+ chanratio = 2 / sample->Channels;
+ divide = freqratio * brratio / chanratio;
+
+ comp = CLread(data->WavFile, sndbuf, unc/divide);
+
+ if (sample->BitsPerSample == 16) {
+ for (i = 0; i < (unc / divide) >> 1; ++i) {
+ ((unsigned short*)sndbuf)[i] =
ConvertLE16(((unsigned short*)sndbuf)[i]);
+ }
+ }
+
+ sample->Length += ConvertToStereo32(sndbuf,
+ &data->PointerInBuffer[sample->Length],
+ sample->Frequency, sample->SampleSize / 8,
+ sample->Channels, comp);
+
+ if (sample->Length < len) {
+ len = sample->Length;
+ }
+ }
+
+ memcpy(buf, data->PointerInBuffer, len);
+ data->PointerInBuffer += len;
+ return len;
}
local void WavFreeStream(Sample* sample)
{
- WavData* data;
-
+ WavData* data;
+
#ifdef DEBUG
- AllocatedSoundMemory -= sizeof(*sample) + WAV_BUFFER_SIZE;
+ AllocatedSoundMemory -= sizeof(*sample) + WAV_BUFFER_SIZE;
#endif
-
- data = (WavData*)sample->User;
- CLclose(data->WavFile);
- free(data);
- free(sample);
+ data = (WavData*)sample->User;
+
+ CLclose(data->WavFile);
+ free(data);
+ free(sample);
}
-/**
-** wav object type structure.
+/**
+** wav object type structure.
*/
local const SampleType WavStreamSampleType = {
- WavReadStream,
- WavFreeStream,
+ WavReadStream,
+ WavFreeStream,
};
/**
-** Load wav.
+** Load wav.
**
-** @param name File name.
-** @param flags Load flags.
+** @param name File name.
+** @param flags Load flags.
**
-** @return Returns the loaded sample.
+** @return Returns the loaded sample.
**
-** @note A second wav loader is in libmodplug!
+** @note A second wav loader is in libmodplug!
**
-** @todo Add ADPCM loading support!
+** @todo Add ADPCM loading support!
*/
global Sample* LoadWav(const char* name, int flags __attribute__((unused)))
{
- CLFile* f;
- WavChunk chunk;
- WavFMT wavfmt;
- unsigned int t;
- int i;
- Sample* sample;
-
- if (!(f = CLopen(name,CL_OPEN_READ))) {
- printf("Can't open file `%s'\n", name);
- return NULL;
- }
- CLread(f, &chunk, sizeof(chunk));
-
- // Convert to native format
-
- chunk.Magic = ConvertLE32(chunk.Magic);
- chunk.Length = ConvertLE32(chunk.Length);
-
- DebugLevel3("Magic: $%x\n" _C_ chunk.Magic);
- DebugLevel3("Length: %d\n" _C_ chunk.Length);
- if (chunk.Magic != RIFF) {
- CLclose(f);
- return NULL;
- }
-
- DebugLevel3Fn("Loading wav file: %s\n" _C_ name);
-
- CLread(f, &t, sizeof(t));
- t = ConvertLE32(t);
- DebugLevel3("Magic: $%lx\n" _C_ t);
- if (t != WAVE) {
- printf("Wrong magic %x (not %x)\n", t, WAVE);
- CLclose(f);
- ExitFatal(-1);
- }
-
- CLread(f, &wavfmt, sizeof(wavfmt));
-
- // Convert to native format
-
- wavfmt.FMTchunk = ConvertLE32(wavfmt.FMTchunk);
- wavfmt.FMTlength = ConvertLE32(wavfmt.FMTlength);
- wavfmt.Encoding = ConvertLE16(wavfmt.Encoding);
- wavfmt.Channels = ConvertLE16(wavfmt.Channels);
- wavfmt.Frequency = ConvertLE32(wavfmt.Frequency);
- wavfmt.ByteRate = ConvertLE32(wavfmt.ByteRate);
- wavfmt.SampleSize = ConvertLE16(wavfmt.SampleSize);
- wavfmt.BitsPerSample = ConvertLE16(wavfmt.BitsPerSample);
-
- DebugLevel3("Magic: $%x\n" _C_ wavfmt.FMTchunk);
- DebugLevel3("Length: %d\n" _C_ wavfmt.FMTlength);
- if (wavfmt.FMTchunk != FMT) {
- printf("Wrong magic %x (not %x)\n", wavfmt.FMTchunk, FMT);
- CLclose(f);
- ExitFatal(-1);
- }
- if (wavfmt.FMTlength != 16 && wavfmt.FMTlength != 18) {
- DebugLevel2("Encoding\t%d\t" _C_ wavfmt.Encoding);
- DebugLevel2("Channels\t%d\t" _C_ wavfmt.Channels);
- DebugLevel2("Frequency\t%d\n" _C_ wavfmt.Frequency);
- DebugLevel2("Byterate\t%d\t" _C_ wavfmt.ByteRate);
- DebugLevel2("SampleSize\t%d\t" _C_ wavfmt.SampleSize);
- DebugLevel2("BitsPerSample\t%d\n" _C_ wavfmt.BitsPerSample);
-
- printf("Wrong length %d (not %d)\n", wavfmt.FMTlength, 16);
- CLclose(f);
- ExitFatal(-1);
- }
-
- if (wavfmt.FMTlength == 18) {
- if (CLread(f, &chunk, 2) != 2) {
- abort();
- }
- }
- DebugLevel3("Encoding\t%d\t" _C_ wavfmt.Encoding);
- DebugLevel3("Channels\t%d\t" _C_ wavfmt.Channels);
- DebugLevel3("Frequency\t%d\n" _C_ wavfmt.Frequency);
- DebugLevel3("Byterate\t%d\t" _C_ wavfmt.ByteRate);
- DebugLevel3("SampleSize\t%d\t" _C_ wavfmt.SampleSize);
- DebugLevel3("BitsPerSample\t%d\n" _C_ wavfmt.BitsPerSample);
-
- //
- // Check if supported
- //
- if (wavfmt.Encoding != WAV_PCM_CODE) {
- printf("Unsupported encoding %d\n", wavfmt.Encoding);
- CLclose(f);
- ExitFatal(-1);
- }
- if (wavfmt.Channels != WAV_MONO && wavfmt.Channels != WAV_STEREO) {
- printf("Unsupported channels %d\n", wavfmt.Channels);
- CLclose(f);
- ExitFatal(-1);
- }
- if (wavfmt.SampleSize != 1 && wavfmt.SampleSize != 2 && wavfmt.SampleSize
!= 4) {
- printf("Unsupported sample size %d\n", wavfmt.SampleSize);
- CLclose(f);
- ExitFatal(-1);
- }
- if (wavfmt.BitsPerSample != 8 && wavfmt.BitsPerSample != 16) {
- printf("Unsupported bits per sample %d\n", wavfmt.BitsPerSample);
- CLclose(f);
- ExitFatal(-1);
- }
- DebugCheck(wavfmt.Frequency != 44100 && wavfmt.Frequency != 22050 &&
- wavfmt.Frequency != 11025);
-
- //
- // Read sample
- //
- sample = malloc(sizeof(*sample) + WAV_BUFFER_SIZE * wavfmt.Channels *
wavfmt.SampleSize);
- sample->Channels = wavfmt.Channels;
- sample->SampleSize = wavfmt.SampleSize * 8 / sample->Channels;
- sample->Frequency = wavfmt.Frequency;
- sample->BitsPerSample = wavfmt.BitsPerSample;
- sample->Length = 0;
-
+ CLFile* f;
+ WavChunk chunk;
+ WavFMT wavfmt;
+ unsigned int t;
+ int i;
+ Sample* sample;
+
+ if (!(f = CLopen(name,CL_OPEN_READ))) {
+ printf("Can't open file `%s'\n", name);
+ return NULL;
+ }
+ CLread(f, &chunk, sizeof(chunk));
- if (flags & PlayAudioStream) {
- WavData* data;
- data = malloc(sizeof(WavData));
+ // Convert to native format
- data->WavFile = f;
- data->PointerInBuffer = sample->Data;
+ chunk.Magic = ConvertLE32(chunk.Magic);
+ chunk.Length = ConvertLE32(chunk.Length);
- sample->Type = &WavStreamSampleType;
- sample->User = data;
+ DebugLevel3("Magic: $%x\n" _C_ chunk.Magic);
+ DebugLevel3("Length: %d\n" _C_ chunk.Length);
+ if (chunk.Magic != RIFF) {
+ CLclose(f);
+ return NULL;
+ }
- CLread(f, &chunk, sizeof(chunk));
+ DebugLevel3Fn("Loading wav file: %s\n" _C_ name);
- DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + WAV_BUFFER_SIZE);
-#ifdef DEBUG
- AllocatedSoundMemory += sizeof(*sample) + WAV_BUFFER_SIZE;
-#endif
- } else {
- for (;;) {
- if ((i = CLread(f, &chunk, sizeof(chunk))) != sizeof(chunk)) {
- // FIXME: have 1 byte remaining, wrong wav or wrong code?
- // if (i) { printf("Rest: %d\n", i); }
- break;
- }
- chunk.Magic = ConvertLE32(chunk.Magic);
- chunk.Length = ConvertLE32(chunk.Length);
-
- DebugLevel3("Magic: $%x\n" _C_ chunk.Magic);
- DebugLevel3("Length: %d\n" _C_ chunk.Length);
- if (chunk.Magic != DATA) {
- CLseek(f, chunk.Length, SEEK_CUR);
- continue;
- }
-
- i = chunk.Length;
- sample = realloc(sample, sizeof(*sample) + sample->Length + i);
- if (!sample) {
- printf("Out of memory!\n");
+ CLread(f, &t, sizeof(t));
+ t = ConvertLE32(t);
+ DebugLevel3("Magic: $%lx\n" _C_ t);
+ if (t != WAVE) {
+ printf("Wrong magic %x (not %x)\n", t, WAVE);
CLclose(f);
ExitFatal(-1);
- }
+ }
- if (CLread(f, sample->Data + sample->Length, i) != i) {
- printf("Unexpected end of file!\n");
+ CLread(f, &wavfmt, sizeof(wavfmt));
+
+ // Convert to native format
+
+ wavfmt.FMTchunk = ConvertLE32(wavfmt.FMTchunk);
+ wavfmt.FMTlength = ConvertLE32(wavfmt.FMTlength);
+ wavfmt.Encoding = ConvertLE16(wavfmt.Encoding);
+ wavfmt.Channels = ConvertLE16(wavfmt.Channels);
+ wavfmt.Frequency = ConvertLE32(wavfmt.Frequency);
+ wavfmt.ByteRate = ConvertLE32(wavfmt.ByteRate);
+ wavfmt.SampleSize = ConvertLE16(wavfmt.SampleSize);
+ wavfmt.BitsPerSample = ConvertLE16(wavfmt.BitsPerSample);
+
+ DebugLevel3("Magic: $%x\n" _C_ wavfmt.FMTchunk);
+ DebugLevel3("Length: %d\n" _C_ wavfmt.FMTlength);
+ if (wavfmt.FMTchunk != FMT) {
+ printf("Wrong magic %x (not %x)\n", wavfmt.FMTchunk, FMT);
CLclose(f);
- free(sample);
ExitFatal(-1);
- }
- sample->Length += i;
}
+ if (wavfmt.FMTlength != 16 && wavfmt.FMTlength != 18) {
+ DebugLevel2("Encoding\t%d\t" _C_ wavfmt.Encoding);
+ DebugLevel2("Channels\t%d\t" _C_ wavfmt.Channels);
+ DebugLevel2("Frequency\t%d\n" _C_ wavfmt.Frequency);
+ DebugLevel2("Byterate\t%d\t" _C_ wavfmt.ByteRate);
+ DebugLevel2("SampleSize\t%d\t" _C_ wavfmt.SampleSize);
+ DebugLevel2("BitsPerSample\t%d\n" _C_ wavfmt.BitsPerSample);
- CLclose(f);
+ printf("Wrong length %d (not %d)\n", wavfmt.FMTlength, 16);
+ CLclose(f);
+ ExitFatal(-1);
+ }
- if (wavfmt.BitsPerSample == 16) {
- for (i = 0; i < sample->Length >> 1; ++i) {
- ((unsigned short*)sample->Data)[i] = ConvertLE16(((unsigned
short*)sample->Data)[i]);
- }
+ if (wavfmt.FMTlength == 18) {
+ if (CLread(f, &chunk, 2) != 2) {
+ abort();
+ }
+ }
+ DebugLevel3("Encoding\t%d\t" _C_ wavfmt.Encoding);
+ DebugLevel3("Channels\t%d\t" _C_ wavfmt.Channels);
+ DebugLevel3("Frequency\t%d\n" _C_ wavfmt.Frequency);
+ DebugLevel3("Byterate\t%d\t" _C_ wavfmt.ByteRate);
+ DebugLevel3("SampleSize\t%d\t" _C_ wavfmt.SampleSize);
+ DebugLevel3("BitsPerSample\t%d\n" _C_ wavfmt.BitsPerSample);
+
+ //
+ // Check if supported
+ //
+ if (wavfmt.Encoding != WAV_PCM_CODE) {
+ printf("Unsupported encoding %d\n", wavfmt.Encoding);
+ CLclose(f);
+ ExitFatal(-1);
+ }
+ if (wavfmt.Channels != WAV_MONO && wavfmt.Channels != WAV_STEREO) {
+ printf("Unsupported channels %d\n", wavfmt.Channels);
+ CLclose(f);
+ ExitFatal(-1);
+ }
+ if (wavfmt.SampleSize != 1 && wavfmt.SampleSize != 2 &&
wavfmt.SampleSize != 4) {
+ printf("Unsupported sample size %d\n", wavfmt.SampleSize);
+ CLclose(f);
+ ExitFatal(-1);
+ }
+ if (wavfmt.BitsPerSample != 8 && wavfmt.BitsPerSample != 16) {
+ printf("Unsupported bits per sample %d\n",
wavfmt.BitsPerSample);
+ CLclose(f);
+ ExitFatal(-1);
}
+ DebugCheck(wavfmt.Frequency != 44100 && wavfmt.Frequency != 22050 &&
+ wavfmt.Frequency != 11025);
+
+ //
+ // Read sample
+ //
+ sample = malloc(sizeof(*sample) + WAV_BUFFER_SIZE * wavfmt.Channels *
wavfmt.SampleSize);
+ sample->Channels = wavfmt.Channels;
+ sample->SampleSize = wavfmt.SampleSize * 8 / sample->Channels;
+ sample->Frequency = wavfmt.Frequency;
+ sample->BitsPerSample = wavfmt.BitsPerSample;
+ sample->Length = 0;
+
+
+ if (flags & PlayAudioStream) {
+ WavData* data;
+ data = malloc(sizeof(WavData));
+
+ data->WavFile = f;
+ data->PointerInBuffer = sample->Data;
+
+ sample->Type = &WavStreamSampleType;
+ sample->User = data;
+
+ CLread(f, &chunk, sizeof(chunk));
+
+ DebugLevel0Fn(" %d\n" _C_ sizeof(*sample) + WAV_BUFFER_SIZE);
+#ifdef DEBUG
+ AllocatedSoundMemory += sizeof(*sample) + WAV_BUFFER_SIZE;
+#endif
+ } else {
+ for (;;) {
+ if ((i = CLread(f, &chunk, sizeof(chunk))) !=
sizeof(chunk)) {
+ // FIXME: have 1 byte remaining, wrong wav or
wrong code?
+ // if (i) { printf("Rest: %d\n", i); }
+ break;
+ }
+ chunk.Magic = ConvertLE32(chunk.Magic);
+ chunk.Length = ConvertLE32(chunk.Length);
+
+ DebugLevel3("Magic: $%x\n" _C_ chunk.Magic);
+ DebugLevel3("Length: %d\n" _C_ chunk.Length);
+ if (chunk.Magic != DATA) {
+ CLseek(f, chunk.Length, SEEK_CUR);
+ continue;
+ }
+
+ i = chunk.Length;
+ sample = realloc(sample, sizeof(*sample) +
sample->Length + i);
+ if (!sample) {
+ printf("Out of memory!\n");
+ CLclose(f);
+ ExitFatal(-1);
+ }
+
+ if (CLread(f, sample->Data + sample->Length, i) != i) {
+ printf("Unexpected end of file!\n");
+ CLclose(f);
+ free(sample);
+ ExitFatal(-1);
+ }
+ sample->Length += i;
+ }
+
+ CLclose(f);
+
+ if (wavfmt.BitsPerSample == 16) {
+ for (i = 0; i < sample->Length >> 1; ++i) {
+ ((unsigned short*)sample->Data)[i] =
ConvertLE16(((unsigned short*)sample->Data)[i]);
+ }
+ }
#ifdef DEBUG
- AllocatedSoundMemory += sample->Length;
+ AllocatedSoundMemory += sample->Length;
#endif
- }
+ }
- return sample;
+ return sample;
}
-#endif // } WITH_SOUND
+#endif // } WITH_SOUND
//@}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Stratagus-CVS] stratagus/src/sound arts_audio.c ccl_sound.c cd...,
address@hidden <=