aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
authorMax Horn2002-07-07 18:04:03 +0000
committerMax Horn2002-07-07 18:04:03 +0000
commit2b97c496c2d2f2de51580708cf5d5d8e6e0360f1 (patch)
tree40b0e3a10c13c1279c346db122f4f97115037dc2 /sound
parent2d72eb552ce648c9c46e16ae6b533996601aa9ac (diff)
downloadscummvm-rg350-2b97c496c2d2f2de51580708cf5d5d8e6e0360f1.tar.gz
scummvm-rg350-2b97c496c2d2f2de51580708cf5d5d8e6e0360f1.tar.bz2
scummvm-rg350-2b97c496c2d2f2de51580708cf5d5d8e6e0360f1.zip
indent run
svn-id: r4475
Diffstat (limited to 'sound')
-rw-r--r--sound/imuse.cpp446
-rw-r--r--sound/imuse.h16
-rw-r--r--sound/mididrv.cpp1350
-rw-r--r--sound/mididrv.h12
-rw-r--r--sound/mixer.cpp284
-rw-r--r--sound/mixer.h66
6 files changed, 1153 insertions, 1021 deletions
diff --git a/sound/imuse.cpp b/sound/imuse.cpp
index 62e79027c2..92a451685c 100644
--- a/sound/imuse.cpp
+++ b/sound/imuse.cpp
@@ -44,14 +44,14 @@
/* Roland to General Midi patch table. Still needs some work. */
static const byte mt32_to_gmidi[128] = {
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
- 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x
- 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x
- 88, 54, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x
- 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x
- 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x
- 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x
- 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x
- 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x
+ 0, 1, 0, 2, 4, 4, 5, 3, 16, 17, 18, 16, 16, 19, 20, 21, // 0x
+ 6, 6, 6, 7, 7, 7, 8, 112, 62, 62, 63, 63, 38, 38, 39, 39, // 1x
+ 88, 54, 52, 98, 97, 99, 14, 54, 102, 96, 53, 102, 81, 100, 14, 80, // 2x
+ 48, 48, 49, 45, 41, 40, 42, 42, 43, 46, 45, 24, 25, 28, 27, 104, // 3x
+ 32, 32, 34, 33, 36, 37, 35, 35, 79, 73, 72, 72, 74, 75, 64, 65, // 4x
+ 66, 67, 71, 71, 68, 69, 70, 22, 56, 59, 57, 57, 60, 60, 58, 61, // 5x
+ 61, 11, 11, 98, 14, 9, 14, 13, 12, 107, 107, 77, 78, 78, 76, 76, // 6x
+ 47, 117, 127, 118, 118, 116, 115, 119, 115, 112, 55, 124, 123, 0, 14, 117 // 7x
};
@@ -69,7 +69,7 @@ struct Instrument;
struct HookDatas {
- byte _jump,_transpose;
+ byte _jump, _transpose;
byte _part_onoff[16];
byte _part_volume[16];
byte _part_program[16];
@@ -94,7 +94,7 @@ struct Player {
int8 _detune;
uint _vol_chan;
byte _vol_eff;
-
+
uint _song_index;
uint _track_index;
uint _timer_counter;
@@ -104,15 +104,15 @@ struct Player {
uint _loop_to_tick;
uint _loop_from_tick;
uint32 _tempo;
- uint32 _tempo_eff; /* NoSave */
+ uint32 _tempo_eff; /* NoSave */
uint32 _cur_pos;
uint32 _next_pos;
uint32 _song_offset;
- uint32 _timer_speed; /* NoSave */
+ uint32 _timer_speed; /* NoSave */
uint _tick_index;
uint _beat_index;
uint _ticks_per_beat;
- byte _speed; /* NoSave */
+ byte _speed; /* NoSave */
bool _abort;
HookDatas _hook;
@@ -175,21 +175,22 @@ struct VolumeFader {
Player *player;
bool active;
byte curvol;
- uint16 speed_lo_max,num_steps;
+ uint16 speed_lo_max, num_steps;
int8 speed_hi;
int8 direction;
int8 speed_lo;
uint16 speed_lo_counter;
-
- void initialize() { active = false; }
- void on_timer();
+
+ void initialize() {
+ active = false;
+ } void on_timer();
};
struct SustainingNotes {
SustainingNotes *next;
SustainingNotes *prev;
Player *player;
- byte note,chan;
+ byte note, chan;
uint32 off_pos;
uint32 pos;
uint16 counter;
@@ -210,12 +211,15 @@ struct IsNoteCmdData {
struct MidiChannel {
Part *_part;
- MidiChannelAdl *adl() { return (MidiChannelAdl*)this; }
- MidiChannelGM *gm() { return (MidiChannelGM*)this; }
+ MidiChannelAdl *adl() {
+ return (MidiChannelAdl *)this;
+ } MidiChannelGM *gm() {
+ return (MidiChannelGM *) this;
+ }
};
-struct MidiChannelGM : MidiChannel {
+struct MidiChannelGM:MidiChannel {
byte _chan;
uint16 _actives[8];
};
@@ -229,10 +233,10 @@ struct Part {
Player *_player;
int16 _pitchbend;
byte _pitchbend_factor;
- int8 _transpose,_transpose_eff;
- byte _vol,_vol_eff;
- int8 _detune,_detune_eff;
- int8 _pan,_pan_eff;
+ int8 _transpose, _transpose_eff;
+ byte _vol, _vol_eff;
+ int8 _detune, _detune_eff;
+ int8 _pan, _pan_eff;
bool _on;
byte _modwheel;
bool _pedal;
@@ -248,13 +252,13 @@ struct Part {
void key_on(byte note, byte velocity);
void key_off(byte note);
void set_param(byte param, int value);
- void init(IMuseDriver *_driver);
+ void init(IMuseDriver * _driver);
void setup(Player *player);
void uninit();
void off();
void silence();
void set_instrument(uint b);
- void set_instrument(Instrument *data);
+ void set_instrument(Instrument * data);
void set_transpose(int8 transpose);
void set_vol(uint8 volume);
@@ -268,7 +272,7 @@ struct Part {
void set_program(byte program);
void set_chorus(uint chorus);
void set_effect_level(uint level);
-
+
int update_actives(uint16 *active);
void set_pitchbend_factor(uint8 value);
void set_onoff(bool on);
@@ -300,13 +304,13 @@ public:
virtual void init(IMuseInternal *eng, OSystem *syst) = 0;
virtual void update_pris() = 0;
virtual void set_instrument(uint slot, byte *instr) = 0;
- virtual void part_set_instrument(Part *part, Instrument *instr) = 0;
+ virtual void part_set_instrument(Part *part, Instrument * instr) = 0;
virtual void part_key_on(Part *part, byte note, byte velocity) = 0;
virtual void part_key_off(Part *part, byte note) = 0;
virtual void part_off(Part *part) = 0;
- virtual void part_changed(Part *part,byte what) = 0;
+ virtual void part_changed(Part *part, byte what) = 0;
virtual void part_set_param(Part *part, byte param, int value) = 0;
- virtual int part_update_active(Part *part,uint16 *active) = 0;
+ virtual int part_update_active(Part *part, uint16 *active) = 0;
};
@@ -314,9 +318,9 @@ public:
// imuse.h contains a public version of the same class.
// the public version, only contains a set of methods.
class IMuseInternal {
-friend struct Player;
+ friend struct Player;
private:
- IMuseDriver *_driver;
+ IMuseDriver * _driver;
byte **_base_sounds;
@@ -324,11 +328,11 @@ private:
byte _hardware_type;
private:
-
- bool _paused;
+
+ bool _paused;
bool _active_volume_faders;
- bool _initialized;
+ bool _initialized;
byte _volume_fader_counter;
int _game_tempo;
@@ -343,19 +347,19 @@ private:
byte _queue_marker;
byte _queue_cleared;
byte _master_volume;
- byte _music_volume; /* Global music volume. Percantage */
+ byte _music_volume; /* Global music volume. Percantage */
uint16 _trigger_count;
-
+
uint16 _channel_volume[8];
- uint16 _channel_volume_eff[8]; /* NoSave */
+ uint16 _channel_volume_eff[8]; /* NoSave */
uint16 _volchan_table[8];
-
+
Player _players[8];
SustainingNotes _sustaining_notes[24];
VolumeFader _volume_fader[8];
Part _parts[32];
-
+
uint16 _active_notes[128];
CommandQueue _cmd_queue[64];
@@ -381,7 +385,7 @@ private:
int enqueue_trigger(int sound, int marker);
int query_queue(int param);
Player *get_player_byid(int id);
-
+
int get_volchan_entry(uint a);
int set_volchan_entry(uint a, uint b);
int set_channel_volume(uint chan, uint vol);
@@ -401,13 +405,17 @@ private:
void unlock();
public:
- Part *parts_ptr() { return _parts; }
- IMuseDriver *driver() { return _driver; }
+ Part *parts_ptr() {
+ return _parts;
+ }
+ IMuseDriver *driver() {
+ return _driver;
+ }
int initialize(OSystem *syst, MidiDriver *midi, SoundMixer *mixer);
/* Public interface */
-
+
void on_timer();
void pause(bool paused);
int terminate();
@@ -425,7 +433,7 @@ public:
void setBase(byte **base);
uint32 property(int prop, uint32 value);
-
+
static IMuseInternal *create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer);
};
@@ -454,12 +462,12 @@ struct Struct10 {
struct Struct11 {
int16 modify_val;
- byte param,flag0x40,flag0x10;
+ byte param, flag0x40, flag0x10;
Struct10 *s10;
};
struct InstrumentExtra {
- byte a,b,c,d,e,f,g,h;
+ byte a, b, c, d, e, f, g, h;
};
struct Instrument {
@@ -481,13 +489,13 @@ struct Instrument {
byte duration;
};
-struct MidiChannelAdl : MidiChannel {
- MidiChannelAdl *_next,*_prev;
+struct MidiChannelAdl:MidiChannel {
+ MidiChannelAdl *_next, *_prev;
byte _waitforpedal;
byte _note;
byte _channel;
byte _twochan;
- byte _vol_1,_vol_2;
+ byte _vol_1, _vol_2;
int16 _duration;
Struct10 _s10a;
@@ -496,7 +504,7 @@ struct MidiChannelAdl : MidiChannel {
Struct11 _s11b;
};
-class IMuseAdlib : public IMuseDriver {
+class IMuseAdlib:public IMuseDriver {
private:
FM_OPL *_opl;
byte *_adlib_reg_cache;
@@ -518,8 +526,10 @@ private:
void adlib_note_on(int chan, byte note, int mod);
void adlib_note_on_ex(int chan, byte note, int mod);
int adlib_read_param(int chan, byte data);
- void adlib_setup_channel(int chan, Instrument *instr, byte vol_1, byte vol_2);
- byte adlib_read(byte port) { return _adlib_reg_cache[port]; }
+ void adlib_setup_channel(int chan, Instrument * instr, byte vol_1, byte vol_2);
+ byte adlib_read(byte port) {
+ return _adlib_reg_cache[port];
+ }
void adlib_set_param(int channel, byte param, int value);
void adlib_key_onoff(int channel);
void adlib_write(byte port, byte value);
@@ -528,51 +538,58 @@ private:
MidiChannelAdl *allocate_midichan(byte pri);
void reset_tick();
- void mc_off(MidiChannel *mc);
+ void mc_off(MidiChannel * mc);
static void link_mc(Part *part, MidiChannelAdl *mc);
- static void mc_inc_stuff(MidiChannelAdl *mc, Struct10 *s10, Struct11 *s11);
- static void mc_init_stuff(MidiChannelAdl *mc, Struct10 *s10, Struct11 *s11, byte flags, InstrumentExtra *ie);
- static void struct10_init(Struct10 *s10, InstrumentExtra *ie);
- static byte struct10_ontimer(Struct10 *s10, Struct11 *s11);
- static void struct10_setup(Struct10 *s10);
+ static void mc_inc_stuff(MidiChannelAdl *mc, Struct10 * s10, Struct11 * s11);
+ static void mc_init_stuff(MidiChannelAdl *mc, Struct10 * s10, Struct11 * s11, byte flags,
+ InstrumentExtra * ie);
+ static void struct10_init(Struct10 * s10, InstrumentExtra * ie);
+ static byte struct10_ontimer(Struct10 * s10, Struct11 * s11);
+ static void struct10_setup(Struct10 * s10);
static int random_nr(int a);
- void mc_key_on(MidiChannel *mc, byte note, byte velocity);
+ void mc_key_on(MidiChannel * mc, byte note, byte velocity);
static void premix_proc(void *param, int16 *buf, uint len);
public:
- IMuseAdlib(SoundMixer *mixer) { _mixer = mixer; }
+ IMuseAdlib(SoundMixer *mixer) {
+ _mixer = mixer;
+ }
void uninit();
void init(IMuseInternal *eng, OSystem *syst);
- void update_pris() { }
- void generate_samples(int16 *buf, int len);
- void on_timer();
+ void update_pris() {
+ }
+ void generate_samples(int16 *buf, int len);
+ void on_timer();
void set_instrument(uint slot, byte *instr);
- void part_set_instrument(Part *part, Instrument *instr);
+ void part_set_instrument(Part *part, Instrument * instr);
void part_key_on(Part *part, byte note, byte velocity);
void part_key_off(Part *part, byte note);
void part_set_param(Part *part, byte param, int value);
- void part_changed(Part *part,byte what);
+ void part_changed(Part *part, byte what);
void part_off(Part *part);
- int part_update_active(Part *part,uint16 *active);
- void adjust_priorities() {}
+ int part_update_active(Part *part, uint16 *active);
+ void adjust_priorities() {
+ }
- uint32 get_base_tempo() {
+ uint32 get_base_tempo() {
#ifdef _WIN32_WCE
- return 0x1F0000 * 2; // Sampled down to 11 kHz
-#else //_WIN32_WCE
- return 0x1F0000; // Was: 0x1924E0;
+ return 0x1F0000 * 2; // Sampled down to 11 kHz
+#else //_WIN32_WCE
+ return 0x1F0000; // Was: 0x1924E0;
#endif //_WIN32_WCE
}
- byte get_hardware_type() { return 1; }
+ byte get_hardware_type() {
+ return 1;
+ }
};
/* IMuseGM classes */
-class IMuseGM : public IMuseDriver {
+class IMuseGM:public IMuseDriver {
IMuseInternal *_se;
OSystem *_system;
MidiDriver *_md;
@@ -602,26 +619,34 @@ class IMuseGM : public IMuseDriver {
void midiInit();
public:
- IMuseGM(MidiDriver *midi) { _md = midi; }
-
- void uninit();
+ IMuseGM(MidiDriver *midi) {
+ _md = midi;
+ } void uninit();
void init(IMuseInternal *eng, OSystem *os);
void update_pris();
void part_off(Part *part);
- int part_update_active(Part *part,uint16 *active);
+ int part_update_active(Part *part, uint16 *active);
- void on_timer() {}
- void set_instrument(uint slot, byte *instr) {}
- void part_set_instrument(Part *part, Instrument *instr) {}
- void part_set_param(Part *part, byte param, int value) {}
+ void on_timer() {
+ }
+ void set_instrument(uint slot, byte *instr) {
+ }
+ void part_set_instrument(Part *part, Instrument * instr) {
+ }
+ void part_set_param(Part *part, byte param, int value) {
+ }
void part_key_on(Part *part, byte note, byte velocity);
void part_key_off(Part *part, byte note);
- void part_changed(Part *part,byte what);
+ void part_changed(Part *part, byte what);
static int midi_driver_thread(void *param);
- uint32 get_base_tempo() { return 0x460000; }
- byte get_hardware_type() { return 5; }
+ uint32 get_base_tempo() {
+ return 0x460000;
+ }
+ byte get_hardware_type() {
+ return 5;
+ }
};
@@ -756,8 +781,8 @@ byte *IMuseInternal::findTag(int sound, char *tag, int index)
ptr = _base_sounds[sound];
if (ptr == NULL) {
- // debug(1, "IMuseInternal::findTag completely failed finding sound %d",
- // sound);
+ // debug(1, "IMuseInternal::findTag completely failed finding sound %d",
+ // sound);
return NULL;
}
@@ -767,13 +792,13 @@ byte *IMuseInternal::findTag(int sound, char *tag, int index)
ptr += 4;
pos = 0;
-
+
while (pos < size) {
if (!memcmp(ptr + pos, tag, 4) && !index--)
return ptr + pos + 8;
pos += READ_BE_UINT32_UNALIGNED(ptr + pos + 4) + 8;
}
-
+
debug(1, "IMuseInternal::findTag failed finding sound %d", sound);
return NULL;
}
@@ -789,7 +814,7 @@ bool IMuseInternal::isMT32(int sound)
if (ptr == NULL)
return false;
- tag = *(((uint32 *)ptr)+1);
+ tag = *(((uint32 *)ptr) + 1);
switch (tag) {
case MKID('ADL '):
return false;
@@ -802,7 +827,7 @@ bool IMuseInternal::isMT32(int sound)
case MKID('SPK '):
return false;
}
-
+
return false;
}
@@ -1139,8 +1164,7 @@ int IMuseInternal::set_volchan(int sound, int volchan)
if (r >= 8) {
for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
- if (player->_active && player->_id == (uint16)sound
- && player->_vol_chan != (uint16)volchan) {
+ if (player->_active && player->_id == (uint16)sound && player->_vol_chan != (uint16)volchan) {
player->_vol_chan = volchan;
player->set_vol(player->_volume);
return 0;
@@ -1182,8 +1206,7 @@ int IMuseInternal::clear_queue()
return 0;
}
-int IMuseInternal::enqueue_command(int a, int b, int c, int d, int e, int f,
- int g)
+int IMuseInternal::enqueue_command(int a, int b, int c, int d, int e, int f, int g)
{
uint16 *p;
uint i;
@@ -1265,7 +1288,7 @@ int IMuseInternal::set_master_volume(uint vol)
vol = vol / (100 / _music_volume);
_master_volume = vol;
-// _s->_sound_volume_master = vol;
+// _s->_sound_volume_master = vol;
for (i = 0; i != 8; i++)
_channel_volume_eff[i] = (_channel_volume[i] + 1) * vol >> 7;
update_volumes();
@@ -1309,8 +1332,7 @@ int IMuseInternal::enqueue_trigger(int sound, int marker)
return 0;
}
-int32 IMuseInternal::do_command(int a, int b, int c, int d, int e, int f, int g,
- int h)
+int32 IMuseInternal::do_command(int a, int b, int c, int d, int e, int f, int g, int h)
{
byte cmd = a & 0xFF;
byte param = a >> 8;
@@ -1330,32 +1352,32 @@ int32 IMuseInternal::do_command(int a, int b, int c, int d, int e, int f, int g,
case 9:
return stop_sound(b);
case 10:
- return stop_all_sounds(); //FIXME: Sam and Max unknown
+ return stop_all_sounds(); //FIXME: Sam and Max unknown
case 11:
return stop_all_sounds();
case 13:
- return get_sound_status(b);
- case 14: { // FIXME: Sam and Max command - Total guess
- int i; // Seems to work as a volume fader
- Player *player;
-
- for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
- if (player->_active && player->_id == (uint16)b) {
- player->fade_vol(e, f);
- return 0;
+ return get_sound_status(b);
+ case 14:{ // FIXME: Sam and Max command - Total guess
+ int i; // Seems to work as a volume fader
+ Player *player;
+
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
+ if (player->_active && player->_id == (uint16)b) {
+ player->fade_vol(e, f);
+ return 0;
+ }
}
- }
- }
- case 15: { // FIXME: Sam and Max command - Total guess
- int i; // Something to do with position?
- Player *player;
- for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
- if (player->_active && player->_id == (uint16)b) {
- player->jump(player->_track_index+1, 0, 0);
- return 0;
+ }
+ case 15:{ // FIXME: Sam and Max command - Total guess
+ int i; // Something to do with position?
+ Player *player;
+ for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) {
+ if (player->_active && player->_id == (uint16)b) {
+ player->jump(player->_track_index + 1, 0, 0);
+ return 0;
+ }
}
- }
- }
+ }
case 16:
return set_volchan(b, c);
@@ -1364,9 +1386,9 @@ int32 IMuseInternal::do_command(int a, int b, int c, int d, int e, int f, int g,
case 18:
return set_volchan_entry(b, c);
case 19:
- return stop_sound(b); //FIXME: Sam and Max unknown
+ return stop_sound(b); //FIXME: Sam and Max unknown
case 20:
- return stop_sound(b); //FIXME: Sam and Max unknown
+ return stop_sound(b); //FIXME: Sam and Max unknown
case 2:
case 3:
return 0;
@@ -1579,8 +1601,9 @@ int IMuseInternal::get_volchan_entry(uint a)
return -1;
}
-uint32 IMuseInternal::property(int prop, uint32 value) {
- switch(prop) {
+uint32 IMuseInternal::property(int prop, uint32 value)
+{
+ switch (prop) {
case IMuse::PROP_TEMPO_BASE:
_game_tempo = value;
break;
@@ -1588,12 +1611,14 @@ uint32 IMuseInternal::property(int prop, uint32 value) {
return 0;
}
-void IMuseInternal::setBase(byte **base) {
+void IMuseInternal::setBase(byte **base)
+{
_base_sounds = base;
}
-IMuseInternal *IMuseInternal::create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer) {
+IMuseInternal *IMuseInternal::create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer)
+{
IMuseInternal *i = new IMuseInternal;
i->initialize(syst, midi, mixer);
return i;
@@ -1603,7 +1628,7 @@ IMuseInternal *IMuseInternal::create(OSystem *syst, MidiDriver *midi, SoundMixer
int IMuseInternal::initialize(OSystem *syst, MidiDriver *midi, SoundMixer *mixer)
{
int i;
-
+
IMuseDriver *driv;
if (midi == NULL) {
@@ -1615,8 +1640,8 @@ int IMuseInternal::initialize(OSystem *syst, MidiDriver *midi, SoundMixer *mixer
_driver = driv;
_hardware_type = driv->get_hardware_type();
_game_tempo = driv->get_base_tempo();
-
- driv->init(this,syst);
+
+ driv->init(this, syst);
_master_volume = 127;
if (_music_volume < 1)
@@ -1788,7 +1813,7 @@ void Player::set_tempo(uint32 b)
uint32 i, j;
i = _se->_game_tempo;
-
+
j = _tempo = b;
while (i & 0xFFFF0000 || j & 0xFFFF0000) {
@@ -2056,8 +2081,7 @@ void Player::parse_sysex(byte *p, uint len)
case 80: /* loop */
decode_sysex_bytes(p + 1, buf, len - 2);
set_loop(read_word(buf),
- read_word(buf + 2),
- read_word(buf + 4), read_word(buf + 6), read_word(buf + 8)
+ read_word(buf + 2), read_word(buf + 4), read_word(buf + 6), read_word(buf + 8)
);
break;
@@ -2067,9 +2091,7 @@ void Player::parse_sysex(byte *p, uint len)
case 96: /* set instrument */
part = get_part(p[0] & 0x0F);
- b =
- (p[1] & 0x0F) << 12 | (p[2] & 0x0F) << 8 | (p[4] & 0x0F) << 4 | (p[4] &
- 0x0F);
+ b = (p[1] & 0x0F) << 12 | (p[2] & 0x0F) << 8 | (p[4] & 0x0F) << 4 | (p[4] & 0x0F);
if (part)
part->set_instrument(b);
break;
@@ -2119,7 +2141,7 @@ void Player::maybe_set_transpose(byte *data)
if (cmd != 0 && cmd < 0x80)
_hook._transpose = 0;
- set_transpose(data[1], (int8) data[2]);
+ set_transpose(data[1], (int8)data[2]);
}
void Player::maybe_part_onoff(byte *data)
@@ -2213,7 +2235,7 @@ void Player::maybe_set_transpose_part(byte *data)
if (cmd != 0 && cmd < 0x80)
*p = 0;
- part_set_transpose(chan, data[2], (int8) data[3]);
+ part_set_transpose(chan, data[2], (int8)data[3]);
}
int Player::set_transpose(byte relative, int b)
@@ -2329,8 +2351,7 @@ bool Player::jump(uint track, uint beat, uint tick)
turn_off_pedals();
- find_sustaining_notes(cur_mtrk + _song_offset, mtrk + track_offs,
- curpos - topos);
+ find_sustaining_notes(cur_mtrk + _song_offset, mtrk + track_offs, curpos - topos);
_beat_index = beat;
_tick_index = tick;
@@ -2347,8 +2368,7 @@ bool Player::jump(uint track, uint beat, uint tick)
return true;
}
-bool Player::set_loop(uint count, uint tobeat, uint totick, uint frombeat,
- uint fromtick)
+bool Player::set_loop(uint count, uint tobeat, uint totick, uint frombeat, uint fromtick)
{
if (tobeat + 1 >= frombeat)
return false;
@@ -2396,7 +2416,7 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l)
/* pos contains number of ticks since current position */
pos = _next_pos - _cur_pos;
- if ((int32) pos < 0)
+ if ((int32)pos < 0)
pos = 0;
/* locate the positions where the notes are turned off.
@@ -2459,8 +2479,7 @@ void Player::find_sustaining_notes(byte *a, byte *b, uint32 l)
sn = _se->_sustain_notes_used;
while (sn) {
next = sn->next;
- if (sn->note == isnote.note && sn->chan == isnote.chan
- && pos < sn->off_pos) {
+ if (sn->note == isnote.note && sn->chan == isnote.chan && pos < sn->off_pos) {
*bitlist_ptr &= ~mask;
/* Unlink from the sustain list */
if (next)
@@ -2747,8 +2766,7 @@ void Player::sequencer_timer()
_beat_index += _tick_index / _ticks_per_beat;
_tick_index %= _ticks_per_beat;
}
- if (_loop_counter && _beat_index >= _loop_from_beat
- && _tick_index >= _loop_from_tick) {
+ if (_loop_counter && _beat_index >= _loop_from_beat && _tick_index >= _loop_from_tick) {
_loop_counter--;
jump(_track_index, _loop_to_beat, _loop_to_tick);
}
@@ -2811,7 +2829,7 @@ void *IMuseInternal::loadReference(IMuseInternal *me, byte type, int ref)
}
}
-int IMuseInternal::save_or_load(Serializer * ser, Scumm *scumm)
+int IMuseInternal::save_or_load(Serializer *ser, Scumm *scumm)
{
const SaveLoadEntry mainEntries[] = {
MKLINE(IMuseInternal, _queue_end, sleUint8),
@@ -2908,14 +2926,11 @@ int IMuseInternal::save_or_load(Serializer * ser, Scumm *scumm)
#endif
ser->_ref_me = this;
- ser->_saveload_ref =
- ser->isSaving()? ((void *)&saveReference) : ((void *)&loadReference);
+ ser->_saveload_ref = ser->isSaving()? ((void *)&saveReference) : ((void *)&loadReference);
ser->saveLoadEntries(this, mainEntries);
- ser->saveLoadArrayOf(_players, ARRAYSIZE(_players), sizeof(_players[0]),
- playerEntries);
- ser->saveLoadArrayOf(_parts, ARRAYSIZE(_parts), sizeof(_parts[0]),
- partEntries);
+ ser->saveLoadArrayOf(_players, ARRAYSIZE(_players), sizeof(_players[0]), playerEntries);
+ ser->saveLoadArrayOf(_parts, ARRAYSIZE(_parts), sizeof(_parts[0]), partEntries);
ser->saveLoadArrayOf(_volume_fader, ARRAYSIZE(_volume_fader),
sizeof(_volume_fader[0]), volumeFaderEntries);
@@ -2992,8 +3007,7 @@ void Part::set_pan(int8 pan)
void Part::set_transpose(int8 transpose)
{
- _transpose_eff = transpose_clamp((_transpose = transpose) +
- _player->_transpose, -12, 12);
+ _transpose_eff = transpose_clamp((_transpose = transpose) + _player->_transpose, -12, 12);
changed(IMuseDriver::pcMod);
}
@@ -3259,8 +3273,9 @@ MidiChannelAdl *IMuseAdlib::allocate_midichan(byte pri)
return best;
}
-void IMuseAdlib::premix_proc(void *param, int16 *buf, uint len) {
- ((IMuseAdlib*)param)->generate_samples(buf, len);
+void IMuseAdlib::premix_proc(void *param, int16 *buf, uint len)
+{
+ ((IMuseAdlib *) param)->generate_samples(buf, len);
}
void IMuseAdlib::init(IMuseInternal *eng, OSystem *syst)
@@ -3278,7 +3293,7 @@ void IMuseAdlib::init(IMuseInternal *eng, OSystem *syst)
_adlib_reg_cache = (byte *)calloc(256, 1);
- _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, syst->property(OSystem::PROP_GET_SAMPLE_RATE,0));
+ _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, syst->property(OSystem::PROP_GET_SAMPLE_RATE, 0));
adlib_write(1, 0x20);
adlib_write(8, 0x40);
@@ -3493,8 +3508,7 @@ void IMuseAdlib::adlib_key_onoff(int channel)
adlib_write(port, val | 0x20);
}
-void IMuseAdlib::adlib_setup_channel(int chan, Instrument * instr,
- byte vol_1, byte vol_2)
+void IMuseAdlib::adlib_setup_channel(int chan, Instrument * instr, byte vol_1, byte vol_2)
{
byte port;
@@ -3551,7 +3565,7 @@ int IMuseAdlib::adlib_read_param(int chan, byte param)
return val;
}
-void IMuseAdlib::generate_samples(int16 * data, int len)
+void IMuseAdlib::generate_samples(int16 *data, int len)
{
int step;
@@ -3759,8 +3773,7 @@ void IMuseAdlib::struct10_init(Struct10 * s10, InstrumentExtra * ie)
}
void IMuseAdlib::mc_init_stuff(MidiChannelAdl *mc, Struct10 * s10,
- Struct11 * s11, byte flags,
- InstrumentExtra * ie)
+ Struct11 * s11, byte flags, InstrumentExtra * ie)
{
Part *part = mc->_part;
@@ -3793,14 +3806,13 @@ void IMuseAdlib::mc_init_stuff(MidiChannelAdl *mc, Struct10 * s10,
s11->s10->unk3 = 0;
break;
default:
- s10->start_value = ((IMuseAdlib*)part->_drv)->adlib_read_param(mc->_channel, s11->param);
+ s10->start_value = ((IMuseAdlib *) part->_drv)->adlib_read_param(mc->_channel, s11->param);
}
struct10_init(s10, ie);
}
-void IMuseAdlib::mc_inc_stuff(MidiChannelAdl *mc, Struct10 * s10,
- Struct11 * s11)
+void IMuseAdlib::mc_inc_stuff(MidiChannelAdl *mc, Struct10 * s10, Struct11 * s11)
{
byte code;
Part *part = mc->_part;
@@ -3811,18 +3823,18 @@ void IMuseAdlib::mc_inc_stuff(MidiChannelAdl *mc, Struct10 * s10,
switch (s11->param) {
case 0:
mc->_vol_2 = s10->start_value + s11->modify_val;
- ((IMuseAdlib*)part->_drv)->adlib_set_param(mc->_channel, 0,
- volume_table[lookup_table[mc->_vol_2]
- [part->_vol_eff >> 2]]);
+ ((IMuseAdlib *) part->_drv)->adlib_set_param(mc->_channel, 0,
+ volume_table[lookup_table[mc->_vol_2]
+ [part->_vol_eff >> 2]]);
break;
case 13:
mc->_vol_1 = s10->start_value + s11->modify_val;
if (mc->_twochan) {
- ((IMuseAdlib*)part->_drv)->adlib_set_param(mc->_channel, 13,
- volume_table[lookup_table[mc->_vol_1]
- [part->_vol_eff >> 2]]);
+ ((IMuseAdlib *) part->_drv)->adlib_set_param(mc->_channel, 13,
+ volume_table[lookup_table[mc->_vol_1]
+ [part->_vol_eff >> 2]]);
} else {
- ((IMuseAdlib*)part->_drv)->adlib_set_param(mc->_channel, 13, mc->_vol_1);
+ ((IMuseAdlib *) part->_drv)->adlib_set_param(mc->_channel, 13, mc->_vol_1);
}
break;
case 30:
@@ -3832,14 +3844,14 @@ void IMuseAdlib::mc_inc_stuff(MidiChannelAdl *mc, Struct10 * s10,
s11->s10->unk3 = (char)s11->modify_val;
break;
default:
- ((IMuseAdlib*)part->_drv)->adlib_set_param(mc->_channel, s11->param,
- s10->start_value + s11->modify_val);
+ ((IMuseAdlib *) part->_drv)->adlib_set_param(mc->_channel, s11->param,
+ s10->start_value + s11->modify_val);
break;
}
}
if (code & 2 && s11->flag0x10)
- ((IMuseAdlib*)part->_drv)->adlib_key_onoff(mc->_channel);
+ ((IMuseAdlib *) part->_drv)->adlib_key_onoff(mc->_channel);
}
void IMuseAdlib::part_changed(Part *part, byte what)
@@ -3864,9 +3876,8 @@ void IMuseAdlib::part_changed(Part *part, byte what)
adlib_set_param(mc->_channel, 0, volume_table[lookup_table[mc->_vol_2]
[part->_vol_eff >> 2]]);
if (mc->_twochan) {
- adlib_set_param(mc->_channel, 13,
- volume_table[lookup_table[mc->_vol_1]
- [part->_vol_eff >> 2]]);
+ adlib_set_param(mc->_channel, 13, volume_table[lookup_table[mc->_vol_1]
+ [part->_vol_eff >> 2]]);
}
}
}
@@ -3905,16 +3916,12 @@ void IMuseAdlib::mc_key_on(MidiChannel * mc2, byte note, byte velocity)
if (mc->_duration != 0)
mc->_duration *= 63;
- vol_1 =
- (instr->oplvl_1 & 0x3F) +
- lookup_table[velocity >> 1][instr->waveform_1 >> 2];
+ vol_1 = (instr->oplvl_1 & 0x3F) + lookup_table[velocity >> 1][instr->waveform_1 >> 2];
if (vol_1 > 0x3F)
vol_1 = 0x3F;
mc->_vol_1 = vol_1;
- vol_2 =
- (instr->oplvl_2 & 0x3F) +
- lookup_table[velocity >> 1][instr->waveform_2 >> 2];
+ vol_2 = (instr->oplvl_2 & 0x3F) + lookup_table[velocity >> 1][instr->waveform_2 >> 2];
if (vol_2 > 0x3F)
vol_2 = 0x3F;
mc->_vol_2 = vol_2;
@@ -3926,19 +3933,16 @@ void IMuseAdlib::mc_key_on(MidiChannel * mc2, byte note, byte velocity)
vol_1 = volume_table[lookup_table[vol_1][c]];
adlib_setup_channel(mc->_channel, instr, vol_1, vol_2);
- adlib_note_on_ex(mc->_channel, part->_transpose_eff + note,
- part->_detune_eff + part->_pitchbend);
+ adlib_note_on_ex(mc->_channel, part->_transpose_eff + note, part->_detune_eff + part->_pitchbend);
if (instr->flags_a & 0x80) {
- mc_init_stuff(mc, &mc->_s10a, &mc->_s11a, instr->flags_a,
- &instr->extra_a);
+ mc_init_stuff(mc, &mc->_s10a, &mc->_s11a, instr->flags_a, &instr->extra_a);
} else {
mc->_s10a.active = 0;
}
if (instr->flags_b & 0x80) {
- mc_init_stuff(mc, &mc->_s10b, &mc->_s11b, instr->flags_b,
- &instr->extra_b);
+ mc_init_stuff(mc, &mc->_s10b, &mc->_s11b, instr->flags_b, &instr->extra_b);
} else {
mc->_s10b.active = 0;
}
@@ -4200,12 +4204,12 @@ void IMuseGM::midiControl0(byte chan, byte value)
void IMuseGM::midiProgram(byte chan, byte program, bool mt32emulate)
{
-// if ((chan + 1) != 10) { /* Ignore percussion prededed by patch change */
- if (mt32emulate)
- program = mt32_to_gmidi[program];
+// if ((chan + 1) != 10) { /* Ignore percussion prededed by patch change */
+ if (mt32emulate)
+ program = mt32_to_gmidi[program];
- _md->send(program << 8 | 0xC0 | chan);
-// }
+ _md->send(program << 8 | 0xC0 | chan);
+// }
}
void IMuseGM::midiPan(byte chan, int8 pan)
@@ -4260,15 +4264,16 @@ void IMuseGM::part_key_off(Part *part, byte note)
}
#if !defined(__MORPHOS__)
-int IMuseGM::midi_driver_thread(void *param) {
- IMuseGM *mid = (IMuseGM*) param;
+int IMuseGM::midi_driver_thread(void *param)
+{
+ IMuseGM *mid = (IMuseGM *) param;
int old_time, cur_time;
old_time = mid->_system->get_msecs();
- for(;;) {
+ for (;;) {
mid->_system->delay_msecs(10);
-
+
cur_time = mid->_system->get_msecs();
while (old_time < cur_time) {
old_time += 10;
@@ -4281,35 +4286,32 @@ int IMuseGM::midi_driver_thread(void *param) {
#include <proto/exec.h>
#include <proto/dos.h>
#include "../morphos/morphos.h"
-int IMuseGM::midi_driver_thread( void *param )
+int IMuseGM::midi_driver_thread(void *param)
{
- IMuseGM *mid = (IMuseGM*) param;
+ IMuseGM *mid = (IMuseGM *) param;
int old_time, cur_time;
bool initialized;
- ObtainSemaphore( &ScummMusicThreadRunning );
+ ObtainSemaphore(&ScummMusicThreadRunning);
- initialized = init_morphos_music( 0 );
+ initialized = init_morphos_music(0);
old_time = mid->_system->get_msecs();
- if( !initialized )
- Wait( SIGBREAKF_CTRL_C );
- else
- {
- for(;;)
- {
+ if (!initialized)
+ Wait(SIGBREAKF_CTRL_C);
+ else {
+ for (;;) {
MusicTimerIORequest->tr_time.tv_micro = 10000;
- MusicTimerIORequest->tr_node.io_Command = TR_ADDREQUEST;
- MusicTimerIORequest->tr_time.tv_secs = 0;
- DoIO( (struct IORequest *)MusicTimerIORequest );
+ MusicTimerIORequest->tr_node.io_Command = TR_ADDREQUEST;
+ MusicTimerIORequest->tr_time.tv_secs = 0;
+ DoIO((struct IORequest *)MusicTimerIORequest);
- if( CheckSignal( SIGBREAKF_CTRL_C ) )
+ if (CheckSignal(SIGBREAKF_CTRL_C))
break;
cur_time = mid->_system->get_msecs();
- while (old_time < cur_time)
- {
+ while (old_time < cur_time) {
old_time += 10;
mid->_se->on_timer();
}
@@ -4318,8 +4320,8 @@ int IMuseGM::midi_driver_thread( void *param )
exit_morphos_music();
- ReleaseSemaphore( &ScummMusicThreadRunning );
- RemTask( NULL );
+ ReleaseSemaphore(&ScummMusicThreadRunning);
+ RemTask(NULL);
return 0;
}
#endif
@@ -4355,8 +4357,7 @@ void IMuseGM::update_pris()
hipri = 0;
hipart = NULL;
for (i = 32, part = _se->parts_ptr(); i; i--, part++) {
- if (part->_player && !part->_percussion && part->_on && !part->_mc
- && part->_pri_eff >= hipri) {
+ if (part->_player && !part->_percussion && part->_on && !part->_mc && part->_pri_eff >= hipri) {
hipri = part->_pri_eff;
hipart = part;
}
@@ -4490,7 +4491,7 @@ void IMuseGM::part_off(Part *part)
* our real IMuseInternal class. This way we reduce the compile time
* and inter source dependencies.
*/
-IMuse::IMuse() : _imuse(NULL)
+IMuse::IMuse():_imuse(NULL)
{
}
@@ -4575,7 +4576,8 @@ uint32 IMuse::property(int prop, uint32 value)
return _imuse->property(prop, value);
}
-IMuse *IMuse::create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer) {
+IMuse *IMuse::create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer)
+{
IMuse *i = new IMuse;
i->_imuse = IMuseInternal::create(syst, midi, mixer);
return i;
diff --git a/sound/imuse.h b/sound/imuse.h
index 2559b2a60a..f265f52492 100644
--- a/sound/imuse.h
+++ b/sound/imuse.h
@@ -28,10 +28,10 @@ public:
PROP_TEMPO_BASE = 1,
};
- IMuse();
- ~IMuse();
+ IMuse();
+ ~IMuse();
- void on_timer(); // For the MacOS 9 port only
+ void on_timer(); // For the MacOS 9 port only
void pause(bool paused);
int save_or_load(Serializer *ser, Scumm *scumm);
int set_music_volume(uint vol);
@@ -49,9 +49,13 @@ public:
static IMuse *create(OSystem *syst, MidiDriver *midi, SoundMixer *mixer);
- static IMuse *create_adlib(OSystem *syst, SoundMixer *mixer) { return create(syst, NULL, mixer); }
- static IMuse *create_midi(OSystem *syst, MidiDriver *midi) { return create(syst, midi, NULL); }
+ static IMuse *create_adlib(OSystem *syst, SoundMixer *mixer) {
+ return create(syst, NULL, mixer);
+ }
+ static IMuse *create_midi(OSystem *syst, MidiDriver *midi) {
+ return create(syst, midi, NULL);
+ }
private:
- IMuseInternal *_imuse; // Pointer to the real imuse object
+ IMuseInternal *_imuse; // Pointer to the real imuse object
};
diff --git a/sound/mididrv.cpp b/sound/mididrv.cpp
index cff0a0e775..de93ddc8eb 100644
--- a/sound/mididrv.cpp
+++ b/sound/mididrv.cpp
@@ -39,7 +39,7 @@
#if defined(WIN32) && !defined(_WIN32_WCE)
/* Windows MIDI driver */
-class MidiDriver_WIN : public MidiDriver {
+class MidiDriver_WIN:public MidiDriver {
public:
int open(int mode);
void close();
@@ -53,7 +53,7 @@ private:
};
enum {
- NUM_PREPARED_HEADERS=2,
+ NUM_PREPARED_HEADERS = 2,
MIDI_EVENT_SIZE = 64,
BUFFER_SIZE = MIDI_EVENT_SIZE * 12,
};
@@ -76,35 +76,38 @@ private:
uint32 property(int prop, uint32 param);
static void CALLBACK midi_callback(HMIDIOUT hmo, UINT wMsg,
- DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
+ DWORD dwInstance, DWORD dwParam1, DWORD dwParam2);
};
-void MidiDriver_WIN::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_WIN::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
void CALLBACK MidiDriver_WIN::midi_callback(HMIDIOUT hmo, UINT wMsg,
- DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) {
+ DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
+{
- switch(wMsg) {
+ switch (wMsg) {
case MM_MOM_DONE:{
- MidiDriver_WIN *md = ((MidiDriver_WIN*)dwInstance);
- if (md->_mode)
- md->fill_all();
- break;
+ MidiDriver_WIN *md = ((MidiDriver_WIN *) dwInstance);
+ if (md->_mode)
+ md->fill_all();
+ break;
}
}
}
-int MidiDriver_WIN::open(int mode) {
+int MidiDriver_WIN::open(int mode)
+{
if (_mode != 0)
return MERR_ALREADY_OPEN;
-
+
_mode = mode;
if (mode == MO_SIMPLE) {
- MMRESULT res = midiOutOpen((HMIDIOUT *) &_mo, MIDI_MAPPER, NULL, NULL, 0);
+ MMRESULT res = midiOutOpen((HMIDIOUT *) & _mo, MIDI_MAPPER, NULL, NULL, 0);
if (res != MMSYSERR_NOERROR)
check_error(res);
} else {
@@ -112,16 +115,15 @@ int MidiDriver_WIN::open(int mode) {
MIDIPROPTIMEDIV mptd;
UINT _midi_device_id = 0;
- check_error(midiStreamOpen(&_ms, &_midi_device_id, 1,
- (uint32)midi_callback, (uint32)this, CALLBACK_FUNCTION));
-
+ check_error(midiStreamOpen(&_ms, &_midi_device_id, 1,
+ (uint32)midi_callback, (uint32)this, CALLBACK_FUNCTION));
+
prepare();
mptd.cbStruct = sizeof(mptd);
mptd.dwTimeDiv = _time_div;
- check_error(midiStreamProperty(_ms, (byte*)&mptd,
- MIDIPROP_SET | MIDIPROP_TIMEDIV));
+ check_error(midiStreamProperty(_ms, (byte *)&mptd, MIDIPROP_SET | MIDIPROP_TIMEDIV));
fill_all();
}
@@ -129,7 +131,8 @@ int MidiDriver_WIN::open(int mode) {
return 0;
}
-void MidiDriver_WIN::fill_all() {
+void MidiDriver_WIN::fill_all()
+{
if (_stream_proc == NULL) {
error("MidiDriver_WIN::fill_all() called, but _stream_proc==NULL");
}
@@ -138,7 +141,7 @@ void MidiDriver_WIN::fill_all() {
MyMidiHdr *mmh = _prepared_headers;
MidiEvent my_evs[64];
- for(i=0; i!=NUM_PREPARED_HEADERS; i++,mmh++) {
+ for (i = 0; i != NUM_PREPARED_HEADERS; i++, mmh++) {
if (!(mmh->hdr.dwFlags & MHDR_INQUEUE)) {
int num = _stream_proc(_stream_param, my_evs, 64);
int i;
@@ -147,29 +150,29 @@ void MidiDriver_WIN::fill_all() {
if (num == 0)
break;
- MIDIEVENT *ev = (MIDIEVENT*)mmh->hdr.lpData;
+ MIDIEVENT *ev = (MIDIEVENT *)mmh->hdr.lpData;
MidiEvent *my_ev = my_evs;
- for(i=0; i!=num; i++,my_ev++) {
+ for (i = 0; i != num; i++, my_ev++) {
ev->dwStreamID = 0;
ev->dwDeltaTime = my_ev->delta;
- switch(my_ev->event>>24) {
+ switch (my_ev->event >> 24) {
case 0:
ev->dwEvent = my_ev->event;
break;
case ME_TEMPO:
/* change tempo event */
- ev->dwEvent = (ME_TEMPO<<24) | (my_ev->event&0xFFFFFF);
+ ev->dwEvent = (ME_TEMPO << 24) | (my_ev->event & 0xFFFFFF);
break;
default:
error("Invalid event type passed");
}
-
+
/* increase stream pointer by 12 bytes
* (need to be 12 bytes, and sizeof(MIDIEVENT) is 16)
*/
- ev = (MIDIEVENT*)((byte*)ev + 12);
+ ev = (MIDIEVENT *)((byte *)ev + 12);
}
mmh->hdr.dwBytesRecorded = num * 12;
@@ -178,28 +181,28 @@ void MidiDriver_WIN::fill_all() {
}
}
-void MidiDriver_WIN::prepare() {
+void MidiDriver_WIN::prepare()
+{
int i;
MyMidiHdr *mmh;
-
- _prepared_headers = (MyMidiHdr*)calloc(sizeof(MyMidiHdr), 2);
- for(i=0,mmh=_prepared_headers; i!=NUM_PREPARED_HEADERS; i++,mmh++) {
+ _prepared_headers = (MyMidiHdr *) calloc(sizeof(MyMidiHdr), 2);
+
+ for (i = 0, mmh = _prepared_headers; i != NUM_PREPARED_HEADERS; i++, mmh++) {
mmh->hdr.dwBufferLength = BUFFER_SIZE;
- mmh->hdr.lpData = (LPSTR)calloc(BUFFER_SIZE,1);
+ mmh->hdr.lpData = (LPSTR) calloc(BUFFER_SIZE, 1);
- check_error(midiOutPrepareHeader(
- (HMIDIOUT)_ms, &mmh->hdr, sizeof(mmh->hdr)));
+ check_error(midiOutPrepareHeader((HMIDIOUT) _ms, &mmh->hdr, sizeof(mmh->hdr)));
}
}
-void MidiDriver_WIN::unprepare() {
+void MidiDriver_WIN::unprepare()
+{
uint i;
MyMidiHdr *mmh = _prepared_headers;
- for(i=0; i!=NUM_PREPARED_HEADERS; i++,mmh++) {
- check_error(midiOutUnprepareHeader(
- (HMIDIOUT)_ms, &mmh->hdr, sizeof(mmh->hdr)));
+ for (i = 0; i != NUM_PREPARED_HEADERS; i++, mmh++) {
+ check_error(midiOutUnprepareHeader((HMIDIOUT) _ms, &mmh->hdr, sizeof(mmh->hdr)));
free(mmh->hdr.lpData);
mmh->hdr.lpData = NULL;
}
@@ -207,32 +210,34 @@ void MidiDriver_WIN::unprepare() {
free(_prepared_headers);
}
-void MidiDriver_WIN::close() {
+void MidiDriver_WIN::close()
+{
int mode_was = _mode;
_mode = 0;
- switch(mode_was) {
+ switch (mode_was) {
case MO_SIMPLE:
check_error(midiOutClose(_mo));
break;
case MO_STREAMING:;
check_error(midiStreamStop(_ms));
- check_error(midiOutReset((HMIDIOUT)_ms));
+ check_error(midiOutReset((HMIDIOUT) _ms));
unprepare();
check_error(midiStreamClose(_ms));
break;
}
}
-void MidiDriver_WIN::send(uint32 b) {
- union {
- DWORD dwData;
- BYTE bData[4];
- } u;
+void MidiDriver_WIN::send(uint32 b)
+{
+ union {
+ DWORD dwData;
+ BYTE bData[4];
+ } u;
if (_mode != MO_SIMPLE)
error("MidiDriver_WIN:send called but driver is not in simple mode");
-
+
u.bData[3] = (byte)((b & 0xFF000000) >> 24);
u.bData[2] = (byte)((b & 0x00FF0000) >> 16);
u.bData[1] = (byte)((b & 0x0000FF00) >> 8);
@@ -242,7 +247,8 @@ void MidiDriver_WIN::send(uint32 b) {
check_error(midiOutShortMsg(_mo, u.dwData));
}
-void MidiDriver_WIN::pause(bool pause) {
+void MidiDriver_WIN::pause(bool pause)
+{
if (_mode == MO_STREAMING) {
if (pause)
check_error(midiStreamPause(_ms));
@@ -251,7 +257,8 @@ void MidiDriver_WIN::pause(bool pause) {
}
}
-void MidiDriver_WIN::check_error(MMRESULT result) {
+void MidiDriver_WIN::check_error(MMRESULT result)
+{
char buf[200];
if (result != MMSYSERR_NOERROR) {
midiOutGetErrorText(result, buf, 200);
@@ -259,11 +266,12 @@ void MidiDriver_WIN::check_error(MMRESULT result) {
}
}
-uint32 MidiDriver_WIN::property(int prop, uint32 param) {
- switch(prop) {
-
- /* 16-bit time division according to standard midi specification */
- case PROP_TIMEDIV:
+uint32 MidiDriver_WIN::property(int prop, uint32 param)
+{
+ switch (prop) {
+
+ /* 16-bit time division according to standard midi specification */
+ case PROP_TIMEDIV:
_time_div = (uint16)param;
return 1;
}
@@ -271,7 +279,8 @@ uint32 MidiDriver_WIN::property(int prop, uint32 param) {
return 0;
}
-MidiDriver *MidiDriver_WIN_create() {
+MidiDriver *MidiDriver_WIN_create()
+{
return new MidiDriver_WIN();
}
@@ -287,7 +296,7 @@ MidiDriver *MidiDriver_WIN_create() {
extern struct IOMidiRequest *ScummMidiRequest;
/* MorphOS MIDI driver */
-class MidiDriver_AMIDI : public MidiDriver {
+class MidiDriver_AMIDI:public MidiDriver {
public:
int open(int mode);
void close();
@@ -297,25 +306,29 @@ public:
private:
StreamCallback *_stream_proc;
- void *_stream_param;
- int _mode;
+ void *_stream_param;
+ int _mode;
};
-void MidiDriver_AMIDI::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_AMIDI::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
-int MidiDriver_AMIDI::open(int mode) {
+int MidiDriver_AMIDI::open(int mode)
+{
_mode = mode;
return 0;
}
-void MidiDriver_AMIDI::close() {
+void MidiDriver_AMIDI::close()
+{
_mode = 0;
}
-void MidiDriver_AMIDI::send(uint32 b) {
+void MidiDriver_AMIDI::send(uint32 b)
+{
if (_mode != MO_SIMPLE)
error("MidiDriver_AMIDI:send called but driver is not in simple mode");
@@ -328,12 +341,14 @@ void MidiDriver_AMIDI::send(uint32 b) {
}
}
-void MidiDriver_AMIDI::pause(bool pause) {
+void MidiDriver_AMIDI::pause(bool pause)
+{
if (_mode == MO_STREAMING) {
}
}
-MidiDriver *MidiDriver_AMIDI_create() {
+MidiDriver *MidiDriver_AMIDI_create()
+{
return new MidiDriver_AMIDI();
}
@@ -343,9 +358,9 @@ MidiDriver *MidiDriver_AMIDI_create() {
#define SEQ_MIDIPUTC 5
#define SPECIAL_CHANNEL 9
-class MidiDriver_SEQ : public MidiDriver {
+class MidiDriver_SEQ:public MidiDriver {
public:
- MidiDriver_SEQ();
+ MidiDriver_SEQ();
int open(int mode);
void close();
void send(uint32 b);
@@ -354,23 +369,26 @@ public:
private:
StreamCallback *_stream_proc;
- void *_stream_param;
- int _mode;
+ void *_stream_param;
+ int _mode;
int device, _device_num;
};
-MidiDriver_SEQ::MidiDriver_SEQ(){
- _mode=0;
- device=0;
- _device_num=0;
+MidiDriver_SEQ::MidiDriver_SEQ()
+{
+ _mode = 0;
+ device = 0;
+ _device_num = 0;
}
-int MidiDriver_SEQ::open(int mode) {
- if (_mode != 0)
+int MidiDriver_SEQ::open(int mode)
+{
+ if (_mode != 0)
return MERR_ALREADY_OPEN;
device = 0;
- _mode=mode;
- if (mode!=MO_SIMPLE) return MERR_STREAMING_NOT_AVAILABLE;
+ _mode = mode;
+ if (mode != MO_SIMPLE)
+ return MERR_STREAMING_NOT_AVAILABLE;
char *device_name = getenv("SCUMMVM_MIDI");
if (device_name != NULL) {
@@ -382,7 +400,8 @@ int MidiDriver_SEQ::open(int mode) {
if (device_name == NULL)
warning("Opening /dev/null (no music will be heard) ");
else
- warning("Cannot open rawmidi device %s - using /dev/null (no music will be heard) ", device_name);
+ warning("Cannot open rawmidi device %s - using /dev/null (no music will be heard) ",
+ device_name);
device = (::open(("/dev/null"), O_RDWR, 0));
if (device < 0)
error("Cannot open /dev/null to dump midi output");
@@ -393,8 +412,9 @@ int MidiDriver_SEQ::open(int mode) {
return 0;
}
-void MidiDriver_SEQ::close() {
- ::close(device);
+void MidiDriver_SEQ::close()
+{
+ ::close(device);
_mode = 0;
}
@@ -435,23 +455,26 @@ void MidiDriver_SEQ::send(uint32 b)
buf[position++] = 0;
break;
default:
- fprintf(stderr, "Unknown : %08x\n", (int) b);
+ fprintf(stderr, "Unknown : %08x\n", (int)b);
break;
}
write(device, buf, position);
}
-void MidiDriver_SEQ::pause(bool pause) {
+void MidiDriver_SEQ::pause(bool pause)
+{
if (_mode == MO_STREAMING) {
}
}
-void MidiDriver_SEQ::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_SEQ::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
-MidiDriver *MidiDriver_SEQ_create() {
+MidiDriver *MidiDriver_SEQ_create()
+{
return new MidiDriver_SEQ();
}
@@ -464,16 +487,16 @@ MidiDriver *MidiDriver_SEQ_create() {
#if defined(MACOSX)
// On MacOSX, these are in a frameworks!
- #include <QuickTime/QuickTimeComponents.h>
- #include <QuickTime/QuickTimeMusic.h>
+#include <QuickTime/QuickTimeComponents.h>
+#include <QuickTime/QuickTimeMusic.h>
#else
- #include <QuickTimeComponents.h>
- #include <QuickTimeMusic.h>
+#include <QuickTimeComponents.h>
+#include <QuickTimeMusic.h>
#endif
/* QuickTime MIDI driver */
-class MidiDriver_QT : public MidiDriver {
+class MidiDriver_QT:public MidiDriver {
public:
int open(int mode);
void close();
@@ -487,16 +510,18 @@ private:
NoteRequest simpleNoteRequest;
StreamCallback *_stream_proc;
- void *_stream_param;
- int _mode;
+ void *_stream_param;
+ int _mode;
};
-void MidiDriver_QT::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_QT::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
-int MidiDriver_QT::open(int mode) {
+int MidiDriver_QT::open(int mode)
+{
ComponentResult qtErr = noErr;
int i;
@@ -516,25 +541,21 @@ int MidiDriver_QT::open(int mode) {
simpleNoteRequest.info.flags = 0;
*(short *)(&simpleNoteRequest.info.polyphony) = EndianS16_NtoB(15); // simultaneous tones
- *(Fixed *) (&simpleNoteRequest.info.typicalPolyphony) =
- EndianU32_NtoB(0x00010000);
+ *(Fixed *) (&simpleNoteRequest.info.typicalPolyphony) = EndianU32_NtoB(0x00010000);
qtErr = NAStuffToneDescription(qtNoteAllocator, 1, &simpleNoteRequest.tone);
if (qtErr != noErr)
goto bail;
for (i = 0; i < 15; i++) {
- qtErr =
- NANewNoteChannel(qtNoteAllocator, &simpleNoteRequest,
- &(qtNoteChannel[i]));
+ qtErr = NANewNoteChannel(qtNoteAllocator, &simpleNoteRequest, &(qtNoteChannel[i]));
if ((qtErr != noErr) || (qtNoteChannel == NULL))
goto bail;
}
return 0;
bail:
- error("Init QT failed %x %x %d\n", (int)qtNoteAllocator, (int)qtNoteChannel,
- (int)qtErr);
+ error("Init QT failed %x %x %d\n", (int)qtNoteAllocator, (int)qtNoteChannel, (int)qtErr);
for (i = 0; i < 15; i++) {
if (qtNoteChannel[i] != NULL)
NADisposeNoteChannel(qtNoteAllocator, qtNoteChannel[i]);
@@ -549,7 +570,8 @@ bail:
return MERR_DEVICE_NOT_AVAILABLE;
}
-void MidiDriver_QT::close() {
+void MidiDriver_QT::close()
+{
_mode = 0;
for (int i = 0; i < 15; i++) {
@@ -564,7 +586,8 @@ void MidiDriver_QT::close() {
}
}
-void MidiDriver_QT::send(uint32 b) {
+void MidiDriver_QT::send(uint32 b)
+{
if (_mode != MO_SIMPLE)
error("MidiDriver_QT:send called but driver is not in simple mode");
@@ -594,8 +617,7 @@ void MidiDriver_QT::send(uint32 b) {
break;
case 0x07: // Volume
- NASetController(qtNoteAllocator, qtNoteChannel[chanID],
- kControllerVolume, midiCmd[2] * 300);
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerVolume, midiCmd[2] * 300);
break;
case 0x0A: // Pan
@@ -604,18 +626,15 @@ void MidiDriver_QT::send(uint32 b) {
break;
case 0x40: // Sustain on/off
- NASetController(qtNoteAllocator, qtNoteChannel[chanID],
- kControllerSustain, midiCmd[2]);
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerSustain, midiCmd[2]);
break;
case 0x5b: // ext effect depth
- NASetController(qtNoteAllocator, qtNoteChannel[chanID],
- kControllerReverb, midiCmd[2] << 8);
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerReverb, midiCmd[2] << 8);
break;
case 0x5d: // chorus depth
- NASetController(qtNoteAllocator, qtNoteChannel[chanID],
- kControllerChorus, midiCmd[2] << 8);
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerChorus, midiCmd[2] << 8);
break;
case 0x7b: // mode message all notes off
@@ -634,10 +653,8 @@ void MidiDriver_QT::send(uint32 b) {
break;
case 0xE0:{ // Pitch bend
- long theBend =
- ((((long)midiCmd[1] + (long)(midiCmd[2] << 8))) - 0x4000) / 4;
- NASetController(qtNoteAllocator, qtNoteChannel[chanID],
- kControllerPitchBend, theBend);
+ long theBend = ((((long)midiCmd[1] + (long)(midiCmd[2] << 8))) - 0x4000) / 4;
+ NASetController(qtNoteAllocator, qtNoteChannel[chanID], kControllerPitchBend, theBend);
}
break;
@@ -648,10 +665,12 @@ void MidiDriver_QT::send(uint32 b) {
}
}
-void MidiDriver_QT::pause(bool) {
+void MidiDriver_QT::pause(bool)
+{
}
-MidiDriver *MidiDriver_QT_create() {
+MidiDriver *MidiDriver_QT_create()
+{
return new MidiDriver_QT();
}
@@ -664,11 +683,10 @@ MidiDriver *MidiDriver_QT_create() {
/* CoreAudio MIDI driver */
/* Based on code by Benjamin W. Zale */
-class MidiDriver_CORE : public MidiDriver {
+class MidiDriver_CORE:public MidiDriver {
public:
- MidiDriver_CORE() : au_MusicDevice(NULL), au_output(NULL) {}
-
- int open(int mode);
+ MidiDriver_CORE():au_MusicDevice(NULL), au_output(NULL) {
+ } int open(int mode);
void close();
void send(uint32 b);
void pause(bool pause);
@@ -684,56 +702,61 @@ private:
};
-void MidiDriver_CORE::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_CORE::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
-int MidiDriver_CORE::open(int mode) {
+int MidiDriver_CORE::open(int mode)
+{
if (au_output != NULL)
return MERR_ALREADY_OPEN;
_mode = mode;
-
+
int err;
- struct AudioUnitConnection auconnect;
+ struct AudioUnitConnection auconnect;
ComponentDescription compdesc;
Component compid;
-
+
// Open the Music Device
compdesc.componentType = kAudioUnitComponentType;
compdesc.componentSubType = kAudioUnitSubType_MusicDevice;
compdesc.componentManufacturer = kAudioUnitID_DLSSynth;
compdesc.componentFlags = 0;
compdesc.componentFlagsMask = 0;
- compid = FindNextComponent(NULL,&compdesc);
- au_MusicDevice = (AudioUnit)OpenComponent(compid);
-
+ compid = FindNextComponent(NULL, &compdesc);
+ au_MusicDevice = (AudioUnit) OpenComponent(compid);
+
// open the output unit
- au_output = (AudioUnit)OpenDefaultComponent(kAudioUnitComponentType,kAudioUnitSubType_Output);
+ au_output = (AudioUnit) OpenDefaultComponent(kAudioUnitComponentType, kAudioUnitSubType_Output);
// connect the units
auconnect.sourceAudioUnit = au_MusicDevice;
auconnect.sourceOutputNumber = 0;
auconnect.destInputNumber = 0;
- err = AudioUnitSetProperty(au_output,kAudioUnitProperty_MakeConnection,kAudioUnitScope_Input,0,(void*)&auconnect,sizeof(struct AudioUnitConnection));
+ err =
+ AudioUnitSetProperty(au_output, kAudioUnitProperty_MakeConnection, kAudioUnitScope_Input, 0,
+ (void *)&auconnect, sizeof(struct AudioUnitConnection));
// initialize the units
AudioUnitInitialize(au_MusicDevice);
AudioUnitInitialize(au_output);
-
+
// start the output
AudioOutputUnitStart(au_output);
-
+
return 0;
}
-void MidiDriver_CORE::close() {
+void MidiDriver_CORE::close()
+{
// Stop the output
AudioOutputUnitStop(au_output);
-
+
// Cleanup
CloseComponent(au_output);
CloseComponent(au_MusicDevice);
@@ -741,28 +764,31 @@ void MidiDriver_CORE::close() {
_mode = 0;
}
-void MidiDriver_CORE::send(uint32 b) {
+void MidiDriver_CORE::send(uint32 b)
+{
if (_mode != MO_SIMPLE)
error("MidiDriver_CORE:send called but driver is not in simple mode");
unsigned char first_byte, seccond_byte, status_byte;
- status_byte = (b & 0x000000FF);
- first_byte = (b & 0x0000FF00) >> 8;
- seccond_byte = (b & 0x00FF0000) >> 16;
+ status_byte = (b & 0x000000FF);
+ first_byte = (b & 0x0000FF00) >> 8;
+ seccond_byte = (b & 0x00FF0000) >> 16;
MusicDeviceMIDIEvent(au_MusicDevice, status_byte, first_byte, seccond_byte, 0);
}
-void MidiDriver_CORE::pause(bool) {
+void MidiDriver_CORE::pause(bool)
+{
}
-MidiDriver *MidiDriver_CORE_create() {
+MidiDriver *MidiDriver_CORE_create()
+{
return new MidiDriver_CORE();
}
#endif // __APPLE__
/* NULL driver */
-class MidiDriver_NULL : public MidiDriver {
+class MidiDriver_NULL:public MidiDriver {
public:
int open(int mode);
void close();
@@ -772,16 +798,26 @@ public:
private:
};
-int MidiDriver_NULL::open(int mode) {
+int MidiDriver_NULL::open(int mode)
+{
warning("Music not enabled - MIDI support selected with no MIDI driver available. Try Adlib");
return 0;
}
-void MidiDriver_NULL::close() {}
-void MidiDriver_NULL::send(uint32 b) {}
-void MidiDriver_NULL::pause(bool pause) {}
-void MidiDriver_NULL::set_stream_callback(void *param, StreamCallback *sc) {}
+void MidiDriver_NULL::close()
+{
+}
+void MidiDriver_NULL::send(uint32 b)
+{
+}
+void MidiDriver_NULL::pause(bool pause)
+{
+}
+void MidiDriver_NULL::set_stream_callback(void *param, StreamCallback *sc)
+{
+}
-MidiDriver *MidiDriver_NULL_create() {
+MidiDriver *MidiDriver_NULL_create()
+{
return new MidiDriver_NULL();
}
@@ -795,16 +831,17 @@ uint32 MidiDriver::property(int prop, uint32 param)
/* retrieve a string representation of an error code */
-const char *MidiDriver::get_error_name(int error_code) {
- static const char * const midi_errors[] = {
+const char *MidiDriver::get_error_name(int error_code)
+{
+ static const char *const midi_errors[] = {
"No error",
"Cannot connect",
"Streaming not available",
"Device not available",
"Driver already open"
};
-
- if ((uint)error_code >= ARRAYSIZE(midi_errors))
+
+ if ((uint) error_code >= ARRAYSIZE(midi_errors))
return "Unknown Error";
return midi_errors[error_code];
}
@@ -814,164 +851,163 @@ const char *MidiDriver::get_error_name(int error_code) {
* Phil Hassey, <philhassey@hotmail.com> (www.imitationpickles.org)
*/
-static unsigned char midi_fm_instruments_table[128][11] =
-{
- /* This set of GM instrument patches was provided by Jorrit Rouwe...
- */
- { 0x21, 0x21, 0x8f, 0x0c, 0xf2, 0xf2, 0x45, 0x76, 0x00, 0x00, 0x08 }, /* Acoustic Grand */
- { 0x31, 0x21, 0x4b, 0x09, 0xf2, 0xf2, 0x54, 0x56, 0x00, 0x00, 0x08 }, /* Bright Acoustic */
- { 0x31, 0x21, 0x49, 0x09, 0xf2, 0xf2, 0x55, 0x76, 0x00, 0x00, 0x08 }, /* Electric Grand */
- { 0xb1, 0x61, 0x0e, 0x09, 0xf2, 0xf3, 0x3b, 0x0b, 0x00, 0x00, 0x06 }, /* Honky-Tonk */
- { 0x01, 0x21, 0x57, 0x09, 0xf1, 0xf1, 0x38, 0x28, 0x00, 0x00, 0x00 }, /* Electric Piano 1 */
- { 0x01, 0x21, 0x93, 0x09, 0xf1, 0xf1, 0x38, 0x28, 0x00, 0x00, 0x00 }, /* Electric Piano 2 */
- { 0x21, 0x36, 0x80, 0x17, 0xa2, 0xf1, 0x01, 0xd5, 0x00, 0x00, 0x08 }, /* Harpsichord */
- { 0x01, 0x01, 0x92, 0x09, 0xc2, 0xc2, 0xa8, 0x58, 0x00, 0x00, 0x0a }, /* Clav */
- { 0x0c, 0x81, 0x5c, 0x09, 0xf6, 0xf3, 0x54, 0xb5, 0x00, 0x00, 0x00 }, /* Celesta */
- { 0x07, 0x11, 0x97, 0x89, 0xf6, 0xf5, 0x32, 0x11, 0x00, 0x00, 0x02 }, /* Glockenspiel */
- { 0x17, 0x01, 0x21, 0x09, 0x56, 0xf6, 0x04, 0x04, 0x00, 0x00, 0x02 }, /* Music Box */
- { 0x18, 0x81, 0x62, 0x09, 0xf3, 0xf2, 0xe6, 0xf6, 0x00, 0x00, 0x00 }, /* Vibraphone */
- { 0x18, 0x21, 0x23, 0x09, 0xf7, 0xe5, 0x55, 0xd8, 0x00, 0x00, 0x00 }, /* Marimba */
- { 0x15, 0x01, 0x91, 0x09, 0xf6, 0xf6, 0xa6, 0xe6, 0x00, 0x00, 0x04 }, /* Xylophone */
- { 0x45, 0x81, 0x59, 0x89, 0xd3, 0xa3, 0x82, 0xe3, 0x00, 0x00, 0x0c }, /* Tubular Bells */
- { 0x03, 0x81, 0x49, 0x89, 0x74, 0xb3, 0x55, 0x05, 0x01, 0x00, 0x04 }, /* Dulcimer */
- { 0x71, 0x31, 0x92, 0x09, 0xf6, 0xf1, 0x14, 0x07, 0x00, 0x00, 0x02 }, /* Drawbar Organ */
- { 0x72, 0x30, 0x14, 0x09, 0xc7, 0xc7, 0x58, 0x08, 0x00, 0x00, 0x02 }, /* Percussive Organ */
- { 0x70, 0xb1, 0x44, 0x09, 0xaa, 0x8a, 0x18, 0x08, 0x00, 0x00, 0x04 }, /* Rock Organ */
- { 0x23, 0xb1, 0x93, 0x09, 0x97, 0x55, 0x23, 0x14, 0x01, 0x00, 0x04 }, /* Church Organ */
- { 0x61, 0xb1, 0x13, 0x89, 0x97, 0x55, 0x04, 0x04, 0x01, 0x00, 0x00 }, /* Reed Organ */
- { 0x24, 0xb1, 0x48, 0x09, 0x98, 0x46, 0x2a, 0x1a, 0x01, 0x00, 0x0c }, /* Accoridan */
- { 0x61, 0x21, 0x13, 0x09, 0x91, 0x61, 0x06, 0x07, 0x01, 0x00, 0x0a }, /* Harmonica */
- { 0x21, 0xa1, 0x13, 0x92, 0x71, 0x61, 0x06, 0x07, 0x00, 0x00, 0x06 }, /* Tango Accordian */
- { 0x02, 0x41, 0x9c, 0x89, 0xf3, 0xf3, 0x94, 0xc8, 0x01, 0x00, 0x0c }, /* Acoustic Guitar(nylon) */
- { 0x03, 0x11, 0x54, 0x09, 0xf3, 0xf1, 0x9a, 0xe7, 0x01, 0x00, 0x0c }, /* Acoustic Guitar(steel) */
- { 0x23, 0x21, 0x5f, 0x09, 0xf1, 0xf2, 0x3a, 0xf8, 0x00, 0x00, 0x00 }, /* Electric Guitar(jazz) */
- { 0x03, 0x21, 0x87, 0x89, 0xf6, 0xf3, 0x22, 0xf8, 0x01, 0x00, 0x06 }, /* Electric Guitar(clean) */
- { 0x03, 0x21, 0x47, 0x09, 0xf9, 0xf6, 0x54, 0x3a, 0x00, 0x00, 0x00 }, /* Electric Guitar(muted) */
- { 0x23, 0x21, 0x4a, 0x0e, 0x91, 0x84, 0x41, 0x19, 0x01, 0x00, 0x08 }, /* Overdriven Guitar */
- { 0x23, 0x21, 0x4a, 0x09, 0x95, 0x94, 0x19, 0x19, 0x01, 0x00, 0x08 }, /* Distortion Guitar */
- { 0x09, 0x84, 0xa1, 0x89, 0x20, 0xd1, 0x4f, 0xf8, 0x00, 0x00, 0x08 }, /* Guitar Harmonics */
- { 0x21, 0xa2, 0x1e, 0x09, 0x94, 0xc3, 0x06, 0xa6, 0x00, 0x00, 0x02 }, /* Acoustic Bass */
- { 0x31, 0x31, 0x12, 0x09, 0xf1, 0xf1, 0x28, 0x18, 0x00, 0x00, 0x0a }, /* Electric Bass(finger) */
- { 0x31, 0x31, 0x8d, 0x09, 0xf1, 0xf1, 0xe8, 0x78, 0x00, 0x00, 0x0a }, /* Electric Bass(pick) */
- { 0x31, 0x32, 0x5b, 0x09, 0x51, 0x71, 0x28, 0x48, 0x00, 0x00, 0x0c }, /* Fretless Bass */
- { 0x01, 0x21, 0x8b, 0x49, 0xa1, 0xf2, 0x9a, 0xdf, 0x00, 0x00, 0x08 }, /* Slap Bass 1 */
- { 0x21, 0x21, 0x8b, 0x11, 0xa2, 0xa1, 0x16, 0xdf, 0x00, 0x00, 0x08 }, /* Slap Bass 2 */
- { 0x31, 0x31, 0x8b, 0x09, 0xf4, 0xf1, 0xe8, 0x78, 0x00, 0x00, 0x0a }, /* Synth Bass 1 */
- { 0x31, 0x31, 0x12, 0x09, 0xf1, 0xf1, 0x28, 0x18, 0x00, 0x00, 0x0a }, /* Synth Bass 2 */
- { 0x31, 0x21, 0x15, 0x09, 0xdd, 0x56, 0x13, 0x26, 0x01, 0x00, 0x08 }, /* Violin */
- { 0x31, 0x21, 0x16, 0x09, 0xdd, 0x66, 0x13, 0x06, 0x01, 0x00, 0x08 }, /* Viola */
- { 0x71, 0x31, 0x49, 0x09, 0xd1, 0x61, 0x1c, 0x0c, 0x01, 0x00, 0x08 }, /* Cello */
- { 0x21, 0x23, 0x4d, 0x89, 0x71, 0x72, 0x12, 0x06, 0x01, 0x00, 0x02 }, /* Contrabass */
- { 0xf1, 0xe1, 0x40, 0x09, 0xf1, 0x6f, 0x21, 0x16, 0x01, 0x00, 0x02 }, /* Tremolo Strings */
- { 0x02, 0x01, 0x1a, 0x89, 0xf5, 0x85, 0x75, 0x35, 0x01, 0x00, 0x00 }, /* Pizzicato Strings */
- { 0x02, 0x01, 0x1d, 0x89, 0xf5, 0xf3, 0x75, 0xf4, 0x01, 0x00, 0x00 }, /* Orchestral Strings */
- { 0x10, 0x11, 0x41, 0x09, 0xf5, 0xf2, 0x05, 0xc3, 0x01, 0x00, 0x02 }, /* Timpani */
- { 0x21, 0xa2, 0x9b, 0x0a, 0xb1, 0x72, 0x25, 0x08, 0x01, 0x00, 0x0e }, /* String Ensemble 1 */
- { 0xa1, 0x21, 0x98, 0x09, 0x7f, 0x3f, 0x03, 0x07, 0x01, 0x01, 0x00 }, /* String Ensemble 2 */
- { 0xa1, 0x61, 0x93, 0x09, 0xc1, 0x4f, 0x12, 0x05, 0x00, 0x00, 0x0a }, /* SynthStrings 1 */
- { 0x21, 0x61, 0x18, 0x09, 0xc1, 0x4f, 0x22, 0x05, 0x00, 0x00, 0x0c }, /* SynthStrings 2 */
- { 0x31, 0x72, 0x5b, 0x8c, 0xf4, 0x8a, 0x15, 0x05, 0x00, 0x00, 0x00 }, /* Choir Aahs */
- { 0xa1, 0x61, 0x90, 0x09, 0x74, 0x71, 0x39, 0x67, 0x00, 0x00, 0x00 }, /* Voice Oohs */
- { 0x71, 0x72, 0x57, 0x09, 0x54, 0x7a, 0x05, 0x05, 0x00, 0x00, 0x0c }, /* Synth Voice */
- { 0x90, 0x41, 0x00, 0x09, 0x54, 0xa5, 0x63, 0x45, 0x00, 0x00, 0x08 }, /* Orchestra Hit */
- { 0x21, 0x21, 0x92, 0x0a, 0x85, 0x8f, 0x17, 0x09, 0x00, 0x00, 0x0c }, /* Trumpet */
- { 0x21, 0x21, 0x94, 0x0e, 0x75, 0x8f, 0x17, 0x09, 0x00, 0x00, 0x0c }, /* Trombone */
- { 0x21, 0x61, 0x94, 0x09, 0x76, 0x82, 0x15, 0x37, 0x00, 0x00, 0x0c }, /* Tuba */
- { 0x31, 0x21, 0x43, 0x09, 0x9e, 0x62, 0x17, 0x2c, 0x01, 0x01, 0x02 }, /* Muted Trumpet */
- { 0x21, 0x21, 0x9b, 0x09, 0x61, 0x7f, 0x6a, 0x0a, 0x00, 0x00, 0x02 }, /* French Horn */
- { 0x61, 0x22, 0x8a, 0x0f, 0x75, 0x74, 0x1f, 0x0f, 0x00, 0x00, 0x08 }, /* Brass Section */
- { 0xa1, 0x21, 0x86, 0x8c, 0x72, 0x71, 0x55, 0x18, 0x01, 0x00, 0x00 }, /* SynthBrass 1 */
- { 0x21, 0x21, 0x4d, 0x09, 0x54, 0xa6, 0x3c, 0x1c, 0x00, 0x00, 0x08 }, /* SynthBrass 2 */
- { 0x31, 0x61, 0x8f, 0x09, 0x93, 0x72, 0x02, 0x0b, 0x01, 0x00, 0x08 }, /* Soprano Sax */
- { 0x31, 0x61, 0x8e, 0x09, 0x93, 0x72, 0x03, 0x09, 0x01, 0x00, 0x08 }, /* Alto Sax */
- { 0x31, 0x61, 0x91, 0x09, 0x93, 0x82, 0x03, 0x09, 0x01, 0x00, 0x0a }, /* Tenor Sax */
- { 0x31, 0x61, 0x8e, 0x09, 0x93, 0x72, 0x0f, 0x0f, 0x01, 0x00, 0x0a }, /* Baritone Sax */
- { 0x21, 0x21, 0x4b, 0x09, 0xaa, 0x8f, 0x16, 0x0a, 0x01, 0x00, 0x08 }, /* Oboe */
- { 0x31, 0x21, 0x90, 0x09, 0x7e, 0x8b, 0x17, 0x0c, 0x01, 0x01, 0x06 }, /* English Horn */
- { 0x31, 0x32, 0x81, 0x09, 0x75, 0x61, 0x19, 0x19, 0x01, 0x00, 0x00 }, /* Bassoon */
- { 0x32, 0x21, 0x90, 0x09, 0x9b, 0x72, 0x21, 0x17, 0x00, 0x00, 0x04 }, /* Clarinet */
- { 0xe1, 0xe1, 0x1f, 0x09, 0x85, 0x65, 0x5f, 0x1a, 0x00, 0x00, 0x00 }, /* Piccolo */
- { 0xe1, 0xe1, 0x46, 0x09, 0x88, 0x65, 0x5f, 0x1a, 0x00, 0x00, 0x00 }, /* Flute */
- { 0xa1, 0x21, 0x9c, 0x09, 0x75, 0x75, 0x1f, 0x0a, 0x00, 0x00, 0x02 }, /* Recorder */
- { 0x31, 0x21, 0x8b, 0x09, 0x84, 0x65, 0x58, 0x1a, 0x00, 0x00, 0x00 }, /* Pan Flute */
- { 0xe1, 0xa1, 0x4c, 0x09, 0x66, 0x65, 0x56, 0x26, 0x00, 0x00, 0x00 }, /* Blown Bottle */
- { 0x62, 0xa1, 0xcb, 0x09, 0x76, 0x55, 0x46, 0x36, 0x00, 0x00, 0x00 }, /* Skakuhachi */
- { 0x62, 0xa1, 0xa2, 0x09, 0x57, 0x56, 0x07, 0x07, 0x00, 0x00, 0x0b }, /* Whistle */
- { 0x62, 0xa1, 0x9c, 0x09, 0x77, 0x76, 0x07, 0x07, 0x00, 0x00, 0x0b }, /* Ocarina */
- { 0x22, 0x21, 0x59, 0x09, 0xff, 0xff, 0x03, 0x0f, 0x02, 0x00, 0x00 }, /* Lead 1 (square) */
- { 0x21, 0x21, 0x0e, 0x09, 0xff, 0xff, 0x0f, 0x0f, 0x01, 0x01, 0x00 }, /* Lead 2 (sawtooth) */
- { 0x22, 0x21, 0x46, 0x89, 0x86, 0x64, 0x55, 0x18, 0x00, 0x00, 0x00 }, /* Lead 3 (calliope) */
- { 0x21, 0xa1, 0x45, 0x09, 0x66, 0x96, 0x12, 0x0a, 0x00, 0x00, 0x00 }, /* Lead 4 (chiff) */
- { 0x21, 0x22, 0x8b, 0x09, 0x92, 0x91, 0x2a, 0x2a, 0x01, 0x00, 0x00 }, /* Lead 5 (charang) */
- { 0xa2, 0x61, 0x9e, 0x49, 0xdf, 0x6f, 0x05, 0x07, 0x00, 0x00, 0x02 }, /* Lead 6 (voice) */
- { 0x20, 0x60, 0x1a, 0x09, 0xef, 0x8f, 0x01, 0x06, 0x00, 0x02, 0x00 }, /* Lead 7 (fifths) */
- { 0x21, 0x21, 0x8f, 0x86, 0xf1, 0xf4, 0x29, 0x09, 0x00, 0x00, 0x0a }, /* Lead 8 (bass+lead) */
- { 0x77, 0xa1, 0xa5, 0x09, 0x53, 0xa0, 0x94, 0x05, 0x00, 0x00, 0x02 }, /* Pad 1 (new age) */
- { 0x61, 0xb1, 0x1f, 0x89, 0xa8, 0x25, 0x11, 0x03, 0x00, 0x00, 0x0a }, /* Pad 2 (warm) */
- { 0x61, 0x61, 0x17, 0x09, 0x91, 0x55, 0x34, 0x16, 0x00, 0x00, 0x0c }, /* Pad 3 (polysynth) */
- { 0x71, 0x72, 0x5d, 0x09, 0x54, 0x6a, 0x01, 0x03, 0x00, 0x00, 0x00 }, /* Pad 4 (choir) */
- { 0x21, 0xa2, 0x97, 0x09, 0x21, 0x42, 0x43, 0x35, 0x00, 0x00, 0x08 }, /* Pad 5 (bowed) */
- { 0xa1, 0x21, 0x1c, 0x09, 0xa1, 0x31, 0x77, 0x47, 0x01, 0x01, 0x00 }, /* Pad 6 (metallic) */
- { 0x21, 0x61, 0x89, 0x0c, 0x11, 0x42, 0x33, 0x25, 0x00, 0x00, 0x0a }, /* Pad 7 (halo) */
- { 0xa1, 0x21, 0x15, 0x09, 0x11, 0xcf, 0x47, 0x07, 0x01, 0x00, 0x00 }, /* Pad 8 (sweep) */
- { 0x3a, 0x51, 0xce, 0x09, 0xf8, 0x86, 0xf6, 0x02, 0x00, 0x00, 0x02 }, /* FX 1 (rain) */
- { 0x21, 0x21, 0x15, 0x09, 0x21, 0x41, 0x23, 0x13, 0x01, 0x00, 0x00 }, /* FX 2 (soundtrack) */
- { 0x06, 0x01, 0x5b, 0x09, 0x74, 0xa5, 0x95, 0x72, 0x00, 0x00, 0x00 }, /* FX 3 (crystal) */
- { 0x22, 0x61, 0x92, 0x8c, 0xb1, 0xf2, 0x81, 0x26, 0x00, 0x00, 0x0c }, /* FX 4 (atmosphere) */
- { 0x41, 0x42, 0x4d, 0x09, 0xf1, 0xf2, 0x51, 0xf5, 0x01, 0x00, 0x00 }, /* FX 5 (brightness) */
- { 0x61, 0xa3, 0x94, 0x89, 0x11, 0x11, 0x51, 0x13, 0x01, 0x00, 0x06 }, /* FX 6 (goblins) */
- { 0x61, 0xa1, 0x8c, 0x89, 0x11, 0x1d, 0x31, 0x03, 0x00, 0x00, 0x06 }, /* FX 7 (echoes) */
- { 0xa4, 0x61, 0x4c, 0x09, 0xf3, 0x81, 0x73, 0x23, 0x01, 0x00, 0x04 }, /* FX 8 (sci-fi) */
- { 0x02, 0x07, 0x85, 0x0c, 0xd2, 0xf2, 0x53, 0xf6, 0x00, 0x01, 0x00 }, /* Sitar */
- { 0x11, 0x13, 0x0c, 0x89, 0xa3, 0xa2, 0x11, 0xe5, 0x01, 0x00, 0x00 }, /* Banjo */
- { 0x11, 0x11, 0x06, 0x09, 0xf6, 0xf2, 0x41, 0xe6, 0x01, 0x02, 0x04 }, /* Shamisen */
- { 0x93, 0x91, 0x91, 0x09, 0xd4, 0xeb, 0x32, 0x11, 0x00, 0x01, 0x08 }, /* Koto */
- { 0x04, 0x01, 0x4f, 0x09, 0xfa, 0xc2, 0x56, 0x05, 0x00, 0x00, 0x0c }, /* Kalimba */
- { 0x21, 0x22, 0x49, 0x09, 0x7c, 0x6f, 0x20, 0x0c, 0x00, 0x01, 0x06 }, /* Bagpipe */
- { 0x31, 0x21, 0x85, 0x09, 0xdd, 0x56, 0x33, 0x16, 0x01, 0x00, 0x0a }, /* Fiddle */
- { 0x20, 0x21, 0x04, 0x8a, 0xda, 0x8f, 0x05, 0x0b, 0x02, 0x00, 0x06 }, /* Shanai */
- { 0x05, 0x03, 0x6a, 0x89, 0xf1, 0xc3, 0xe5, 0xe5, 0x00, 0x00, 0x06 }, /* Tinkle Bell */
- { 0x07, 0x02, 0x15, 0x09, 0xec, 0xf8, 0x26, 0x16, 0x00, 0x00, 0x0a }, /* Agogo */
- { 0x05, 0x01, 0x9d, 0x09, 0x67, 0xdf, 0x35, 0x05, 0x00, 0x00, 0x08 }, /* Steel Drums */
- { 0x18, 0x12, 0x96, 0x09, 0xfa, 0xf8, 0x28, 0xe5, 0x00, 0x00, 0x0a }, /* Woodblock */
- { 0x10, 0x00, 0x86, 0x0c, 0xa8, 0xfa, 0x07, 0x03, 0x00, 0x00, 0x06 }, /* Taiko Drum */
- { 0x11, 0x10, 0x41, 0x0c, 0xf8, 0xf3, 0x47, 0x03, 0x02, 0x00, 0x04 }, /* Melodic Tom */
- { 0x01, 0x10, 0x8e, 0x09, 0xf1, 0xf3, 0x06, 0x02, 0x02, 0x00, 0x0e }, /* Synth Drum */
- { 0x0e, 0xc0, 0x00, 0x09, 0x1f, 0x1f, 0x00, 0xff, 0x00, 0x03, 0x0e }, /* Reverse Cymbal */
- { 0x06, 0x03, 0x80, 0x91, 0xf8, 0x56, 0x24, 0x84, 0x00, 0x02, 0x0e }, /* Guitar Fret Noise */
- { 0x0e, 0xd0, 0x00, 0x0e, 0xf8, 0x34, 0x00, 0x04, 0x00, 0x03, 0x0e }, /* Breath Noise */
- { 0x0e, 0xc0, 0x00, 0x09, 0xf6, 0x1f, 0x00, 0x02, 0x00, 0x03, 0x0e }, /* Seashore */
- { 0xd5, 0xda, 0x95, 0x49, 0x37, 0x56, 0xa3, 0x37, 0x00, 0x00, 0x00 }, /* Bird Tweet */
- { 0x35, 0x14, 0x5c, 0x11, 0xb2, 0xf4, 0x61, 0x15, 0x02, 0x00, 0x0a }, /* Telephone ring */
- { 0x0e, 0xd0, 0x00, 0x09, 0xf6, 0x4f, 0x00, 0xf5, 0x00, 0x03, 0x0e }, /* Helicopter */
- { 0x26, 0xe4, 0x00, 0x09, 0xff, 0x12, 0x01, 0x16, 0x00, 0x01, 0x0e }, /* Applause */
- { 0x00, 0x00, 0x00, 0x09, 0xf3, 0xf6, 0xf0, 0xc9, 0x00, 0x02, 0x0e } /* Gunshot */
+static unsigned char midi_fm_instruments_table[128][11] = {
+ /* This set of GM instrument patches was provided by Jorrit Rouwe...
+ */
+ {0x21, 0x21, 0x8f, 0x0c, 0xf2, 0xf2, 0x45, 0x76, 0x00, 0x00, 0x08}, /* Acoustic Grand */
+ {0x31, 0x21, 0x4b, 0x09, 0xf2, 0xf2, 0x54, 0x56, 0x00, 0x00, 0x08}, /* Bright Acoustic */
+ {0x31, 0x21, 0x49, 0x09, 0xf2, 0xf2, 0x55, 0x76, 0x00, 0x00, 0x08}, /* Electric Grand */
+ {0xb1, 0x61, 0x0e, 0x09, 0xf2, 0xf3, 0x3b, 0x0b, 0x00, 0x00, 0x06}, /* Honky-Tonk */
+ {0x01, 0x21, 0x57, 0x09, 0xf1, 0xf1, 0x38, 0x28, 0x00, 0x00, 0x00}, /* Electric Piano 1 */
+ {0x01, 0x21, 0x93, 0x09, 0xf1, 0xf1, 0x38, 0x28, 0x00, 0x00, 0x00}, /* Electric Piano 2 */
+ {0x21, 0x36, 0x80, 0x17, 0xa2, 0xf1, 0x01, 0xd5, 0x00, 0x00, 0x08}, /* Harpsichord */
+ {0x01, 0x01, 0x92, 0x09, 0xc2, 0xc2, 0xa8, 0x58, 0x00, 0x00, 0x0a}, /* Clav */
+ {0x0c, 0x81, 0x5c, 0x09, 0xf6, 0xf3, 0x54, 0xb5, 0x00, 0x00, 0x00}, /* Celesta */
+ {0x07, 0x11, 0x97, 0x89, 0xf6, 0xf5, 0x32, 0x11, 0x00, 0x00, 0x02}, /* Glockenspiel */
+ {0x17, 0x01, 0x21, 0x09, 0x56, 0xf6, 0x04, 0x04, 0x00, 0x00, 0x02}, /* Music Box */
+ {0x18, 0x81, 0x62, 0x09, 0xf3, 0xf2, 0xe6, 0xf6, 0x00, 0x00, 0x00}, /* Vibraphone */
+ {0x18, 0x21, 0x23, 0x09, 0xf7, 0xe5, 0x55, 0xd8, 0x00, 0x00, 0x00}, /* Marimba */
+ {0x15, 0x01, 0x91, 0x09, 0xf6, 0xf6, 0xa6, 0xe6, 0x00, 0x00, 0x04}, /* Xylophone */
+ {0x45, 0x81, 0x59, 0x89, 0xd3, 0xa3, 0x82, 0xe3, 0x00, 0x00, 0x0c}, /* Tubular Bells */
+ {0x03, 0x81, 0x49, 0x89, 0x74, 0xb3, 0x55, 0x05, 0x01, 0x00, 0x04}, /* Dulcimer */
+ {0x71, 0x31, 0x92, 0x09, 0xf6, 0xf1, 0x14, 0x07, 0x00, 0x00, 0x02}, /* Drawbar Organ */
+ {0x72, 0x30, 0x14, 0x09, 0xc7, 0xc7, 0x58, 0x08, 0x00, 0x00, 0x02}, /* Percussive Organ */
+ {0x70, 0xb1, 0x44, 0x09, 0xaa, 0x8a, 0x18, 0x08, 0x00, 0x00, 0x04}, /* Rock Organ */
+ {0x23, 0xb1, 0x93, 0x09, 0x97, 0x55, 0x23, 0x14, 0x01, 0x00, 0x04}, /* Church Organ */
+ {0x61, 0xb1, 0x13, 0x89, 0x97, 0x55, 0x04, 0x04, 0x01, 0x00, 0x00}, /* Reed Organ */
+ {0x24, 0xb1, 0x48, 0x09, 0x98, 0x46, 0x2a, 0x1a, 0x01, 0x00, 0x0c}, /* Accoridan */
+ {0x61, 0x21, 0x13, 0x09, 0x91, 0x61, 0x06, 0x07, 0x01, 0x00, 0x0a}, /* Harmonica */
+ {0x21, 0xa1, 0x13, 0x92, 0x71, 0x61, 0x06, 0x07, 0x00, 0x00, 0x06}, /* Tango Accordian */
+ {0x02, 0x41, 0x9c, 0x89, 0xf3, 0xf3, 0x94, 0xc8, 0x01, 0x00, 0x0c}, /* Acoustic Guitar(nylon) */
+ {0x03, 0x11, 0x54, 0x09, 0xf3, 0xf1, 0x9a, 0xe7, 0x01, 0x00, 0x0c}, /* Acoustic Guitar(steel) */
+ {0x23, 0x21, 0x5f, 0x09, 0xf1, 0xf2, 0x3a, 0xf8, 0x00, 0x00, 0x00}, /* Electric Guitar(jazz) */
+ {0x03, 0x21, 0x87, 0x89, 0xf6, 0xf3, 0x22, 0xf8, 0x01, 0x00, 0x06}, /* Electric Guitar(clean) */
+ {0x03, 0x21, 0x47, 0x09, 0xf9, 0xf6, 0x54, 0x3a, 0x00, 0x00, 0x00}, /* Electric Guitar(muted) */
+ {0x23, 0x21, 0x4a, 0x0e, 0x91, 0x84, 0x41, 0x19, 0x01, 0x00, 0x08}, /* Overdriven Guitar */
+ {0x23, 0x21, 0x4a, 0x09, 0x95, 0x94, 0x19, 0x19, 0x01, 0x00, 0x08}, /* Distortion Guitar */
+ {0x09, 0x84, 0xa1, 0x89, 0x20, 0xd1, 0x4f, 0xf8, 0x00, 0x00, 0x08}, /* Guitar Harmonics */
+ {0x21, 0xa2, 0x1e, 0x09, 0x94, 0xc3, 0x06, 0xa6, 0x00, 0x00, 0x02}, /* Acoustic Bass */
+ {0x31, 0x31, 0x12, 0x09, 0xf1, 0xf1, 0x28, 0x18, 0x00, 0x00, 0x0a}, /* Electric Bass(finger) */
+ {0x31, 0x31, 0x8d, 0x09, 0xf1, 0xf1, 0xe8, 0x78, 0x00, 0x00, 0x0a}, /* Electric Bass(pick) */
+ {0x31, 0x32, 0x5b, 0x09, 0x51, 0x71, 0x28, 0x48, 0x00, 0x00, 0x0c}, /* Fretless Bass */
+ {0x01, 0x21, 0x8b, 0x49, 0xa1, 0xf2, 0x9a, 0xdf, 0x00, 0x00, 0x08}, /* Slap Bass 1 */
+ {0x21, 0x21, 0x8b, 0x11, 0xa2, 0xa1, 0x16, 0xdf, 0x00, 0x00, 0x08}, /* Slap Bass 2 */
+ {0x31, 0x31, 0x8b, 0x09, 0xf4, 0xf1, 0xe8, 0x78, 0x00, 0x00, 0x0a}, /* Synth Bass 1 */
+ {0x31, 0x31, 0x12, 0x09, 0xf1, 0xf1, 0x28, 0x18, 0x00, 0x00, 0x0a}, /* Synth Bass 2 */
+ {0x31, 0x21, 0x15, 0x09, 0xdd, 0x56, 0x13, 0x26, 0x01, 0x00, 0x08}, /* Violin */
+ {0x31, 0x21, 0x16, 0x09, 0xdd, 0x66, 0x13, 0x06, 0x01, 0x00, 0x08}, /* Viola */
+ {0x71, 0x31, 0x49, 0x09, 0xd1, 0x61, 0x1c, 0x0c, 0x01, 0x00, 0x08}, /* Cello */
+ {0x21, 0x23, 0x4d, 0x89, 0x71, 0x72, 0x12, 0x06, 0x01, 0x00, 0x02}, /* Contrabass */
+ {0xf1, 0xe1, 0x40, 0x09, 0xf1, 0x6f, 0x21, 0x16, 0x01, 0x00, 0x02}, /* Tremolo Strings */
+ {0x02, 0x01, 0x1a, 0x89, 0xf5, 0x85, 0x75, 0x35, 0x01, 0x00, 0x00}, /* Pizzicato Strings */
+ {0x02, 0x01, 0x1d, 0x89, 0xf5, 0xf3, 0x75, 0xf4, 0x01, 0x00, 0x00}, /* Orchestral Strings */
+ {0x10, 0x11, 0x41, 0x09, 0xf5, 0xf2, 0x05, 0xc3, 0x01, 0x00, 0x02}, /* Timpani */
+ {0x21, 0xa2, 0x9b, 0x0a, 0xb1, 0x72, 0x25, 0x08, 0x01, 0x00, 0x0e}, /* String Ensemble 1 */
+ {0xa1, 0x21, 0x98, 0x09, 0x7f, 0x3f, 0x03, 0x07, 0x01, 0x01, 0x00}, /* String Ensemble 2 */
+ {0xa1, 0x61, 0x93, 0x09, 0xc1, 0x4f, 0x12, 0x05, 0x00, 0x00, 0x0a}, /* SynthStrings 1 */
+ {0x21, 0x61, 0x18, 0x09, 0xc1, 0x4f, 0x22, 0x05, 0x00, 0x00, 0x0c}, /* SynthStrings 2 */
+ {0x31, 0x72, 0x5b, 0x8c, 0xf4, 0x8a, 0x15, 0x05, 0x00, 0x00, 0x00}, /* Choir Aahs */
+ {0xa1, 0x61, 0x90, 0x09, 0x74, 0x71, 0x39, 0x67, 0x00, 0x00, 0x00}, /* Voice Oohs */
+ {0x71, 0x72, 0x57, 0x09, 0x54, 0x7a, 0x05, 0x05, 0x00, 0x00, 0x0c}, /* Synth Voice */
+ {0x90, 0x41, 0x00, 0x09, 0x54, 0xa5, 0x63, 0x45, 0x00, 0x00, 0x08}, /* Orchestra Hit */
+ {0x21, 0x21, 0x92, 0x0a, 0x85, 0x8f, 0x17, 0x09, 0x00, 0x00, 0x0c}, /* Trumpet */
+ {0x21, 0x21, 0x94, 0x0e, 0x75, 0x8f, 0x17, 0x09, 0x00, 0x00, 0x0c}, /* Trombone */
+ {0x21, 0x61, 0x94, 0x09, 0x76, 0x82, 0x15, 0x37, 0x00, 0x00, 0x0c}, /* Tuba */
+ {0x31, 0x21, 0x43, 0x09, 0x9e, 0x62, 0x17, 0x2c, 0x01, 0x01, 0x02}, /* Muted Trumpet */
+ {0x21, 0x21, 0x9b, 0x09, 0x61, 0x7f, 0x6a, 0x0a, 0x00, 0x00, 0x02}, /* French Horn */
+ {0x61, 0x22, 0x8a, 0x0f, 0x75, 0x74, 0x1f, 0x0f, 0x00, 0x00, 0x08}, /* Brass Section */
+ {0xa1, 0x21, 0x86, 0x8c, 0x72, 0x71, 0x55, 0x18, 0x01, 0x00, 0x00}, /* SynthBrass 1 */
+ {0x21, 0x21, 0x4d, 0x09, 0x54, 0xa6, 0x3c, 0x1c, 0x00, 0x00, 0x08}, /* SynthBrass 2 */
+ {0x31, 0x61, 0x8f, 0x09, 0x93, 0x72, 0x02, 0x0b, 0x01, 0x00, 0x08}, /* Soprano Sax */
+ {0x31, 0x61, 0x8e, 0x09, 0x93, 0x72, 0x03, 0x09, 0x01, 0x00, 0x08}, /* Alto Sax */
+ {0x31, 0x61, 0x91, 0x09, 0x93, 0x82, 0x03, 0x09, 0x01, 0x00, 0x0a}, /* Tenor Sax */
+ {0x31, 0x61, 0x8e, 0x09, 0x93, 0x72, 0x0f, 0x0f, 0x01, 0x00, 0x0a}, /* Baritone Sax */
+ {0x21, 0x21, 0x4b, 0x09, 0xaa, 0x8f, 0x16, 0x0a, 0x01, 0x00, 0x08}, /* Oboe */
+ {0x31, 0x21, 0x90, 0x09, 0x7e, 0x8b, 0x17, 0x0c, 0x01, 0x01, 0x06}, /* English Horn */
+ {0x31, 0x32, 0x81, 0x09, 0x75, 0x61, 0x19, 0x19, 0x01, 0x00, 0x00}, /* Bassoon */
+ {0x32, 0x21, 0x90, 0x09, 0x9b, 0x72, 0x21, 0x17, 0x00, 0x00, 0x04}, /* Clarinet */
+ {0xe1, 0xe1, 0x1f, 0x09, 0x85, 0x65, 0x5f, 0x1a, 0x00, 0x00, 0x00}, /* Piccolo */
+ {0xe1, 0xe1, 0x46, 0x09, 0x88, 0x65, 0x5f, 0x1a, 0x00, 0x00, 0x00}, /* Flute */
+ {0xa1, 0x21, 0x9c, 0x09, 0x75, 0x75, 0x1f, 0x0a, 0x00, 0x00, 0x02}, /* Recorder */
+ {0x31, 0x21, 0x8b, 0x09, 0x84, 0x65, 0x58, 0x1a, 0x00, 0x00, 0x00}, /* Pan Flute */
+ {0xe1, 0xa1, 0x4c, 0x09, 0x66, 0x65, 0x56, 0x26, 0x00, 0x00, 0x00}, /* Blown Bottle */
+ {0x62, 0xa1, 0xcb, 0x09, 0x76, 0x55, 0x46, 0x36, 0x00, 0x00, 0x00}, /* Skakuhachi */
+ {0x62, 0xa1, 0xa2, 0x09, 0x57, 0x56, 0x07, 0x07, 0x00, 0x00, 0x0b}, /* Whistle */
+ {0x62, 0xa1, 0x9c, 0x09, 0x77, 0x76, 0x07, 0x07, 0x00, 0x00, 0x0b}, /* Ocarina */
+ {0x22, 0x21, 0x59, 0x09, 0xff, 0xff, 0x03, 0x0f, 0x02, 0x00, 0x00}, /* Lead 1 (square) */
+ {0x21, 0x21, 0x0e, 0x09, 0xff, 0xff, 0x0f, 0x0f, 0x01, 0x01, 0x00}, /* Lead 2 (sawtooth) */
+ {0x22, 0x21, 0x46, 0x89, 0x86, 0x64, 0x55, 0x18, 0x00, 0x00, 0x00}, /* Lead 3 (calliope) */
+ {0x21, 0xa1, 0x45, 0x09, 0x66, 0x96, 0x12, 0x0a, 0x00, 0x00, 0x00}, /* Lead 4 (chiff) */
+ {0x21, 0x22, 0x8b, 0x09, 0x92, 0x91, 0x2a, 0x2a, 0x01, 0x00, 0x00}, /* Lead 5 (charang) */
+ {0xa2, 0x61, 0x9e, 0x49, 0xdf, 0x6f, 0x05, 0x07, 0x00, 0x00, 0x02}, /* Lead 6 (voice) */
+ {0x20, 0x60, 0x1a, 0x09, 0xef, 0x8f, 0x01, 0x06, 0x00, 0x02, 0x00}, /* Lead 7 (fifths) */
+ {0x21, 0x21, 0x8f, 0x86, 0xf1, 0xf4, 0x29, 0x09, 0x00, 0x00, 0x0a}, /* Lead 8 (bass+lead) */
+ {0x77, 0xa1, 0xa5, 0x09, 0x53, 0xa0, 0x94, 0x05, 0x00, 0x00, 0x02}, /* Pad 1 (new age) */
+ {0x61, 0xb1, 0x1f, 0x89, 0xa8, 0x25, 0x11, 0x03, 0x00, 0x00, 0x0a}, /* Pad 2 (warm) */
+ {0x61, 0x61, 0x17, 0x09, 0x91, 0x55, 0x34, 0x16, 0x00, 0x00, 0x0c}, /* Pad 3 (polysynth) */
+ {0x71, 0x72, 0x5d, 0x09, 0x54, 0x6a, 0x01, 0x03, 0x00, 0x00, 0x00}, /* Pad 4 (choir) */
+ {0x21, 0xa2, 0x97, 0x09, 0x21, 0x42, 0x43, 0x35, 0x00, 0x00, 0x08}, /* Pad 5 (bowed) */
+ {0xa1, 0x21, 0x1c, 0x09, 0xa1, 0x31, 0x77, 0x47, 0x01, 0x01, 0x00}, /* Pad 6 (metallic) */
+ {0x21, 0x61, 0x89, 0x0c, 0x11, 0x42, 0x33, 0x25, 0x00, 0x00, 0x0a}, /* Pad 7 (halo) */
+ {0xa1, 0x21, 0x15, 0x09, 0x11, 0xcf, 0x47, 0x07, 0x01, 0x00, 0x00}, /* Pad 8 (sweep) */
+ {0x3a, 0x51, 0xce, 0x09, 0xf8, 0x86, 0xf6, 0x02, 0x00, 0x00, 0x02}, /* FX 1 (rain) */
+ {0x21, 0x21, 0x15, 0x09, 0x21, 0x41, 0x23, 0x13, 0x01, 0x00, 0x00}, /* FX 2 (soundtrack) */
+ {0x06, 0x01, 0x5b, 0x09, 0x74, 0xa5, 0x95, 0x72, 0x00, 0x00, 0x00}, /* FX 3 (crystal) */
+ {0x22, 0x61, 0x92, 0x8c, 0xb1, 0xf2, 0x81, 0x26, 0x00, 0x00, 0x0c}, /* FX 4 (atmosphere) */
+ {0x41, 0x42, 0x4d, 0x09, 0xf1, 0xf2, 0x51, 0xf5, 0x01, 0x00, 0x00}, /* FX 5 (brightness) */
+ {0x61, 0xa3, 0x94, 0x89, 0x11, 0x11, 0x51, 0x13, 0x01, 0x00, 0x06}, /* FX 6 (goblins) */
+ {0x61, 0xa1, 0x8c, 0x89, 0x11, 0x1d, 0x31, 0x03, 0x00, 0x00, 0x06}, /* FX 7 (echoes) */
+ {0xa4, 0x61, 0x4c, 0x09, 0xf3, 0x81, 0x73, 0x23, 0x01, 0x00, 0x04}, /* FX 8 (sci-fi) */
+ {0x02, 0x07, 0x85, 0x0c, 0xd2, 0xf2, 0x53, 0xf6, 0x00, 0x01, 0x00}, /* Sitar */
+ {0x11, 0x13, 0x0c, 0x89, 0xa3, 0xa2, 0x11, 0xe5, 0x01, 0x00, 0x00}, /* Banjo */
+ {0x11, 0x11, 0x06, 0x09, 0xf6, 0xf2, 0x41, 0xe6, 0x01, 0x02, 0x04}, /* Shamisen */
+ {0x93, 0x91, 0x91, 0x09, 0xd4, 0xeb, 0x32, 0x11, 0x00, 0x01, 0x08}, /* Koto */
+ {0x04, 0x01, 0x4f, 0x09, 0xfa, 0xc2, 0x56, 0x05, 0x00, 0x00, 0x0c}, /* Kalimba */
+ {0x21, 0x22, 0x49, 0x09, 0x7c, 0x6f, 0x20, 0x0c, 0x00, 0x01, 0x06}, /* Bagpipe */
+ {0x31, 0x21, 0x85, 0x09, 0xdd, 0x56, 0x33, 0x16, 0x01, 0x00, 0x0a}, /* Fiddle */
+ {0x20, 0x21, 0x04, 0x8a, 0xda, 0x8f, 0x05, 0x0b, 0x02, 0x00, 0x06}, /* Shanai */
+ {0x05, 0x03, 0x6a, 0x89, 0xf1, 0xc3, 0xe5, 0xe5, 0x00, 0x00, 0x06}, /* Tinkle Bell */
+ {0x07, 0x02, 0x15, 0x09, 0xec, 0xf8, 0x26, 0x16, 0x00, 0x00, 0x0a}, /* Agogo */
+ {0x05, 0x01, 0x9d, 0x09, 0x67, 0xdf, 0x35, 0x05, 0x00, 0x00, 0x08}, /* Steel Drums */
+ {0x18, 0x12, 0x96, 0x09, 0xfa, 0xf8, 0x28, 0xe5, 0x00, 0x00, 0x0a}, /* Woodblock */
+ {0x10, 0x00, 0x86, 0x0c, 0xa8, 0xfa, 0x07, 0x03, 0x00, 0x00, 0x06}, /* Taiko Drum */
+ {0x11, 0x10, 0x41, 0x0c, 0xf8, 0xf3, 0x47, 0x03, 0x02, 0x00, 0x04}, /* Melodic Tom */
+ {0x01, 0x10, 0x8e, 0x09, 0xf1, 0xf3, 0x06, 0x02, 0x02, 0x00, 0x0e}, /* Synth Drum */
+ {0x0e, 0xc0, 0x00, 0x09, 0x1f, 0x1f, 0x00, 0xff, 0x00, 0x03, 0x0e}, /* Reverse Cymbal */
+ {0x06, 0x03, 0x80, 0x91, 0xf8, 0x56, 0x24, 0x84, 0x00, 0x02, 0x0e}, /* Guitar Fret Noise */
+ {0x0e, 0xd0, 0x00, 0x0e, 0xf8, 0x34, 0x00, 0x04, 0x00, 0x03, 0x0e}, /* Breath Noise */
+ {0x0e, 0xc0, 0x00, 0x09, 0xf6, 0x1f, 0x00, 0x02, 0x00, 0x03, 0x0e}, /* Seashore */
+ {0xd5, 0xda, 0x95, 0x49, 0x37, 0x56, 0xa3, 0x37, 0x00, 0x00, 0x00}, /* Bird Tweet */
+ {0x35, 0x14, 0x5c, 0x11, 0xb2, 0xf4, 0x61, 0x15, 0x02, 0x00, 0x0a}, /* Telephone ring */
+ {0x0e, 0xd0, 0x00, 0x09, 0xf6, 0x4f, 0x00, 0xf5, 0x00, 0x03, 0x0e}, /* Helicopter */
+ {0x26, 0xe4, 0x00, 0x09, 0xff, 0x12, 0x01, 0x16, 0x00, 0x01, 0x0e}, /* Applause */
+ {0x00, 0x00, 0x00, 0x09, 0xf3, 0xf6, 0xf0, 0xc9, 0x00, 0x02, 0x0e} /* Gunshot */
};
/* logarithmic relationship between midi and FM volumes */
static int my_midi_fm_vol_table[128] = {
- 0, 11, 16, 19, 22, 25, 27, 29, 32, 33, 35, 37, 39, 40, 42, 43,
- 45, 46, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
- 64, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77,
- 78, 79, 80, 80, 81, 82, 83, 83, 84, 85, 86, 86, 87, 88, 89, 89,
- 90, 91, 91, 92, 93, 93, 94, 95, 96, 96, 97, 97, 98, 99, 99, 100,
- 101, 101, 102, 103, 103, 104, 104, 105, 106, 106, 107, 107, 108,
- 109, 109, 110, 110, 111, 112, 112, 113, 113, 114, 114, 115, 115,
- 116, 117, 117, 118, 118, 119, 119, 120, 120, 121, 121, 122, 122,
- 123, 123, 124, 124, 125, 125, 126, 126, 127
+ 0, 11, 16, 19, 22, 25, 27, 29, 32, 33, 35, 37, 39, 40, 42, 43,
+ 45, 46, 48, 49, 50, 51, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62,
+ 64, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77,
+ 78, 79, 80, 80, 81, 82, 83, 83, 84, 85, 86, 86, 87, 88, 89, 89,
+ 90, 91, 91, 92, 93, 93, 94, 95, 96, 96, 97, 97, 98, 99, 99, 100,
+ 101, 101, 102, 103, 103, 104, 104, 105, 106, 106, 107, 107, 108,
+ 109, 109, 110, 110, 111, 112, 112, 113, 113, 114, 114, 115, 115,
+ 116, 117, 117, 118, 118, 119, 119, 120, 120, 121, 121, 122, 122,
+ 123, 123, 124, 124, 125, 125, 126, 126, 127
};
-class MidiDriver_MIDIEMU : public MidiDriver {
+class MidiDriver_MIDIEMU:public MidiDriver {
public:
- MidiDriver_MIDIEMU();
+ MidiDriver_MIDIEMU();
int open(int mode);
void close();
void send(uint32 b);
void pause(bool pause);
void set_stream_callback(void *param, StreamCallback *sc);
static int midiemu_callback_thread(void *param);
-
+
private:
struct midi_channel {
int inum;
@@ -1008,46 +1044,50 @@ private:
midi_channel ch[16];
};
-static unsigned char adlib_opadd[] = {0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12};
-MidiDriver_MIDIEMU::MidiDriver_MIDIEMU(){
+static unsigned char adlib_opadd[] = { 0x00, 0x01, 0x02, 0x08, 0x09, 0x0A, 0x10, 0x11, 0x12 };
+MidiDriver_MIDIEMU::MidiDriver_MIDIEMU()
+{
int i, j;
-
+
_mode = 0;
for (i = 0; i < 128; i++)
- for (j = 0; j < 11; j++)
+ for (j = 0; j < 11; j++)
myinsbank[i][j] = midi_fm_instruments_table[i][j];
for (i = 0; i < 16; i++) {
ch[i].inum = 0;
- for (j = 0; j < 11; j++)
+ for (j = 0; j < 11; j++)
ch[i].ins[j] = myinsbank[ch[i].inum][j];
- ch[i].vol = 127;
+ ch[i].vol = 127;
ch[i].nshift = -25;
ch[i].on = 1;
ch[i].pitchbend = 0x2000;
- }
+ }
/* General init */
- for (i=0; i < 9; i++) {
+ for (i = 0; i < 9; i++) {
chp[i][0] = -1;
chp[i][2] = 0;
- }
-
+ }
+
adlib_mode = ADLIB_MELODIC;
}
-int MidiDriver_MIDIEMU::open(int mode) {
- _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, g_system->property(OSystem::PROP_GET_SAMPLE_RATE,0));
- g_mixer->setup_premix((void*) this, premix_proc);
+int MidiDriver_MIDIEMU::open(int mode)
+{
+ _opl = OPLCreate(OPL_TYPE_YM3812, 3579545, g_system->property(OSystem::PROP_GET_SAMPLE_RATE, 0));
+ g_mixer->setup_premix((void *)this, premix_proc);
if (_stream_proc)
g_system->create_thread(midiemu_callback_thread, this);
return 0;
}
-void MidiDriver_MIDIEMU::close() {
+void MidiDriver_MIDIEMU::close()
+{
_mode = 0;
}
-void MidiDriver_MIDIEMU::generate_samples(int16 *data, uint len) {
+void MidiDriver_MIDIEMU::generate_samples(int16 *data, uint len)
+{
if (!_opl) {
memset(data, 0, len * sizeof(*data));
} else {
@@ -1055,8 +1095,9 @@ void MidiDriver_MIDIEMU::generate_samples(int16 *data, uint len) {
}
}
-void MidiDriver_MIDIEMU::premix_proc(void *param, int16 *buf, unsigned int len) {
- ((MidiDriver_MIDIEMU*)param)->generate_samples(buf, len);
+void MidiDriver_MIDIEMU::premix_proc(void *param, int16 *buf, unsigned int len)
+{
+ ((MidiDriver_MIDIEMU *) param)->generate_samples(buf, len);
}
void MidiDriver_MIDIEMU::send(uint32 b)
@@ -1064,191 +1105,203 @@ void MidiDriver_MIDIEMU::send(uint32 b)
unsigned char channel = (char)(b & 0x0F);
switch (b & 0xF0) {
- case 0x80: {/*note off*/
- unsigned char note = (unsigned char)((b >> 8) & 0x7F);
- for (int i = 0; i < 9; i++)
- if ((chp[i][0] == channel) && (chp[i][1] == note)) {
- midi_fm_endnote(i);
- chp[i][0] = -1;
- }
- }
- break;
- case 0x90: { /*note on*/
- unsigned char note = (unsigned char)((b >> 8) & 0x7F);
- unsigned char vel = (unsigned char)((b >> 16) & 0x7F);
- int i, j;
- int onl, on, nv;
- unsigned char ins[11];
- on = -1;
- if (ch[channel].on != 0) {
- for (i = 0; i < 9; i++)
- chp[i][2]++;
-
- j = 0;
- onl = 0;
- for (i = 0; i < 9; i++)
- if ((chp[i][0] == -1) && (chp[i][2] > onl)) {
- onl = chp[i][2];
- on = i;
- j = 1;
+ case 0x80:{ /*note off */
+ unsigned char note = (unsigned char)((b >> 8) & 0x7F);
+ for (int i = 0; i < 9; i++)
+ if ((chp[i][0] == channel) && (chp[i][1] == note)) {
+ midi_fm_endnote(i);
+ chp[i][0] = -1;
}
+ }
+ break;
+ case 0x90:{ /*note on */
+ unsigned char note = (unsigned char)((b >> 8) & 0x7F);
+ unsigned char vel = (unsigned char)((b >> 16) & 0x7F);
+ int i, j;
+ int onl, on, nv;
+ unsigned char ins[11];
+ on = -1;
+ if (ch[channel].on != 0) {
+ for (i = 0; i < 9; i++)
+ chp[i][2]++;
- if (on == -1) {
+ j = 0;
onl = 0;
for (i = 0; i < 9; i++)
- if (chp[i][2] > onl) {
+ if ((chp[i][0] == -1) && (chp[i][2] > onl)) {
onl = chp[i][2];
on = i;
+ j = 1;
}
- }
- if (j == 0)
- midi_fm_endnote(on);
-
- if ((vel != 0) && (ch[channel].inum >= 0) && (ch[channel].inum < 128)) {
- if ((adlib_mode == ADLIB_MELODIC) || (channel < 12))
- midi_fm_instrument(on, ch[channel].ins);
- else {
- //the following fails to be effective
- //at doing rythm sounds .. (cmf blah)
- ins[0] = ins[1] = ch[channel].ins[0];
- ins[2] = ins[3] = ch[channel].ins[2];
- ins[4] = ins[5] = ch[channel].ins[4];
- ins[6] = ins[7] = ch[channel].ins[6];
- ins[8] = ins[9] = ch[channel].ins[8];
- ins[10] = (ch[channel].ins[10] | 1);
- midi_fm_instrument(on,ins);
+ if (on == -1) {
+ onl = 0;
+ for (i = 0; i < 9; i++)
+ if (chp[i][2] > onl) {
+ onl = chp[i][2];
+ on = i;
+ }
}
- nv = (ch[channel].vol * vel) / 128;
+ if (j == 0)
+ midi_fm_endnote(on);
+
+ if ((vel != 0) && (ch[channel].inum >= 0) && (ch[channel].inum < 128)) {
+ if ((adlib_mode == ADLIB_MELODIC) || (channel < 12))
+ midi_fm_instrument(on, ch[channel].ins);
+ else {
+ //the following fails to be effective
+ //at doing rythm sounds .. (cmf blah)
+ ins[0] = ins[1] = ch[channel].ins[0];
+ ins[2] = ins[3] = ch[channel].ins[2];
+ ins[4] = ins[5] = ch[channel].ins[4];
+ ins[6] = ins[7] = ch[channel].ins[6];
+ ins[8] = ins[9] = ch[channel].ins[8];
+ ins[10] = (ch[channel].ins[10] | 1);
+ midi_fm_instrument(on, ins);
+ }
+
+ nv = (ch[channel].vol * vel) / 128;
#ifdef LUCAS_MODE
- nv *= 2;
+ nv *= 2;
#endif
- if (nv > 127) nv = 127;
- nv = my_midi_fm_vol_table[nv];
+ if (nv > 127)
+ nv = 127;
+ nv = my_midi_fm_vol_table[nv];
#ifdef LUCAS_MODE
- nv = (int)((double) sqrt((double) nv) * 11); /* TO CHANGE !!! */
+ nv = (int)((double)sqrt((double)nv) * 11); /* TO CHANGE !!! */
#endif
- }
-
- midi_fm_playnote(on, note + ch[channel].nshift, nv * 2, ch[channel].pitchbend);
- chp[on][0] = channel;
- chp[on][1] = note;
- chp[on][2] = 0;
- } else {
- if (vel == 0) { //same code as end note
+ }
+
+ midi_fm_playnote(on, note + ch[channel].nshift, nv * 2, ch[channel].pitchbend);
+ chp[on][0] = channel;
+ chp[on][1] = note;
+ chp[on][2] = 0;
+ } else {
+ if (vel == 0) { //same code as end note
+ for (i = 0; i < 9; i++)
+ if ((chp[i][0] == channel) && (chp[i][1] == note)) {
+ // midi_fm_volume(i,0); // really end the note
+ midi_fm_endnote(i);
+ chp[i][0] = -1;
+ }
+ } else { // i forget what this is for.
+ chp[on][0] = -1;
+ chp[on][2] = 0;
+ }
+ }
+ }
+ break;
+
+ case 0xa0:{ /*key after touch */
+ unsigned char note = (unsigned char)((b >> 8) & 0x7F);
+ unsigned char vel = (unsigned char)((b >> 16) & 0x7F);
+
+ for (int i = 0; i < 9; i++)
+ if ((chp[i][0] == channel) & (chp[i][1] == note)) {
+ int nv = (ch[channel].vol * vel) / 128;
+ if (nv > 127)
+ nv = 127;
+ nv = my_midi_fm_vol_table[nv];
+ midi_fm_volume(i, nv * 2);
+ }
+ }
+ break;
+
+ case 0xb0:{ /* control change */
+ int i;
+ unsigned char ctrl = (unsigned char)((b >> 8) & 0x7F);
+ unsigned char vel = (unsigned char)((b >> 16) & 0x7F);
+
+ /* FIXME: Except for Volume, the Modulation and Sustain
+ code is just a random guess. */
+ switch (ctrl) {
+ case 0x01: /* Modulation */
+ for (i = 0; i < 9; i++)
+ if (chp[i][0] == channel)
+ midi_write_adlib(0x20 + adlib_opadd[i], vel);
+ break;
+ case 0x07: /* Volume */
+ ch[channel].vol = vel;
+ break;
+ case 0x0A: /* Pan */
+ /* This is not a warning as we do not support OPL3 => no stereo anyway
+ debug(1, "MIDI sub-command 0xB0 (Control Change) case %02X (Pan) not handled in MIDIEMU driver.", ctrl); */
+ break;
+ case 0x40: /* Sustain on/off */
for (i = 0; i < 9; i++)
- if ((chp[i][0] == channel) && (chp[i][1] == note)) {
- // midi_fm_volume(i,0); // really end the note
+ if (chp[i][0] == channel)
+ midi_write_adlib(0x80 + adlib_opadd[i], vel);
+ break;
+ case 0x5B: /* Extended depth effect */
+ debug(1,
+ "MIDI sub-command 0xB0 (Control Change) case %02X (Extended Depth) not handled in MIDIEMU driver.",
+ ctrl);
+ break;
+ case 0x5D: /* Chorus depth */
+ debug(1,
+ "MIDI sub-command 0xB0 (Control Change) case %02X (Chorus Depth) not handled in MIDIEMU driver.",
+ ctrl);
+ break;
+ case 0x7B: /* All notes off */
+ for (i = 0; i < 9; i++) {
+ if (chp[i][0] == channel) {
midi_fm_endnote(i);
chp[i][0] = -1;
}
- } else { // i forget what this is for.
- chp[on][0] = -1;
- chp[on][2] = 0;
- }
- }
- }
- break;
-
- case 0xa0: { /*key after touch */
- unsigned char note = (unsigned char)((b >> 8) & 0x7F);
- unsigned char vel = (unsigned char)((b >> 16) & 0x7F);
-
- for (int i = 0; i < 9; i++)
- if ((chp[i][0] == channel) & (chp[i][1] == note)) {
- int nv = (ch[channel].vol * vel) / 128;
- if (nv > 127) nv = 127;
- nv = my_midi_fm_vol_table[nv];
- midi_fm_volume(i, nv * 2);
- }
- }
- break;
-
- case 0xb0: { /* control change */
- int i;
- unsigned char ctrl = (unsigned char)((b >> 8) & 0x7F);
- unsigned char vel = (unsigned char)((b >> 16) & 0x7F);
-
- /* FIXME: Except for Volume, the Modulation and Sustain
- code is just a random guess. */
- switch(ctrl) {
- case 0x01: /* Modulation */
- for (i = 0; i < 9; i++)
- if (chp[i][0] == channel)
- midi_write_adlib(0x20 + adlib_opadd[i], vel);
- break;
- case 0x07: /* Volume */
- ch[channel].vol = vel;
- break;
- case 0x0A: /* Pan */
- /* This is not a warning as we do not support OPL3 => no stereo anyway
- debug(1, "MIDI sub-command 0xB0 (Control Change) case %02X (Pan) not handled in MIDIEMU driver.", ctrl); */
- break;
- case 0x40: /* Sustain on/off */
- for (i = 0; i < 9; i++)
- if (chp[i][0] == channel)
- midi_write_adlib(0x80 + adlib_opadd[i], vel);
- break;
- case 0x5B: /* Extended depth effect */
- debug(1, "MIDI sub-command 0xB0 (Control Change) case %02X (Extended Depth) not handled in MIDIEMU driver.", ctrl);
- break;
- case 0x5D: /* Chorus depth */
- debug(1, "MIDI sub-command 0xB0 (Control Change) case %02X (Chorus Depth) not handled in MIDIEMU driver.", ctrl);
- break;
- case 0x7B: /* All notes off */
- for (i = 0; i < 9; i++) {
- if (chp[i][0] == channel) {
- midi_fm_endnote(i);
- chp[i][0] = -1;
}
+ break;
+ default:
+ debug(1, "MIDI sub-command 0xB0 (Control Change) case %02X not handled in MIDIEMU driver.",
+ ctrl);
+ break;
}
- break;
- default:
- debug(1, "MIDI sub-command 0xB0 (Control Change) case %02X not handled in MIDIEMU driver.", ctrl);
- break;
}
- } break;
-
- case 0xc0: { /* patch change */
- unsigned char instrument = (unsigned char)((b >> 8) & 0x7F);
- ch[channel].inum = instrument;
- for (int j = 0; j < 11; j++)
- ch[channel].ins[j] = myinsbank[ch[channel].inum][j];
- } break;
-
- case 0xd0: /* channel touch */
+ break;
+
+ case 0xc0:{ /* patch change */
+ unsigned char instrument = (unsigned char)((b >> 8) & 0x7F);
+ ch[channel].inum = instrument;
+ for (int j = 0; j < 11; j++)
+ ch[channel].ins[j] = myinsbank[ch[channel].inum][j];
+ } break;
+
+ case 0xd0: /* channel touch */
debug(1, "MIDI command 0xD0 (Channel Touch) not handled in MIDIEMU driver.");
- break;
-
- case 0xe0: { /* pitch wheel */
- int pitchbend = ((b >> 8) & 0x7F) | (((b >> 16) & 0x7F) << 7);
- ch[channel].pitchbend = pitchbend;
- for (int i = 0; i < 9; i++) {
- if (chp[i][0] == channel) {
- int nv = ch[channel].vol;
- if (nv > 127) nv = 127;
- nv = my_midi_fm_vol_table[nv];
- midi_fm_playnote(i, chp[i][1] + ch[channel].nshift, nv * 2, pitchbend);
+ break;
+
+ case 0xe0:{ /* pitch wheel */
+ int pitchbend = ((b >> 8) & 0x7F) | (((b >> 16) & 0x7F) << 7);
+ ch[channel].pitchbend = pitchbend;
+ for (int i = 0; i < 9; i++) {
+ if (chp[i][0] == channel) {
+ int nv = ch[channel].vol;
+ if (nv > 127)
+ nv = 127;
+ nv = my_midi_fm_vol_table[nv];
+ midi_fm_playnote(i, chp[i][1] + ch[channel].nshift, nv * 2, pitchbend);
+ }
}
}
- } break;
+ break;
default:
- fprintf(stderr, "Unknown : %08x\n", (int) b);
+ fprintf(stderr, "Unknown : %08x\n", (int)b);
break;
}
}
-void MidiDriver_MIDIEMU::pause(bool pause) {
+void MidiDriver_MIDIEMU::pause(bool pause)
+{
if (_mode == MO_STREAMING) {
}
}
#define NUMBER_MIDI_EVENTS 64
-int MidiDriver_MIDIEMU::midiemu_callback_thread(void *param) {
- MidiDriver_MIDIEMU *driver = (MidiDriver_MIDIEMU*) param;
+int MidiDriver_MIDIEMU::midiemu_callback_thread(void *param)
+{
+ MidiDriver_MIDIEMU *driver = (MidiDriver_MIDIEMU *) param;
MidiEvent my_evs[NUMBER_MIDI_EVENTS];
bool need_midi_data = true;
@@ -1266,14 +1319,14 @@ int MidiDriver_MIDIEMU::midiemu_callback_thread(void *param) {
need_midi_data = false;
}
- for (i=0; i<number; i++) {
+ for (i = 0; i < number; i++) {
uint32 event;
event = my_evs[i].event;
- if ((event>>24) == ME_TEMPO) {
+ if ((event >> 24) == ME_TEMPO) {
event = (ME_TEMPO << 24) | (event & 0xFFFFFF);
}
- driver->send(event);
+ driver->send(event);
if (my_evs[i].delta) {
g_system->delay_msecs(my_evs[i].delta);
}
@@ -1285,22 +1338,26 @@ int MidiDriver_MIDIEMU::midiemu_callback_thread(void *param) {
return 0;
}
-void MidiDriver_MIDIEMU::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_MIDIEMU::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
-MidiDriver *MidiDriver_MIDIEMU_create() {
+MidiDriver *MidiDriver_MIDIEMU_create()
+{
return new MidiDriver_MIDIEMU();
}
-void MidiDriver_MIDIEMU::midi_write_adlib(unsigned int reg, unsigned char val) {
+void MidiDriver_MIDIEMU::midi_write_adlib(unsigned int reg, unsigned char val)
+{
OPLWrite(_opl, 0, reg);
OPLWrite(_opl, 1, val);
adlib_data[reg] = val;
}
-void MidiDriver_MIDIEMU::midi_fm_instrument(int voice, unsigned char *inst) {
+void MidiDriver_MIDIEMU::midi_fm_instrument(int voice, unsigned char *inst)
+{
#if 0
/* Just gotta make sure this happens because who knows when it'll be reset otherwise.... */
midi_write_adlib(0xbd, 0);
@@ -1308,7 +1365,7 @@ void MidiDriver_MIDIEMU::midi_fm_instrument(int voice, unsigned char *inst) {
midi_write_adlib(0x20 + adlib_opadd[voice], inst[0]);
midi_write_adlib(0x23 + adlib_opadd[voice], inst[1]);
-
+
#ifdef LUCAS_MODE
midi_write_adlib(0x43 + adlib_opadd[voice], 0x3f);
if ((inst[10] & 1) == 0)
@@ -1318,10 +1375,10 @@ void MidiDriver_MIDIEMU::midi_fm_instrument(int voice, unsigned char *inst) {
#else
midi_write_adlib(0x40 + adlib_opadd[voice], inst[2]);
if ((inst[10] & 1) == 0)
- midi_write_adlib(0x43 + adlib_opadd[voice],inst[3]);
+ midi_write_adlib(0x43 + adlib_opadd[voice], inst[3]);
else
midi_write_adlib(0x43 + adlib_opadd[voice], 0);
-#endif
+#endif
midi_write_adlib(0x60 + adlib_opadd[voice], inst[4]);
midi_write_adlib(0x63 + adlib_opadd[voice], inst[5]);
@@ -1329,21 +1386,24 @@ void MidiDriver_MIDIEMU::midi_fm_instrument(int voice, unsigned char *inst) {
midi_write_adlib(0x83 + adlib_opadd[voice], inst[7]);
midi_write_adlib(0xe0 + adlib_opadd[voice], inst[8]);
midi_write_adlib(0xe3 + adlib_opadd[voice], inst[9]);
-
+
midi_write_adlib(0xc0 + voice, inst[10]);
}
-void MidiDriver_MIDIEMU::midi_fm_volume(int voice, int volume) {
+void MidiDriver_MIDIEMU::midi_fm_volume(int voice, int volume)
+{
volume >>= 2;
if ((adlib_data[0xc0 + voice] & 1) == 1)
midi_write_adlib(0x40 + adlib_opadd[voice],
- (unsigned char)((63 - volume) | (adlib_data[0x40 + adlib_opadd[voice]] & 0xc0)));
+ (unsigned char)((63 - volume) |
+ (adlib_data[0x40 + adlib_opadd[voice]] & 0xc0)));
midi_write_adlib(0x43 + adlib_opadd[voice],
- (unsigned char)((63 - volume) | (adlib_data[0x43 + adlib_opadd[voice]] & 0xc0)));
+ (unsigned char)((63 - volume) | (adlib_data[0x43 + adlib_opadd[voice]] & 0xc0)));
}
-static int fnums[] = { 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, 0x1e5, 0x202, 0x220, 0x241, 0x263, 0x287, 0x2ae };
+static int fnums[] =
+ { 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, 0x1e5, 0x202, 0x220, 0x241, 0x263, 0x287, 0x2ae };
/* These tables 'borrowed' from Timidity tables.c
@@ -1351,108 +1411,109 @@ static int fnums[] = { 0x16b, 0x181, 0x198, 0x1b0, 0x1ca, 0x1e5, 0x202, 0x220, 0
Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
*/
double bend_fine[256] = {
- 1.0, 1.0002256593050698, 1.0004513695322617, 1.0006771306930664,
- 1.0009029427989777, 1.0011288058614922, 1.0013547198921082, 1.0015806849023274,
- 1.0018067009036538, 1.002032767907594, 1.0022588859256572, 1.0024850549693551,
- 1.0027112750502025, 1.0029375461797159, 1.0031638683694153, 1.0033902416308227,
- 1.0036166659754628, 1.0038431414148634, 1.0040696679605541, 1.0042962456240678,
- 1.0045228744169397, 1.0047495543507072, 1.0049762854369111, 1.0052030676870944,
- 1.0054299011128027, 1.0056567857255843, 1.00588372153699, 1.006110708558573,
- 1.0063377468018897, 1.0065648362784985, 1.0067919769999607, 1.0070191689778405,
- 1.0072464122237039, 1.0074737067491204, 1.0077010525656616, 1.0079284496849015,
- 1.0081558981184175, 1.008383397877789, 1.008610948974598, 1.0088385514204294,
- 1.0090662052268706, 1.0092939104055114, 1.0095216669679448, 1.0097494749257656,
- 1.009977334290572, 1.0102052450739643, 1.0104332072875455, 1.0106612209429215,
- 1.0108892860517005, 1.0111174026254934, 1.0113455706759138, 1.0115737902145781,
- 1.0118020612531047, 1.0120303838031153, 1.0122587578762337, 1.012487183484087,
- 1.0127156606383041, 1.0129441893505169, 1.0131727696323602, 1.0134014014954713,
- 1.0136300849514894, 1.0138588200120575, 1.0140876066888203, 1.0143164449934257,
- 1.0145453349375237, 1.0147742765327674, 1.0150032697908125, 1.0152323147233171,
- 1.015461411341942, 1.0156905596583505, 1.0159197596842091, 1.0161490114311862,
- 1.0163783149109531, 1.0166076701351838, 1.0168370771155553, 1.0170665358637463,
- 1.0172960463914391, 1.0175256087103179, 1.0177552228320703, 1.0179848887683858,
- 1.0182146065309567, 1.0184443761314785, 1.0186741975816487, 1.0189040708931674,
- 1.0191339960777379, 1.0193639731470658, 1.0195940021128593, 1.0198240829868295,
- 1.0200542157806898, 1.0202844005061564, 1.0205146371749483, 1.0207449257987866,
- 1.0209752663893958, 1.0212056589585028, 1.0214361035178368, 1.0216666000791297,
- 1.0218971486541166, 1.0221277492545349, 1.0223584018921241, 1.0225891065786274,
- 1.0228198633257899, 1.0230506721453596, 1.023281533049087, 1.0235124460487257,
- 1.0237434111560313, 1.0239744283827625, 1.0242054977406807, 1.0244366192415495,
- 1.0246677928971357, 1.0248990187192082, 1.025130296719539, 1.0253616269099028,
- 1.0255930093020766, 1.0258244439078401, 1.0260559307389761, 1.0262874698072693,
- 1.0265190611245079, 1.0267507047024822, 1.0269824005529853, 1.027214148687813,
- 1.0274459491187637, 1.0276778018576387, 1.0279097069162415, 1.0281416643063788,
- 1.0283736740398595, 1.0286057361284953, 1.0288378505841009, 1.0290700174184932,
- 1.0293022366434921, 1.0295345082709197, 1.0297668323126017, 1.0299992087803651,
- 1.030231637686041, 1.0304641190414621, 1.0306966528584645, 1.0309292391488862,
- 1.0311618779245688, 1.0313945691973556, 1.0316273129790936, 1.0318601092816313,
- 1.0320929581168212, 1.0323258594965172, 1.0325588134325767, 1.0327918199368598,
- 1.0330248790212284, 1.0332579906975481, 1.0334911549776868, 1.033724371873515,
- 1.0339576413969056, 1.0341909635597348, 1.0344243383738811, 1.0346577658512259,
- 1.034891246003653, 1.0351247788430489, 1.0353583643813031, 1.0355920026303078,
- 1.0358256936019572, 1.0360594373081489, 1.0362932337607829, 1.0365270829717617,
- 1.0367609849529913, 1.0369949397163791, 1.0372289472738365, 1.0374630076372766,
- 1.0376971208186156, 1.0379312868297725, 1.0381655056826686, 1.0383997773892284,
- 1.0386341019613787, 1.0388684794110492, 1.0391029097501721, 1.0393373929906822,
- 1.0395719291445176, 1.0398065182236185, 1.0400411602399278, 1.0402758552053915,
- 1.0405106031319582, 1.0407454040315787, 1.0409802579162071, 1.0412151647977996,
- 1.0414501246883161, 1.0416851375997183, 1.0419202035439705, 1.0421553225330404,
- 1.042390494578898, 1.042625719693516, 1.0428609978888699, 1.043096329176938,
- 1.0433317135697009, 1.0435671510791424, 1.0438026417172486, 1.0440381854960086,
- 1.0442737824274138, 1.044509432523459, 1.044745135796141, 1.0449808922574599,
- 1.0452167019194181, 1.0454525647940205, 1.0456884808932754, 1.0459244502291931,
- 1.0461604728137874, 1.0463965486590741, 1.046632677777072, 1.0468688601798024,
- 1.0471050958792898, 1.047341384887561, 1.0475777272166455, 1.047814122878576,
- 1.048050571885387, 1.0482870742491166, 1.0485236299818055, 1.0487602390954964,
- 1.0489969016022356, 1.0492336175140715, 1.0494703868430555, 1.0497072096012419,
- 1.0499440858006872, 1.0501810154534512, 1.050417998571596, 1.0506550351671864,
- 1.0508921252522903, 1.0511292688389782, 1.0513664659393229, 1.0516037165654004,
- 1.0518410207292894, 1.0520783784430709, 1.0523157897188296, 1.0525532545686513,
- 1.0527907730046264, 1.0530283450388465, 1.0532659706834067, 1.0535036499504049,
- 1.0537413828519411, 1.0539791694001188, 1.0542170096070436, 1.0544549034848243,
- 1.0546928510455722, 1.0549308523014012, 1.0551689072644284, 1.0554070159467728,
- 1.0556451783605572, 1.0558833945179062, 1.0561216644309479, 1.0563599881118126,
- 1.0565983655726334, 1.0568367968255465, 1.0570752818826903, 1.0573138207562065,
- 1.057552413458239, 1.0577910600009348, 1.0580297603964437, 1.058268514656918,
- 1.0585073227945128, 1.0587461848213857, 1.058985100749698, 1.0592240705916123
+ 1.0, 1.0002256593050698, 1.0004513695322617, 1.0006771306930664,
+ 1.0009029427989777, 1.0011288058614922, 1.0013547198921082, 1.0015806849023274,
+ 1.0018067009036538, 1.002032767907594, 1.0022588859256572, 1.0024850549693551,
+ 1.0027112750502025, 1.0029375461797159, 1.0031638683694153, 1.0033902416308227,
+ 1.0036166659754628, 1.0038431414148634, 1.0040696679605541, 1.0042962456240678,
+ 1.0045228744169397, 1.0047495543507072, 1.0049762854369111, 1.0052030676870944,
+ 1.0054299011128027, 1.0056567857255843, 1.00588372153699, 1.006110708558573,
+ 1.0063377468018897, 1.0065648362784985, 1.0067919769999607, 1.0070191689778405,
+ 1.0072464122237039, 1.0074737067491204, 1.0077010525656616, 1.0079284496849015,
+ 1.0081558981184175, 1.008383397877789, 1.008610948974598, 1.0088385514204294,
+ 1.0090662052268706, 1.0092939104055114, 1.0095216669679448, 1.0097494749257656,
+ 1.009977334290572, 1.0102052450739643, 1.0104332072875455, 1.0106612209429215,
+ 1.0108892860517005, 1.0111174026254934, 1.0113455706759138, 1.0115737902145781,
+ 1.0118020612531047, 1.0120303838031153, 1.0122587578762337, 1.012487183484087,
+ 1.0127156606383041, 1.0129441893505169, 1.0131727696323602, 1.0134014014954713,
+ 1.0136300849514894, 1.0138588200120575, 1.0140876066888203, 1.0143164449934257,
+ 1.0145453349375237, 1.0147742765327674, 1.0150032697908125, 1.0152323147233171,
+ 1.015461411341942, 1.0156905596583505, 1.0159197596842091, 1.0161490114311862,
+ 1.0163783149109531, 1.0166076701351838, 1.0168370771155553, 1.0170665358637463,
+ 1.0172960463914391, 1.0175256087103179, 1.0177552228320703, 1.0179848887683858,
+ 1.0182146065309567, 1.0184443761314785, 1.0186741975816487, 1.0189040708931674,
+ 1.0191339960777379, 1.0193639731470658, 1.0195940021128593, 1.0198240829868295,
+ 1.0200542157806898, 1.0202844005061564, 1.0205146371749483, 1.0207449257987866,
+ 1.0209752663893958, 1.0212056589585028, 1.0214361035178368, 1.0216666000791297,
+ 1.0218971486541166, 1.0221277492545349, 1.0223584018921241, 1.0225891065786274,
+ 1.0228198633257899, 1.0230506721453596, 1.023281533049087, 1.0235124460487257,
+ 1.0237434111560313, 1.0239744283827625, 1.0242054977406807, 1.0244366192415495,
+ 1.0246677928971357, 1.0248990187192082, 1.025130296719539, 1.0253616269099028,
+ 1.0255930093020766, 1.0258244439078401, 1.0260559307389761, 1.0262874698072693,
+ 1.0265190611245079, 1.0267507047024822, 1.0269824005529853, 1.027214148687813,
+ 1.0274459491187637, 1.0276778018576387, 1.0279097069162415, 1.0281416643063788,
+ 1.0283736740398595, 1.0286057361284953, 1.0288378505841009, 1.0290700174184932,
+ 1.0293022366434921, 1.0295345082709197, 1.0297668323126017, 1.0299992087803651,
+ 1.030231637686041, 1.0304641190414621, 1.0306966528584645, 1.0309292391488862,
+ 1.0311618779245688, 1.0313945691973556, 1.0316273129790936, 1.0318601092816313,
+ 1.0320929581168212, 1.0323258594965172, 1.0325588134325767, 1.0327918199368598,
+ 1.0330248790212284, 1.0332579906975481, 1.0334911549776868, 1.033724371873515,
+ 1.0339576413969056, 1.0341909635597348, 1.0344243383738811, 1.0346577658512259,
+ 1.034891246003653, 1.0351247788430489, 1.0353583643813031, 1.0355920026303078,
+ 1.0358256936019572, 1.0360594373081489, 1.0362932337607829, 1.0365270829717617,
+ 1.0367609849529913, 1.0369949397163791, 1.0372289472738365, 1.0374630076372766,
+ 1.0376971208186156, 1.0379312868297725, 1.0381655056826686, 1.0383997773892284,
+ 1.0386341019613787, 1.0388684794110492, 1.0391029097501721, 1.0393373929906822,
+ 1.0395719291445176, 1.0398065182236185, 1.0400411602399278, 1.0402758552053915,
+ 1.0405106031319582, 1.0407454040315787, 1.0409802579162071, 1.0412151647977996,
+ 1.0414501246883161, 1.0416851375997183, 1.0419202035439705, 1.0421553225330404,
+ 1.042390494578898, 1.042625719693516, 1.0428609978888699, 1.043096329176938,
+ 1.0433317135697009, 1.0435671510791424, 1.0438026417172486, 1.0440381854960086,
+ 1.0442737824274138, 1.044509432523459, 1.044745135796141, 1.0449808922574599,
+ 1.0452167019194181, 1.0454525647940205, 1.0456884808932754, 1.0459244502291931,
+ 1.0461604728137874, 1.0463965486590741, 1.046632677777072, 1.0468688601798024,
+ 1.0471050958792898, 1.047341384887561, 1.0475777272166455, 1.047814122878576,
+ 1.048050571885387, 1.0482870742491166, 1.0485236299818055, 1.0487602390954964,
+ 1.0489969016022356, 1.0492336175140715, 1.0494703868430555, 1.0497072096012419,
+ 1.0499440858006872, 1.0501810154534512, 1.050417998571596, 1.0506550351671864,
+ 1.0508921252522903, 1.0511292688389782, 1.0513664659393229, 1.0516037165654004,
+ 1.0518410207292894, 1.0520783784430709, 1.0523157897188296, 1.0525532545686513,
+ 1.0527907730046264, 1.0530283450388465, 1.0532659706834067, 1.0535036499504049,
+ 1.0537413828519411, 1.0539791694001188, 1.0542170096070436, 1.0544549034848243,
+ 1.0546928510455722, 1.0549308523014012, 1.0551689072644284, 1.0554070159467728,
+ 1.0556451783605572, 1.0558833945179062, 1.0561216644309479, 1.0563599881118126,
+ 1.0565983655726334, 1.0568367968255465, 1.0570752818826903, 1.0573138207562065,
+ 1.057552413458239, 1.0577910600009348, 1.0580297603964437, 1.058268514656918,
+ 1.0585073227945128, 1.0587461848213857, 1.058985100749698, 1.0592240705916123
};
double bend_coarse[128] = {
- 1.0, 1.0594630943592953, 1.122462048309373, 1.189207115002721,
- 1.2599210498948732, 1.3348398541700344, 1.4142135623730951, 1.4983070768766815,
- 1.5874010519681994, 1.681792830507429, 1.7817974362806785, 1.8877486253633868,
- 2.0, 2.1189261887185906, 2.244924096618746, 2.3784142300054421,
- 2.5198420997897464, 2.6696797083400687, 2.8284271247461903, 2.996614153753363,
- 3.1748021039363992, 3.363585661014858, 3.5635948725613571, 3.7754972507267741,
- 4.0, 4.2378523774371812, 4.4898481932374912, 4.7568284600108841,
- 5.0396841995794928, 5.3393594166801366, 5.6568542494923806, 5.993228307506727,
- 6.3496042078727974, 6.727171322029716, 7.1271897451227151, 7.5509945014535473,
- 8.0, 8.4757047548743625, 8.9796963864749824, 9.5136569200217682,
- 10.079368399158986, 10.678718833360273, 11.313708498984761, 11.986456615013454,
- 12.699208415745595, 13.454342644059432, 14.25437949024543, 15.101989002907095,
- 16.0, 16.951409509748721, 17.959392772949972, 19.027313840043536,
- 20.158736798317967, 21.357437666720553, 22.627416997969522, 23.972913230026901,
- 25.398416831491197, 26.908685288118864, 28.508758980490853, 30.203978005814196,
- 32.0, 33.902819019497443, 35.918785545899944, 38.054627680087073,
- 40.317473596635935, 42.714875333441107, 45.254833995939045, 47.945826460053802,
- 50.796833662982394, 53.817370576237728, 57.017517960981706, 60.407956011628393,
- 64.0, 67.805638038994886, 71.837571091799887, 76.109255360174146,
- 80.63494719327187, 85.429750666882214, 90.509667991878089, 95.891652920107603,
- 101.59366732596479, 107.63474115247546, 114.03503592196341, 120.81591202325679,
- 128.0, 135.61127607798977, 143.67514218359977, 152.21851072034829,
- 161.26989438654374, 170.85950133376443, 181.01933598375618, 191.78330584021521,
- 203.18733465192958, 215.26948230495091, 228.07007184392683, 241.63182404651357,
- 256.0, 271.22255215597971, 287.35028436719938, 304.43702144069658,
- 322.53978877308765, 341.71900266752868, 362.03867196751236, 383.56661168043064,
- 406.37466930385892, 430.53896460990183, 456.14014368785394, 483.26364809302686,
- 512.0, 542.44510431195943, 574.70056873439876, 608.87404288139317,
- 645.0795775461753, 683.43800533505737, 724.07734393502471, 767.13322336086128,
- 812.74933860771785, 861.07792921980365, 912.28028737570787, 966.52729618605372,
- 1024.0, 1084.8902086239189, 1149.4011374687975, 1217.7480857627863,
- 1290.1591550923506, 1366.8760106701147, 1448.1546878700494, 1534.2664467217226
+ 1.0, 1.0594630943592953, 1.122462048309373, 1.189207115002721,
+ 1.2599210498948732, 1.3348398541700344, 1.4142135623730951, 1.4983070768766815,
+ 1.5874010519681994, 1.681792830507429, 1.7817974362806785, 1.8877486253633868,
+ 2.0, 2.1189261887185906, 2.244924096618746, 2.3784142300054421,
+ 2.5198420997897464, 2.6696797083400687, 2.8284271247461903, 2.996614153753363,
+ 3.1748021039363992, 3.363585661014858, 3.5635948725613571, 3.7754972507267741,
+ 4.0, 4.2378523774371812, 4.4898481932374912, 4.7568284600108841,
+ 5.0396841995794928, 5.3393594166801366, 5.6568542494923806, 5.993228307506727,
+ 6.3496042078727974, 6.727171322029716, 7.1271897451227151, 7.5509945014535473,
+ 8.0, 8.4757047548743625, 8.9796963864749824, 9.5136569200217682,
+ 10.079368399158986, 10.678718833360273, 11.313708498984761, 11.986456615013454,
+ 12.699208415745595, 13.454342644059432, 14.25437949024543, 15.101989002907095,
+ 16.0, 16.951409509748721, 17.959392772949972, 19.027313840043536,
+ 20.158736798317967, 21.357437666720553, 22.627416997969522, 23.972913230026901,
+ 25.398416831491197, 26.908685288118864, 28.508758980490853, 30.203978005814196,
+ 32.0, 33.902819019497443, 35.918785545899944, 38.054627680087073,
+ 40.317473596635935, 42.714875333441107, 45.254833995939045, 47.945826460053802,
+ 50.796833662982394, 53.817370576237728, 57.017517960981706, 60.407956011628393,
+ 64.0, 67.805638038994886, 71.837571091799887, 76.109255360174146,
+ 80.63494719327187, 85.429750666882214, 90.509667991878089, 95.891652920107603,
+ 101.59366732596479, 107.63474115247546, 114.03503592196341, 120.81591202325679,
+ 128.0, 135.61127607798977, 143.67514218359977, 152.21851072034829,
+ 161.26989438654374, 170.85950133376443, 181.01933598375618, 191.78330584021521,
+ 203.18733465192958, 215.26948230495091, 228.07007184392683, 241.63182404651357,
+ 256.0, 271.22255215597971, 287.35028436719938, 304.43702144069658,
+ 322.53978877308765, 341.71900266752868, 362.03867196751236, 383.56661168043064,
+ 406.37466930385892, 430.53896460990183, 456.14014368785394, 483.26364809302686,
+ 512.0, 542.44510431195943, 574.70056873439876, 608.87404288139317,
+ 645.0795775461753, 683.43800533505737, 724.07734393502471, 767.13322336086128,
+ 812.74933860771785, 861.07792921980365, 912.28028737570787, 966.52729618605372,
+ 1024.0, 1084.8902086239189, 1149.4011374687975, 1217.7480857627863,
+ 1290.1591550923506, 1366.8760106701147, 1448.1546878700494, 1534.2664467217226
};
-void MidiDriver_MIDIEMU::midi_fm_playnote(int voice, int note, int volume, int pitchbend) {
+void MidiDriver_MIDIEMU::midi_fm_playnote(int voice, int note, int volume, int pitchbend)
+{
int freq = fnums[note % 12];
int oct = note / 12;
int c;
@@ -1461,14 +1522,15 @@ void MidiDriver_MIDIEMU::midi_fm_playnote(int voice, int note, int volume, int p
pitchbend -= 0x2000;
if (pitchbend != 0) {
pitchbend *= 2;
- if(pitchbend >= 0)
- pf = (float)(bend_fine[(pitchbend>>5) & 0xFF] * bend_coarse[(pitchbend>>13) & 0x7F]);
+ if (pitchbend >= 0)
+ pf = (float)(bend_fine[(pitchbend >> 5) & 0xFF] * bend_coarse[(pitchbend >> 13) & 0x7F]);
else {
pitchbend = -pitchbend;
- pf = (float)(1.0 / (bend_fine[(pitchbend>>5) & 0xFF] * bend_coarse[(pitchbend>>13) & 0x7F]));
+ pf =
+ (float)(1.0 / (bend_fine[(pitchbend >> 5) & 0xFF] * bend_coarse[(pitchbend >> 13) & 0x7F]));
}
- freq = (int) ((float) freq * pf);
-
+ freq = (int)((float)freq * pf);
+
while (freq >= (fnums[0] * 2)) {
freq /= 2;
oct += 1;
@@ -1480,14 +1542,15 @@ void MidiDriver_MIDIEMU::midi_fm_playnote(int voice, int note, int volume, int p
}
midi_fm_volume(voice, volume);
- midi_write_adlib(0xa0 + voice, (unsigned char) (freq & 0xff));
+ midi_write_adlib(0xa0 + voice, (unsigned char)(freq & 0xff));
c = ((freq & 0x300) >> 8) + (oct << 2) + (1 << 5);
- midi_write_adlib(0xb0 + voice, (unsigned char) c);
+ midi_write_adlib(0xb0 + voice, (unsigned char)c);
}
-void MidiDriver_MIDIEMU::midi_fm_endnote(int voice) {
- midi_write_adlib(0xb0 + voice, (unsigned char) (adlib_data[0xb0 + voice] & (255 - 32)));
+void MidiDriver_MIDIEMU::midi_fm_endnote(int voice)
+{
+ midi_write_adlib(0xb0 + voice, (unsigned char)(adlib_data[0xb0 + voice] & (255 - 32)));
}
@@ -1503,7 +1566,7 @@ void MidiDriver_MIDIEMU::midi_fm_endnote(int voice) {
#if SND_LIB_MINOR >= 6
#define snd_seq_flush_output(x) snd_seq_drain_output(x)
-#define snd_seq_set_client_group(x,name) /*nop*/
+#define snd_seq_set_client_group(x,name) /*nop */
#define my_snd_seq_open(seqp) snd_seq_open(seqp, "hw", SND_SEQ_OPEN_OUTPUT, 0)
#else
/* SND_SEQ_OPEN_OUT causes oops on early version of ALSA */
@@ -1516,9 +1579,9 @@ void MidiDriver_MIDIEMU::midi_fm_endnote(int voice) {
#define ADDR_DELIM ".:"
-class MidiDriver_ALSA : public MidiDriver {
+class MidiDriver_ALSA:public MidiDriver {
public:
- MidiDriver_ALSA();
+ MidiDriver_ALSA();
int open(int mode);
void close();
void send(uint32 b);
@@ -1527,64 +1590,68 @@ public:
private:
void send_event(int do_flush);
- snd_seq_event_t ev;
+ snd_seq_event_t ev;
StreamCallback *_stream_proc;
- void *_stream_param;
- int _mode;
+ void *_stream_param;
+ int _mode;
snd_seq_t *seq_handle;
int seq_client, seq_port;
int my_client, my_port;
static int parse_addr(char *arg, int *client, int *port);
};
-MidiDriver_ALSA::MidiDriver_ALSA() : _mode(0), seq_handle(0), seq_client(0), seq_port(0), my_client(0), my_port(0) {
+MidiDriver_ALSA::MidiDriver_ALSA():_mode(0), seq_handle(0), seq_client(0), seq_port(0), my_client(0),
+my_port(0)
+{
}
int MidiDriver_ALSA::parse_addr(char *arg, int *client, int *port)
{
- char *p;
+ char *p;
- if (isdigit(*arg)) {
- if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)
- return -1;
- *client = atoi(arg);
- *port = atoi(p + 1);
- } else {
- if (*arg == 's' || *arg == 'S') {
- *client = SND_SEQ_ADDRESS_SUBSCRIBERS;
- *port = 0;
- } else
- return -1;
- }
- return 0;
+ if (isdigit(*arg)) {
+ if ((p = strpbrk(arg, ADDR_DELIM)) == NULL)
+ return -1;
+ *client = atoi(arg);
+ *port = atoi(p + 1);
+ } else {
+ if (*arg == 's' || *arg == 'S') {
+ *client = SND_SEQ_ADDRESS_SUBSCRIBERS;
+ *port = 0;
+ } else
+ return -1;
+ }
+ return 0;
}
void MidiDriver_ALSA::send_event(int do_flush)
{
- snd_seq_ev_set_direct(&ev);
- snd_seq_ev_set_source(&ev, my_port);
- snd_seq_ev_set_dest(&ev, seq_client, seq_port);
+ snd_seq_ev_set_direct(&ev);
+ snd_seq_ev_set_source(&ev, my_port);
+ snd_seq_ev_set_dest(&ev, seq_client, seq_port);
- snd_seq_event_output(seq_handle, &ev);
- if (do_flush)
- snd_seq_flush_output(seq_handle);
+ snd_seq_event_output(seq_handle, &ev);
+ if (do_flush)
+ snd_seq_flush_output(seq_handle);
}
-int MidiDriver_ALSA::open(int mode) {
- char * var;
+int MidiDriver_ALSA::open(int mode)
+{
+ char *var;
unsigned int caps;
-
- if (_mode != 0)
+
+ if (_mode != 0)
return MERR_ALREADY_OPEN;
- _mode=mode;
-
- if (mode!=MO_SIMPLE) return MERR_STREAMING_NOT_AVAILABLE;
-
+ _mode = mode;
+
+ if (mode != MO_SIMPLE)
+ return MERR_STREAMING_NOT_AVAILABLE;
+
if (!(var = getenv("SCUMMVM_PORT"))) {
error("You have to define the environnement variable SCUMMVM_PORT");
return -1;
}
-
+
if (parse_addr(var, &seq_client, &seq_port) < 0) {
error("Invalid port %s", var);
return -1;
@@ -1594,38 +1661,41 @@ int MidiDriver_ALSA::open(int mode) {
error("Can't open sequencer");
return -1;
}
-
+
my_client = snd_seq_client_id(seq_handle);
snd_seq_set_client_name(seq_handle, "SCUMMVM");
snd_seq_set_client_group(seq_handle, "input");
-
+
caps = SND_SEQ_PORT_CAP_READ;
if (seq_client == SND_SEQ_ADDRESS_SUBSCRIBERS)
caps = ~SND_SEQ_PORT_CAP_SUBS_READ;
- my_port = snd_seq_create_simple_port(seq_handle, "SCUMMVM", caps, SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION);
+ my_port =
+ snd_seq_create_simple_port(seq_handle, "SCUMMVM", caps,
+ SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION);
if (my_port < 0) {
- snd_seq_close(seq_handle);
- error("Can't create port");
- return -1;
+ snd_seq_close(seq_handle);
+ error("Can't create port");
+ return -1;
}
- if (seq_client != SND_SEQ_ADDRESS_SUBSCRIBERS) {
- /* subscribe to MIDI port */
- if (snd_seq_connect_to(seq_handle, my_port, seq_client, seq_port) < 0) {
- snd_seq_close(seq_handle);
- error("Can't subscribe to MIDI port (%d:%d)", seq_client, seq_port);
- return -1;
- }
- }
+ if (seq_client != SND_SEQ_ADDRESS_SUBSCRIBERS) {
+ /* subscribe to MIDI port */
+ if (snd_seq_connect_to(seq_handle, my_port, seq_client, seq_port) < 0) {
+ snd_seq_close(seq_handle);
+ error("Can't subscribe to MIDI port (%d:%d)", seq_client, seq_port);
+ return -1;
+ }
+ }
printf("ALSA client initialised [%d:%d]\n", my_client, my_port);
-
+
return 0;
}
-void MidiDriver_ALSA::close() {
+void MidiDriver_ALSA::close()
+{
_mode = 0;
- if (seq_handle)
+ if (seq_handle)
snd_seq_close(seq_handle);
}
@@ -1642,7 +1712,7 @@ void MidiDriver_ALSA::send(uint32 b)
ev.data.raw32.d[0] = midiCmd[0];
ev.data.raw32.d[1] = midiCmd[1];
ev.data.raw32.d[2] = midiCmd[2];
-
+
unsigned char chanID = midiCmd[0] & 0x0F;
switch (midiCmd[0] & 0xF0) {
case 0x80:
@@ -1664,8 +1734,7 @@ void MidiDriver_ALSA::send(uint32 b)
break;
case 0xE0:{
- long theBend =
- ((((long)midiCmd[1] + (long)(midiCmd[2] << 8))) - 0x4000) / 4;
+ long theBend = ((((long)midiCmd[1] + (long)(midiCmd[2] << 8))) - 0x4000) / 4;
snd_seq_ev_set_pitchbend(&ev, chanID, theBend);
send_event(1);
}
@@ -1679,18 +1748,21 @@ void MidiDriver_ALSA::send(uint32 b)
}
}
-void MidiDriver_ALSA::pause(bool pause) {
+void MidiDriver_ALSA::pause(bool pause)
+{
if (_mode == MO_STREAMING) {
/* Err... and what? */
}
}
-void MidiDriver_ALSA::set_stream_callback(void *param, StreamCallback *sc) {
+void MidiDriver_ALSA::set_stream_callback(void *param, StreamCallback *sc)
+{
_stream_param = param;
_stream_proc = sc;
}
-MidiDriver *MidiDriver_ALSA_create() {
+MidiDriver *MidiDriver_ALSA_create()
+{
return new MidiDriver_ALSA();
}
diff --git a/sound/mididrv.h b/sound/mididrv.h
index 977308afe8..bea41556a1 100644
--- a/sound/mididrv.h
+++ b/sound/mididrv.h
@@ -27,14 +27,14 @@ struct MidiEvent {
/* Lowlevel Abstract Midi Driver Class */
class MidiDriver {
-
+
public:
/* called whenever the midi driver is in streaming mode,
* and more midi commands need to be generated
* return 0 to tell the mididriver that the end of stream was reached
*/
- typedef int StreamCallback(void *param, MidiEvent *ev, int num);
-
+ typedef int StreamCallback (void *param, MidiEvent * ev, int num);
+
/* open modes, pass one of those to open() */
enum {
@@ -46,7 +46,7 @@ public:
* event = (ME_xxx<<24) | <24-bit data associated with event>
*/
enum {
- ME_NONE = 0,
+ ME_NONE = 0,
ME_TEMPO = 1,
};
@@ -64,7 +64,7 @@ public:
PROP_TIMEDIV = 1,
};
-
+
/* open the midi driver.
* returns 0 if successful.
* otherwise an error code. */
@@ -88,7 +88,7 @@ public:
/* Get or set a property */
- virtual uint32 property(int prop, uint32 param) ;
+ virtual uint32 property(int prop, uint32 param);
/* retrieve a string representation of an error code */
static const char *get_error_name(int error_code);
diff --git a/sound/mixer.cpp b/sound/mixer.cpp
index 115ca37fb8..cc24bf3a17 100644
--- a/sound/mixer.cpp
+++ b/sound/mixer.cpp
@@ -23,9 +23,10 @@
#include "stdafx.h"
#include "scumm.h"
-void SoundMixer::uninsert(Channel *chan) {
+void SoundMixer::uninsert(Channel * chan)
+{
- for(int i=0; i!=NUM_CHANNELS; i++) {
+ for (int i = 0; i != NUM_CHANNELS; i++) {
if (_channels[i] == chan) {
if (_handles[i]) {
*_handles[i] = 0;
@@ -38,7 +39,8 @@ void SoundMixer::uninsert(Channel *chan) {
error("SoundMixer::channel_deleted chan not found");
}
-int SoundMixer::append(int index, void *sound, uint32 size, uint rate, byte flags) {
+int SoundMixer::append(int index, void *sound, uint32 size, uint rate, byte flags)
+{
_syst->lock_mutex(_mutex);
Channel *chan = _channels[index];
@@ -54,7 +56,8 @@ int SoundMixer::append(int index, void *sound, uint32 size, uint rate, byte flag
return 1;
}
-int SoundMixer::insert_at(PlayingSoundHandle *handle, int index, Channel *chan) {
+int SoundMixer::insert_at(PlayingSoundHandle *handle, int index, Channel * chan)
+{
if (_channels[index] != NULL) {
error("Trying to put a mixer where it cannot go ");
}
@@ -65,13 +68,14 @@ int SoundMixer::insert_at(PlayingSoundHandle *handle, int index, Channel *chan)
return index;
}
-int SoundMixer::insert(PlayingSoundHandle *handle, Channel *chan) {
- for(int i=0; i!=NUM_CHANNELS; i++) {
+int SoundMixer::insert(PlayingSoundHandle *handle, Channel * chan)
+{
+ for (int i = 0; i != NUM_CHANNELS; i++) {
if (_channels[i] == NULL) {
return insert_at(handle, i, chan);
}
}
-
+
warning("SoundMixer::insert out of mixer slots");
chan->real_destroy();
@@ -79,28 +83,35 @@ int SoundMixer::insert(PlayingSoundHandle *handle, Channel *chan) {
}
-int SoundMixer::play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags) {
+int SoundMixer::play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate,
+ byte flags)
+{
return insert(handle, new Channel_RAW(this, sound, size, rate, flags));
}
-int SoundMixer::play_stream(PlayingSoundHandle *handle, int idx, void *sound, uint32 size, uint rate, byte flags) {
+int SoundMixer::play_stream(PlayingSoundHandle *handle, int idx, void *sound, uint32 size,
+ uint rate, byte flags)
+{
return insert_at(handle, idx, new Channel_STREAM(this, sound, size, rate, flags));
}
#ifdef COMPRESSED_SOUND_FILE
-int SoundMixer::play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags) {
+int SoundMixer::play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags)
+{
return insert(handle, new Channel_MP3(this, sound, size, flags));
}
-int SoundMixer::play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, mad_timer_t duration) {
+int SoundMixer::play_mp3_cdtrack(PlayingSoundHandle *handle, FILE * file, mad_timer_t duration)
+{
/* Stop the previously playing CD track (if any) */
return insert(handle, new Channel_MP3_CDMUSIC(this, file, duration));
}
#endif
-void SoundMixer::mix(int16 *buf, uint len) {
+void SoundMixer::mix(int16 *buf, uint len)
+{
if (_paused) {
- memset(buf, 0, 2 * len * sizeof(int16));
+ memset(buf, 0, 2 * len * sizeof(int16));
return;
}
@@ -117,23 +128,25 @@ void SoundMixer::mix(int16 *buf, uint len) {
_syst->lock_mutex(_mutex);
/* now mix all channels */
- for(int i=0; i!=NUM_CHANNELS; i++)
+ for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i])
_channels[i]->mix(buf, len);
_syst->unlock_mutex(_mutex);
}
-void SoundMixer::on_generate_samples(void *s, byte *samples, int len) {
- ((SoundMixer*)s)->mix((int16*)samples, len>>2);
+void SoundMixer::on_generate_samples(void *s, byte *samples, int len)
+{
+ ((SoundMixer *)s)->mix((int16 *)samples, len >> 2);
}
-bool SoundMixer::bind_to_system(OSystem *syst) {
- _volume_table = (int16*)calloc(256*sizeof(int16),1);
-
- uint rate = (uint)syst->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
+bool SoundMixer::bind_to_system(OSystem *syst)
+{
+ _volume_table = (int16 *)calloc(256 * sizeof(int16), 1);
+
+ uint rate = (uint) syst->property(OSystem::PROP_GET_SAMPLE_RATE, 0);
_output_rate = rate;
-
+
_syst = syst;
_mutex = _syst->create_mutex();
@@ -143,56 +156,67 @@ bool SoundMixer::bind_to_system(OSystem *syst) {
return syst->set_sound_proc(this, on_generate_samples, OSystem::SOUND_16BIT);
}
-void SoundMixer::stop_all() {
- for(int i=0; i!=NUM_CHANNELS; i++)
+void SoundMixer::stop_all()
+{
+ for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i])
_channels[i]->destroy();
}
-void SoundMixer::stop(PlayingSoundHandle psh) {
- if (psh && _channels[psh-1])
- _channels[psh-1]->destroy();
+void SoundMixer::stop(PlayingSoundHandle psh)
+{
+ if (psh && _channels[psh - 1])
+ _channels[psh - 1]->destroy();
}
-void SoundMixer::stop(int index) {
+void SoundMixer::stop(int index)
+{
if (_channels[index])
_channels[index]->destroy();
}
-void SoundMixer::pause(bool paused) {
- _paused = paused;
+void SoundMixer::pause(bool paused)
+{
+ _paused = paused;
}
-bool SoundMixer::has_active_channel() {
- for(int i=0; i!=NUM_CHANNELS; i++)
+bool SoundMixer::has_active_channel()
+{
+ for (int i = 0; i != NUM_CHANNELS; i++)
if (_channels[i])
return true;
return false;
}
-void SoundMixer::setup_premix(void *param, PremixProc *proc) {
+void SoundMixer::setup_premix(void *param, PremixProc *proc)
+{
_premix_param = param;
_premix_proc = proc;
}
-void SoundMixer::set_volume(int volume) {
- for(int i=0; i!=256; i++)
- _volume_table[i] =((int8)i) * volume;
+void SoundMixer::set_volume(int volume)
+{
+ for (int i = 0; i != 256; i++)
+ _volume_table[i] = ((int8)i) * volume;
}
#ifdef COMPRESSED_SOUND_FILE
-bool SoundMixer::Channel::sound_finished() {
+bool SoundMixer::Channel::sound_finished()
+{
warning("sound_finished should never be called on a non-MP3 mixer ");
return false;
}
#endif
-void SoundMixer::Channel::append(void *sound, uint32 size) {
+void SoundMixer::Channel::append(void *sound, uint32 size)
+{
error("append method should never be called on something else than a _STREAM mixer ");
}
/* RAW mixer */
-SoundMixer::Channel_RAW::Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags) {
+SoundMixer::Channel_RAW::Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate,
+ byte flags)
+{
_mixer = mixer;
_flags = flags;
_ptr = sound;
@@ -204,15 +228,19 @@ SoundMixer::Channel_RAW::Channel_RAW(SoundMixer *mixer, void *sound, uint32 size
/* adjust the magnitute to prevent division error */
while (size & 0xFFFF0000)
- size >>= 1, rate = (rate>>1) + 1;
+ size >>= 1, rate = (rate >> 1) + 1;
_rate = rate;
_size = size * mixer->_output_rate / rate;
- if (_flags & FLAG_16BITS) _size = _size >> 1;
- if (_flags & FLAG_STEREO) _size = _size >> 1;
+ if (_flags & FLAG_16BITS)
+ _size = _size >> 1;
+ if (_flags & FLAG_STEREO)
+ _size = _size >> 1;
}
-static int16 *mix_signed_mono_8(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_signed_mono_8(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
uint32 fp_pos = *fp_pos_ptr;
byte *s = *s_ptr;
uint len = *len_ptr;
@@ -230,7 +258,9 @@ static int16 *mix_signed_mono_8(int16 *data, uint *len_ptr, byte **s_ptr, uint32
return data;
}
-static int16 *mix_unsigned_mono_8(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_unsigned_mono_8(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
uint32 fp_pos = *fp_pos_ptr;
byte *s = *s_ptr;
uint len = *len_ptr;
@@ -248,12 +278,16 @@ static int16 *mix_unsigned_mono_8(int16 *data, uint *len_ptr, byte **s_ptr, uint
return data;
}
-static int16 *mix_signed_stereo_8(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_signed_stereo_8(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
warning("Mixing stereo signed 8 bit is not supported yet ");
return data;
}
-static int16 *mix_unsigned_stereo_8(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_unsigned_stereo_8(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
uint32 fp_pos = *fp_pos_ptr;
byte *s = *s_ptr;
uint len = *len_ptr;
@@ -271,9 +305,11 @@ static int16 *mix_unsigned_stereo_8(int16 *data, uint *len_ptr, byte **s_ptr, ui
return data;
}
-static int16 *mix_signed_mono_16(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_signed_mono_16(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
uint32 fp_pos = *fp_pos_ptr;
- unsigned char volume = ((int) vol_tab[1]) * 32 / 255;
+ unsigned char volume = ((int)vol_tab[1]) * 32 / 255;
byte *s = *s_ptr;
uint len = *len_ptr;
do {
@@ -291,19 +327,23 @@ static int16 *mix_signed_mono_16(int16 *data, uint *len_ptr, byte **s_ptr, uint3
return data;
}
-static int16 *mix_unsigned_mono_16(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_unsigned_mono_16(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
warning("Mixing mono unsigned 16 bit is not supported yet ");
return data;
}
-static int16 *mix_signed_stereo_16(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_signed_stereo_16(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
uint32 fp_pos = *fp_pos_ptr;
- unsigned char volume = ((int) vol_tab[1]) * 32 / 255;
+ unsigned char volume = ((int)vol_tab[1]) * 32 / 255;
byte *s = *s_ptr;
uint len = *len_ptr;
do {
fp_pos += fp_speed;
- *data++ += (((int16)(*(s ) << 8) | *(s + 1)) * volume) / 32;
+ *data++ += (((int16)(*(s) << 8) | *(s + 1)) * volume) / 32;
*data++ += (((int16)(*(s + 2) << 8) | *(s + 3)) * volume) / 32;
s += (fp_pos >> 16) << 2;
fp_pos &= 0x0000FFFF;
@@ -315,24 +355,22 @@ static int16 *mix_signed_stereo_16(int16 *data, uint *len_ptr, byte **s_ptr, uin
return data;
}
-static int16 *mix_unsigned_stereo_16(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) {
+static int16 *mix_unsigned_stereo_16(int16 *data, uint * len_ptr, byte **s_ptr, uint32 *fp_pos_ptr,
+ int fp_speed, const int16 *vol_tab, byte *s_end)
+{
warning("Mixing stereo unsigned 16 bit is not supported yet ");
return data;
}
-static int16 *(*mixer_helper_table[16])(int16 *data, uint *len_ptr, byte **s_ptr, uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab, byte *s_end) = {
- mix_signed_mono_8,
- mix_unsigned_mono_8,
- mix_signed_stereo_8,
- mix_unsigned_stereo_8,
- mix_signed_mono_16,
- mix_unsigned_mono_16,
- mix_signed_stereo_16,
- mix_unsigned_stereo_16
-};
+static int16 *(*mixer_helper_table[16]) (int16 *data, uint * len_ptr, byte **s_ptr,
+ uint32 *fp_pos_ptr, int fp_speed, const int16 *vol_tab,
+ byte *s_end) = {
+mix_signed_mono_8, mix_unsigned_mono_8, mix_signed_stereo_8, mix_unsigned_stereo_8,
+ mix_signed_mono_16, mix_unsigned_mono_16, mix_signed_stereo_16, mix_unsigned_stereo_16};
-void SoundMixer::Channel_RAW::mix(int16 *data, uint len) {
+void SoundMixer::Channel_RAW::mix(int16 *data, uint len)
+{
byte *s, *s_org = NULL;
uint32 fp_pos;
byte *end;
@@ -353,29 +391,29 @@ void SoundMixer::Channel_RAW::mix(int16 *data, uint len) {
/* determine how many samples to read from the file */
uint num = len * _fp_speed >> 16;
- s_org = (byte*)malloc(num);
+ s_org = (byte *)malloc(num);
if (s_org == NULL)
error("Channel_RAW::mix out of memory");
-
- uint num_read = fread(s_org, 1, num, (FILE*)_ptr);
+
+ uint num_read = fread(s_org, 1, num, (FILE *) _ptr);
if (num - num_read != 0)
memset(s_org + num_read, 0x80, num - num_read);
-
+
s = s_org;
fp_pos = 0;
end = s_org + num;
} else {
- s = (byte*)_ptr + _pos;
+ s = (byte *)_ptr + _pos;
fp_pos = _fp_pos;
- end = (byte *) _ptr + _realsize;
+ end = (byte *)_ptr + _realsize;
}
const uint32 fp_speed = _fp_speed;
const int16 *vol_tab = _mixer->_volume_table;
- mixer_helper_table[_flags & 0x07](data, &len, &s, &fp_pos, fp_speed, vol_tab, end);
+ mixer_helper_table[_flags & 0x07] (data, &len, &s, &fp_pos, fp_speed, vol_tab, end);
- _pos = s - (byte*) _ptr;
+ _pos = s - (byte *)_ptr;
_fp_pos = fp_pos;
if (_flags & FLAG_FILE) {
@@ -387,7 +425,8 @@ void SoundMixer::Channel_RAW::mix(int16 *data, uint len) {
}
-void SoundMixer::Channel_RAW::real_destroy() {
+void SoundMixer::Channel_RAW::real_destroy()
+{
if (_flags & FLAG_AUTOFREE)
free(_ptr);
_mixer->uninsert(this);
@@ -395,11 +434,13 @@ void SoundMixer::Channel_RAW::real_destroy() {
}
/* STREAM mixer */
-SoundMixer::Channel_STREAM::Channel_STREAM(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags) {
+SoundMixer::Channel_STREAM::Channel_STREAM(SoundMixer *mixer, void *sound, uint32 size, uint rate,
+ byte flags)
+{
_mixer = mixer;
_flags = flags;
_buffer_size = 1024 * size;
- _ptr = (byte *) malloc(_buffer_size);
+ _ptr = (byte *)malloc(_buffer_size);
memcpy(_ptr, sound, size);
_end_of_data = _ptr + size;
if (_flags & FLAG_AUTOFREE)
@@ -411,36 +452,37 @@ SoundMixer::Channel_STREAM::Channel_STREAM(SoundMixer *mixer, void *sound, uint3
/* adjust the magnitute to prevent division error */
while (size & 0xFFFF0000)
- size >>= 1, rate = (rate>>1) + 1;
+ size >>= 1, rate = (rate >> 1) + 1;
_rate = rate;
}
-void SoundMixer::Channel_STREAM::append(void *data, uint32 len) {
+void SoundMixer::Channel_STREAM::append(void *data, uint32 len)
+{
byte *new_end = _end_of_data + len;
- byte *cur_pos = _pos; /* This is just to prevent the variable to move during the tests :-) */
+ byte *cur_pos = _pos; /* This is just to prevent the variable to move during the tests :-) */
if (new_end > (_ptr + _buffer_size)) {
/* Wrap-around case */
- if ((_end_of_data < cur_pos) ||
- (new_end >= cur_pos)) {
+ if ((_end_of_data < cur_pos) || (new_end >= cur_pos)) {
warning("Mixer full... Trying to not break too much ");
- return;
+ return;
}
memcpy(_end_of_data, data, (_ptr + _buffer_size) - _end_of_data);
- memcpy(_ptr, (byte *) data + ((_ptr + _buffer_size) - _end_of_data), len - ((_ptr + _buffer_size) - _end_of_data));
+ memcpy(_ptr, (byte *)data + ((_ptr + _buffer_size) - _end_of_data),
+ len - ((_ptr + _buffer_size) - _end_of_data));
} else {
- if ((_end_of_data < cur_pos) &&
- (new_end >= cur_pos)) {
+ if ((_end_of_data < cur_pos) && (new_end >= cur_pos)) {
warning("Mixer full... Trying to not break too much ");
- return;
+ return;
}
memcpy(_end_of_data, data, len);
}
_end_of_data = new_end;
}
-void SoundMixer::Channel_STREAM::mix(int16 *data, uint len) {
+void SoundMixer::Channel_STREAM::mix(int16 *data, uint len)
+{
uint32 fp_pos;
const uint32 fp_speed = _fp_speed;
const int16 *vol_tab = _mixer->_volume_table;
@@ -454,16 +496,18 @@ void SoundMixer::Channel_STREAM::mix(int16 *data, uint len) {
fp_pos = _fp_pos;
if (_pos < end_of_data) {
- mixer_helper_table[_flags & 0x07](data, &len, &_pos, &fp_pos, fp_speed, vol_tab, end_of_data);
+ mixer_helper_table[_flags & 0x07] (data, &len, &_pos, &fp_pos, fp_speed, vol_tab, end_of_data);
} else {
- mixer_helper_table[_flags & 0x07](data, &len, &_pos, &fp_pos, fp_speed, vol_tab, _ptr + _buffer_size);
+ mixer_helper_table[_flags & 0x07] (data, &len, &_pos, &fp_pos, fp_speed, vol_tab,
+ _ptr + _buffer_size);
if (len != 0) {
_pos = _ptr;
- mixer_helper_table[_flags & 0x07](data, &len, &_pos, &fp_pos, fp_speed, vol_tab, end_of_data);
+ mixer_helper_table[_flags & 0x07] (data, &len, &_pos, &fp_pos, fp_speed, vol_tab,
+ end_of_data);
} else
_to_be_destroyed = true;
- }
- if (len != 0) {
+ }
+ if (len != 0) {
// FIXME: BBrox, what does this mean? :)
// Commented by Ender to remove non-existant
// streamer bug in Dig smush movies.
@@ -474,7 +518,8 @@ void SoundMixer::Channel_STREAM::mix(int16 *data, uint len) {
_fp_pos = fp_pos;
}
-void SoundMixer::Channel_STREAM::real_destroy() {
+void SoundMixer::Channel_STREAM::real_destroy()
+{
free(_ptr);
_mixer->uninsert(this);
delete this;
@@ -484,7 +529,8 @@ void SoundMixer::Channel_STREAM::real_destroy() {
/* MP3 mixer goes here */
#ifdef COMPRESSED_SOUND_FILE
-SoundMixer::Channel_MP3::Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags) {
+SoundMixer::Channel_MP3::Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags)
+{
_mixer = mixer;
_flags = flags;
_pos_in_frame = 0xFFFFFFFF;
@@ -492,7 +538,7 @@ SoundMixer::Channel_MP3::Channel_MP3(SoundMixer *mixer, void *sound, uint size,
_size = size;
_ptr = sound;
_to_be_destroyed = false;
-
+
mad_stream_init(&_stream);
#ifdef _WIN32_WCE
// 11 kHz on WinCE
@@ -530,10 +576,11 @@ static inline int scale_sample(mad_fixed_t sample)
return sample >> (MAD_F_FRACBITS + 2 - 16);
}
-void SoundMixer::Channel_MP3::mix(int16 *data, uint len) {
+void SoundMixer::Channel_MP3::mix(int16 *data, uint len)
+{
mad_fixed_t const *ch;
const int16 *vol_tab = _mixer->_volume_table;
- unsigned char volume = ((int) vol_tab[1]) * 32 / 255;
+ unsigned char volume = ((int)vol_tab[1]) * 32 / 255;
if (_to_be_destroyed) {
real_destroy();
@@ -546,7 +593,7 @@ void SoundMixer::Channel_MP3::mix(int16 *data, uint len) {
if (_silence_cut > 0) {
_silence_cut--;
} else {
- int16 sample = (int16) ((scale_sample(*ch++) * volume) / 32);
+ int16 sample = (int16)((scale_sample(*ch++) * volume) / 32);
*data++ += sample;
*data++ += sample;
len--;
@@ -555,13 +602,14 @@ void SoundMixer::Channel_MP3::mix(int16 *data, uint len) {
}
if (len == 0)
return;
-
+
if (_position >= _size) {
real_destroy();
return;
}
- mad_stream_buffer(&_stream, ((unsigned char *)_ptr) + _position, _size + MAD_BUFFER_GUARD - _position);
+ mad_stream_buffer(&_stream, ((unsigned char *)_ptr) + _position,
+ _size + MAD_BUFFER_GUARD - _position);
if (mad_frame_decode(&_frame, &_stream) == -1) {
/* End of audio... */
@@ -578,7 +626,8 @@ void SoundMixer::Channel_MP3::mix(int16 *data, uint len) {
}
}
-void SoundMixer::Channel_MP3::real_destroy() {
+void SoundMixer::Channel_MP3::real_destroy()
+{
if (_flags & FLAG_AUTOFREE)
free(_ptr);
_mixer->uninsert(this);
@@ -592,7 +641,9 @@ void SoundMixer::Channel_MP3::real_destroy() {
/* MP3 CD music */
#define MP3CD_BUFFERING_SIZE 131072
-SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, mad_timer_t duration) {
+SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE * file,
+ mad_timer_t duration)
+{
_mixer = mixer;
_file = file;
_duration = duration;
@@ -610,11 +661,12 @@ SoundMixer::Channel_MP3_CDMUSIC::Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* fi
mad_synth_init(&_synth);
}
-void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
+void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len)
+{
mad_fixed_t const *ch;
mad_timer_t frame_duration;
const int16 *vol_tab = _mixer->_volume_table;
- unsigned char volume = ((int) vol_tab[1]) * 32 / 255;
+ unsigned char volume = ((int)vol_tab[1]) * 32 / 255;
if (_to_be_destroyed) {
real_destroy();
@@ -624,17 +676,17 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
if (!_initialized) {
int skip_loop;
// just skipped
- memset(_ptr, 0,_buffer_size);
+ memset(_ptr, 0, _buffer_size);
_size = fread(_ptr, 1, _buffer_size, _file);
if (!_size) {
- real_destroy();
- return;
+ real_destroy();
+ return;
}
// Resync
- mad_stream_buffer(&_stream,(unsigned char *)_ptr,_size);
+ mad_stream_buffer(&_stream, (unsigned char *)_ptr, _size);
skip_loop = 2;
while (skip_loop != 0) {
- if (mad_frame_decode(&_frame,&_stream) == 0) {
+ if (mad_frame_decode(&_frame, &_stream) == 0) {
/* Do not decrease duration - see if it's a problem */
skip_loop--;
if (skip_loop == 0) {
@@ -652,7 +704,7 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
mad_frame_mute(&_frame);
mad_synth_mute(&_synth);
// Resume decoding
- if (mad_frame_decode(&_frame,&_stream) == 0) {
+ if (mad_frame_decode(&_frame, &_stream) == 0) {
_pos_in_frame = 0;
_initialized = true;
} else {
@@ -662,11 +714,11 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
}
}
- while(1) {
+ while (1) {
// Get samples, play samples ...
ch = _synth.pcm.samples[0] + _pos_in_frame;
while ((_pos_in_frame < _synth.pcm.length) && (len > 0)) {
- int16 sample = (int16) ((scale_sample(*ch++) * volume) / 32);
+ int16 sample = (int16)((scale_sample(*ch++) * volume) / 32);
*data++ += sample;
*data++ += sample;
len--;
@@ -687,12 +739,12 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
if (!_stream.next_frame) {
memset(_ptr, 0, _buffer_size + MAD_BUFFER_GUARD);
- _size = fread(_ptr, 1, _buffer_size, _file);
+ _size = fread(_ptr, 1, _buffer_size, _file);
not_decoded = 0;
} else {
not_decoded = _stream.bufend - _stream.next_frame;
memcpy(_ptr, _stream.next_frame, not_decoded);
- _size = fread((unsigned char *)_ptr + not_decoded, 1, _buffer_size - not_decoded, _file);
+ _size = fread((unsigned char *)_ptr + not_decoded, 1, _buffer_size - not_decoded, _file);
}
_stream.error = (enum mad_error)0;
// Restream
@@ -709,11 +761,13 @@ void SoundMixer::Channel_MP3_CDMUSIC::mix(int16 *data, uint len) {
}
}
-bool SoundMixer::Channel_MP3_CDMUSIC::sound_finished() {
+bool SoundMixer::Channel_MP3_CDMUSIC::sound_finished()
+{
return mad_timer_compare(_duration, mad_timer_zero) <= 0;
}
-void SoundMixer::Channel_MP3_CDMUSIC::real_destroy() {
+void SoundMixer::Channel_MP3_CDMUSIC::real_destroy()
+{
free(_ptr);
_mixer->uninsert(this);
mad_synth_finish(&_synth);
@@ -725,5 +779,3 @@ void SoundMixer::Channel_MP3_CDMUSIC::real_destroy() {
#endif
-
-
diff --git a/sound/mixer.h b/sound/mixer.h
index ac38312b19..531cfc9c69 100644
--- a/sound/mixer.h
+++ b/sound/mixer.h
@@ -29,20 +29,21 @@
typedef uint32 PlayingSoundHandle;
class SoundMixer {
-private:
+private:
class Channel {
public:
bool _to_be_destroyed;
virtual void mix(int16 *data, uint len) = 0;
- void destroy() { _to_be_destroyed = true; }
- virtual void real_destroy() = 0;
+ void destroy() {
+ _to_be_destroyed = true;
+ } virtual void real_destroy() = 0;
virtual void append(void *sound, uint32 size);
#ifdef COMPRESSED_SOUND_FILE
virtual bool sound_finished();
#endif
};
- class Channel_RAW : public Channel {
+ class Channel_RAW:public Channel {
SoundMixer *_mixer;
void *_ptr;
uint32 _pos;
@@ -51,15 +52,15 @@ private:
uint32 _fp_pos;
uint32 _realsize, _rate;
byte _flags;
-
+
public:
void mix(int16 *data, uint len);
- Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags);
+ Channel_RAW(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags);
void real_destroy();
};
- class Channel_STREAM : public Channel {
+ class Channel_STREAM:public Channel {
SoundMixer *_mixer;
byte *_ptr;
byte *_end_of_data;
@@ -71,15 +72,15 @@ private:
byte _flags;
public:
- void append(void *sound, uint32 size);
+ void append(void *sound, uint32 size);
void mix(int16 *data, uint len);
- Channel_STREAM(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags);
+ Channel_STREAM(SoundMixer *mixer, void *sound, uint32 size, uint rate, byte flags);
void real_destroy();
};
#ifdef COMPRESSED_SOUND_FILE
- class Channel_MP3 : public Channel {
+ class Channel_MP3:public Channel {
SoundMixer *_mixer;
void *_ptr;
struct mad_stream _stream;
@@ -93,12 +94,12 @@ private:
public:
void mix(int16 *data, uint len);
- Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags);
+ Channel_MP3(SoundMixer *mixer, void *sound, uint size, byte flags);
void real_destroy();
};
- class Channel_MP3_CDMUSIC : public Channel {
+ class Channel_MP3_CDMUSIC:public Channel {
SoundMixer *_mixer;
void *_ptr;
struct mad_stream _stream;
@@ -108,12 +109,12 @@ private:
uint32 _size;
uint32 _buffer_size;
mad_timer_t _duration;
- FILE *_file;
+ FILE *_file;
bool _initialized;
public:
void mix(int16 *data, uint len);
- Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE* file, mad_timer_t duration);
- void real_destroy();
+ Channel_MP3_CDMUSIC(SoundMixer *mixer, FILE * file, mad_timer_t duration);
+ void real_destroy();
bool sound_finished();
};
@@ -122,11 +123,11 @@ private:
static void on_generate_samples(void *s, byte *samples, int len);
public:
- typedef void PremixProc(void *param, int16 *data, uint len);
+ typedef void PremixProc (void *param, int16 *data, uint len);
OSystem *_syst;
void *_mutex;
-
+
uint _output_rate;
int16 *_volume_table;
@@ -143,25 +144,26 @@ public:
Channel *_channels[NUM_CHANNELS];
PlayingSoundHandle *_handles[NUM_CHANNELS];
- int insert(PlayingSoundHandle *handle, Channel *chan);
- int insert_at(PlayingSoundHandle *handle, int index, Channel *chan);
+ int insert(PlayingSoundHandle *handle, Channel * chan);
+ int insert_at(PlayingSoundHandle *handle, int index, Channel * chan);
void append(void *data, uint32 len);
- void uninsert(Channel *chan);
+ void uninsert(Channel * chan);
/* start playing a raw sound */
enum {
/* Do *NOT* change any of these flags without looking at the code in mixer.cpp */
- FLAG_UNSIGNED = 1, /* unsigned samples */
- FLAG_STEREO = 2, /* sound is in stereo */
- FLAG_16BITS = 4, /* sound is 16 bits wide */
- FLAG_AUTOFREE = 8, /* sound buffer is freed automagically at the end of playing */
- FLAG_FILE = 16, /* sound is a FILE * that's read from */
+ FLAG_UNSIGNED = 1, /* unsigned samples */
+ FLAG_STEREO = 2, /* sound is in stereo */
+ FLAG_16BITS = 4, /* sound is 16 bits wide */
+ FLAG_AUTOFREE = 8, /* sound buffer is freed automagically at the end of playing */
+ FLAG_FILE = 16, /* sound is a FILE * that's read from */
};
int play_raw(PlayingSoundHandle *handle, void *sound, uint32 size, uint rate, byte flags);
- int play_stream(PlayingSoundHandle *handle, int index, void *sound, uint32 size, uint rate, byte flags);
+ int play_stream(PlayingSoundHandle *handle, int index, void *sound, uint32 size, uint rate,
+ byte flags);
#ifdef COMPRESSED_SOUND_FILE
int play_mp3(PlayingSoundHandle *handle, void *sound, uint32 size, byte flags);
- int play_mp3_cdtrack(PlayingSoundHandle *handle, FILE* file, mad_timer_t duration);
+ int play_mp3_cdtrack(PlayingSoundHandle *handle, FILE * file, mad_timer_t duration);
#endif
/* Premix procedure, useful when using fmopl adlib */
@@ -196,16 +198,16 @@ public:
};
-struct MP3OffsetTable { /* Compressed Sound (.SO3) */
+struct MP3OffsetTable { /* Compressed Sound (.SO3) */
int org_offset;
int new_offset;
int num_tags;
int compressed_size;
};
-struct BundleAudioTable { /* Dig/CMI .bun audio */
- char filename[13];
- int size;
- int offset;
+struct BundleAudioTable { /* Dig/CMI .bun audio */
+ char filename[13];
+ int size;
+ int offset;
};
#endif /* _mixer_h_included */