SoundHandle StartTalkSound(int offset, int b, int mode)
{
Stream file;
SoundHandle handle = new SoundHandle();
var id = -1;
if (vm.Game.GameId == GameId.CurseOfMonkeyIsland)
{
sfxMode |= mode;
return handle;
}
else if (vm.Game.GameId == GameId.Dig)
{
sfxMode |= mode;
if (!(vm.Game.Features.HasFlag(GameFeatures.Demo)))
return handle;
throw new NotImplementedException();
}
else
{
if (_sfxFilename == null)
{
// Console.Error.WriteLine("StartTalkSound: SFX file not found");
return handle;
}
// Some games frequently assume that starting one sound effect will
// automatically stop any other that may be playing at that time. So
// that is what we do here, but we make an exception for speech.
if (mode == 1 && (vm.Game.GameId == GameId.Tentacle || vm.Game.GameId == GameId.SamNMax))
{
id = 777777 + _talkSoundChannel;
_mixer.StopID(id);
}
int num = 0;
if (b > 8)
{
num = (b - 8) >> 1;
}
offset += 8;
_mouthSyncTimes = new ushort[num + 1];
file = ServiceLocator.FileStorage.OpenFileRead(_sfxFilename);
var br = new BinaryReader(file);
file.Seek(offset, SeekOrigin.Begin);
for (int i = 0; i < num; i++)
{
_mouthSyncTimes[i] = br.ReadUInt16BigEndian();
}
// Adjust offset to account for the mouth sync times. It is noteworthy
// that we do not adjust the size here for compressed streams, since
// they only set size to the size of the compressed sound data.
offset += num * 2;
// TODO: In case we ever set up the size for VOC streams, we should
// really check whether the size contains the _mouthSyncTimes.
// if (SoundMode == SoundMode.VOCMode)
// size -= num * 2;
_mouthSyncTimes[num] = 0xFFFF;
sfxMode |= mode;
_curSoundPos = 0;
_mouthSyncMode = true;
}
var input = new VocStream(file, true);
var iMuseDigital = vm.MusicEngine as IMuseDigital;
if (iMuseDigital != null)
{
iMuseDigital.StartVoice(TalkSoundID, input);
}
else
{
if (mode == 1)
{
handle = _mixer.PlayStream(SoundType.SFX, input, id);
}
else
{
handle = _mixer.PlayStream(SoundType.Speech, input, id);
}
}
return handle;
}