| | 1 | | using UnityEngine; |
| | 2 | |
|
| | 3 | | namespace DCL |
| | 4 | | { |
| | 5 | | public static class MetricsScoreUtils |
| | 6 | | { |
| | 7 | | public static long ComputeAudioClipScore(AudioClip audioClip) |
| | 8 | | { |
| 21 | 9 | | long baseOverhead = 3000; // Measured 2708 profiling AudioClip with 1 sample and 2 channels. |
| | 10 | | // Rounding up just in case. |
| | 11 | |
|
| | 12 | | // For most cases the sample resolution should be of 65535 (PCM) |
| | 13 | | // But the size seems to be rounded up to 4 bytes. (Maybe due to Mono aligning the bytes?) |
| | 14 | | const double BYTES_PER_SAMPLE = 4; |
| 21 | 15 | | return (long) (audioClip.samples * audioClip.channels * BYTES_PER_SAMPLE) + baseOverhead; |
| | 16 | | } |
| | 17 | |
|
| | 18 | | public static long ComputeTextureScore(Texture2D texture) |
| | 19 | | { |
| | 20 | | // https://forum.unity.com/threads/does-unity-always-use-double-memory-for-texture-in-runtime.198270/ |
| | 21 | | const double ARBITRARY_UNITY_MEMORY_MULTIPLIER = 2; |
| | 22 | |
|
| | 23 | | // The mipmap memory increase should be actually 1.33 according to many sources |
| | 24 | | const double MIPMAP_FACTOR = 1.4f; |
| | 25 | | const double BYTES_PER_PIXEL = 4; |
| 221 | 26 | | return (long) (texture.width * texture.height * BYTES_PER_PIXEL * MIPMAP_FACTOR * |
| | 27 | | ARBITRARY_UNITY_MEMORY_MULTIPLIER); |
| | 28 | | } |
| | 29 | | } |
| | 30 | | } |