MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / panAndExpand

Function panAndExpand

extlibs/soloud/src/core/soloud.cpp:901–1338  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

899 }
900
901 void panAndExpand(AudioSourceInstance *aVoice, float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize, float *aScratch, unsigned int aChannels)
902 {
903 float pan[MAX_CHANNELS]; // current speaker volume
904 float pand[MAX_CHANNELS]; // destination speaker volume
905 float pani[MAX_CHANNELS]; // speaker volume increment per sample
906 unsigned int j, k;
907 for (k = 0; k < aChannels; k++)
908 {
909 pan[k] = aVoice->mCurrentChannelVolume[k];
910 pand[k] = aVoice->mChannelVolume[k] * aVoice->mOverallVolume;
911 pani[k] = (pand[k] - pan[k]) / aSamplesToRead; // TODO: this is a bit inconsistent.. but it's a hack to begin with
912 }
913
914 int ofs = 0;
915 switch (aChannels)
916 {
917 case 1: // Target is mono. Sum everything. (1->1, 2->1, 4->1, 6->1, 8->1)
918 for (j = 0, ofs = 0; j < aVoice->mChannels; j++, ofs += aBufferSize)
919 {
920 pan[0] = aVoice->mCurrentChannelVolume[0];
921 for (k = 0; k < aSamplesToRead; k++)
922 {
923 pan[0] += pani[0];
924 aBuffer[k] += aScratch[ofs + k] * pan[0];
925 }
926 }
927 break;
928 case 2:
929 switch (aVoice->mChannels)
930 {
931 case 8: // 8->2, just sum lefties and righties, add a bit of center and sub?
932 for (j = 0; j < aSamplesToRead; j++)
933 {
934 pan[0] += pani[0];
935 pan[1] += pani[1];
936 float s1 = aScratch[j];
937 float s2 = aScratch[aBufferSize + j];
938 float s3 = aScratch[aBufferSize * 2 + j];
939 float s4 = aScratch[aBufferSize * 3 + j];
940 float s5 = aScratch[aBufferSize * 4 + j];
941 float s6 = aScratch[aBufferSize * 5 + j];
942 float s7 = aScratch[aBufferSize * 6 + j];
943 float s8 = aScratch[aBufferSize * 7 + j];
944 aBuffer[j + 0] += 0.2f * (s1 + s3 + s4 + s5 + s7) * pan[0];
945 aBuffer[j + aBufferSize] += 0.2f * (s2 + s3 + s4 + s6 + s8) * pan[1];
946 }
947 break;
948 case 6: // 6->2, just sum lefties and righties, add a bit of center and sub?
949 for (j = 0; j < aSamplesToRead; j++)
950 {
951 pan[0] += pani[0];
952 pan[1] += pani[1];
953 float s1 = aScratch[j];
954 float s2 = aScratch[aBufferSize + j];
955 float s3 = aScratch[aBufferSize * 2 + j];
956 float s4 = aScratch[aBufferSize * 3 + j];
957 float s5 = aScratch[aBufferSize * 4 + j];
958 float s6 = aScratch[aBufferSize * 5 + j];

Callers 1

mixBusMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected