Exemplo n.º 1
0
static int TIMIDITY_GetSome(void *context, void *data, int bytes, SDL_bool *done)
{
    TIMIDITY_Music *music = (TIMIDITY_Music *)context;
    int filled, amount, expected;

    if (music->stream) {
        filled = SDL_AudioStreamGet(music->stream, data, bytes);
        if (filled != 0) {
            return filled;
        }
    }

    if (!music->play_count) {
        /* All done */
        *done = SDL_TRUE;
        return 0;
    }

    if (music->stream) {
        expected = music->buffer_size;
        amount = Timidity_PlaySome(music->song, music->buffer, music->buffer_size);
        if (SDL_AudioStreamPut(music->stream, music->buffer, amount) < 0) {
            return -1;
        }
    } else {
        expected = bytes;
        amount = Timidity_PlaySome(music->song, data, bytes);
    }
        
    if (amount < expected) {
        if (music->play_count == 1) {
            /* We didn't consume anything and we're done */
            music->play_count = 0;
        } else {
            int play_count = -1;
            if (music->play_count > 0) {
                play_count = (music->play_count - 1);
            }
            if (TIMIDITY_Play(music, play_count) < 0) {
                return -1;
            }
        }
    }
    if (music->stream) {
        /* We'll pick it up from the stream next time around */
        return 0;
    } else {
        /* We wrote output data */
        return amount;
    }
}
Exemplo n.º 2
0
static Uint32 MIDI_read(Sound_Sample *sample)
{
    Uint32 retval;
    Sound_SampleInternal *internal = (Sound_SampleInternal *) sample->opaque;
    MidiSong *song = (MidiSong *) internal->decoder_private;

    retval = Timidity_PlaySome(song, internal->buffer, internal->buffer_size);

        /* Make sure the read went smoothly... */
    if (retval == 0)
        sample->flags |= SOUND_SAMPLEFLAG_EOF;

    else if (retval == -1)
        sample->flags |= SOUND_SAMPLEFLAG_ERROR;

        /* (next call this EAGAIN may turn into an EOF or error.) */
    else if (retval < internal->buffer_size)
        sample->flags |= SOUND_SAMPLEFLAG_EAGAIN;

    return(retval);
} /* MIDI_read */
Exemplo n.º 3
0
static void audio_callback(void *userdata, Uint8 *stream, int len)
{
    if (Timidity_PlaySome(song, stream, len) == 0)
	done_flag = 1;
}
Exemplo n.º 4
0
/* Mixing function */
void music_mixer(void *udata, Uint8 *stream, int len)
{
	int left = 0;

	if ( music_playing && music_active ) {
		/* Handle fading */
		if ( music_playing->fading != MIX_NO_FADING ) {
			if ( music_playing->fade_step++ < music_playing->fade_steps ) {
				int volume;
				int fade_step = music_playing->fade_step;
				int fade_steps = music_playing->fade_steps;

				if ( music_playing->fading == MIX_FADING_OUT ) {
					volume = (music_volume * (fade_steps-fade_step)) / fade_steps;
				} else { /* Fading in */
					volume = (music_volume * fade_step) / fade_steps;
				}
				music_internal_volume(volume);
			} else {
				if ( music_playing->fading == MIX_FADING_OUT ) {
					music_internal_halt();
					if ( music_finished_hook ) {
						music_finished_hook();
					}
					return;
				}
				music_playing->fading = MIX_NO_FADING;
			}
		}
		
		if (music_halt_or_loop() == 0)
			return;
		
		
		switch (music_playing->type) {
#ifdef CMD_MUSIC
			case MUS_CMD:
				/* The playing is done externally */
				break;
#endif
#ifdef WAV_MUSIC
			case MUS_WAV:
				left = WAVStream_PlaySome(stream, len);
				break;
#endif
#ifdef MOD_MUSIC
			case MUS_MOD:
				left = MOD_playAudio(music_playing->data.module, stream, len);
				break;
#endif
#ifdef MID_MUSIC
#ifdef USE_TIMIDITY_MIDI
			case MUS_MID:
				if ( timidity_ok ) {
					int samples = len / samplesize;
  					Timidity_PlaySome(stream, samples);
				}
				break;
#endif
#endif
#ifdef OGG_MUSIC
			case MUS_OGG:
				
				left = OGG_playAudio(music_playing->data.ogg, stream, len);
				break;
#endif
#ifdef FLAC_MUSIC
			case MUS_FLAC:
				left = FLAC_playAudio(music_playing->data.flac, stream, len);
				break;
#endif
#ifdef MP3_MUSIC
			case MUS_MP3:
				left = (len - smpeg.SMPEG_playAudio(music_playing->data.mp3, stream, len));
				break;
#endif
#ifdef MP3_MAD_MUSIC
			case MUS_MP3_MAD:
				left = mad_getSamples(music_playing->data.mp3_mad, stream, len);
				break;
#endif
			default:
				/* Unknown music type?? */
				break;
		}
	}

	/* Handle seamless music looping */
	if (left > 0 && left < len && music_halt_or_loop()) {
		music_mixer(udata, stream+(len-left), left);
	}
}
Exemplo n.º 5
0
/* Mixing function */
void music_mixer(void *udata, Uint8 *stream, int len)
{
	Mix_Music *music_playing_aux = music_playing;//maks
	if ( music_playing_aux && music_active ) {
		/* Handle fading */
		if ( music_playing_aux->fading != MIX_NO_FADING ) {
			if ( music_playing_aux->fade_step++ < music_playing_aux->fade_steps ) {
				int volume;
				int fade_step = music_playing_aux->fade_step;
				int fade_steps = music_playing_aux->fade_steps;

				if ( music_playing_aux->fading == MIX_FADING_OUT ) {
					volume = (music_volume * (fade_steps-fade_step)) / fade_steps;
				} else { /* Fading in */
					volume = (music_volume * fade_step) / fade_steps;
				}
				music_internal_volume(volume);
			} else {
				if ( music_playing_aux->fading == MIX_FADING_OUT ) {
					music_internal_halt();
					if ( music_finished_hook ) {
						music_finished_hook();
					}
					return;
				}
				music_playing_aux->fading = MIX_NO_FADING;
			}
		}
		/* Restart music if it has to loop */
		if ( !music_internal_playing() ) {
			/* Restart music if it has to loop at a high level */
			if ( music_loops && --music_loops ) {
				Mix_Fading current_fade = music_playing_aux->fading;
				music_internal_play(music_playing_aux, 0.0);
				music_playing_aux->fading = current_fade;
			} else {
				music_internal_halt();
				if ( music_finished_hook ) {
					music_finished_hook();
				}
				return;
			}
		}
		switch (music_playing_aux->type) {
#ifdef CMD_MUSIC
			case MUS_CMD:
				/* The playing is done externally */
				break;
#endif
#ifdef WAV_MUSIC
			case MUS_WAV:
				WAVStream_PlaySome(stream, len);
				break;
#endif
#ifdef MOD_MUSIC
			case MUS_MOD:
				VC_WriteBytes((SBYTE *)stream, len);
				if ( music_swap8 ) {
					Uint8 *dst;
					int i;

					dst = stream;
					for ( i=len; i; --i ) {
						*dst++ ^= 0x80;
					}
				} else
				if ( music_swap16 ) {
					Uint8 *dst, tmp;
					int i;

					dst = stream;
					for ( i=(len/2); i; --i ) {
						tmp = dst[0];
						dst[0] = dst[1];
						dst[1] = tmp;
						dst += 2;
					}
				}
				break;
#endif
#ifdef MID_MUSIC
#ifdef USE_TIMIDITY_MIDI
			case MUS_MID:
				if ( timidity_ok ) {
					int samples = len / samplesize;
  					Timidity_PlaySome(stream, samples);
				}
				break;
#endif
#endif
#ifdef OGG_MUSIC
			case MUS_OGG:
				OGG_playAudio(music_playing_aux->data.ogg, stream, len);
				break;
#endif
#ifdef MP3_MUSIC
			case MUS_MP3: //maks
				//SMPEG_playAudio(music_playing_aux->data.mp3, stream, len);
				{
					static Uint8 *mp3Buf = NULL;
					static int lenBuf = 0;
					int decoded;

					if(!mp3Buf || len > lenBuf) mp3Buf = realloc(mp3Buf, len);
					lenBuf = len;

					decoded = MAD_Decode(music_playing_aux->data.mp3, mp3Buf, len, used_mixer.channels);

					if(decoded > 0)
					{
						SDL_MixAudio(stream, mp3Buf, decoded, music_playing_aux->data.mp3->volume);
					}
					else
					{
						music_playing_aux->data.mp3->playing = 0;
					}
				}
				break;
#endif
			default:
				/* Unknown music type?? */
				break;
		}
	}
}