r661 - in trunk: . game
black at icculus.org
black at icculus.org
Mon Mar 6 13:46:24 EST 2006
Author: black
Date: 2006-03-06 13:46:24 -0500 (Mon, 06 Mar 2006)
New Revision: 661
Modified:
trunk/game/g_audio.c
trunk/game/g_main.c
trunk/game/m_menucore.h
trunk/lhsound.c
trunk/lhsound.h
trunk/sound.c
trunk/sound.h
Log:
Added #ifndef... and a newline to m_menucore.h.
Changed the script name for the shell commands executed in g_main.c.
Added channel support to lhsound:
lhsoundSample now takes a channelcount param which it uses as stride (with the info from providedformat).
Changed sound to create a sample for each channel (up to 8) on load.
Updated g_audio to always use channel 0 (perhaps add support for playing stereo music or surround ambient effects
to the sound mixer later - I dont think its supporting multiple speakers correctly right now anyway).
Modified: trunk/game/g_audio.c
===================================================================
--- trunk/game/g_audio.c 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/game/g_audio.c 2006-03-06 18:46:24 UTC (rev 661)
@@ -146,7 +146,8 @@
{
// start mixing this sound
sound = (Sound *)Resource_GetData(entity->sound.resourceindex);
- lhsoundBindSample(sound->samplenumber);
+ //TODO: add support for multiple channels
+ lhsoundBindSample(sound->samplenumber[0]);
lhsoundBegin(LHSOUND_RENDER_SEGMENT_STRIP);
// output the previous mix point so that we have a valid
// segment, all later points will be added individually
Modified: trunk/game/g_main.c
===================================================================
--- trunk/game/g_main.c 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/game/g_main.c 2006-03-06 18:46:24 UTC (rev 661)
@@ -207,11 +207,11 @@
// run config scripts
if (System_CheckParm("-dedicated", 0))
- Shell_ExecuteScript( "console", "exec server.cfg\n" );
+ Shell_ExecuteScript( "init", "exec server.cfg\n" );
else
{
- Shell_ExecuteScript( "console", "exec default.cfg\n" );
- Shell_ExecuteScript( "console", "exec config.cfg\n" );
+ Shell_ExecuteScript( "init", "exec default.cfg\n" );
+ Shell_ExecuteScript( "init", "exec config.cfg\n" );
}
// TODO: make a cvar able to change these
Modified: trunk/game/m_menucore.h
===================================================================
--- trunk/game/m_menucore.h 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/game/m_menucore.h 2006-03-06 18:46:24 UTC (rev 661)
@@ -1,3 +1,7 @@
+
+#ifndef M_MENUCORE_H
+#define M_MENUCORE_H
+
typedef struct Menu_Inheritance
{
int addpos[2];
@@ -108,4 +112,6 @@
void Menu_Main(void);
void Menu_Init(void);
Nbool Menu_IsVisible(void);
-Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent);
\ No newline at end of file
+Nbool Menu_KeyEvent(NUint mod, NUint sym, UNUSED NUint character, Nbool downevent);
+
+#endif
Modified: trunk/lhsound.c
===================================================================
--- trunk/lhsound.c 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/lhsound.c 2006-03-06 18:46:24 UTC (rev 661)
@@ -50,6 +50,7 @@
// used only during Begin...End
lhsound_rendermode_t rendermode;
+ lhsound_bool_t mixbeginstate; // only true or false
unsigned int numpoints;
lhsound_point_t points[2];
@@ -145,12 +146,14 @@
}
}
-void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data)
+void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data, unsigned channelcount)
{
unsigned int i;
unsigned int bytes;
lhsound_format_t internalformat;
LHSOUNDASSERT(length >= 1, LHSOUND_ERROR_INVALID_VALUE);
+ LHSOUNDASSERT(channelcount >= 1, LHSOUND_ERROR_INVALID_VALUE);
+ LHSOUNDASSERT(data != LHSOUND_NULL, LHSOUND_ERROR_INVALID_VALUE);
// decide which internal format and detect invalid formats
// TODO: add swapped versions
bytes = 1;
@@ -191,7 +194,7 @@
{
const unsigned char *in;
signed char *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = *in - 128;
out[0] = out[-1]; // for LINEAR resample
}
@@ -200,7 +203,7 @@
{
const signed char *in;
signed char *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = *in;
out[0] = out[-1]; // for LINEAR resample
}
@@ -209,7 +212,7 @@
{
const unsigned short *in;
signed short *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = *in - 32768;
out[0] = out[-1]; // for LINEAR resample
}
@@ -218,7 +221,7 @@
{
const signed short *in;
signed short *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = *in;
out[0] = out[-1]; // for LINEAR resample
}
@@ -227,7 +230,7 @@
{
const unsigned int *in;
float *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = (float)((double)*in / (2048.0 * 1024.0 * 1024.0) - 1.0);
out[0] = out[-1]; // for LINEAR resample
}
@@ -236,7 +239,7 @@
{
const signed int *in;
float *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = (float)((double)*in / (2048.0 * 1024.0 * 1024.0));
out[0] = out[-1]; // for LINEAR resample
}
@@ -245,7 +248,7 @@
{
const float *in;
float *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = *in;
out[0] = out[-1]; // for LINEAR resample
}
@@ -254,7 +257,7 @@
{
const double *in;
float *out;
- for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in++, out++)
+ for (i = 0, in = data, out = lhsound_state.boundsample->data;i < length;i++, in+=channelcount, out++)
*out = *in;
out[0] = out[-1]; // for LINEAR resample
}
@@ -458,18 +461,16 @@
{
switch (pname)
{
- case LHSOUND_MIX_BUFFER_LENGTH:LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION);output[0] = lhsound_state.mixbufferlength;break;
+ case LHSOUND_MIX_BUFFER_LENGTH:LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_TRUE, LHSOUND_ERROR_INVALID_OPERATION);output[0] = lhsound_state.mixbufferlength;break;
default:LHSOUNDERROR(LHSOUND_ERROR_INVALID_ENUM);break;
}
}
void lhsoundMixBegin(int bufferlength)
{
- LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION);
+ LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_FALSE, LHSOUND_ERROR_INVALID_OPERATION);
LHSOUNDASSERT(bufferlength >= 1 && bufferlength < 65536, LHSOUND_ERROR_INVALID_VALUE);
- //FIXME: AK this is bad since it would allow a End call without a BeginCall
- // but I guess its because of Geti, anyway, commented out since it should be solved somehow else
- //lhsound_state.rendermode = LHSOUND_TRUE;
+ lhsound_state.mixbeginstate = LHSOUND_TRUE;
if (lhsound_state.mixbufferlength != bufferlength)
{
lhsound_state.mixbufferlength = bufferlength;
@@ -491,10 +492,10 @@
unsigned short s;
}
swaptest;
- // FIXME: same as in mixbegin
- LHSOUNDASSERT(lhsound_state.rendermode != LHSOUND_RENDER_NONE, LHSOUND_ERROR_INVALID_OPERATION);
+ LHSOUNDASSERT(lhsound_state.mixbeginstate == LHSOUND_TRUE, LHSOUND_ERROR_INVALID_OPERATION);
LHSOUNDASSERT(bufferlength == lhsound_state.mixbufferlength, LHSOUND_ERROR_INVALID_VALUE);
LHSOUNDASSERT(stride != 0, LHSOUND_ERROR_INVALID_VALUE);
+ lhsound_state.mixbeginstate = LHSOUND_FALSE;
swaptest.s = 1;
switch (format)
{
@@ -610,6 +611,6 @@
default:
break;
}
- }
+ }
}
Modified: trunk/lhsound.h
===================================================================
--- trunk/lhsound.h 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/lhsound.h 2006-03-06 18:46:24 UTC (rev 661)
@@ -2,13 +2,19 @@
#ifndef LHSOUND_H
#define LHSOUND_H
+// FIXME: this isnt actually used at all, so better remove it if it stays this way..
#define LHSOUND_ZERO 0
#define LHSOUND_ONE 1
-#define LHSOUND_FALSE 0
-#define LHSOUND_TRUE 1
#define LHSOUND_NULL ((void *)0)
+typedef enum lhsound_bool_e
+{
+ LHSOUND_FALSE,
+ LHSOUND_TRUE,
+}
+lhsound_bool_t;
+
typedef enum lhsound_error_e
{
LHSOUND_ERROR_NONE,
@@ -100,7 +106,9 @@
void lhsoundGenSamples(int count, int *array);
void lhsoundDeleteSamples(unsigned int count, int *array);
-void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data);
+// expects the data to be tightly packed, channelcount specifies the stride (actual stride = sizeof(providedformat)*channelcount)
+// note that a sample can only contain one channel, so you have to create a sample for each channel of e.g. a stereo wave
+void lhsoundSample(unsigned int length, lhsound_format_t providedformat, const void *data, unsigned channelcount);
void lhsoundSampleParami(lhsound_sampleparam_t parameter, int value);
void lhsoundBegin(lhsound_rendermode_t mode);
Modified: trunk/sound.c
===================================================================
--- trunk/sound.c 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/sound.c 2006-03-06 18:46:24 UTC (rev 661)
@@ -195,44 +195,55 @@
void Sound_Load(ResourceEntry *r)
{
- int samplenumber;
Sound *sound;
SoundInfo info;
+ int channelcount;
+ int channel;
+ int samplenumber[SOUND_MAX_CHANNEL_COUNT];
+
if (!Sound_LoadWaveFile(r->name, &info, r->memzone))
{
Console_Printf("Sound_Load: failed to load \"%s\" - error: %s\n", r->name, info.errormessage);
return;
}
- lhsoundGenSamples(1, &samplenumber);
- lhsoundBindSample(samplenumber);
- lhsoundSample(info.length, info.lhsoundformat, info.data);
- // TODO: add mipmaps and use LHSOUND_LINEAR_MIPMAP_LINEAR
- lhsoundSampleParami(LHSOUND_SAMPLE_MINFILTER, LHSOUND_LINEAR);
- lhsoundSampleParami(LHSOUND_SAMPLE_MAGFILTER, LHSOUND_LINEAR);
+ // init the local decl
+ channelcount = Min(info.channels, SOUND_MAX_CHANNEL_COUNT);
+ lhsoundGenSamples(channelcount, &samplenumber[0]);
+ // bind the sounds and load them
+ for( channel = 0 ; channel < channelcount ; channel++ )
+ {
+ void *channelStart = (NUint8*) info.data + channel * info.bytespersample;
+
+ lhsoundBindSample(samplenumber[channel]);
+ lhsoundSample(info.length, info.lhsoundformat, channelStart, info.channels);
+ // TODO: add mipmaps and use LHSOUND_LINEAR_MIPMAP_LINEAR
+ lhsoundSampleParami(LHSOUND_SAMPLE_MINFILTER, LHSOUND_LINEAR);
+ lhsoundSampleParami(LHSOUND_SAMPLE_MAGFILTER, LHSOUND_LINEAR);
+ }
lhsoundBindSample(0);
// since no errors were encountered, set up the resource data now
sound = Mem_Alloc(r->memzone, sizeof(Sound));
+ sound->channels = channelcount;
sound->speed = info.framespersecond;
- sound->channels = info.channels;
- sound->samplenumber = samplenumber;
+ for( channel = 0 ; channel < channelcount ; channel++ )
+ sound->samplenumber[channel] = samplenumber[channel];
+
r->data = (void *)sound;
Mem_Free(info.data);
}
void Sound_Unload(ResourceEntry *r)
{
- int samplenumber;
Sound *sound = (Sound *)r->data;
- samplenumber = sound->samplenumber;
- lhsoundDeleteSamples(1, &samplenumber);
+ lhsoundDeleteSamples(sound->channels, &sound->samplenumber[0]);
}
-NUint32 Sound_GetNumber(NUint32 resourceindex)
+NUint32 Sound_GetNumber(NUint32 resourceindex, NUint32 channel)
{
Sound *sound = (Sound *)Resource_GetData(resourceindex);
- if (!sound)
+ if (!sound || sound->channels >= channel)
return 0;
- return sound->samplenumber;
+ return sound->samplenumber[channel];
}
Modified: trunk/sound.h
===================================================================
--- trunk/sound.h 2006-03-05 15:28:05 UTC (rev 660)
+++ trunk/sound.h 2006-03-06 18:46:24 UTC (rev 661)
@@ -2,17 +2,20 @@
#ifndef SOUND_H
#define SOUND_H
+#define SOUND_MAX_CHANNEL_COUNT 8
+
typedef struct Sound
{
NUint32 speed;
NUint32 channels;
- NUint32 samplenumber;
+ NUint32 samplenumber[SOUND_MAX_CHANNEL_COUNT];
}
Sound;
void Sound_Load(ResourceEntry *r);
void Sound_Unload(ResourceEntry *r);
-NUint32 Sound_GetNumber(NUint32 resourceindex);
+// FIXME: use this function in g_audio perhaps?
+NUint32 Sound_GetNumber(NUint32 resourceindex, NUint32 channel);
#endif
More information about the neither-commits
mailing list