shithub: opus

Download patch

ref: c8e3728000d451b1ed023c61b8052c8a4d1d8256
parent: 24af30377eb98a9821e0069e7c8d41b612015569
author: Jean-Marc Valin <[email protected]>
date: Wed Jun 30 10:44:20 EDT 2010

Created tester based on testcelt.c

--- a/src/hybrid_encoder.c
+++ b/src/hybrid_encoder.c
@@ -60,7 +60,10 @@
 {
 	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 @@
 	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;
 }
--- a/src/test_hybrid.c
+++ b/src/test_hybrid.c
@@ -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
@@ -29,13 +30,96 @@
    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;
+   }
 
-	enc = hybrid_encoder_create();
-	return 0;
+   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;
+   }
+
+   hybrid_encoder_destroy(enc);
+   /*hybrid_decoder_destroy(dec);*/
+   fclose(fin);
+   fclose(fout);
+   free(in);
+   free(out);
+   return 0;
 }