Example #1
0
        public void TestGetProcessHandle()
        {
            PoolMapper      poolMapper    = new PoolMapper(DummyProcessHandle, true);
            MemoryPoolState memoryPoolDsp = MemoryPoolState.Create(MemoryPoolState.LocationType.Dsp);
            MemoryPoolState memoryPoolCpu = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);

            Assert.AreEqual(0xFFFF8001, poolMapper.GetProcessHandle(ref memoryPoolCpu));
            Assert.AreEqual(DummyProcessHandle, poolMapper.GetProcessHandle(ref memoryPoolDsp));
        }
Example #2
0
        public void TestIsMapped()
        {
            MemoryPoolState memoryPool = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);

            memoryPool.SetCpuAddress(0x1000000, 0x1000);

            Assert.IsFalse(memoryPool.IsMapped());

            memoryPool.DspAddress = 0x2000000;

            Assert.IsTrue(memoryPool.IsMapped());
        }
Example #3
0
        public void TestTranslate()
        {
            MemoryPoolState memoryPool = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);

            memoryPool.SetCpuAddress(0x1000000, 0x1000);

            memoryPool.DspAddress = 0x2000000;

            Assert.AreEqual(0x2000FE0, memoryPool.Translate(0x1000FE0, 0x10));
            Assert.AreEqual(0x2000FFF, memoryPool.Translate(0x1000FFF, 0x1));
            Assert.AreEqual(0x0, memoryPool.Translate(0x1000FFF, 0x2));
            Assert.AreEqual(0x0, memoryPool.Translate(0x1001000, 0x10));
            Assert.AreEqual(0x0, memoryPool.Translate(0x2000000, 0x10));
        }
Example #4
0
        public void TestContains()
        {
            MemoryPoolState memoryPool = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);

            memoryPool.SetCpuAddress(0x1000000, 0x1000);

            memoryPool.DspAddress = 0x2000000;

            Assert.IsTrue(memoryPool.Contains(0x1000000, 0x10));
            Assert.IsTrue(memoryPool.Contains(0x1000FE0, 0x10));
            Assert.IsTrue(memoryPool.Contains(0x1000FFF, 0x1));
            Assert.IsFalse(memoryPool.Contains(0x1000FFF, 0x2));
            Assert.IsFalse(memoryPool.Contains(0x1001000, 0x10));
            Assert.IsFalse(memoryPool.Contains(0x2000000, 0x10));
        }
Example #5
0
        public void TestInitializeSystemPool()
        {
            PoolMapper      poolMapper    = new PoolMapper(DummyProcessHandle, true);
            MemoryPoolState memoryPoolDsp = MemoryPoolState.Create(MemoryPoolState.LocationType.Dsp);
            MemoryPoolState memoryPoolCpu = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);

            const CpuAddress CpuAddress = 0x20000;
            const DspAddress DspAddress = CpuAddress; // TODO: DSP LLE
            const ulong      CpuSize    = 0x1000;

            Assert.IsFalse(poolMapper.InitializeSystemPool(ref memoryPoolCpu, CpuAddress, CpuSize));
            Assert.IsTrue(poolMapper.InitializeSystemPool(ref memoryPoolDsp, CpuAddress, CpuSize));

            Assert.AreEqual(CpuAddress, memoryPoolDsp.CpuAddress);
            Assert.AreEqual(CpuSize, memoryPoolDsp.Size);
            Assert.AreEqual(DspAddress, memoryPoolDsp.DspAddress);
        }
Example #6
0
        public void TestGetReference()
        {
            MemoryPoolState[] memoryPoolState = new MemoryPoolState[1];
            memoryPoolState[0] = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);
            memoryPoolState[0].SetCpuAddress(0x1000000, 0x10000);
            memoryPoolState[0].DspAddress = 0x4000000;

            AddressInfo addressInfo = AddressInfo.Create(0x1000000, 0x1000);

            addressInfo.ForceMappedDspAddress = 0x2000000;

            Assert.AreEqual(0x2000000, addressInfo.GetReference(true));

            addressInfo.SetupMemoryPool(memoryPoolState.AsSpan());

            Assert.AreEqual(0x4000000, addressInfo.GetReference(true));
        }
