public override void NoteOn(byte note, byte velocity) { if (!_allocated) { return; } _out.note = note; _out.sustainNoteOff = 0; _out.length = _instrument[0]; if (_instrument[4] < PCSpeakerDriver._outInstrumentData.Length) { _out.instrument = PCSpeakerDriver._outInstrumentData[_instrument[4]]; } else { _out.instrument = null; } _out.unkA = 0; _out.unkB = _instrument[1]; _out.unkC = _instrument[2]; _out.unkE = 0; _out.unk60 = 0; _out.active = 1; // In case we get a note on event on the last active channel, we reset the // last active channel, thus we assure the frequency is correctly set, even // when the same note was sent. if (_owner._lastActiveChannel == this) { _owner._lastActiveChannel = null; _owner._lastActiveOut = 0; } _owner.UpdateNote(); _out.unkC += PCSpeakerDriver.GetEffectModifier((ushort)(_instrument[3] + ((velocity & 0xFE) << 4))); if (_out.unkC > 63) { _out.unkC = 63; } if ((_instrument[5] & 0x80) != 0) { _owner.SetupEffects(this, _out.effectEnvelopeA, _out.effectDefA, _instrument[5], _instrument, 6); } if ((_instrument[14] & 0x80) != 0) { _owner.SetupEffects(this, _out.effectEnvelopeB, _out.effectDefB, _instrument[14], _instrument, 15); } }
public void Init(PCSpeakerDriver owner, int channel) { _owner = owner; _channel = channel; _allocated = false; }
void SetupMusic() { var selectedDevice = Settings.AudioDevice; var deviceHandle = MidiDriver.DetectDevice(Game.Music, selectedDevice); switch (MidiDriver.GetMusicType(deviceHandle)) { case MusicType.Null: Sound.MusicType = MusicDriverTypes.None; break; case MusicType.PCSpeaker: Sound.MusicType = MusicDriverTypes.PCSpeaker; break; case MusicType.PCjr: Sound.MusicType = MusicDriverTypes.PCjr; break; case MusicType.CMS: Sound.MusicType = MusicDriverTypes.CMS; break; case MusicType.FMTowns: Sound.MusicType = MusicDriverTypes.FMTowns; break; case MusicType.AdLib: Sound.MusicType = MusicDriverTypes.AdLib; break; case MusicType.C64: Sound.MusicType = MusicDriverTypes.C64; break; case MusicType.AppleIIGS: Sound.MusicType = MusicDriverTypes.AppleIIGS; break; default: Sound.MusicType = MusicDriverTypes.Midi; break; } // Init iMuse if (Game.Version >= 7) { // Setup for digital iMuse is performed in another place // HACK: don't know why I have to keep this to work var adlibMidiDriver = (MidiDriver)MidiDriver.CreateMidi(Mixer, MidiDriver.DetectDevice(MusicDriverTypes.AdLib, "adlib")); // Setup for digital iMuse is performed in another place Audio.IMuse.IMuse.Create(null, adlibMidiDriver); } else if (Game.Platform == Platform.Apple2GS && Game.Version == 0) { MusicEngine = new Player_AppleII(this, Mixer); } else if (Game.Platform == Platform.C64 && Game.Version <= 1) { var sid = new SID(); MusicEngine = new Player_SID(this, Mixer, sid); } else if (_game.Platform == Platform.Amiga && Game.Version == 2) { var modPlayer = new Player_MOD(Mixer); MusicEngine = new Player_V2A(this, modPlayer); } else if (Game.Platform == Platform.Amiga && Game.Version == 3) { var modPlayer = new Player_MOD(Mixer); MusicEngine = new Player_V3A(this, modPlayer); } else if (Game.Platform == Platform.Amiga && Game.Version <= 4) { MusicEngine = new Player_V4A(this, Mixer); } else if (Game.Platform == Platform.Macintosh && Game.GameId == GameId.Loom) { MusicEngine = new Player_V3M(this, Mixer); } else if (Game.Platform == Platform.Macintosh && Game.GameId == GameId.Monkey1) { MusicEngine = new Player_V5M(this, Mixer); } else if (Game.GameId == GameId.Maniac && Game.Version == 1) { MusicEngine = new Player_V1(this, Mixer, Sound.MusicType == MusicDriverTypes.PCjr); } else if ((Sound.MusicType == MusicDriverTypes.PCSpeaker || Sound.MusicType == MusicDriverTypes.PCjr) && (Game.Version >= 2 && Game.Version <= 4)) { MusicEngine = new Player_V2(this, Mixer, Sound.MusicType == MusicDriverTypes.PCjr); } else if (Sound.MusicType == MusicDriverTypes.CMS) { MusicEngine = new Player_V2CMS(this, Mixer); } else if (Game.Platform == Platform.FMTowns && (Game.Version == 3 || Game.GameId == GameId.Monkey1)) { MusicEngine = TownsPlayer = new Player_Towns_v1(this, Mixer); if (!TownsPlayer.Init()) Debug.WriteLine("Failed to initialize FM-Towns audio driver"); } else if (Game.GameId == GameId.Loom || Game.GameId == GameId.Indy3) { MusicEngine = new Player_AD(this, Mixer); } else { MidiDriver nativeMidiDriver = null; MidiDriver adlibMidiDriver = null; if (Sound.MusicType == MusicDriverTypes.AdLib || Sound.MusicType == MusicDriverTypes.FMTowns) { adlibMidiDriver = (MidiDriver)MidiDriver.CreateMidi(Mixer, MidiDriver.DetectDevice(Sound.MusicType == MusicDriverTypes.FMTowns ? MusicDriverTypes.FMTowns : MusicDriverTypes.AdLib, selectedDevice)); adlibMidiDriver.Property(AdlibMidiDriver.PropertyOldAdLib, (Game.Version < 5) ? 1 : 0); adlibMidiDriver.Property(AdlibMidiDriver.PropertyScummOPL3, (Game.GameId == GameId.SamNMax) ? 1 : 0); } else if (Sound.MusicType == MusicDriverTypes.PCSpeaker) { adlibMidiDriver = new PCSpeakerDriver(Mixer); } IMuse = Audio.IMuse.IMuse.Create(nativeMidiDriver, adlibMidiDriver); if (Game.Platform == Platform.FMTowns) { MusicEngine = TownsPlayer = new Player_Towns_v2(this, Mixer, IMuse, true); if (!TownsPlayer.Init()) throw new InvalidOperationException("ScummEngine::setupMusic(): Failed to initialize FM-Towns audio driver"); } else { MusicEngine = IMuse; } if (IMuse != null) { IMuse.AddSysexHandler(0x7D, Game.GameId == GameId.SamNMax ? new SysExFunc(new SamAndMaxSysEx().Do) : new SysExFunc(new ScummSysEx().Do)); IMuse.Property(ImuseProperty.GameId, (uint)Game.GameId); // IMuse.Property(ImuseProperty.NativeMt32, _native_mt32); // if (MidiDriver.GetMusicType(deviceHandle) != MusicType.MT32) // MT-32 Emulation shouldn't be GM/GS initialized // IMuse.Property(ImuseProperty.Gs, _enable_gs); if (Sound.MusicType == MusicDriverTypes.PCSpeaker) IMuse.Property(ImuseProperty.PcSpeaker, 1); } } if (MusicEngine != null) { MusicEngine.SetMusicVolume(192); } }