@@ -43,7 +43,10 @@ void sound_deinit(void);
4343
4444
4545
46-
46+ static float fadey ;
47+ extern cvar_t * s_xmp_startPattern ;
48+ static int startpat ;
49+ static int gopat ;
4750extern int samplingrate ; // from snd_dma
4851
4952void S_XMP_StartSong ( void )
@@ -58,6 +61,29 @@ void S_XMP_EndSong ( void )
5861
5962
6063
64+ }
65+
66+
67+ // TODO: A callback to set this appropriately from game context (monster sight, level triggers)
68+ void S_XMP_CheckForFade ( void )
69+ {
70+ gopat = s_xmp_startPattern -> integer ;
71+
72+ if ((gopat != startpat ))
73+ {
74+ fadey -= 0.025f ;
75+ // Com_Printf("AHHHFADING TO PATTERN %i!!! %f\n", startpat, fadey);
76+ xmp_set_player (xmpsong , XMP_PLAYER_VOLUME , (fadey * 128 ));
77+ }
78+
79+ if ((startpat != gopat ) && (fadey < 0.01 ))
80+ {
81+ startpat = gopat ;
82+ xmp_set_position (xmpsong , startpat );
83+ xmp_set_player (xmpsong , XMP_PLAYER_VOLUME , 128 );
84+ fadey = 1 ;
85+ }
86+
6187}
6288
6389int aintistreaming = 0 ;
@@ -79,7 +105,7 @@ S_XMP_CodecOpenStream
79105=================
80106*/
81107
82- // FIXME: there's a memory leak here if you start the same song many many many many times.
108+ // FIXME: there's a memory leak here if you start the same song many many many many times?
83109snd_stream_t * S_XMP_CodecOpenStream (const char * filename )
84110{
85111 // First let's close whatever song we had....
@@ -130,7 +156,14 @@ snd_stream_t *S_XMP_CodecOpenStream(const char *filename)
130156 FS_FCloseFile (file ); // unfortunately these do not help with the leak
131157
132158 if (itsloaded == 0 )
133- itsloaded = xmp_start_player (xmpsong , xmpspeed , 0 ); // TODO: do sample rate of the mixer.
159+ {
160+ itsloaded = xmp_start_player (xmpsong , xmpspeed , 0 );
161+ startpat = s_xmp_startPattern -> integer ;
162+ gopat = startpat ;
163+ fadey = 1.0 ;
164+ xmp_set_player (xmpsong , XMP_PLAYER_VOLUME , 128 );
165+ xmp_set_position (xmpsong , startpat );
166+ }
134167
135168 if (itsloaded == 0 ) {
136169 // Com_Printf("XMP loaded our buffer of the file %s which is %i long \n", filename, thelength);
@@ -197,6 +230,8 @@ int S_XMP_CodecReadStream(snd_stream_t *stream, int bytes, void *buffer)
197230 return 0 ;
198231 }
199232
233+ S_XMP_CheckForFade ();
234+
200235 return bytes ;
201236}
202237
0 commit comments