コード例 #1
0
ファイル: midi.c プロジェクト: HonorLee-cn/sdlpal
VOID
MIDI_Play(
   INT       iNumRIX,
   BOOL      fLoop
)
/*++
  Purpose:

    Start playing the specified music in MIDI format.

  Parameters:

    [IN]  iNumRIX - number of the music. 0 to stop playing current music.

    [IN]  fLoop - Whether the music should be looped or not.

  Return value:

    None.

--*/
{
   FILE            *fp;
   unsigned char   *buf;
   int              size;
   SDL_RWops       *rw;

#ifdef TIMIDITY
   if (g_pMid != NULL && iNumRIX == iMidCurrent && Timidity_Active())
#else
   if (g_pMid != NULL && iNumRIX == iMidCurrent && native_midi_active())
#endif
   {
      return;
   }

   SOUND_PlayCDA(-1);
#ifdef TIMIDITY
   Timidity_FreeSong(g_pMid);
#else
   native_midi_freesong(g_pMid);
#endif
   g_pMid = NULL;
   iMidCurrent = -1;

   if (g_fNoMusic || iNumRIX <= 0)
   {
      return;
   }

   fp = fopen(PAL_PREFIX "midi.mkf", "rb");
   if (fp == NULL)
   {
      return;
   }

   if (iNumRIX > PAL_MKFGetChunkCount(fp))
   {
      fclose(fp);
      return;
   }

   size = PAL_MKFGetChunkSize(iNumRIX, fp);
   if (size <= 0)
   {
      fclose(fp);
      return;
   }

   buf = (unsigned char *)UTIL_malloc(size);

   PAL_MKFReadChunk((LPBYTE)buf, size, iNumRIX, fp);
   fclose(fp);

   rw = SDL_RWFromConstMem((const void *)buf, size);

#ifdef TIMIDITY
   g_pMid = Timidity_LoadSong_RW(rw);
#else
   g_pMid = native_midi_loadsong_RW(rw);
#endif
   if (g_pMid != NULL)
   {
#ifdef TIMIDITY
      Timidity_Start(g_pMid);
#else
      native_midi_start(g_pMid);
#endif

      iMidCurrent = iNumRIX;
      fMidLoop = fLoop;
   }

   SDL_RWclose(rw);
   free(buf);
}
コード例 #2
0
ファイル: midi.c プロジェクト: CecilHarvey/sdlpal
VOID
MIDI_Play(
   INT       iNumRIX,
   BOOL      fLoop
)
/*++
  Purpose:

    Start playing the specified music in MIDI format.

  Parameters:

    [IN]  iNumRIX - number of the music. 0 to stop playing current music.

    [IN]  fLoop - Whether the music should be looped or not.

  Return value:

    None.

--*/
{
   FILE            *fp;
   unsigned char   *buf;
   int              size;
   SDL_RWops       *rw;
#ifdef PAL_WIN95
   char             filename[1024];
#endif

   if (g_pMid != NULL && iNumRIX == iMidCurrent && native_midi_active())
   {
      return;
   }

   SOUND_PlayCDA(-1);
   native_midi_freesong(g_pMid);
   g_pMid = NULL;
   iMidCurrent = -1;

   if (g_fNoMusic || iNumRIX <= 0)
   {
      return;
   }

#ifdef PAL_WIN95
   sprintf(filename, "%s/musics/%.3d.mid", PAL_PREFIX, iNumRIX);

   g_pMid = native_midi_loadsong(filename);
   if (g_pMid != NULL)
   {
      native_midi_start(g_pMid);

      iMidCurrent = iNumRIX;
      fMidLoop = fLoop;
   }
#else
   fp = UTIL_OpenFile("midi.mkf");
   if (fp == NULL)
   {
      return;
   }

   if (iNumRIX > PAL_MKFGetChunkCount(fp))
   {
      fclose(fp);
      return;
   }

   size = PAL_MKFGetChunkSize(iNumRIX, fp);
   if (size <= 0)
   {
      fclose(fp);
      return;
   }

   buf = (unsigned char *)UTIL_malloc(size);

   PAL_MKFReadChunk((LPBYTE)buf, size, iNumRIX, fp);
   fclose(fp);

   rw = SDL_RWFromConstMem((const void *)buf, size);

   g_pMid = native_midi_loadsong_RW(rw);
   if (g_pMid != NULL)
   {
      native_midi_start(g_pMid);

      iMidCurrent = iNumRIX;
      fMidLoop = fLoop;
   }

   SDL_RWclose(rw);
   free(buf);
#endif
}
コード例 #3
0
ファイル: music.c プロジェクト: iaco79/IrrGameDemo
/* Play a music chunk.  Returns 0, or -1 if there was an error.
 */
