| 1855 | } |
| 1856 | |
| 1857 | static void Master(const MixContext* mix_context) |
| 1858 | { |
| 1859 | DM_PROFILE(__FUNCTION__); |
| 1860 | |
| 1861 | SoundSystem* sound = g_SoundSystem; |
| 1862 | |
| 1863 | uint32_t frame_size = 2 * (sound->m_UseFloatOutput ? sizeof(float) : sizeof(int16_t)); |
| 1864 | |
| 1865 | uint32_t n = mix_context->m_FrameCount; |
| 1866 | void* out = sound->m_OutBuffers[sound->m_NextOutBuffer]; |
| 1867 | int* master_index = sound->m_GroupMap.Get(MASTER_GROUP_HASH); |
| 1868 | SoundGroup* master = &sound->m_Groups[*master_index]; |
| 1869 | float* mix_buffer[2] = {master->m_MixBuffer[0], master->m_MixBuffer[1]}; |
| 1870 | |
| 1871 | if (master->m_Gain.IsZero()) |
| 1872 | { |
| 1873 | memset(out, 0, n * frame_size); |
| 1874 | return; |
| 1875 | } |
| 1876 | |
| 1877 | for (uint32_t i = 0; i < MAX_GROUPS; i++) { |
| 1878 | SoundGroup* g = &sound->m_Groups[i]; |
| 1879 | if (g->m_MixBuffer[0] == nullptr) |
| 1880 | { |
| 1881 | continue; |
| 1882 | } |
| 1883 | if (g->m_NameHash == MASTER_GROUP_HASH) |
| 1884 | { |
| 1885 | continue; |
| 1886 | } |
| 1887 | if (g->m_Gain.IsZero()) |
| 1888 | { |
| 1889 | continue; |
| 1890 | } |
| 1891 | float gain; |
| 1892 | float gaind = GetRampDelta(mix_context, &g->m_Gain, n, gain); |
| 1893 | ApplyClampedGain(mix_buffer, g->m_MixBuffer, n, gain, gaind); |
| 1894 | } |
| 1895 | |
| 1896 | float gain; |
| 1897 | float gaind = GetRampDelta(mix_context, &master->m_Gain, n, gain); |
| 1898 | if (sound->m_UseFloatOutput == 0 && sound->m_NonInterleavedOutput == 0) { |
| 1899 | ApplyGainAndInterleaveToS16((int16_t*)out, mix_buffer, n, gain, gaind); |
| 1900 | } |
| 1901 | else { |
| 1902 | assert(sound->m_UseFloatOutput == 1 && sound->m_NonInterleavedOutput == 1); |
| 1903 | if (sound->m_NormalizeFloatOutput) { |
| 1904 | gain *= 1.0f / 32768.0f; |
| 1905 | gaind *= 1.0f / 32768.0f; |
| 1906 | } |
| 1907 | float* ob[] = {(float*)out, (float*)out + n}; |
| 1908 | ApplyGain(ob, mix_buffer, n, gain, gaind); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | static void StepGroupValues() |
| 1913 | { |
no test coverage detected