public void StartSound(int nr) { Debug.Assert(_vm != null); var data = _vm.ResourceManager.GetSound(_vm.Sound.MusicType, nr); Debug.Assert(data != null); if ((_vm.Game.GameId != GameId.Indy3) && (_vm.Game.GameId != GameId.Loom)) Debug.WriteLine("player_v3a - unknown game"); if (!_isinit) { int i; int offset = 4; int numInstruments; byte[] ptr; if (_vm.Game.GameId == GameId.Indy3) { ptr = _vm.ResourceManager.GetSound(_vm.Sound.MusicType, 83); numInstruments = 12; } else { ptr = _vm.ResourceManager.GetSound(_vm.Sound.MusicType, 79); numInstruments = 9; } Debug.Assert(ptr != null); _wavetable = new instData[numInstruments + 1]; for (i = 0; i < numInstruments; i++) { _wavetable[i] = new instData(); for (int j = 0; j < 6; j++) { int off, len; off = ptr.ToUInt16BigEndian(offset); len = ptr.ToUInt16BigEndian(offset + 2); _wavetable[i]._ilen[j] = (ushort)len; if (len != 0) { _wavetable[i]._idat[j] = new byte[len]; Array.Copy(ptr, off, _wavetable[i]._idat[j], 0, len); } else _wavetable[i]._idat[j] = null; off = ptr.ToUInt16BigEndian(offset + 4); len = ptr.ToUInt16BigEndian(offset + 6); _wavetable[i]._llen[j] = (ushort)len; if (len != 0) { _wavetable[i]._ldat[j] = new byte[len]; Array.Copy(ptr, off, _wavetable[i]._ldat[j], 0, len); } else _wavetable[i]._ldat[j] = null; _wavetable[i]._oct[j] = ptr.ToUInt16BigEndian(offset + 8); offset += 10; } if (_vm.Game.GameId == GameId.Indy3) { _wavetable[i]._pitadjust = 0; offset += 2; } else { _wavetable[i]._pitadjust = ptr.ToInt16BigEndian(offset + 2); offset += 4; } } _wavetable[i] = null; _isinit = true; } if (GetSoundStatus(nr) != 0) StopSound(nr); // if a sound is playing, restart it if (data[26] != 0) { if (_curSong != 0) StopSound(_curSong); _curSong = nr; _songData = data; _songPtr = 0x1C; _songDelay = 1; _music_timer = 0; } else { int size = data.ToUInt16BigEndian(12); int rate = 3579545 / data.ToUInt16BigEndian(20); var sound = new byte[size]; int vol = (data[24] << 1) | (data[24] >> 5); // if I boost this to 0-255, it gets too loud and starts to clip Array.Copy(data, data.ToUInt16BigEndian(8), sound, 0, size); int loopStart = 0, loopEnd = 0; int loopcount = data[27]; if (loopcount > 1) { loopStart = data.ToUInt16BigEndian(10) - data.ToUInt16BigEndian(8); loopEnd = data.ToUInt16BigEndian(14); } int i = getSfxChan(); if (i == -1) { return; } _sfx[i].id = nr; _sfx[i].dur = 1 + loopcount * 60 * size / rate; if (data.ToUInt16BigEndian(16) != 0) { _sfx[i].rate = (uint)(data.ToUInt16BigEndian(20) << 16); _sfx[i].delta = data.ToInt32BigEndian(32); _sfx[i].dur = data.ToInt32BigEndian(40); } else { _sfx[i].delta = 0; } _mod.StartChannel(nr | 0x100, sound, size, rate, vol, loopStart, loopEnd); } }
public void StartSound(int nr) { Debug.Assert(_vm != null); var data = _vm.ResourceManager.GetSound(_vm.Sound.MusicType, nr); Debug.Assert(data != null); if ((_vm.Game.GameId != GameId.Indy3) && (_vm.Game.GameId != GameId.Loom)) { Debug.WriteLine("player_v3a - unknown game"); } if (!_isinit) { int i; int offset = 4; int numInstruments; byte[] ptr; if (_vm.Game.GameId == GameId.Indy3) { ptr = _vm.ResourceManager.GetSound(_vm.Sound.MusicType, 83); numInstruments = 12; } else { ptr = _vm.ResourceManager.GetSound(_vm.Sound.MusicType, 79); numInstruments = 9; } Debug.Assert(ptr != null); _wavetable = new instData[numInstruments + 1]; for (i = 0; i < numInstruments; i++) { _wavetable[i] = new instData(); for (int j = 0; j < 6; j++) { int off, len; off = ptr.ToUInt16BigEndian(offset); len = ptr.ToUInt16BigEndian(offset + 2); _wavetable[i]._ilen[j] = (ushort)len; if (len != 0) { _wavetable[i]._idat[j] = new byte[len]; Array.Copy(ptr, off, _wavetable[i]._idat[j], 0, len); } else { _wavetable[i]._idat[j] = null; } off = ptr.ToUInt16BigEndian(offset + 4); len = ptr.ToUInt16BigEndian(offset + 6); _wavetable[i]._llen[j] = (ushort)len; if (len != 0) { _wavetable[i]._ldat[j] = new byte[len]; Array.Copy(ptr, off, _wavetable[i]._ldat[j], 0, len); } else { _wavetable[i]._ldat[j] = null; } _wavetable[i]._oct[j] = ptr.ToUInt16BigEndian(offset + 8); offset += 10; } if (_vm.Game.GameId == GameId.Indy3) { _wavetable[i]._pitadjust = 0; offset += 2; } else { _wavetable[i]._pitadjust = ptr.ToInt16BigEndian(offset + 2); offset += 4; } } _wavetable[i] = null; _isinit = true; } if (GetSoundStatus(nr) != 0) { StopSound(nr); // if a sound is playing, restart it } if (data[26] != 0) { if (_curSong != 0) { StopSound(_curSong); } _curSong = nr; _songData = data; _songPtr = 0x1C; _songDelay = 1; _music_timer = 0; } else { int size = data.ToUInt16BigEndian(12); int rate = 3579545 / data.ToUInt16BigEndian(20); var sound = new byte[size]; int vol = (data[24] << 1) | (data[24] >> 5); // if I boost this to 0-255, it gets too loud and starts to clip Array.Copy(data, data.ToUInt16BigEndian(8), sound, 0, size); int loopStart = 0, loopEnd = 0; int loopcount = data[27]; if (loopcount > 1) { loopStart = data.ToUInt16BigEndian(10) - data.ToUInt16BigEndian(8); loopEnd = data.ToUInt16BigEndian(14); } int i = getSfxChan(); if (i == -1) { return; } _sfx[i].id = nr; _sfx[i].dur = 1 + loopcount * 60 * size / rate; if (data.ToUInt16BigEndian(16) != 0) { _sfx[i].rate = (uint)(data.ToUInt16BigEndian(20) << 16); _sfx[i].delta = data.ToInt32BigEndian(32); _sfx[i].dur = data.ToInt32BigEndian(40); } else { _sfx[i].delta = 0; } _mod.StartChannel(nr | 0x100, sound, size, rate, vol, loopStart, loopEnd); } }