11 signed char endcallback( FSOUND_STREAM *stream,
void *buf,
int len,
int param )
28 if (
m) FSOUND_Stream_Stop(
m );
32 if (
m) FSOUND_Stream_Close(
m );
37 m = FSOUND_Stream_OpenFile( file, FSOUND_NORMAL|FSOUND_MPEGACCURATE, 0 );
68 FSOUND_Stream_SetEndCallback(
m, endcallback, 0 );
69 FSOUND_Stream_SetSynchCallback(
m, endcallback, 0 );
70 channel = FSOUND_Stream_Play( FSOUND_FREE,
m );
73 for (
unsigned int i = 0;
i < fadeout*10;
i++) {
74 float ratio = ( (
float) i )/(fadeout*10.);
87 printf(
"Setting %d to %d\n", this->channel, (
int) ( vol*
GetMaxVolume() ) );
88 F_API FSOUND_SetVolume( this->channel, (
int) ( vol*
GetMaxVolume() ) );
96 #include <SDL/SDL_thread.h>
97 #include <SDL/SDL_mixer.h>
110 m = Mix_LoadMUS( file );
113 bool Play(
float fadeout,
float fadein,
Music &oldmusic )
116 int fadesteps = fadeout*100;
117 for (
int i = fadesteps;
i >= 0;
i--) {
121 Mix_FadeInMusic(
m, 1, fadein ) != -1;
131 if (
m) Mix_StopMusic(
m );
135 if (
m) Mix_FreeMusic(
m );
146 #endif //tells VCC not to generate min/max macros
149 #define sleep( sec ) Sleep( sec*1000 );
164 int fadeout = 0, fadein = 0;
175 vfprintf( stderr, str, ap );
177 fprintf( stderr,
": %s.\n", SDL_GetError() );
183 static int maxVol = FSOUND_GetSFXMasterVolume();
215 static std::vector< std::string >paths;
217 char mycurpath[8192];
218 getcwd( mycurpath, 8191 );
219 mycurpath[8191] =
'\0';
220 paths.push_back( std::string( mycurpath ) );
223 struct passwd *pwent;
224 pwent = getpwuid( getuid() );
225 chdir( pwent->pw_dir );
228 chdir(
".vegastrike" );
229 }
else if ( !paths.empty() ) {
230 chdir( paths.back().c_str() );
245 if (music.
m == NULL) {
249 if (music.
m == NULL) {
258 music.
Play( fadeout, fadein, oldmusic );
262 invalid_string =
false;
271 printf(
"\ne\n[SONG DONE]\n" );
272 invalid_string =
true;
275 int main(
int argc,
char **argv )
278 int audio_rate, audio_channels,
281 audio_buffers = 4096;
285 if (SDL_Init( SDL_INIT_AUDIO ) < 0)
290 if ( !FSOUND_Init( 44100, 64, FSOUND_INIT_GLOBALFOCUS ) ) {
291 printf(
"SOUND Error %d\n", FSOUND_GetError() );
300 if (Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, audio_buffers ) < 0)
303 Mix_QuerySpec( &audio_rate, &audio_format, &audio_channels );
304 bits = audio_format&0xFF;
306 printf(
"Opened audio at %d Hz %d bit %s, %d bytes audio buffer\n", audio_rate,
307 bits, audio_channels > 1 ?
"stereo" :
"mono", audio_buffers );
309 for (
int i = 0;
i < 10 && mysocket == -1;
i++)
313 printf(
"\n[CONNECTED]\n" );
314 char ministr[2] = {
'\0',
'\0'};
326 while (arg !=
'\0' && arg !=
'\n') {
333 printf(
"%s", str.c_str() );
334 if ( (str != curmus || invalid_string)
336 || ( !Mix_PlayingMusic() )
341 printf(
"\n[PLAYING %s WITH %d FADEIN AND %d FADEOUT]\n", str.c_str(),
fadein,
fadeout );
343 invalid_string =
false;
345 printf(
"\n[UNABLE TO PLAY %s WITH %d FADEIN AND %d FADEOUT]\n", str.c_str(),
fadein,
fadeout );
349 printf(
"\n[%s WITH %d FADEIN AND %d FADEOUT IS ALREADY PLAYING]\n", str.c_str(),
fadein,
fadeout );
355 while (arg !=
'\0' && arg !=
'\n') {
362 printf(
"%s", str.c_str() );
363 fadein = atoi( str.c_str() );
364 printf(
"\n[SETTING FADEIN TO %d]\n", fadein );
369 while (arg !=
'\0' && arg !=
'\n') {
376 printf(
"%s", str.c_str() );
377 fadeout = atoi( str.c_str() );
378 printf(
"\n[SETTING FADEOUT TO %d]\n", fadeout );
383 while (arg !=
'\0' && arg !=
'\n') {
390 printf(
"%s", str.c_str() );
391 volume = atof( str.c_str() );
392 printf(
"\n[SETTING VOLUME TO %f]\n", volume );
400 printf(
"\n[TERMINATING MUSIC SERVER]\n" );