コード例 #1
0
        public void Play(int track, int numLoops, int startFrame, int duration, bool only_emulate)
        {
            if (numLoops != 0 || startFrame != 0)
            {
                _cd.track    = track;
                _cd.numLoops = numLoops;
                _cd.start    = startFrame;
                _cd.duration = duration;

                // Try to load the track from a compressed data file, and if found, use
                // that. If not found, attempt to start regular Audio CD playback of
                // the requested track.
                string[] trackName = new string[2];
                trackName[0] = string.Format("track{0}", track);
                trackName[1] = string.Format("track{0:00}", track);
                ISeekableAudioStream stream = null;
                var directory = ServiceLocator.FileStorage.GetDirectoryName(_vm.Game.Path);
                for (int i = 0; stream == null && i < 2; ++i)
                {
                    var path = ScummHelper.LocatePath(directory, trackName[i]);
                    if (path != null)
                    {
                        // TODO: open stream
                    }
                }

                // Stop any currently playing emulated track
                _mixer.StopHandle(_handle);

                if (stream != null)
                {
                    var start = new Timestamp(0, startFrame, 75);
                    var end   = duration != 0 ? new Timestamp(0, startFrame + duration, 75) : stream.Length;

                    /*
                     * FIXME: Seems numLoops == 0 and numLoops == 1 both indicate a single repetition,
                     * while all other positive numbers indicate precisely the number of desired
                     * repetitions. Finally, -1 means infinitely many
                     */
                    _emulating = true;
                    _handle    = _mixer.PlayStream(SoundType.Music, LoopingAudioStream.Create(stream, start, end, (numLoops < 1) ? numLoops + 1 : numLoops), -1, _cd.volume, _cd.balance);
                }
                else
                {
                    _emulating = false;
                    if (!only_emulate)
                    {
                        PlayCD(track, numLoops, startFrame, duration);
                    }
                }
            }
        }
コード例 #2
0
        private void PlaySample(QueueElement elem)
        {
            var sampleData = _resMan.FetchRes(GetSampleId((int)elem.id));

            for (var cnt = 0; cnt < MAX_ROOMS_PER_FX; cnt++)
            {
                if (_fxList[elem.id].roomVolList[cnt].roomNo != 0)
                {
                    if ((_fxList[elem.id].roomVolList[cnt].roomNo == (int)Logic.ScriptVars[(int)ScriptVariableNames.SCREEN]) ||
                        (_fxList[elem.id].roomVolList[cnt].roomNo == -1))
                    {
                        byte  volL   = (byte)((_fxList[elem.id].roomVolList[cnt].leftVol * 10 * _sfxVolL) / 255);
                        byte  volR   = (byte)((_fxList[elem.id].roomVolList[cnt].rightVol * 10 * _sfxVolR) / 255);
                        sbyte pan    = (sbyte)((volR - volL) / 2);
                        byte  volume = (byte)((volR + volL) / 2);

                        if (SystemVars.Platform == Platform.PSX)
                        {
                            int size      = sampleData.ToInt32(0);
                            var audStream = new LoopingAudioStream(new XAStream(new MemoryStream(sampleData, 4, size - 4), 11025), (_fxList[elem.id].type == FX_LOOP) ? 0 : 1);
                            elem.handle = _mixer.PlayStream(SoundType.SFX, audStream, (int)elem.id, volume, pan);
                        }
                        else
                        {
                            uint       size = sampleData.ToUInt32(0x28);
                            AudioFlags flags;
                            if (sampleData.ToUInt16(0x22) == 16)
                            {
                                flags = AudioFlags.Is16Bits | AudioFlags.LittleEndian;
                            }
                            else
                            {
                                flags = AudioFlags.Unsigned;
                            }
                            if (sampleData.ToUInt16(0x16) == 2)
                            {
                                flags |= AudioFlags.Stereo;
                            }
                            var stream = new LoopingAudioStream(new RawStream(flags, 11025, false, new MemoryStream(sampleData, 0x2C, (int)size)),
                                                                (_fxList[elem.id].type == FX_LOOP) ? 0 : 1);
                            elem.handle = _mixer.PlayStream(SoundType.SFX, stream, (int)elem.id, volume, pan);
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
コード例 #3
0
ファイル: Sound.cs プロジェクト: scemino/nscumm
        private void PlaySample(QueueElement elem)
        {
            var sampleData = _resMan.FetchRes(GetSampleId((int)elem.id));
            for (var cnt = 0; cnt < MAX_ROOMS_PER_FX; cnt++)
            {
                if (_fxList[elem.id].roomVolList[cnt].roomNo != 0)
                {
                    if ((_fxList[elem.id].roomVolList[cnt].roomNo == (int)Logic.ScriptVars[(int)ScriptVariableNames.SCREEN]) ||
                            (_fxList[elem.id].roomVolList[cnt].roomNo == -1))
                    {

                        byte volL = (byte)((_fxList[elem.id].roomVolList[cnt].leftVol * 10 * _sfxVolL) / 255);
                        byte volR = (byte)((_fxList[elem.id].roomVolList[cnt].rightVol * 10 * _sfxVolR) / 255);
                        sbyte pan = (sbyte)((volR - volL) / 2);
                        byte volume = (byte)((volR + volL) / 2);

                        if (SystemVars.Platform == Platform.PSX)
                        {
                            int size = sampleData.ToInt32(0);
                            var audStream = new LoopingAudioStream(new XAStream(new MemoryStream(sampleData, 4, size - 4), 11025), (_fxList[elem.id].type == FX_LOOP) ? 0 : 1);
                            elem.handle = _mixer.PlayStream(SoundType.SFX, audStream, (int)elem.id, volume, pan);
                        }
                        else
                        {
                            uint size = sampleData.ToUInt32(0x28);
                            AudioFlags flags;
                            if (sampleData.ToUInt16(0x22) == 16)
                                flags = AudioFlags.Is16Bits | AudioFlags.LittleEndian;
                            else
                                flags = AudioFlags.Unsigned;
                            if (sampleData.ToUInt16(0x16) == 2)
                                flags |= AudioFlags.Stereo;
                            var stream = new LoopingAudioStream(new RawStream(flags, 11025, false, new MemoryStream(sampleData, 0x2C, (int)size)),
                                                             (_fxList[elem.id].type == FX_LOOP) ? 0 : 1);
                            elem.handle = _mixer.PlayStream(SoundType.SFX, stream, (int)elem.id, volume, pan);
                        }
                    }
                }
                else
                    break;
            }
        }