Пример #1
0
int main(int argc, char *argv[])
{
    SDL_AudioSpec audio;
    SDL_RWops *rw;

    if (SDL_Init(SDL_INIT_AUDIO) < 0)
    {
	fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError());
	return 1;
    }

    atexit(SDL_Quit);

    if (argc != 2)
    {
	fprintf(stderr, "Usage: %s midifile\n", argv[0]);
	return 1;
    }

    audio.freq = 44100;
    audio.format = AUDIO_S16SYS;
    audio.channels = 2;
    audio.samples = 4096;
    audio.callback = audio_callback;

    if (SDL_OpenAudio(&audio, NULL) < 0)
    {
	fprintf(stderr, "Couldn't open audio device. %s\n", SDL_GetError());
	return 1;
    }

    if (Timidity_Init() < 0)
    {
	fprintf(stderr, "Could not initialise TiMidity.\n");
	return 1;
    }
    
    rw = SDL_RWFromFile(argv[1], "rb");
    if (rw == NULL)
    {
	fprintf(stderr, "Could not create RWops from MIDI file.\n");
	return 1;
    }
	
    song = Timidity_LoadSong(rw, &audio);
    SDL_RWclose(rw);
    
    if (song == NULL)
    {
	fprintf(stderr, "Could not open MIDI file.\n");
	return 1;
    }

    Timidity_SetVolume(song, 100);
    Timidity_Start(song);
    
    SDL_PauseAudio(0);
    while (!done_flag)
    {
	SDL_Delay(10);
    }
    SDL_PauseAudio(1);
    Timidity_FreeSong(song);
    Timidity_Exit();
    
    return 0;
}
Пример #2
0
static void MIDI_quit(void)
{
    Timidity_Exit();
} /* MIDI_quit */
Пример #3
0
static void TIMIDITY_Close(void)
{
    Timidity_Exit();
}