Example #7
0
        public AudioRenderSystem(AudioRendererManager manager, IWritableEvent systemEvent)
        {
            _manager            = manager;
            _terminationEvent   = new ManualResetEvent(false);
            _dspMemoryPoolState = MemoryPoolState.Create(MemoryPoolState.LocationType.Dsp);
            _voiceContext       = new VoiceContext();
            _mixContext         = new MixContext();
            _sinkContext        = new SinkContext();
            _splitterContext    = new SplitterContext();
            _effectContext      = new EffectContext();

            _commandProcessingTimeEstimator = null;
            _systemEvent      = systemEvent;
            _behaviourContext = new BehaviourContext();

            _totalElapsedTicksUpdating = 0;
            _sessionId = 0;
        }
Example #8
0
        public void TestMappings()
        {
            PoolMapper      poolMapper    = new PoolMapper(DummyProcessHandle, true);
            MemoryPoolState memoryPoolDsp = MemoryPoolState.Create(MemoryPoolState.LocationType.Dsp);
            MemoryPoolState memoryPoolCpu = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);

            const CpuAddress CpuAddress = 0x20000;
            const DspAddress DspAddress = CpuAddress; // TODO: DSP LLE
            const ulong      CpuSize    = 0x1000;

            memoryPoolDsp.SetCpuAddress(CpuAddress, CpuSize);
            memoryPoolCpu.SetCpuAddress(CpuAddress, CpuSize);

            Assert.AreEqual(DspAddress, poolMapper.Map(ref memoryPoolCpu));
            Assert.AreEqual(DspAddress, poolMapper.Map(ref memoryPoolDsp));
            Assert.AreEqual(DspAddress, memoryPoolDsp.DspAddress);
            Assert.IsTrue(poolMapper.Unmap(ref memoryPoolCpu));

            memoryPoolDsp.IsUsed = true;
            Assert.IsFalse(poolMapper.Unmap(ref memoryPoolDsp));
            memoryPoolDsp.IsUsed = false;
            Assert.IsTrue(poolMapper.Unmap(ref memoryPoolDsp));
        }
Example #9
0
        public void TestTryAttachBuffer()
        {
            const CpuAddress CpuAddress = 0x20000;
            const DspAddress DspAddress = CpuAddress; // TODO: DSP LLE
            const ulong      CpuSize    = 0x1000;

            const int        MemoryPoolStateArraySize = 0x10;
            const CpuAddress CpuAddressRegionEnding   = CpuAddress * MemoryPoolStateArraySize;

            MemoryPoolState[] memoryPoolStateArray = new MemoryPoolState[MemoryPoolStateArraySize];

            for (int i = 0; i < memoryPoolStateArray.Length; i++)
            {
                memoryPoolStateArray[i] = MemoryPoolState.Create(MemoryPoolState.LocationType.Cpu);
                memoryPoolStateArray[i].SetCpuAddress(CpuAddress + (ulong)i * CpuSize, CpuSize);
            }

            ErrorInfo errorInfo;

            AddressInfo addressInfo = AddressInfo.Create();

            PoolMapper poolMapper = new PoolMapper(DummyProcessHandle, true);

            Assert.IsTrue(poolMapper.TryAttachBuffer(out errorInfo, ref addressInfo, 0, 0));

            Assert.AreEqual(ResultCode.InvalidAddressInfo, errorInfo.ErrorCode);
            Assert.AreEqual(0, errorInfo.ExtraErrorInfo);
            Assert.AreEqual(0, addressInfo.ForceMappedDspAddress);

            Assert.IsTrue(poolMapper.TryAttachBuffer(out errorInfo, ref addressInfo, CpuAddress, CpuSize));

            Assert.AreEqual(ResultCode.InvalidAddressInfo, errorInfo.ErrorCode);
            Assert.AreEqual(CpuAddress, errorInfo.ExtraErrorInfo);
            Assert.AreEqual(DspAddress, addressInfo.ForceMappedDspAddress);

            poolMapper = new PoolMapper(DummyProcessHandle, false);

            Assert.IsFalse(poolMapper.TryAttachBuffer(out errorInfo, ref addressInfo, 0, 0));

            addressInfo.ForceMappedDspAddress = 0;

            Assert.IsFalse(poolMapper.TryAttachBuffer(out errorInfo, ref addressInfo, CpuAddress, CpuSize));

            Assert.AreEqual(ResultCode.InvalidAddressInfo, errorInfo.ErrorCode);
            Assert.AreEqual(CpuAddress, errorInfo.ExtraErrorInfo);
            Assert.AreEqual(0, addressInfo.ForceMappedDspAddress);

            poolMapper = new PoolMapper(DummyProcessHandle, memoryPoolStateArray.AsMemory(), false);

            Assert.IsFalse(poolMapper.TryAttachBuffer(out errorInfo, ref addressInfo, CpuAddressRegionEnding, CpuSize));

            Assert.AreEqual(ResultCode.InvalidAddressInfo, errorInfo.ErrorCode);
            Assert.AreEqual(CpuAddressRegionEnding, errorInfo.ExtraErrorInfo);
            Assert.AreEqual(0, addressInfo.ForceMappedDspAddress);
            Assert.IsFalse(addressInfo.HasMemoryPoolState);

            Assert.IsTrue(poolMapper.TryAttachBuffer(out errorInfo, ref addressInfo, CpuAddress, CpuSize));

            Assert.AreEqual(ResultCode.Success, errorInfo.ErrorCode);
            Assert.AreEqual(0, errorInfo.ExtraErrorInfo);
            Assert.AreEqual(0, addressInfo.ForceMappedDspAddress);
            Assert.IsTrue(addressInfo.HasMemoryPoolState);
        }
