public void Clear() { TrackId = 0; pan = 0; vol = 0; VolFadeDest = 0; VolFadeStep = 0; VolFadeDelay = 0; VolFadeUsed = false; // SoundId = 0; SoundName = null; Used = false; ToBeRemoved = false; SouStreamUsed = false; SndDataExtComp = false; SoundPriority = 0; RegionOffset = 0; DataOffset = 0; CurRegion = 0; CurHookId = 0; VolGroupId = 0; SoundType = 0; FeedSize = 0; DataMod12Bit = 0; MixerFlags = AudioFlags.None; SoundDesc = null; MixChanHandle = new SoundHandle(); Stream = null; }
public int GetRegionOffset(SoundDesc soundDesc, int region) { // Debug.WriteLine("getRegionOffset() region:{0}", region); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); return(soundDesc.Region[region].Offset); }
public int GetJumpFade(SoundDesc soundDesc, int number) { // Debug.WriteLine("getJumpFade() number:{0}", number); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(number >= 0 && number < soundDesc.NumJumps); return(soundDesc.Jump[number].FadeDelay); }
static SoundDesc[] CreateSounds() { var sounds = new SoundDesc[IMuseDigital.MaxImuseSounds]; for (int i = 0; i < sounds.Length; i++) { sounds[i] = new SoundDesc(); } return(sounds); }
bool CheckForProperHandle(SoundDesc soundDesc) { if (soundDesc == null) { return(false); } for (int l = 0; l < IMuseDigital.MaxImuseSounds; l++) { if (soundDesc.SoundId == _sounds[l].SoundId) { return(true); } } return(false); }
public void GetSyncSizeAndPtrById(SoundDesc soundDesc, int number, out int syncSize, out byte[] syncPtr) { Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(number >= 0); if (number < soundDesc.NumSyncs) { syncSize = soundDesc.Sync[number].Ptr.Length; syncPtr = soundDesc.Sync[number].Ptr; } else { syncSize = 0; syncPtr = null; } }
public SoundDesc CloneSound(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); var desc = OpenSound(soundDesc.SoundId, soundDesc.Name, soundDesc.Type, soundDesc.VolGroupId, soundDesc.Disk); if (desc == null) { desc = OpenSound(soundDesc.SoundId, soundDesc.Name, soundDesc.Type, soundDesc.VolGroupId, 1); } if (desc == null) { desc = OpenSound(soundDesc.SoundId, soundDesc.Name, soundDesc.Type, soundDesc.VolGroupId, 2); } return(desc); }
bool OpenMusicBundle(SoundDesc sound, ref int disk) { bool result; sound.Bundle = new BundleMgr(_cacheBundleDir); if (_vm.Game.GameId == GameId.CurseOfMonkeyIsland) { if (_vm.Game.Features.HasFlag(GameFeatures.Demo)) { result = sound.Bundle.Open("music.bun", ref sound.Compressed); } else { if (disk == -1) { disk = _vm.Variables[_vm.VariableCurrentDisk.Value]; } var musicfile = string.Format("musdisk{0}.bun", disk); // if (_disk != _vm.Variables[_vm.VariableCurrentDisk.Value]) // { // _vm.IMuseDigital.ParseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0); // _vm.IMuseDigital.ParseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0); // _vm.IMuseDigital.StopAllSounds(); // sound.bundle.CloseFile(); // } result = sound.Bundle.Open(musicfile, ref sound.Compressed); // FIXME: Shouldn't we only set _disk if result == true? _disk = (byte)_vm.Variables[_vm.VariableCurrentDisk.Value]; } } else if (_vm.Game.GameId == GameId.Dig) { result = sound.Bundle.Open("digmusic.bun", ref sound.Compressed); } else { throw new InvalidOperationException("openMusicBundle() Don't know which bundle file to load"); } _vm.Variables[_vm.VariableMusicBundleLoaded.Value] = result ? 1 : 0; return(result); }
public int GetRegionIdByJumpId(SoundDesc soundDesc, int jumpId) { // Debug.WriteLine("getRegionIdByJumpId() jumpId:{0}", jumpId); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(jumpId >= 0 && jumpId < soundDesc.NumJumps); int dest = soundDesc.Jump[jumpId].Dest; for (int l = 0; l < soundDesc.NumRegions; l++) { if (dest == soundDesc.Region[l].Offset) { return(l); } } return(-1); }
public SoundDesc Clone() { var desc = new SoundDesc(); desc.Freq = Freq; desc.Channels = Channels; desc.Bits = Bits; desc.NumJumps = NumJumps; desc.Region = new Region[Region.Length]; Array.Copy(Region, desc.Region, Region.Length); desc.NumRegions = NumRegions; desc.Jump = new Jump[Jump.Length]; Array.Copy(Jump, desc.Jump, Jump.Length); desc.NumSyncs = NumSyncs; desc.Sync = new Sync[Sync.Length]; Array.Copy(Sync, desc.Sync, Sync.Length); desc.NumMarkers = NumMarkers; desc.Marker = new Marker[Marker.Length]; Array.Copy(Marker, desc.Marker, Marker.Length); desc.EndFlag = EndFlag; desc.InUse = InUse; if (AllData != null) { desc.AllData = new byte[AllData.Length]; Array.Copy(AllData, desc.AllData, AllData.Length); } desc.OffsetData = OffsetData; if (ResPtr != null) { desc.ResPtr = new byte[ResPtr.Length]; Array.Copy(ResPtr, desc.ResPtr, ResPtr.Length); } desc.Name = Name; desc.SoundId = SoundId; desc.Bundle = Bundle; desc.Type = Type; desc.VolGroupId = VolGroupId; desc.Disk = Disk; desc.CompressedStream = CompressedStream; desc.Compressed = Compressed; desc.LastFileName = LastFileName; return(desc); }
public void CloseSound(SoundDesc soundDesc) { // Debug.WriteLine("Close sound: {0}", soundDesc.SoundId); Debug.Assert(CheckForProperHandle(soundDesc)); // if (soundDesc.resPtr != null) // { // bool found = false; // for (int l = 0; l < IMuseDigital.MAX_IMUSE_SOUNDS; l++) // { // if ((_sounds[l].soundId == soundDesc.soundId) && (_sounds[l] != soundDesc)) // found = true; // } // TODO: unlock // if (!found) // _vm._res.unlock(rtSound, soundDesc.soundId); // } soundDesc.Clear(); }
public int GetJumpIdByRegionAndHookId(SoundDesc soundDesc, int region, int hookId) { // Debug.WriteLine("getJumpIdByRegionAndHookId() region:{0}, hookId:{1}", region, hookId); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); var offset = soundDesc.Region[region].Offset; for (var l = 0; l < soundDesc.NumJumps; l++) { if (offset == soundDesc.Jump[l].Offset) { if (soundDesc.Jump[l].HookId == hookId) { return(l); } } } return(-1); }
public bool CheckForTriggerByRegionAndMarker(SoundDesc soundDesc, int region, string marker) { // Debug.WriteLine("checkForTriggerByRegionAndMarker() region:{0}, marker:{1}", region, marker); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); var offset = soundDesc.Region[region].Offset; for (int l = 0; l < soundDesc.NumMarkers; l++) { if (offset == soundDesc.Marker[l].Pos) { if (soundDesc.Marker[l].Ptr == marker) { return(true); } } } return(false); }
void PrepareSoundFromRMAP(BinaryReader file, SoundDesc sound, int offset, int size) { throw new NotImplementedException("PrepareSoundFromRMAP"); // TODO: vs PrepareSoundFromRMAP // int l; // // file.Seek(offset, SeekOrigin.Begin); // uint tag = file.readUint32BE(); // Debug.Assert(tag == MKTAG('R', 'M', 'A', 'P')); // int version = file.readUint32BE(); // if (version != 3) // { // if (version == 2) // { // warning("prepareSoundFromRMAP: Wrong version of compressed *.bun file, expected 3, but it's 2"); // warning("Suggested to recompress with latest tool from daily builds"); // } // else // error("prepareSoundFromRMAP: Wrong version number, expected 3, but it's: %d", version); // } // sound.bits = file.readUint32BE(); // sound.freq = file.readUint32BE(); // sound.channels = file.readUint32BE(); // sound.numRegions = file.readUint32BE(); // sound.numJumps = file.readUint32BE(); // sound.numSyncs = file.readUint32BE(); // if (version >= 3) // sound.numMarkers = file.readUint32BE(); // else // sound.numMarkers = 0; // // sound.region = new Region[sound.numRegions]; // Debug.Assert(sound.region); // sound.jump = new Jump[sound.numJumps]; // Debug.Assert(sound.jump); // sound.sync = new Sync[sound.numSyncs]; // Debug.Assert(sound.sync); // sound.marker = new Marker[sound.numMarkers]; // Debug.Assert(sound.marker); // // for (l = 0; l < sound.numRegions; l++) // { // sound.region[l].offset = file.readUint32BE(); // sound.region[l].length = file.readUint32BE(); // } // for (l = 0; l < sound.numJumps; l++) // { // sound.jump[l].offset = file.readUint32BE(); // sound.jump[l].dest = file.readUint32BE(); // sound.jump[l].hookId = file.readUint32BE(); // sound.jump[l].fadeDelay = file.readUint32BE(); // } // for (l = 0; l < sound.numSyncs; l++) // { // sound.sync[l].size = file.readUint32BE(); // sound.sync[l].ptr = new byte[sound.sync[l].size]; // file.read(sound.sync[l].ptr, sound.sync[l].size); // } // if (version >= 3) // { // for (l = 0; l < sound.numMarkers; l++) // { // sound.marker[l].pos = file.readUint32BE(); // sound.marker[l].length = file.readUint32BE(); // sound.marker[l].ptr = new char[sound.marker[l].length]; // file.read(sound.marker[l].ptr, sound.marker[l].length); // } // } }
public int GetFreq(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return(soundDesc.Freq); }
public int GetBits(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return soundDesc.Bits; }
public bool IsSndDataExtComp(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return soundDesc.Compressed; }
public SoundDesc CloneSound(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); var desc = OpenSound(soundDesc.SoundId, soundDesc.Name, soundDesc.Type, soundDesc.VolGroupId, soundDesc.Disk); if (desc == null) desc = OpenSound(soundDesc.SoundId, soundDesc.Name, soundDesc.Type, soundDesc.VolGroupId, 1); if (desc == null) desc = OpenSound(soundDesc.SoundId, soundDesc.Name, soundDesc.Type, soundDesc.VolGroupId, 2); return desc; }
bool OpenVoiceBundle(SoundDesc sound, ref int disk) { bool result; sound.Bundle = new BundleMgr(_cacheBundleDir); if (_vm.Game.GameId == GameId.CurseOfMonkeyIsland) { if (_vm.Game.Features.HasFlag(GameFeatures.Demo)) { result = sound.Bundle.Open("voice.bun", ref sound.Compressed); } else { if (disk == -1) disk = _vm.Variables[_vm.VariableCurrentDisk.Value]; var voxfile = string.Format("voxdisk{0}.bun", disk); // if (_disk != _vm.Variables[_vm.VariableCurrentDisk]) { // _vm._imuseDigital.parseScriptCmds(0x1000, 0, 0, 0, 0, 0, 0, 0); // _vm._imuseDigital.parseScriptCmds(0x2000, 0, 0, 0, 0, 0, 0, 0); // _vm._imuseDigital.stopAllSounds(); // sound.bundle.closeFile(); // } result = sound.Bundle.Open(voxfile, ref sound.Compressed); // FIXME: Shouldn't we only set _disk if result == true? _disk = (byte)_vm.Variables[_vm.VariableCurrentDisk.Value]; } } else if (_vm.Game.GameId == GameId.Dig) result = sound.Bundle.Open("digvoice.bun", ref sound.Compressed); else throw new InvalidOperationException("openVoiceBundle() Don't know which bundle file to load"); _vm.Variables[_vm.VariableMusicBundleLoaded.Value] = result ? 1 : 0; return result; }
void SwitchToNextRegion(Track track) { Debug.Assert(track != null); if (track.TrackId >= MaxDigitalTracks) { FlushTrack(track); // Debug.WriteLine("SwToNeReg(trackId:{0}) - fadetrack can't go next region, exiting SwToNeReg", track.TrackId); return; } int num_regions = _sound.GetNumRegions(track.SoundDesc); if (++track.CurRegion == num_regions) { FlushTrack(track); // Debug.WriteLine("SwToNeReg(trackId:{0}) - end of region, exiting SwToNeReg", track.TrackId); return; } SoundDesc soundDesc = track.SoundDesc; if (_triggerUsed && track.SoundDesc.NumMarkers != 0) { if (_sound.CheckForTriggerByRegionAndMarker(soundDesc, track.CurRegion, _triggerParams.Marker)) { // Debug.WriteLine("SwToNeReg(trackId:{0}) - trigger {1} reached", track.TrackId, _triggerParams.Marker); // Debug.WriteLine("SwToNeReg(trackId:{0}) - exit current region {1}", track.TrackId, track.CurRegion); // Debug.WriteLine("SwToNeReg(trackId:{0}) - call cloneToFadeOutTrack(delay:{1})", track.TrackId, _triggerParams.FadeOutDelay); Track fadeTrack = CloneToFadeOutTrack(track, _triggerParams.FadeOutDelay); if (fadeTrack != null) { fadeTrack.DataOffset = _sound.GetRegionOffset(fadeTrack.SoundDesc, fadeTrack.CurRegion); fadeTrack.RegionOffset = 0; // Debug.WriteLine("SwToNeReg(trackId:{0})-sound({1}) select region {2}, curHookId: {3}", fadeTrack.TrackId, fadeTrack.SoundId, fadeTrack.CurRegion, fadeTrack.CurHookId); fadeTrack.CurHookId = 0; } FlushTrack(track); StartMusic(_triggerParams.Filename, _triggerParams.SoundId, _triggerParams.HookId, _triggerParams.Volume); _triggerUsed = false; return; } } int jumpId = _sound.GetJumpIdByRegionAndHookId(soundDesc, track.CurRegion, track.CurHookId); if (jumpId != -1) { int region = _sound.GetRegionIdByJumpId(soundDesc, jumpId); Debug.Assert(region != -1); int sampleHookId = _sound.GetJumpHookId(soundDesc, jumpId); Debug.Assert(sampleHookId != -1); // Debug.WriteLine("SwToNeReg(trackId:{0}) - JUMP found - sound:{1}, track hookId:{2}, data hookId:{3}", track.TrackId, track.SoundId, track.CurHookId, sampleHookId); if (track.CurHookId == sampleHookId) { int fadeDelay = (60 * _sound.GetJumpFade(soundDesc, jumpId)) / 1000; // Debug.WriteLine("SwToNeReg(trackId:{0}) - sound({1}) match hookId", track.TrackId, track.SoundId); if (fadeDelay != 0) { // Debug.WriteLine("SwToNeReg(trackId:{0}) - call cloneToFadeOutTrack(delay:{1})", track.TrackId, fadeDelay); var fadeTrack = CloneToFadeOutTrack(track, fadeDelay); if (fadeTrack != null) { fadeTrack.DataOffset = _sound.GetRegionOffset(fadeTrack.SoundDesc, fadeTrack.CurRegion); fadeTrack.RegionOffset = 0; // Debug.WriteLine("SwToNeReg(trackId:{0}) - sound({1}) faded track, select region {2}, curHookId: {3}", fadeTrack.TrackId, fadeTrack.SoundId, fadeTrack.CurRegion, fadeTrack.CurHookId); fadeTrack.CurHookId = 0; } } track.CurRegion = region; // Debug.WriteLine("SwToNeReg(trackId:{0}) - sound({1}) jump to region {2}, curHookId: {3}", track.TrackId, track.SoundId, track.CurRegion, track.CurHookId); track.CurHookId = 0; } else { // Debug.WriteLine("SwToNeReg(trackId:{0}) - Normal switch region, sound({1}), hookId({2})", track.TrackId, track.SoundId, track.CurHookId); } } else { // Debug.WriteLine("SwToNeReg(trackId:{0}) - Normal switch region, sound({1}), hookId({2})", track.TrackId, track.SoundId, track.CurHookId); } // Debug.WriteLine("SwToNeReg(trackId:{0}) - sound({1}), select region {2}", track.TrackId, track.SoundId, track.CurRegion); track.DataOffset = _sound.GetRegionOffset(soundDesc, track.CurRegion); track.RegionOffset = 0; // Debug.WriteLine("SwToNeReg(trackId:{0}) - end of func", track.TrackId); }
int GetNumJumps(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return(soundDesc.NumJumps); }
public int GetNumRegions(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return(soundDesc.NumRegions); }
public bool IsEndOfRegion(SoundDesc soundDesc, int region) { Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); return(soundDesc.EndFlag); }
public int GetChannels(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return(soundDesc.Channels); }
public int GetBits(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return(soundDesc.Bits); }
void PrepareSound(byte[] ptr, SoundDesc sound) { if (ptr.ToText() == "Crea") { bool quit = false; int len; int offset = ptr.ToInt16(20); int code = ptr.ToInt16(24); sound.NumRegions = 0; sound.Region = new Region[70]; sound.NumJumps = 0; sound.Jump = new Jump[1]; sound.NumSyncs = 0; sound.ResPtr = ptr; sound.Bits = 8; sound.Channels = 1; while (!quit) { len = ptr.ToInt32(offset); code = len & 0xFF; if ((code != 0) && (code != 1) && (code != 6) && (code != 7)) { // try again with 2 bytes forward (workaround for some FT sounds (ex.362, 363) offset += 2; len = ptr.ToInt32(offset); code = len & 0xFF; if ((code != 0) && (code != 1) && (code != 6) && (code != 7)) { throw new NotSupportedException(string.Format("Invalid code in VOC file : {0}", code)); } } offset += 4; len >>= 8; switch (code) { case 0: quit = true; break; case 1: { int time_constant = ptr[offset]; offset += 2; len -= 2; sound.Freq = (ushort)VocStream.GetSampleRateFromVOCRate(time_constant); sound.Region[sound.NumRegions].Offset = offset; sound.Region[sound.NumRegions].Length = len; sound.NumRegions++; } break; case 6: // begin of loop sound.Jump[0].Dest = offset + 8; sound.Jump[0].HookId = 0; sound.Jump[0].FadeDelay = 0; break; case 7: // end of loop sound.Jump[0].Offset = offset - 4; sound.NumJumps++; sound.Region[sound.NumRegions].Offset = offset - 4; sound.Region[sound.NumRegions].Length = 0; sound.NumRegions++; break; default: throw new InvalidOperationException(string.Format("Invalid code in VOC file : {0}", code)); // quit = true; // break; } offset += len; } } else if (ptr.ToText() == "iMUS") { string tag; int size = 0; int posPtr = 16; int curIndexRegion = 0; int curIndexJump = 0; int curIndexSync = 0; int curIndexMarker = 0; sound.NumRegions = 0; sound.NumJumps = 0; sound.NumSyncs = 0; sound.NumMarkers = 0; CountElements(ptr, posPtr, ref sound.NumRegions, ref sound.NumJumps, ref sound.NumSyncs, ref sound.NumMarkers); sound.Region = new Region[sound.NumRegions]; sound.Jump = new Jump[sound.NumJumps]; sound.Sync = new Sync[sound.NumSyncs]; sound.Marker = new Marker[sound.NumMarkers]; do { tag = ptr.ToText(posPtr); posPtr += 4; switch (tag) { case "FRMT": posPtr += 12; sound.Bits = (byte)ptr.ToUInt32BigEndian(posPtr); posPtr += 4; sound.Freq = (ushort)ptr.ToUInt32BigEndian(posPtr); posPtr += 4; sound.Channels = (byte)ptr.ToUInt32BigEndian(posPtr); posPtr += 4; break; case "TEXT": if (string.Equals(ptr.ToText(posPtr + 8), "exit")) { sound.Marker[curIndexMarker].Pos = ptr.ToInt32BigEndian(posPtr + 4); sound.Marker[curIndexMarker].Ptr = ptr.GetText(posPtr + 8); curIndexMarker++; } size = ptr.ToInt32BigEndian(posPtr); posPtr += size + 4; break; case "STOP": size = ptr.ToInt32BigEndian(posPtr); posPtr += size + 4; break; case "REGN": posPtr += 4; sound.Region[curIndexRegion].Offset = ptr.ToInt32BigEndian(posPtr); posPtr += 4; sound.Region[curIndexRegion].Length = ptr.ToInt32BigEndian(posPtr); posPtr += 4; curIndexRegion++; break; case "JUMP": posPtr += 4; sound.Jump[curIndexJump].Offset = ptr.ToInt32BigEndian(posPtr); posPtr += 4; sound.Jump[curIndexJump].Dest = ptr.ToInt32BigEndian(posPtr); posPtr += 4; sound.Jump[curIndexJump].HookId = (byte)ptr.ToInt32BigEndian(posPtr); posPtr += 4; sound.Jump[curIndexJump].FadeDelay = (short)ptr.ToInt32BigEndian(posPtr); posPtr += 4; curIndexJump++; break; case "SYNC": size = ptr.ToInt32BigEndian(posPtr); posPtr += 4; sound.Sync[curIndexSync].Ptr = new byte[size]; Array.Copy(ptr, posPtr, sound.Sync[curIndexSync].Ptr, 0, size); curIndexSync++; posPtr += size; break; case "DATA": posPtr += 4; break; default: throw new InvalidOperationException( string.Format("ImuseDigiSndMgr::prepareSound({0}/{1}) Unknown sfx header '{2}'", sound.SoundId, sound.Name, tag)); } } while (tag != "DATA"); sound.OffsetData = posPtr; } else { throw new InvalidOperationException("ImuseDigiSndMgr::prepareSound(): Unknown sound format"); } }
public bool IsEndOfRegion(SoundDesc soundDesc, int region) { Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); return soundDesc.EndFlag; }
int GetNumJumps(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return soundDesc.NumJumps; }
bool CheckForProperHandle(SoundDesc soundDesc) { if (soundDesc == null) return false; for (int l = 0; l < IMuseDigital.MaxImuseSounds; l++) { if (soundDesc.SoundId == _sounds[l].SoundId) return true; } return false; }
public int GetJumpIdByRegionAndHookId(SoundDesc soundDesc, int region, int hookId) { // Debug.WriteLine("getJumpIdByRegionAndHookId() region:{0}, hookId:{1}", region, hookId); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); var offset = soundDesc.Region[region].Offset; for (var l = 0; l < soundDesc.NumJumps; l++) { if (offset == soundDesc.Jump[l].Offset) { if (soundDesc.Jump[l].HookId == hookId) return l; } } return -1; }
public int GetFreq(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return soundDesc.Freq; }
public int GetChannels(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return soundDesc.Channels; }
public bool IsSndDataExtComp(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return(soundDesc.Compressed); }
public int GetNumRegions(SoundDesc soundDesc) { Debug.Assert(CheckForProperHandle(soundDesc)); return soundDesc.NumRegions; }
public int GetJumpFade(SoundDesc soundDesc, int number) { // Debug.WriteLine("getJumpFade() number:{0}", number); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(number >= 0 && number < soundDesc.NumJumps); return soundDesc.Jump[number].FadeDelay; }
public int GetRegionOffset(SoundDesc soundDesc, int region) { // Debug.WriteLine("getRegionOffset() region:{0}", region); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); return soundDesc.Region[region].Offset; }
static SoundDesc[] CreateSounds() { var sounds = new SoundDesc[IMuseDigital.MaxImuseSounds]; for (int i = 0; i < sounds.Length; i++) { sounds[i] = new SoundDesc(); } return sounds; }
public bool CheckForTriggerByRegionAndMarker(SoundDesc soundDesc, int region, string marker) { // Debug.WriteLine("checkForTriggerByRegionAndMarker() region:{0}, marker:{1}", region, marker); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); var offset = soundDesc.Region[region].Offset; for (int l = 0; l < soundDesc.NumMarkers; l++) { if (offset == soundDesc.Marker[l].Pos) { if (soundDesc.Marker[l].Ptr == marker) return true; } } return false; }
public int GetRegionIdByJumpId(SoundDesc soundDesc, int jumpId) { // Debug.WriteLine("getRegionIdByJumpId() jumpId:{0}", jumpId); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(jumpId >= 0 && jumpId < soundDesc.NumJumps); int dest = soundDesc.Jump[jumpId].Dest; for (int l = 0; l < soundDesc.NumRegions; l++) { if (dest == soundDesc.Region[l].Offset) { return l; } } return -1; }
public int GetDataFromRegion(SoundDesc soundDesc, int region, out byte[] buf, int offset, int size) { // Debug.WriteLine("GetDataFromRegion() soundId:{4,4}, region:{0}, offset:{1,7}, size:{2,4}, numRegions:{3}", region, offset, size, soundDesc.NumRegions, soundDesc.SoundId); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(offset >= 0 && size >= 0); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); buf = null; int region_offset = soundDesc.Region[region].Offset; int region_length = soundDesc.Region[region].Length; int offset_data = soundDesc.OffsetData; int start = region_offset - offset_data; if (offset + size + offset_data > region_length) { size = region_length - offset; soundDesc.EndFlag = true; } else { soundDesc.EndFlag = false; } int header_size = soundDesc.OffsetData; bool header_outside = ((_vm.Game.GameId == GameId.CurseOfMonkeyIsland) && !(_vm.Game.Features.HasFlag(GameFeatures.Demo))); if ((soundDesc.Bundle != null) && (!soundDesc.Compressed)) { size = soundDesc.Bundle.DecompressSampleByCurIndex(start + offset, size, out buf, header_size, header_outside); } else if (soundDesc.ResPtr != null) { buf = new byte[size]; Array.Copy(soundDesc.ResPtr, start + offset + header_size, buf, 0, size); } else if ((soundDesc.Bundle != null) && (soundDesc.Compressed)) { buf = new byte[size]; int offsetMs = (((offset * 8 * 10) / soundDesc.Bits) / (soundDesc.Channels * soundDesc.Freq)) * 100; var fileName = string.Format("{0}_reg{1:D3}", soundDesc.Name, region); if (fileName != soundDesc.LastFileName) { int offs = 0, len = 0; fileName = string.Format("{0}_reg{1:D3}.fla", soundDesc.Name, region); var cmpFile = soundDesc.Bundle.GetFile(fileName, ref offs, ref len); // if (len != 0) // { // Console.Error.WriteLine("FLAC library compiled support needed"); // } if (len == 0) { fileName = string.Format("{0}_reg{1:D3}.ogg", soundDesc.Name, region); cmpFile = soundDesc.Bundle.GetFile(fileName, ref offs, ref len); // if (len != 0) // { // Console.Error.WriteLine("Vorbis library compiled support needed"); // } } if (len == 0) { fileName = string.Format("{0}_reg{1:D3}.mp3", soundDesc.Name, region); cmpFile = soundDesc.Bundle.GetFile(fileName, ref offs, ref len); // if (len != 0) // { // Console.Error.WriteLine("Mad library compiled support needed"); // } } Debug.Assert(len != 0); if (soundDesc.CompressedStream == null) { // var tmp = cmpFile.ReadStream(len); // Debug.Assert(tmp); #if USE_FLAC if (soundMode == 3) soundDesc.compressedStream = Audio::makeFLACStream(tmp, DisposeAfterUse::YES); #endif #if USE_VORBIS if (soundMode == 2) soundDesc.compressedStream = Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); #endif #if USE_MAD if (soundMode == 1) soundDesc.compressedStream = Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); #endif // Debug.Assert(soundDesc.compressedStream!=null); // soundDesc.compressedStream.Seek(offsetMs); } soundDesc.LastFileName = fileName; } var tmpBuf = new short[size / 2]; size = soundDesc.CompressedStream.ReadBuffer(tmpBuf, size / 2) * 2; // TODO: vs check this for (int i = 0; i < size / 2; i++) { buf[i * 2] = (byte)(tmpBuf[i] & 0xFF); buf[i * 2 + 1] = (byte)((tmpBuf[i] & 0xFF00) >> 8); } if (soundDesc.CompressedStream.IsEndOfData || soundDesc.EndFlag) { soundDesc.CompressedStream.Dispose(); soundDesc.CompressedStream = null; soundDesc.LastFileName = null; soundDesc.EndFlag = true; } } return size; }
public int GetDataFromRegion(SoundDesc soundDesc, int region, out byte[] buf, int offset, int size) { // Debug.WriteLine("GetDataFromRegion() soundId:{4,4}, region:{0}, offset:{1,7}, size:{2,4}, numRegions:{3}", region, offset, size, soundDesc.NumRegions, soundDesc.SoundId); Debug.Assert(CheckForProperHandle(soundDesc)); Debug.Assert(offset >= 0 && size >= 0); Debug.Assert(region >= 0 && region < soundDesc.NumRegions); buf = null; int region_offset = soundDesc.Region[region].Offset; int region_length = soundDesc.Region[region].Length; int offset_data = soundDesc.OffsetData; int start = region_offset - offset_data; if (offset + size + offset_data > region_length) { size = region_length - offset; soundDesc.EndFlag = true; } else { soundDesc.EndFlag = false; } int header_size = soundDesc.OffsetData; bool header_outside = ((_vm.Game.GameId == GameId.CurseOfMonkeyIsland) && !(_vm.Game.Features.HasFlag(GameFeatures.Demo))); if ((soundDesc.Bundle != null) && (!soundDesc.Compressed)) { size = soundDesc.Bundle.DecompressSampleByCurIndex(start + offset, size, out buf, header_size, header_outside); } else if (soundDesc.ResPtr != null) { buf = new byte[size]; Array.Copy(soundDesc.ResPtr, start + offset + header_size, buf, 0, size); } else if ((soundDesc.Bundle != null) && (soundDesc.Compressed)) { buf = new byte[size]; int offsetMs = (((offset * 8 * 10) / soundDesc.Bits) / (soundDesc.Channels * soundDesc.Freq)) * 100; var fileName = string.Format("{0}_reg{1:D3}", soundDesc.Name, region); if (fileName != soundDesc.LastFileName) { int offs = 0, len = 0; fileName = string.Format("{0}_reg{1:D3}.fla", soundDesc.Name, region); var cmpFile = soundDesc.Bundle.GetFile(fileName, ref offs, ref len); // if (len != 0) // { // Console.Error.WriteLine("FLAC library compiled support needed"); // } if (len == 0) { fileName = string.Format("{0}_reg{1:D3}.ogg", soundDesc.Name, region); cmpFile = soundDesc.Bundle.GetFile(fileName, ref offs, ref len); // if (len != 0) // { // Console.Error.WriteLine("Vorbis library compiled support needed"); // } } if (len == 0) { fileName = string.Format("{0}_reg{1:D3}.mp3", soundDesc.Name, region); cmpFile = soundDesc.Bundle.GetFile(fileName, ref offs, ref len); // if (len != 0) // { // Console.Error.WriteLine("Mad library compiled support needed"); // } } Debug.Assert(len != 0); if (soundDesc.CompressedStream == null) { // var tmp = cmpFile.ReadStream(len); // Debug.Assert(tmp); #if USE_FLAC if (soundMode == 3) { soundDesc.compressedStream = Audio::makeFLACStream(tmp, DisposeAfterUse::YES); } #endif #if USE_VORBIS if (soundMode == 2) { soundDesc.compressedStream = Audio::makeVorbisStream(tmp, DisposeAfterUse::YES); } #endif #if USE_MAD if (soundMode == 1) { soundDesc.compressedStream = Audio::makeMP3Stream(tmp, DisposeAfterUse::YES); } #endif // Debug.Assert(soundDesc.compressedStream!=null); // soundDesc.compressedStream.Seek(offsetMs); } soundDesc.LastFileName = fileName; } var tmpBuf = new short[size / 2]; size = soundDesc.CompressedStream.ReadBuffer(tmpBuf, size / 2) * 2; // TODO: vs check this for (int i = 0; i < size / 2; i++) { buf[i * 2] = (byte)(tmpBuf[i] & 0xFF); buf[i * 2 + 1] = (byte)((tmpBuf[i] & 0xFF00) >> 8); } if (soundDesc.CompressedStream.IsEndOfData || soundDesc.EndFlag) { soundDesc.CompressedStream.Dispose(); soundDesc.CompressedStream = null; soundDesc.LastFileName = null; soundDesc.EndFlag = true; } } return(size); }
public SoundDesc Clone() { var desc = new SoundDesc(); desc.Freq = Freq; desc.Channels = Channels; desc.Bits = Bits; desc.NumJumps = NumJumps; desc.Region = new Region[Region.Length]; Array.Copy(Region, desc.Region, Region.Length); desc.NumRegions = NumRegions; desc.Jump = new Jump[Jump.Length]; Array.Copy(Jump, desc.Jump, Jump.Length); desc.NumSyncs = NumSyncs; desc.Sync = new Sync[Sync.Length]; Array.Copy(Sync, desc.Sync, Sync.Length); desc.NumMarkers = NumMarkers; desc.Marker = new Marker[Marker.Length]; Array.Copy(Marker, desc.Marker, Marker.Length); desc.EndFlag = EndFlag; desc.InUse = InUse; if (AllData != null) { desc.AllData = new byte[AllData.Length]; Array.Copy(AllData, desc.AllData, AllData.Length); } desc.OffsetData = OffsetData; if (ResPtr != null) { desc.ResPtr = new byte[ResPtr.Length]; Array.Copy(ResPtr, desc.ResPtr, ResPtr.Length); } desc.Name = Name; desc.SoundId = SoundId; desc.Bundle = Bundle; desc.Type = Type; desc.VolGroupId = VolGroupId; desc.Disk = Disk; desc.CompressedStream = CompressedStream; desc.Compressed = Compressed; desc.LastFileName = LastFileName; return desc; }