Created tester based on testcelt.c
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Wed, 30 Jun 2010 18:44:20 +0000 (14:44 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Wed, 30 Jun 2010 18:44:20 +0000 (14:44 -0400)
src/hybrid_encoder.c
src/test_hybrid.c

index b712052..e68baa7 100644 (file)
@@ -60,7 +60,10 @@ int hybrid_encode(HybridEncoder *st, short *pcm, int frame_size,
 {
        int celt_ret;
        ec_enc enc;
+       ec_byte_buffer buf;
 
+       ec_byte_writeinit_buffer(&buf, data, bytes_per_packet);
+       ec_enc_init(&enc,&buf);
 
        /* FIXME: Call SILK encoder for the low band */
 
@@ -68,7 +71,7 @@ int hybrid_encode(HybridEncoder *st, short *pcm, int frame_size,
        celt_encoder_ctl(st->celt_enc, CELT_SET_START_BAND(13));
 
        /* Encode high band with CELT */
-       celt_ret = celt_encode(st->celt_enc, pcm, frame_size, data, bytes_per_packet);
+       celt_ret = celt_encode_with_ec(st->celt_enc, pcm, NULL, frame_size, data, bytes_per_packet, &enc);
 
        return celt_ret;
 }
index 2e25da5..f49ea76 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (c) 2010 Xiph.Org Foundation
+/* Copyright (c) 2007-2008 CSIRO
+   Copyright (c) 2007-2009 Xiph.Org Foundation
    Written by Jean-Marc Valin */
 /*
    Redistribution and use in source and binary forms, with or without
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
 
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <string.h>
 #include "hybrid.h"
 
-int main(int argc, char **argv)
+
+#define MAX_PACKET 1024
+
+int main(int argc, char *argv[])
 {
-       HybridEncoder *enc;
+   int err;
+   char *inFile, *outFile;
+   FILE *fin, *fout;
+   HybridEncoder *enc;
+   int len;
+   int frame_size, channels;
+   int bytes_per_packet;
+   unsigned char data[MAX_PACKET];
+   int rate;
+   int count = 0;
+   int skip;
+   short *in, *out;
+   if (argc != 9 && argc != 8 && argc != 7)
+   {
+      fprintf (stderr, "Usage: test_hybrid <rate> <channels> <frame size> "
+               " <bytes per packet>  "
+               "<input> <output>\n");
+      return 1;
+   }
+
+   rate = atoi(argv[1]);
+   channels = atoi(argv[2]);
+   frame_size = atoi(argv[3]);
+
+   bytes_per_packet = atoi(argv[4]);
+   if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET)
+   {
+      fprintf (stderr, "bytes per packet must be between 0 and %d\n",
+                        MAX_PACKET);
+      return 1;
+   }
+
+   inFile = argv[argc-2];
+   fin = fopen(inFile, "rb");
+   if (!fin)
+   {
+      fprintf (stderr, "Could not open input file %s\n", argv[argc-2]);
+      return 1;
+   }
+   outFile = argv[argc-1];
+   fout = fopen(outFile, "wb+");
+   if (!fout)
+   {
+      fprintf (stderr, "Could not open output file %s\n", argv[argc-1]);
+      return 1;
+   }
+
+   enc = hybrid_encoder_create();
+   /*dec = hybrid_decoder_create();*/
+
+   in = (short*)malloc(frame_size*channels*sizeof(short));
+   out = (short*)malloc(frame_size*channels*sizeof(short));
+   while (!feof(fin))
+   {
+      err = fread(in, sizeof(short), frame_size*channels, fin);
+      if (feof(fin))
+         break;
+      len = hybrid_encode(enc, in, frame_size, data, bytes_per_packet);
+      if (len <= 0)
+      {
+         fprintf (stderr, "hybrid_encode() returned %d\n", len);
+         return 1;
+      }
+      /* This is for simulating bit errors */
+      /*hybrid_decode(dec, data, len, out, frame_size);*/
+      count++;
+      fwrite(out+skip, sizeof(short), (frame_size-skip)*channels, fout);
+      skip = 0;
+   }
 
-       enc = hybrid_encoder_create();
-       return 0;
+   hybrid_encoder_destroy(enc);
+   /*hybrid_decoder_destroy(dec);*/
+   fclose(fin);
+   fclose(fout);
+   free(in);
+   free(out);
+   return 0;
 }