Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.xiph.org/xiph/opus.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Marc Valin <jean-marc.valin@octasic.com>2010-06-30 22:44:20 +0400
committerJean-Marc Valin <jean-marc.valin@octasic.com>2010-06-30 22:44:20 +0400
commitc8e3728000d451b1ed023c61b8052c8a4d1d8256 (patch)
tree73e5660d942527b9c29f9365d6f07dba968a4806 /src
parent24af30377eb98a9821e0069e7c8d41b612015569 (diff)
Created tester based on testcelt.c
Diffstat (limited to 'src')
-rw-r--r--src/hybrid_encoder.c5
-rw-r--r--src/test_hybrid.c94
2 files changed, 93 insertions, 6 deletions
diff --git a/src/hybrid_encoder.c b/src/hybrid_encoder.c
index b7120529..e68baa73 100644
--- a/src/hybrid_encoder.c
+++ b/src/hybrid_encoder.c
@@ -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;
}
diff --git a/src/test_hybrid.c b/src/test_hybrid.c
index 2e25da56..f49ea766 100644
--- 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;
+ }
+
+ 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;
}