Example #10
0
        public long RequestUpdateAudioRenderer(ServiceCtx Context)
        {
            long OutputPosition = Context.Request.ReceiveBuff[0].Position;
            long OutputSize     = Context.Request.ReceiveBuff[0].Size;

            AMemoryHelper.FillWithZeros(Context.Memory, OutputPosition, (int)OutputSize);

            long InputPosition = Context.Request.SendBuff[0].Position;

            UpdateDataHeader InputDataHeader = AMemoryHelper.Read <UpdateDataHeader>(Context.Memory, InputPosition);

            UpdateDataHeader OutputDataHeader = new UpdateDataHeader();

            int UpdateHeaderSize = Marshal.SizeOf <UpdateDataHeader>();

            OutputDataHeader.Revision               = Params.Revision;
            OutputDataHeader.BehaviorSize           = 0xb0;
            OutputDataHeader.MemoryPoolsSize        = (Params.EffectCount + Params.VoiceCount * 4) * 0x10;
            OutputDataHeader.VoicesSize             = Params.VoiceCount * 0x10;
            OutputDataHeader.EffectsSize            = Params.EffectCount * 0x10;
            OutputDataHeader.SinksSize              = Params.SinkCount * 0x20;
            OutputDataHeader.PerformanceManagerSize = 0x10;
            OutputDataHeader.TotalSize              = UpdateHeaderSize +
                                                      OutputDataHeader.BehaviorSize +
                                                      OutputDataHeader.MemoryPoolsSize +
                                                      OutputDataHeader.VoicesSize +
                                                      OutputDataHeader.EffectsSize +
                                                      OutputDataHeader.SinksSize +
                                                      OutputDataHeader.PerformanceManagerSize;

            AMemoryHelper.Write(Context.Memory, OutputPosition, OutputDataHeader);

            int InMemoryPoolOffset = UpdateHeaderSize + InputDataHeader.BehaviorSize;

            int OutMemoryPoolOffset = UpdateHeaderSize;

            for (int Offset = 0; Offset < OutputDataHeader.MemoryPoolsSize; Offset += 0x10, InMemoryPoolOffset += 0x20)
            {
                MemoryPoolState PoolState = (MemoryPoolState)Context.Memory.ReadInt32(InputPosition + InMemoryPoolOffset + 0x10);

                //TODO: Figure out what the other values does.
                if (PoolState == MemoryPoolState.RequestAttach)
                {
                    Context.Memory.WriteInt32(OutputPosition + OutMemoryPoolOffset + Offset, (int)MemoryPoolState.Attached);
                }
                else if (PoolState == MemoryPoolState.RequestDetach)
                {
                    Context.Memory.WriteInt32(OutputPosition + OutMemoryPoolOffset + Offset, (int)MemoryPoolState.Detached);
                }
            }

            int OutVoicesOffset = OutMemoryPoolOffset + OutputDataHeader.MemoryPoolsSize;

            for (int Offset = 0; Offset < OutputDataHeader.VoicesSize; Offset += 0x10)
            {
                Context.Memory.WriteInt32(OutputPosition + OutVoicesOffset + Offset + 8, (int)VoicePlaybackState.Finished);
            }

            //TODO: We shouldn't be signaling this here.
            UpdateEvent.WaitEvent.Set();

            return(0);
        }