@@ -69,14 +69,28 @@ void getStats() {
6969
7070 @ Test
7171 void processByteStream () {
72- ProcessBuffer buffer = new ProcessBuffer (48000 , 48000 , 1 );
72+ ProcessBuffer buffer = new ProcessBuffer (48000 , 48000 , 1 , 1 );
73+
74+ assertEquals (0 , process (audioProcessing , buffer ));
75+ }
76+
77+ @ Test
78+ void processByteStreamDownMix () {
79+ ProcessBuffer buffer = new ProcessBuffer (48000 , 44100 , 2 , 1 );
80+
81+ assertEquals (0 , process (audioProcessing , buffer ));
82+ }
83+
84+ @ Test
85+ void processByteStreamUpMix () {
86+ ProcessBuffer buffer = new ProcessBuffer (48000 , 44100 , 1 , 2 );
7387
7488 assertEquals (0 , process (audioProcessing , buffer ));
7589 }
7690
7791 @ Test
7892 void processReverseStream () {
79- ProcessBuffer buffer = new ProcessBuffer (48000 , 48000 , 1 );
93+ ProcessBuffer buffer = new ProcessBuffer (48000 , 48000 , 1 , 1 );
8094
8195 assertEquals (0 , processReverse (audioProcessing , buffer ));
8296 }
@@ -106,7 +120,8 @@ private static class ProcessBuffer {
106120
107121 final int bytesPerFrame = 2 ;
108122
109- final int channels ;
123+ final int channelsIn ;
124+ final int channelsOut ;
110125
111126 final int sampleRateIn ;
112127 final int sampleRateOut ;
@@ -124,21 +139,22 @@ private static class ProcessBuffer {
124139 AudioProcessingStreamConfig streamConfigOut ;
125140
126141
127- ProcessBuffer (int sampleRateIn , int sampleRateOut , int channels ) {
128- this .channels = channels ;
142+ ProcessBuffer (int sampleRateIn , int sampleRateOut , int channelsIn , int channelsOut ) {
129143 this .sampleRateIn = sampleRateIn ;
130144 this .sampleRateOut = sampleRateOut ;
145+ this .channelsIn = channelsIn ;
146+ this .channelsOut = channelsOut ;
131147
132- nSamplesIn = sampleRateIn / 100 * channels ; // 10 ms frame
133- nSamplesOut = sampleRateOut / 100 * channels ;
134- frameSizeIn = nSamplesIn * bytesPerFrame ;
135- frameSizeOut = nSamplesOut * bytesPerFrame ;
148+ nSamplesIn = sampleRateIn / 100 ; // 10 ms frame
149+ nSamplesOut = sampleRateOut / 100 ;
150+ frameSizeIn = nSamplesIn * bytesPerFrame * channelsIn ;
151+ frameSizeOut = Math . max ( nSamplesIn , nSamplesOut ) * bytesPerFrame * channelsOut ;
136152
137153 src = new byte [frameSizeIn ];
138154 dst = new byte [frameSizeOut ];
139155
140- streamConfigIn = new AudioProcessingStreamConfig (sampleRateIn , channels );
141- streamConfigOut = new AudioProcessingStreamConfig (sampleRateOut , channels );
156+ streamConfigIn = new AudioProcessingStreamConfig (sampleRateIn , channelsIn );
157+ streamConfigOut = new AudioProcessingStreamConfig (sampleRateOut , channelsOut );
142158 }
143159 }
144160}
0 commit comments