Exemple #1
0
int DM_Music_PlayFile(const char *filename, int looped)
{
    if(!filename) return false;

    if(!fluid_is_midifile(filename))
    {
        // It doesn't look like MIDI.
        App_Log(DE2_LOG_VERBOSE, "[FluidSynth] Cannot play \"%s\": not a MIDI file", filename);
        return false;
    }

    if(sfontId < 0)
    {
        App_Log(DE2_LOG_VERBOSE, "[FluidSynth] Cannot play \"%s\" without an SF2 soundfont", filename);
        return false;
    }

    // If we are playing something, make sure it's stopped.
    stopPlayer();

    DENG_ASSERT(fsPlayer == NULL);

    // Create a new player.
    fsPlayer = new_fluid_player(DMFluid_Synth());
    fluid_player_add(fsPlayer, filename);
    fluid_player_set_loop(fsPlayer, looped? -1 /*infinite times*/ : 1);
    fluid_player_play(fsPlayer);

    startPlayer();

    DSFLUIDSYNTH_TRACE("PlayFile: playing '" << filename << "' using player "
                       << fsPlayer << " looped:" << looped << " sfont:" << sfontId);
    return true;
}
Exemple #2
0
	void midiStreamCallback(void* userData, u32 requestedChunkSize, u8* chunkData)
	{
		LOCK();
			s32 soundSize = 0;
			s32 totalSize = 0;
			while (totalSize < (s32)requestedChunkSize)
			{
				if (s_midiFormat == MFMT_GUS_PATCH)
				{
					soundSize = WildMidi_GetOutput(s_song, (char*)&chunkData[totalSize], requestedChunkSize-totalSize);
				}
				else if (s_midiFormat == MFMT_SOUND_FONT)
				{
					if (!s_fluidPlaying)
					{
						fluid_player_play( s_fluidPlayer );
						fluid_player_set_loop(s_fluidPlayer, -1);
						s_fluidPlaying = true;
					}
					soundSize = fillFluidBuffer(requestedChunkSize, chunkData, s_sampleRate, s_fluidSynth, s_fluidPlayer);
				}

				//we've finished the loop, start the song all over again.
				if (soundSize == 0)
				{
					if (s_midiFormat == MFMT_GUS_PATCH)
					{
						unsigned long beginning = 0;
						WildMidi_FastSeek(s_song, &beginning);
						soundSize = WildMidi_GetOutput(s_song, (char*)&chunkData[totalSize], requestedChunkSize-totalSize);
					}
					else if (s_midiFormat == MFMT_SOUND_FONT)
					{
						LOG( LOG_ERROR, "midi synthesizer should handle looping." );
					}
				}

				totalSize += soundSize;
			};
		UNLOCK();
	}