public IEnumerable <byte[]> GetSounds(MusicDriverTypes music) { for (byte i = 0; i < Index.SoundResources.Count; i++) { if (Index.SoundResources[i].RoomNum != 0) { yield return(GetSound(music, i)); } } }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { _reader.BaseStream.Seek(offset, SeekOrigin.Begin); var size = _reader.ReadUInt16(); // wa_size _reader.BaseStream.Seek(-2, SeekOrigin.Current); var data = _reader.ReadBytes(size); return(data); }
public void LoadSound(MusicDriverTypes music, int id) { if (id == 0 || _sounds.ContainsKey(id)) { return; } NukeResource(ResType.Sound, id); byte[] data = null; var resource = Index.SoundResources[id]; if (resource.RoomNum != 0) { var disk = OpenRoom(resource.RoomNum); if (disk != null) { var roomOffset = GetRoomOffset(disk, resource.RoomNum); if (Game.IsOldBundle && Game.Version == 3 && Game.Platform == Platform.Amiga) { data = ((ResourceFile3_16)disk).ReadAmigaSound(roomOffset + resource.Offset); } else if (Game.Version == 3 && (Game.Platform == Platform.Amiga || Game.Platform == Platform.FMTowns)) { data = ((ResourceFile3)disk).ReadAmigaSound(roomOffset + resource.Offset); } else if (Game.Version == 4 && Game.Platform == Platform.Amiga) { data = ((ResourceFile4)disk).ReadAmigaSound(roomOffset + resource.Offset); } else { data = disk.ReadSound(music, roomOffset + resource.Offset); // For games using AD except Indy3 and Loom we are using our iMuse // implementation. See output initialization in // ScummEngine::setupMusic for more information. if (data != null && Game.Version < 5 && Game.GameId != GameId.Indy3 && Game.GameId != GameId.Loom && music == MusicDriverTypes.AdLib) { data = ConvertADResource(data, id); } } } } if (data != null) { ExpireResources(data.Length); _sounds[id] = data; _allocatedSize += data.Length; SetSoundCounter(id, 1); } }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { GotoResourceHeader(offset); var tag = ToTag(_reader.ReadBytes(4)); if (tag != "SOUN") { throw new NotSupportedException("Expected SO block."); } var size = _reader.ReadUInt32BigEndian(); return(_reader.ReadBytes((int)size)); }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { _reader.BaseStream.Seek(offset, SeekOrigin.Begin); var wa_offs = offset; var wa_size = _reader.ReadUInt16(); int ad_size = 0; int ad_offs = 0; _reader.BaseStream.Seek(wa_size - 2, SeekOrigin.Current); if (!(_game.Platform == Platform.AtariST || _game.Platform == Platform.Macintosh)) { ad_offs = (int)_reader.BaseStream.Position; ad_size = _reader.ReadUInt16(); } _reader.BaseStream.Seek(wa_offs, SeekOrigin.Begin); var data = _reader.ReadBytes(wa_size); return(data); }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { GotoResourceHeader(offset); var chunk = ReadChunk(_reader); if (chunk.Tag != "SO") { throw new NotSupportedException("Expected sound block."); } var totalSize = chunk.Size - 6; Dictionary <string, Chunk> offsets = new Dictionary <string, Chunk>(); while (totalSize > 0) { chunk = ReadChunk(_reader); if (chunk.Tag == "SO") { totalSize -= 6; if (ReadBlockSound()) { continue; } } else if (chunk.Tag == "WA") { offsets[chunk.Tag] = chunk; } else if (chunk.Tag == "AD") { offsets[chunk.Tag] = chunk; } else if (chunk.Tag == "AD") { offsets[chunk.Tag] = chunk; } totalSize -= chunk.Size; _reader.BaseStream.Seek(chunk.Size - 6, SeekOrigin.Current); } if (music == MusicDriverTypes.PCSpeaker || music == MusicDriverTypes.PCjr) { if (offsets.ContainsKey("WA")) { _reader.BaseStream.Seek(offsets["WA"].Offset - 6, SeekOrigin.Begin); return(_reader.ReadBytes((int)offsets["WA"].Size + 6)); } } else if (music == MusicDriverTypes.CMS) { bool hasAdLibMusicTrack = false; if (offsets.ContainsKey("AD")) { _reader.BaseStream.Seek(offsets["AD"].Offset + 2, SeekOrigin.Begin); hasAdLibMusicTrack = (_reader.PeekChar() == 0x80); } if (hasAdLibMusicTrack) { _reader.BaseStream.Seek(offsets["AD"].Offset - 4, SeekOrigin.Begin); return(_reader.ReadBytes((int)offsets["AD"].Offset + 4)); } else if (offsets.ContainsKey("WA")) { _reader.BaseStream.Seek(offsets["WA"].Offset - 6, SeekOrigin.Begin); return(_reader.ReadBytes((int)offsets["WA"].Offset + 6)); } } else if (music == MusicDriverTypes.AdLib) { if (offsets.ContainsKey("AD")) { _reader.BaseStream.Seek(offsets["AD"].Offset, SeekOrigin.Begin); return(_reader.ReadBytes((int)offsets["AD"].Size - 6)); } } return(null); }
public abstract byte[] ReadSound(MusicDriverTypes music, long offset);
/// <summary> /// Returns the device handle based on the present devices and the flags parameter. /// </summary> /// <returns>The device handle based on the present devices and the flags parameter.</returns> /// <param name="flags">Flags.</param> /// <param name = "selectedDevice">The selected device</param> public static DeviceHandle DetectDevice(MusicDriverTypes flags, string selectedDevice) { var result = new DeviceHandle(); var handle = GetDeviceHandle(selectedDevice); var musicType = GetMusicType(handle); switch (musicType) { case MusicType.PCSpeaker: if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { result = handle; } break; case MusicType.PCjr: if (flags.HasFlag(MusicDriverTypes.PCjr)) { result = handle; } break; case MusicType.AdLib: if (flags.HasFlag(MusicDriverTypes.AdLib)) { result = handle; } break; case MusicType.CMS: if (flags.HasFlag(MusicDriverTypes.CMS)) { result = handle; } break; case MusicType.FMTowns: if (flags.HasFlag(MusicDriverTypes.FMTowns)) { result = handle; } break; case MusicType.Null: result = handle; break; } if (!result.IsValid) { MusicType mt = MusicType.Null; if (flags.HasFlag(MusicDriverTypes.FMTowns)) { mt = MusicType.FMTowns; } else if (flags.HasFlag(MusicDriverTypes.AdLib)) { mt = MusicType.AdLib; } else if (flags.HasFlag(MusicDriverTypes.PCjr)) { mt = MusicType.PCjr; } else if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { mt = MusicType.PCSpeaker; } var device = MusicManager.GetPlugins().SelectMany(p => p.GetDevices()).FirstOrDefault(d => d.MusicType == mt); if (device != null) { result = device.Handle; } } return result; }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { GotoResourceHeader(offset); var chunk = ReadChunk(_reader); if (chunk.Tag != "SO") throw new NotSupportedException("Expected sound block."); var totalSize = chunk.Size - 6; Dictionary<string,Chunk> offsets = new Dictionary<string, Chunk>(); while (totalSize > 0) { chunk = ReadChunk(_reader); if (chunk.Tag == "SO") { totalSize -= 6; if (ReadBlockSound()) { continue; } } else if (chunk.Tag == "WA") { offsets[chunk.Tag] = chunk; } else if (chunk.Tag == "AD") { offsets[chunk.Tag] = chunk; } else if (chunk.Tag == "AD") { offsets[chunk.Tag] = chunk; } totalSize -= chunk.Size; _reader.BaseStream.Seek(chunk.Size - 6, SeekOrigin.Current); } if (music == MusicDriverTypes.PCSpeaker || music == MusicDriverTypes.PCjr) { if (offsets.ContainsKey("WA")) { _reader.BaseStream.Seek(offsets["WA"].Offset - 6, SeekOrigin.Begin); return _reader.ReadBytes((int)offsets["WA"].Size + 6); } } else if (music == MusicDriverTypes.CMS) { bool hasAdLibMusicTrack = false; if (offsets.ContainsKey("AD")) { _reader.BaseStream.Seek(offsets["AD"].Offset + 2, SeekOrigin.Begin); hasAdLibMusicTrack = (_reader.PeekChar() == 0x80); } if (hasAdLibMusicTrack) { _reader.BaseStream.Seek(offsets["AD"].Offset - 4, SeekOrigin.Begin); return _reader.ReadBytes((int)offsets["AD"].Offset + 4); } else if (offsets.ContainsKey("WA")) { _reader.BaseStream.Seek(offsets["WA"].Offset - 6, SeekOrigin.Begin); return _reader.ReadBytes((int)offsets["WA"].Offset + 6); } } else if (music == MusicDriverTypes.AdLib) { if (offsets.ContainsKey("AD")) { _reader.BaseStream.Seek(offsets["AD"].Offset, SeekOrigin.Begin); return _reader.ReadBytes((int)offsets["AD"].Size - 6); } } return null; }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { GotoResourceHeader(offset); var tag = ToTag(_reader.ReadBytes(4)); if (tag != "SOUN") { throw new NotSupportedException("Expected SO block."); } var size = _reader.ReadUInt32BigEndian(); var pos = _reader.BaseStream.Position + size - 8; do { tag = ToTag(_reader.ReadBytes(4)); size = _reader.ReadUInt32BigEndian(); switch (tag) { case "ADL ": if (music == MusicDriverTypes.AdLib || music == MusicDriverTypes.FMTowns) { _reader.BaseStream.Seek(-8, SeekOrigin.Current); return(_reader.ReadBytes((int)size + 8)); } _reader.BaseStream.Seek(size, SeekOrigin.Current); break; case "AMI ": _reader.BaseStream.Seek(-8, SeekOrigin.Current); return(_reader.ReadBytes((int)size + 8)); case "SPK ": if (music == MusicDriverTypes.PCSpeaker) { _reader.BaseStream.Seek(-8, SeekOrigin.Current); return(_reader.ReadBytes((int)size + 8)); } _reader.BaseStream.Seek(size, SeekOrigin.Current); break; case "MIDI": if (music == MusicDriverTypes.Midi) { _reader.BaseStream.Seek(-8, SeekOrigin.Current); return(_reader.ReadBytes((int)size + 8)); } _reader.BaseStream.Seek(size, SeekOrigin.Current); break; case "Mac0": _reader.BaseStream.Seek(-12, SeekOrigin.Current); size = _reader.ReadUInt32BigEndian() - 8; return(_reader.ReadBytes((int)size)); case "TOWS": _reader.BaseStream.Seek(-12, SeekOrigin.Current); size = _reader.ReadUInt32BigEndian(); return(_reader.ReadBytes((int)size)); case "SOU ": break; default: // skip // Console.WriteLine("Skip Block: {0}", tag); _reader.BaseStream.Seek(size, SeekOrigin.Current); break; } } while (_reader.BaseStream.Position < pos); return(null); }
/// <summary> /// Returns the device handle based on the present devices and the flags parameter. /// </summary> /// <returns>The device handle based on the present devices and the flags parameter.</returns> /// <param name="flags">Flags.</param> /// <param name = "selectedDevice">The selected device</param> public static DeviceHandle DetectDevice(MusicDriverTypes flags, string selectedDevice) { var result = new DeviceHandle(); var handle = GetDeviceHandle(selectedDevice); var musicType = GetMusicType(handle); switch (musicType) { case MusicType.PCSpeaker: if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { result = handle; } break; case MusicType.PCjr: if (flags.HasFlag(MusicDriverTypes.PCjr)) { result = handle; } break; case MusicType.AdLib: if (flags.HasFlag(MusicDriverTypes.AdLib)) { result = handle; } break; case MusicType.CMS: if (flags.HasFlag(MusicDriverTypes.CMS)) { result = handle; } break; case MusicType.FMTowns: if (flags.HasFlag(MusicDriverTypes.FMTowns)) { result = handle; } break; case MusicType.Null: result = handle; break; } if (!result.IsValid) { MusicType mt = MusicType.Null; if (flags.HasFlag(MusicDriverTypes.FMTowns)) { mt = MusicType.FMTowns; } else if (flags.HasFlag(MusicDriverTypes.AdLib)) { mt = MusicType.AdLib; } else if (flags.HasFlag(MusicDriverTypes.PCjr)) { mt = MusicType.PCjr; } else if (flags.HasFlag(MusicDriverTypes.PCSpeaker)) { mt = MusicType.PCSpeaker; } var device = MusicManager.GetPlugins().SelectMany(p => p.GetDevices()).FirstOrDefault(d => d.MusicType == mt); if (device != null) { result = device.Handle; } } return(result); }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { GotoResourceHeader(offset); var tag = ToTag(_reader.ReadBytes(4)); if (tag != "SOUN") throw new NotSupportedException("Expected SO block."); var size = _reader.ReadUInt32BigEndian(); var pos = _reader.BaseStream.Position + size - 8; do { tag = ToTag(_reader.ReadBytes(4)); size = _reader.ReadUInt32BigEndian(); switch (tag) { case "ADL ": if (music == MusicDriverTypes.AdLib|| music == MusicDriverTypes.FMTowns) { _reader.BaseStream.Seek(-8, SeekOrigin.Current); return _reader.ReadBytes((int)size + 8); } _reader.BaseStream.Seek(size, SeekOrigin.Current); break; case "AMI ": _reader.BaseStream.Seek(-8, SeekOrigin.Current); return _reader.ReadBytes((int)size + 8); case "SPK ": if (music == MusicDriverTypes.PCSpeaker) { _reader.BaseStream.Seek(-8, SeekOrigin.Current); return _reader.ReadBytes((int)size + 8); } _reader.BaseStream.Seek(size, SeekOrigin.Current); break; case "MIDI": if (music == MusicDriverTypes.Midi) { _reader.BaseStream.Seek(-8, SeekOrigin.Current); return _reader.ReadBytes((int)size + 8); } _reader.BaseStream.Seek(size, SeekOrigin.Current); break; case "Mac0": _reader.BaseStream.Seek(-12, SeekOrigin.Current); size = _reader.ReadUInt32BigEndian() - 8; return _reader.ReadBytes((int)size); case "TOWS": _reader.BaseStream.Seek(-12, SeekOrigin.Current); size = _reader.ReadUInt32BigEndian(); return _reader.ReadBytes((int)size); case "SOU ": break; default: // skip // Console.WriteLine("Skip Block: {0}", tag); _reader.BaseStream.Seek(size, SeekOrigin.Current); break; } } while (_reader.BaseStream.Position < pos); return null; }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { _reader.BaseStream.Seek(offset, SeekOrigin.Begin); var wa_offs = offset; var wa_size = _reader.ReadUInt16(); int ad_size = 0; int ad_offs = 0; _reader.BaseStream.Seek(wa_size - 2, SeekOrigin.Current); if (!(_game.Platform == Platform.AtariST || _game.Platform == Platform.Macintosh)) { ad_offs = (int)_reader.BaseStream.Position; ad_size = _reader.ReadUInt16(); } _reader.BaseStream.Seek(wa_offs, SeekOrigin.Begin); var data = _reader.ReadBytes(wa_size); return data; }
public IEnumerable<byte[]> GetSounds(MusicDriverTypes music) { for (byte i = 0; i < Index.SoundResources.Count; i++) { if (Index.SoundResources[i].RoomNum != 0) { yield return GetSound(music, i); } } }
public byte[] GetSound(MusicDriverTypes music, int id) { return GetResource(_sounds, id, () => LoadSound(music, id)); }
public void LoadSound(MusicDriverTypes music, int id) { if (id == 0 || _sounds.ContainsKey(id)) return; NukeResource(ResType.Sound, id); byte[] data = null; var resource = Index.SoundResources[id]; if (resource.RoomNum != 0) { var disk = OpenRoom(resource.RoomNum); if (disk != null) { var roomOffset = GetRoomOffset(disk, resource.RoomNum); if (Game.IsOldBundle && Game.Version == 3 && Game.Platform == Platform.Amiga) { data = ((ResourceFile3_16)disk).ReadAmigaSound(roomOffset + resource.Offset); } else if (Game.Version == 3 && (Game.Platform == Platform.Amiga || Game.Platform == Platform.FMTowns)) { data = ((ResourceFile3)disk).ReadAmigaSound(roomOffset + resource.Offset); } else if (Game.Version == 4 && Game.Platform == Platform.Amiga) { data = ((ResourceFile4)disk).ReadAmigaSound(roomOffset + resource.Offset); } else { data = disk.ReadSound(music, roomOffset + resource.Offset); // For games using AD except Indy3 and Loom we are using our iMuse // implementation. See output initialization in // ScummEngine::setupMusic for more information. if (data != null && Game.Version < 5 && Game.GameId != GameId.Indy3 && Game.GameId != GameId.Loom && music == MusicDriverTypes.AdLib) { data = ConvertADResource(data, id); } } } } if (data != null) { ExpireResources(data.Length); _sounds[id] = data; _allocatedSize += data.Length; SetSoundCounter(id, 1); } }
public override byte[] ReadSound(MusicDriverTypes music, long offset) { _reader.BaseStream.Seek(offset, SeekOrigin.Begin); var size = _reader.ReadUInt16(); // wa_size _reader.BaseStream.Seek(-2, SeekOrigin.Current); var data = _reader.ReadBytes(size); return data; }
public byte[] GetSound(MusicDriverTypes music, int id) { return(GetResource(_sounds, id, () => LoadSound(music, id))); }