Oscilloscope now reacts to music when speech is disabled

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@518 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
gewlitys
2003-01-02 02:02:34 +00:00
parent 625cdaecd7
commit 218150a809
3 changed files with 136 additions and 56 deletions
+1
View File
@@ -1,4 +1,5 @@
0.2: 0.2:
- Oscilloscope now reacts to music when speech is disabled (OpenAL) -Mika
- Rewritten input code (better and adds joystick/pad support), from slayne - Rewritten input code (better and adds joystick/pad support), from slayne
- Biadapt scaling for pure mode, from fOSSiL - Biadapt scaling for pure mode, from fOSSiL
- Saving user data in "%APPDATA%/Application Data" on windows - SvdB - Saving user data in "%APPDATA%/Application Data" on windows - SvdB
+2 -1
View File
@@ -34,7 +34,8 @@ PLRPlaySong (MUSIC_REF MusicRef, BOOLEAN Continuous, BYTE Priority)
if (pmus) if (pmus)
{ {
LockMutex (soundSource[MUSIC_SOURCE].stream_mutex); LockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
PlayStream ((*pmus), MUSIC_SOURCE, Continuous, AL_FALSE); PlayStream ((*pmus), MUSIC_SOURCE, Continuous,
speechVolumeScale == 0.0f ? AL_TRUE : AL_FALSE);
UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex); UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
curMusicRef = MusicRef; curMusicRef = MusicRef;
@@ -65,7 +65,8 @@ advance_track (int channel_finished)
if (tcur < tct) if (tcur < tct)
{ {
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
PlayStream (track_clip[tcur].sample, SPEECH_SOURCE, FALSE, TRUE); PlayStream (track_clip[tcur].sample, SPEECH_SOURCE, AL_FALSE,
speechVolumeScale == 0.0f ? AL_FALSE : AL_TRUE);
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
do_subtitles (0); do_subtitles (0);
} }
@@ -262,8 +263,11 @@ FastForward ()
int int
GetSoundData (void *data) GetSoundData (void *data)
{ {
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex); if (speechVolumeScale != 0.0f)
{
// speech is enabled
LockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
if (soundSource[SPEECH_SOURCE].sample && soundSource[SPEECH_SOURCE].sample->decoder && if (soundSource[SPEECH_SOURCE].sample && soundSource[SPEECH_SOURCE].sample->decoder &&
PlayingStream (SPEECH_SOURCE) && soundSource[SPEECH_SOURCE].sbuffer && PlayingStream (SPEECH_SOURCE) && soundSource[SPEECH_SOURCE].sbuffer &&
soundSource[SPEECH_SOURCE].sbuf_size > 0) soundSource[SPEECH_SOURCE].sbuf_size > 0)
@@ -325,8 +329,82 @@ GetSoundData (void *data)
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
return 1; return 1;
} }
UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex); UnlockMutex (soundSource[SPEECH_SOURCE].stream_mutex);
}
else if (musicVolumeScale != 0.0f)
{
// speech is disabled but music is not so process it instead
LockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
if (soundSource[MUSIC_SOURCE].sample && soundSource[MUSIC_SOURCE].sample->decoder &&
PlayingStream (MUSIC_SOURCE) && soundSource[MUSIC_SOURCE].sbuffer &&
soundSource[MUSIC_SOURCE].sbuf_size > 0)
{
float played_time = (GetTimeCounter () - soundSource[MUSIC_SOURCE].start_time) /
(float)ONE_SECOND;
int played_data = (int) (played_time * (float)soundSource[MUSIC_SOURCE].
sample->decoder->frequency * 4.0f);
int delta = played_data - soundSource[MUSIC_SOURCE].total_decoded;
unsigned int pos, i, step;
UBYTE *scopedata = (UBYTE *) data;
UBYTE *sbuffer = soundSource[MUSIC_SOURCE].sbuffer;
assert (soundSource[MUSIC_SOURCE].sample->decoder->frequency >= 11025);
assert (soundSource[MUSIC_SOURCE].sample->decoder->format == AL_FORMAT_STEREO16);
step = soundSource[MUSIC_SOURCE].sample->decoder->frequency / 11025 * 16;
if (step % 2 == 1)
step++;
if (delta < 0)
{
//fprintf (stderr, "GetSoundData(): something's messed with timing, delta %d\n", delta);
delta = 0;
}
else if (delta > (int)(soundSource[MUSIC_SOURCE].sbuf_size * 2))
{
//fprintf (stderr, "GetSoundData(): something's messed with timing, delta %d\n", delta);
delta = 0;
}
//fprintf (stderr, "played_data %d total_decoded %d delta %d\n", played_data, soundSource[MUSIC_SOURCE].total_decoded, delta);
pos = soundSource[MUSIC_SOURCE].sbuf_start + delta;
if (pos % 2 == 1)
pos++;
assert (pos >= 0);
for (i = 0; i < RADAR_WIDTH; ++i)
{
SWORD s;
for (;;)
{
if (pos >= soundSource[MUSIC_SOURCE].sbuf_size)
pos = pos - soundSource[MUSIC_SOURCE].sbuf_size;
else
break;
}
s = (*(SWORD*)(&sbuffer[pos])) + (*(SWORD*)(&sbuffer[pos + 2]));
s = (s / 1260) + (RADAR_HEIGHT >> 1);
if (s < 0)
s = 0;
else if (s >= RADAR_HEIGHT)
s = RADAR_HEIGHT - 1;
scopedata[i] = (UBYTE) s;
pos += step;
}
UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
return 1;
}
UnlockMutex (soundSource[MUSIC_SOURCE].stream_mutex);
}
return 0; return 0;
} }