| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547 |
- using Ryujinx.Audio.Renderer.Dsp.Command;
- using System;
- using System.Diagnostics;
- namespace Ryujinx.Audio.Renderer.Server
- {
- /// <summary>
- /// <see cref="ICommandProcessingTimeEstimator"/> version 2. (added with REV5)
- /// </summary>
- public class CommandProcessingTimeEstimatorVersion2 : ICommandProcessingTimeEstimator
- {
- private uint _sampleCount;
- private uint _bufferCount;
- public CommandProcessingTimeEstimatorVersion2(uint sampleCount, uint bufferCount)
- {
- _sampleCount = sampleCount;
- _bufferCount = bufferCount;
- }
- public uint Estimate(PerformanceCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)489.35f;
- }
- return (uint)491.18f;
- }
- public uint Estimate(ClearMixBufferCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- float costPerBuffer = 668.8f;
- float baseCost = 193.2f;
- if (_sampleCount == 160)
- {
- costPerBuffer = 260.4f;
- baseCost = 139.65f;
- }
- return (uint)(baseCost + costPerBuffer * _bufferCount);
- }
- public uint Estimate(BiquadFilterCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)4813.2f;
- }
- return (uint)6915.4f;
- }
- public uint Estimate(MixRampGroupedCommand command)
- {
- const float costPerSample = 7.245f;
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- int volumeCount = 0;
- for (int i = 0; i < command.MixBufferCount; i++)
- {
- if (command.Volume0[i] != 0.0f || command.Volume1[i] != 0.0f)
- {
- volumeCount++;
- }
- }
- return (uint)(_sampleCount * costPerSample * volumeCount);
- }
- public uint Estimate(MixRampCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)1859.0f;
- }
- return (uint)2286.1f;
- }
- public uint Estimate(DepopPrepareCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)306.62f;
- }
- return (uint)293.22f;
- }
- public uint Estimate(VolumeRampCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)1403.9f;
- }
- return (uint)1884.3f;
- }
- public uint Estimate(PcmInt16DataSourceCommandVersion1 command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- float costPerSample = 1195.5f;
- float baseCost = 7797.0f;
- if (_sampleCount == 160)
- {
- costPerSample = 749.27f;
- baseCost = 6138.9f;
- }
- return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f))));
- }
- public uint Estimate(AdpcmDataSourceCommandVersion1 command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- float costPerSample = 3564.1f;
- float baseCost = 6225.5f;
- if (_sampleCount == 160)
- {
- costPerSample = 2125.6f;
- baseCost = 9039.5f;
- }
- return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f))));
- }
- public uint Estimate(DepopForMixBuffersCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)762.96f;
- }
- return (uint)726.96f;
- }
- public uint Estimate(CopyMixBufferCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)836.32f;
- }
- return (uint)1000.9f;
- }
- public uint Estimate(MixCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)1342.2f;
- }
- return (uint)1833.2f;
- }
- public uint Estimate(DelayCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- if (command.Enabled)
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)41636.0f;
- case 2:
- return (uint)97861.0f;
- case 4:
- return (uint)192520.0f;
- case 6:
- return (uint)301760.0f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- else
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)578.53f;
- case 2:
- return (uint)663.06f;
- case 4:
- return (uint)703.98f;
- case 6:
- return (uint)760.03f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- }
- if (command.Enabled)
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)8770.3f;
- case 2:
- return (uint)25741.0f;
- case 4:
- return (uint)47551.0f;
- case 6:
- return (uint)81629.0f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- else
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)521.28f;
- case 2:
- return (uint)585.4f;
- case 4:
- return (uint)629.88f;
- case 6:
- return (uint)713.57f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- }
- public uint Estimate(ReverbCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- if (command.Enabled)
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)97192.0f;
- case 2:
- return (uint)103280.0f;
- case 4:
- return (uint)109580.0f;
- case 6:
- return (uint)115070.0f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- else
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)492.01f;
- case 2:
- return (uint)554.46f;
- case 4:
- return (uint)595.86f;
- case 6:
- return (uint)656.62f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- }
- if (command.Enabled)
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)136460.0f;
- case 2:
- return (uint)145750.0f;
- case 4:
- return (uint)154800.0f;
- case 6:
- return (uint)161970.0f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- else
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)495.79f;
- case 2:
- return (uint)527.16f;
- case 4:
- return (uint)598.75f;
- case 6:
- return (uint)666.03f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- }
- public uint Estimate(Reverb3dCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- if (command.Enabled)
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)138840.0f;
- case 2:
- return (uint)135430.0f;
- case 4:
- return (uint)199180.0f;
- case 6:
- return (uint)247350.0f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- else
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)718.7f;
- case 2:
- return (uint)751.3f;
- case 4:
- return (uint)797.46f;
- case 6:
- return (uint)867.43f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- }
- if (command.Enabled)
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)199950.0f;
- case 2:
- return (uint)195200.0f;
- case 4:
- return (uint)290580.0f;
- case 6:
- return (uint)363490.0f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- else
- {
- switch (command.Parameter.ChannelCount)
- {
- case 1:
- return (uint)534.24f;
- case 2:
- return (uint)570.87f;
- case 4:
- return (uint)660.93f;
- case 6:
- return (uint)694.6f;
- default:
- throw new NotImplementedException($"{command.Parameter.ChannelCount}");
- }
- }
- }
- public uint Estimate(AuxiliaryBufferCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- if (command.Enabled)
- {
- return (uint)7177.9f;
- }
- return (uint)489.16f;
- }
- if (command.Enabled)
- {
- return (uint)9499.8f;
- }
- return (uint)485.56f;
- }
- public uint Estimate(VolumeCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)1280.3f;
- }
- return (uint)1737.8f;
- }
- public uint Estimate(CircularBufferSinkCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- float costPerBuffer = 1726.0f;
- float baseCost = 1369.7f;
- if (_sampleCount == 160)
- {
- costPerBuffer = 853.63f;
- baseCost = 1284.5f;
- }
- return (uint)(baseCost + costPerBuffer * command.InputCount);
- }
- public uint Estimate(DownMixSurroundToStereoCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)10009.0f;
- }
- return (uint)14577.0f;
- }
- public uint Estimate(UpsampleCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- if (_sampleCount == 160)
- {
- return (uint)292000.0f;
- }
- return (uint)0.0f;
- }
- public uint Estimate(DeviceSinkCommand command)
- {
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- Debug.Assert(command.InputCount == 2 || command.InputCount == 6);
- if (command.InputCount == 2)
- {
- if (_sampleCount == 160)
- {
- return (uint)9261.5f;
- }
- return (uint)9336.1f;
- }
- if (_sampleCount == 160)
- {
- return (uint)9111.8f;
- }
- return (uint)9566.7f;
- }
- public uint Estimate(PcmFloatDataSourceCommandVersion1 command)
- {
- // NOTE: This was added between REV7 and REV8 and for some reasons the estimator v2 was changed...
- Debug.Assert(_sampleCount == 160 || _sampleCount == 240);
- float costPerSample = 3490.9f;
- float baseCost = 10091.0f;
- if (_sampleCount == 160)
- {
- costPerSample = 2310.4f;
- baseCost = 7845.3f;
- }
- return (uint)(baseCost + (costPerSample * (((command.SampleRate / 200.0f) / _sampleCount) * (command.Pitch * 0.000030518f))));
- }
- public uint Estimate(DataSourceVersion2Command command)
- {
- return 0;
- }
- public uint Estimate(LimiterCommandVersion1 command)
- {
- return 0;
- }
- public uint Estimate(LimiterCommandVersion2 command)
- {
- return 0;
- }
- public uint Estimate(GroupedBiquadFilterCommand command)
- {
- return 0;
- }
- public uint Estimate(CaptureBufferCommand command)
- {
- return 0;
- }
- }
- }
|