ref: 8dfba387f8e72aa921b39c785bce9a8ef219bbf8
parent: 51319268d6ccf4aca8ec0afefe2a3a41acb31497
author: Jean-Marc Valin <[email protected]>
date: Fri Aug 26 21:40:46 EDT 2011
Switching to multi-stream API So far no new functionality
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -46,6 +46,7 @@
#include <string.h>
#include <opus.h>
+#include <opus_multistream.h>
#include <ogg/ogg.h>
#if defined WIN32 || defined _WIN32
@@ -385,10 +386,11 @@
printf ("Copyright (C) 2008-2011 Jean-Marc Valin\n");
}
-static OpusDecoder *process_header(ogg_packet *op, opus_int32 *rate, int *channels, int *preskip, float *gain, int quiet)
+static OpusMSDecoder *process_header(ogg_packet *op, opus_int32 *rate, int *channels, int *preskip, float *gain, int quiet)
{
- OpusDecoder *st;
+ OpusMSDecoder *st;
OpusHeader header;
+ unsigned char mapping[256] = {0,1};
if (opus_header_parse(op->packet, op->bytes, &header)==0)
{
@@ -407,7 +409,7 @@
if (!*rate)
*rate = header.input_sample_rate;
*preskip = header.preskip;
- st = opus_decoder_create(48000, header.channels);
+ st = opus_multistream_decoder_create(48000, header.channels, 1, header.channels==2 ? 1 : 0, mapping);
if (!st)
{
fprintf (stderr, "Decoder initialization failed.\n");
@@ -486,7 +488,7 @@
FILE *fin, *fout=NULL;
float output[MAX_FRAME_SIZE];
int frame_size=0;
- void *st=NULL;
+ OpusMSDecoder *st=NULL;
int packet_count=0;
int stream_init = 0;
int quiet = 0;
@@ -509,7 +511,6 @@
ogg_page og;
ogg_packet op;
ogg_stream_state os;
- int enh_enabled;
int print_bitrate=0;
int close_in=0;
int eos=0;
@@ -530,8 +531,6 @@
shapemem.mute=960;
shapemem.fs=0;
- enh_enabled = 1;
-
/*Process options*/
while(1)
{
@@ -688,7 +687,7 @@
}
fout = out_file_open(outFile, rate, &channels);
- } else if (strncmp((char*)op.packet, "OpusTags", 8)==0)
+ } else if (packet_count==1)
{
if (!quiet)
print_comments((char*)op.packet, op.bytes);
@@ -706,9 +705,9 @@
int ret;
/*Decode frame*/
if (!lost)
- ret = opus_decode_float(st, (unsigned char*)op.packet, op.bytes, output, MAX_FRAME_SIZE, 0);
+ ret = opus_multistream_decode_float(st, (unsigned char*)op.packet, op.bytes, output, MAX_FRAME_SIZE, 0);
else
- ret = opus_decode_float(st, NULL, 0, output, MAX_FRAME_SIZE, 0);
+ ret = opus_multistream_decode_float(st, NULL, 0, output, MAX_FRAME_SIZE, 0);
/*for (i=0;i<frame_size*channels;i++)
printf ("%d\n", (int)output[i]);*/
@@ -794,7 +793,7 @@
if (st)
{
- opus_decoder_destroy(st);
+ opus_multistream_decoder_destroy(st);
} else {
fprintf (stderr, "This doesn't look like a Opus file\n");
}
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -46,6 +46,7 @@
#endif
#include "opus.h"
+#include "opus_multistream.h"
#include "opus_header.h"
#include <ogg/ogg.h>
#include "wav_io.h"
@@ -260,7 +261,7 @@
opus_int32 frame_size = 960;
int quiet=0;
int nbBytes;
- void *st;
+ OpusMSEncoder *st;
unsigned char bits[MAX_FRAME_BYTES];
int with_cbr = 0;
int with_cvbr = 0;
@@ -321,6 +322,7 @@
SpeexResamplerState *resampler=NULL;
int extra_samples;
int signal = OPUS_SIGNAL_AUTO;
+ unsigned char mapping[256] = {0, 1};
opus_version = opus_get_version_string();
snprintf(vendor_string, sizeof(vendor_string), "%s\n",opus_version);
@@ -497,11 +499,10 @@
bytes_per_packet = MAX_FRAME_BYTES;
/*Initialize OPUS encoder*/
- st = opus_encoder_create(48000, chan, OPUS_APPLICATION_AUDIO);
-
- opus_encoder_ctl(st, OPUS_SET_SIGNAL(signal));
+ st = opus_multistream_encoder_create(48000, chan, 1, chan==2, mapping, OPUS_APPLICATION_AUDIO);
+ opus_multistream_encoder_ctl(st, OPUS_SET_SIGNAL(signal));
header.channels = chan;
- opus_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&lookahead));
+ opus_multistream_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&lookahead));
header.preskip = lookahead;
if (resampler)
header.preskip += speex_resampler_get_output_latency(resampler);
@@ -531,7 +532,7 @@
{
int tmp = (bitrate*1000);
- if (opus_encoder_ctl(st, OPUS_SET_BITRATE(tmp)) != OPUS_OK)
+ if (opus_multistream_encoder_ctl(st, OPUS_SET_BITRATE(tmp)) != OPUS_OK)
{
fprintf (stderr, "bitrate request failed\n");
return 1;
@@ -539,7 +540,7 @@
}
if (!with_cbr)
{
- if (opus_encoder_ctl(st, OPUS_SET_VBR(1)) != OPUS_OK)
+ if (opus_multistream_encoder_ctl(st, OPUS_SET_VBR(1)) != OPUS_OK)
{
fprintf (stderr, "VBR request failed\n");
return 1;
@@ -546,7 +547,7 @@
}
if (!with_cvbr)
{
- if (opus_encoder_ctl(st, OPUS_SET_VBR_CONSTRAINT(0)) != OPUS_OK)
+ if (opus_multistream_encoder_ctl(st, OPUS_SET_VBR_CONSTRAINT(0)) != OPUS_OK)
{
fprintf (stderr, "VBR constraint failed\n");
return 1;
@@ -555,7 +556,7 @@
}
if (complexity!=-127) {
- if (opus_encoder_ctl(st, OPUS_SET_COMPLEXITY(complexity)) != OPUS_OK)
+ if (opus_multistream_encoder_ctl(st, OPUS_SET_COMPLEXITY(complexity)) != OPUS_OK)
{
fprintf (stderr, "Only complexity 0 through 10 is supported\n");
return 1;
@@ -646,10 +647,10 @@
id++;
/*Encode current frame*/
- nbBytes = opus_encode_float(st, input, frame_size, bits, bytes_per_packet);
+ nbBytes = opus_multistream_encode_float(st, input, frame_size, bits, bytes_per_packet);
if (nbBytes<0)
{
- fprintf(stderr, "Got error %d while encoding. Aborting.\n", nbBytes);
+ fprintf(stderr, "Encoding failed: %s. Aborting.\n", opus_strerror(nbBytes));
break;
}
nb_encoded += frame_size;
@@ -730,7 +731,7 @@
if (!with_cbr && !quiet)
fprintf (stderr, "Average rate %0.3fkbit/sec, %d peak bytes per packet\n", (total_bytes*8.0/((float)nb_encoded/header.input_sample_rate))/1000.0, peak_bytes);
- opus_encoder_destroy(st);
+ opus_multistream_encoder_destroy(st);
ogg_stream_clear(&os);
if (close_in)