Fix matrix export via CTL func.
authorAndrew Allen <bitllama@google.com>
Tue, 7 Nov 2017 21:26:23 +0000 (13:26 -0800)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Fri, 10 Nov 2017 19:17:22 +0000 (14:17 -0500)
Ensure matrix is properly exported from
projection encoder.

Change-Id: I5ede77e4f4d0dc82074e2230780777af542a416e
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
src/opus_projection_decoder.c
src/opus_projection_encoder.c

index a9b1d65..0d1ee41 100644 (file)
@@ -103,7 +103,7 @@ int opus_projection_decoder_init(OpusProjectionDecoder *st, opus_int32 Fs,
 
   /* Assign demixing matrix. */
   st->demixing_matrix_size_in_bytes = expected_matrix_size;
-  mapping_matrix_init(get_demixing_matrix(st), nb_input_streams, channels, 0,
+  mapping_matrix_init(get_demixing_matrix(st), channels, nb_input_streams, 0,
     buf, demixing_matrix_size);
 
   /* Set trivial mapping so each input channel pairs with a matrix column. */
index e34b0e5..a2c2f35 100644 (file)
@@ -361,7 +361,7 @@ int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...)
   break;
   case OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST:
   {
-    int i;
+    int i, j, k, l;
     int nb_input_streams;
     int nb_output_streams;
     unsigned char *external_char;
@@ -388,10 +388,14 @@ int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...)
     }
 
     /* Copy demixing matrix subset to output destination. */
-    for (i = 0; i < nb_input_streams * nb_output_streams; i++)
-    {
-      external_char[2*i] = (unsigned char)internal_short[i];
-      external_char[2*i+1] = (unsigned char)(internal_short[i] >> 8);
+    l = 0;
+    for (i = 0; i < nb_input_streams; i++) {
+      for (j = 0; j < nb_output_streams; j++) {
+        k = demixing_matrix->rows * i + j;
+        external_char[2*l] = (unsigned char)internal_short[k];
+        external_char[2*l+1] = (unsigned char)(internal_short[k] >> 8);
+        l++;
+      }
     }
   }
   break;