static int music_internal_play(Mix_Music *music, double position)
{
	int retval = 0;

#if defined(__MACOSX__) && defined(USE_NATIVE_MIDI)
	/* This fixes a bug with native MIDI on Mac OS X, where you
	   can't really stop and restart MIDI from the audio callback.
	*/
	if ( music == music_playing && music->type == MUS_MID && native_midi_ok ) {
		/* Just a seek suffices to restart playing */
		music_internal_position(position);
		return 0;
	}
#endif

	/* Note the music we're playing */
	if ( music_playing ) {
		music_internal_halt();
	}
	music_playing = music;

	/* Set the initial volume */
	if ( music->type != MUS_MOD ) {
		music_internal_initialize_volume();
	}

	/* Set up for playback */
	switch (music->type) {
#ifdef CMD_MUSIC
	    case MUS_CMD:
		MusicCMD_Start(music->data.cmd);
		break;
#endif
#ifdef WAV_MUSIC
	    case MUS_WAV:
		WAVStream_Start(music->data.wave);
		break;
#endif
#ifdef MODPLUG_MUSIC
	    case MUS_MODPLUG:
		/* can't set volume until file is loaded, so finally set it now */
		music_internal_initialize_volume();
		modplug_play(music->data.modplug);
		break;
#endif
#ifdef MOD_MUSIC
	    case MUS_MOD:
		MOD_play(music->data.module);
		/* Player_SetVolume() does nothing before Player_Start() */
		music_internal_initialize_volume();
		break;
#endif
#ifdef MID_MUSIC
	    case MUS_MID:
#ifdef USE_NATIVE_MIDI
		if ( native_midi_ok ) {
			native_midi_start(music->data.nativemidi, music_loops);
			goto skip;
		}
#endif
#ifdef USE_FLUIDSYNTH_MIDI
		if (fluidsynth_ok ) {
			fluidsynth_start(music->data.fluidsynthmidi);
			goto skip;
		}
#endif
#ifdef USE_TIMIDITY_MIDI
		if ( timidity_ok ) {
			Timidity_Start(music->data.midi);
			goto skip;
		}
#endif
		break;
#endif
#ifdef OGG_MUSIC
	    case MUS_OGG:
		OGG_play(music->data.ogg);
		break;
#endif
#ifdef FLAC_MUSIC
	    case MUS_FLAC:
		FLAC_play(music->data.flac);
		break;
#endif
#ifdef MP3_MUSIC
	    case MUS_MP3:
		smpeg.SMPEG_enableaudio(music->data.mp3,1);
		smpeg.SMPEG_enablevideo(music->data.mp3,0);
		smpeg.SMPEG_play(music_playing->data.mp3);
		break;
#endif
#ifdef MP3_MAD_MUSIC
	    case MUS_MP3_MAD:
		mad_start(music->data.mp3_mad);
		break;
#endif
	    default:
		Mix_SetError("Can't play unknown music type");
		retval = -1;
		break;
	}

skip:
	/* Set the playback position, note any errors if an offset is used */
	if ( retval == 0 ) {
		if ( position > 0.0 ) {
			if ( music_internal_position(position) < 0 ) {
				Mix_SetError("Position not implemented for music type");
				retval = -1;
			}
		} else {
			music_internal_position(0.0);
		}
	}

	/* If the setup failed, we're not playing any music anymore */
	if ( retval < 0 ) {
		music_playing = NULL;
	}
	return(retval);
}