12 #include "../stdafx.h" 13 #include "../openttd.h" 14 #include "../sound_type.h" 18 #include <sys/types.h> 26 #include <pspaudiolib.h> 29 #include "../safeguards.h" 39 MidSongOptions options;
48 static void AudioOutCallback(
void *buf,
unsigned int _reqn,
void *userdata)
50 memset(buf, 0, _reqn * PSP_NUM_AUDIO_CHANNELS);
51 if (
_midi.status == MIDI_PLAYING) {
52 mid_song_read_wave(
_midi.song, buf, _reqn * PSP_NUM_AUDIO_CHANNELS);
62 _midi.status = MIDI_STOPPED;
65 if (mid_init(param == NULL ? NULL : const_cast<char *>(param[0])) < 0) {
69 if (param != NULL || mid_init_no_config() < 0) {
70 return "error initializing timidity";
73 DEBUG(driver, 1,
"successfully initialised timidity");
75 _midi.options.rate = 44100;
76 _midi.options.format = MID_AUDIO_S16LSB;
77 _midi.options.channels = 2;
79 _midi.options.buffer_size = PSP_NUM_AUDIO_SAMPLES;
81 _midi.options.buffer_size =
_midi.options.rate;
86 pspAudioSetChannelCallback(
_midi.options.channels, &AudioOutCallback, NULL);
87 pspAudioSetVolume(
_midi.options.channels, PSP_VOLUME_MAX, PSP_VOLUME_MAX);
103 _midi.stream = mid_istream_open_file(filename);
104 if (
_midi.stream == NULL) {
105 DEBUG(driver, 0,
"Could not open music file");
110 mid_istream_close(
_midi.stream);
111 _midi.song_length = mid_song_get_total_time(
_midi.song);
113 if (
_midi.song == NULL) {
114 DEBUG(driver, 1,
"Invalid MIDI file");
118 mid_song_start(
_midi.song);
119 _midi.status = MIDI_PLAYING;
124 _midi.status = MIDI_STOPPED;
126 if (
_midi.song != NULL) mid_song_free(
_midi.song);
132 if (
_midi.status == MIDI_PLAYING) {
133 _midi.song_position = mid_song_get_time(
_midi.song);
134 if (
_midi.song_position >=
_midi.song_length) {
135 _midi.status = MIDI_STOPPED;
136 _midi.song_position = 0;
140 return (
_midi.status == MIDI_PLAYING);
145 if (
_midi.song != NULL) mid_song_set_volume(
_midi.song, vol);
const char * Start(const char *const *param)
Start this driver.
bool IsSongPlaying()
Are we currently playing a song?
static FMusicDriver_LibTimidity iFMusicDriver_LibTimidity
Factory for the libtimidity driver.
void PlaySong(const char *filename)
Play a particular song.
MidiState
The state of playing.
#define DEBUG(name, level,...)
Output a line of debugging information.
void SetVolume(byte vol)
Set the volume, if possible.
Factory for the libtimidity driver.
void Stop()
Stop this driver.
static struct @24 _midi
Metadata about the midi we're playing.
Base for LibTimidity music playback.
void StopSong()
Stop playing the current song.