prepend 1 sample zero padding in case of SBR and enc_delay is odd
[fdkaac.git] / src / main.c
index 5e0dc0cfdcc9902a10e821c02d5e9f16a6f78825..7d1a68fc885fb1abbe95b878b3161063eac15f98 100644 (file)
@@ -493,12 +493,8 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
            HANDLE_AACENCODER encoder, uint32_t frame_length, 
            m4af_ctx_t *m4af)
 {
-    struct buffer_t {
-        uint8_t *data;
-        uint32_t len, size;
-    };
     int16_t *ibuf = 0, *ip;
-    struct buffer_t obuf[2] = {{ 0 }}, *obp;
+    aacenc_result_t obuf[2] = {{ 0 }}, *obp;
     unsigned flip = 0;
     int nread = 1;
     int rc = -1;
@@ -530,8 +526,7 @@ int encode(aacenc_param_ex_t *params, pcm_reader_t *reader,
         remaining = nread;
         do {
             obp = &obuf[flip];
-            consumed = aac_encode_frame(encoder, fmt, ip, remaining,
-                                        &obp->data, &obp->len, &obp->size);
+            consumed = aac_encode_frame(encoder, fmt, ip, remaining, obp);
             if (consumed < 0) goto END;
             if (consumed == 0 && obp->len == 0) goto DONE;
             if (obp->len == 0) break;
@@ -828,6 +823,16 @@ int main(int argc, char **argv)
         m4af_set_priming_mode(m4af, params.gapless_mode + 1);
         m4af_begin_write(m4af);
     }
+    if (sbr_mode && (aacinfo.encoderDelay & 1)) {
+        /*
+         * Since odd delay cannot be exactly expressed in downsampled scale,
+         * we push one zero frame to the encoder here, to make delay even
+         */
+        int16_t zero[8] = { 0 };
+        aacenc_result_t obuf = { 0 };
+        aac_encode_frame(encoder, sample_format, zero, 1, &obuf);
+        free(obuf.data);
+    }
     frame_count = encode(&params, reader, encoder, aacinfo.frameLength, m4af);
     if (frame_count < 0)
         goto END;
This page took 0.009796 seconds and 4 git commands to generate.