ref: bc8191a9e7c258f910d8dfed6c682aabdbc40236
parent: 8dfba387f8e72aa921b39c785bce9a8ef219bbf8
author: Gregory Maxwell <greg@xiph.org>
date: Mon Aug 29 09:55:07 EDT 2011
Build fixes for the multistream error codes and some whitespace cleanup.
--- a/src/opusdec.c
+++ b/src/opusdec.c
@@ -187,7 +187,7 @@
char *c=comments;
int len, i, nb_fields;
char *end;
-
+
if (strncmp(c, "OpusTags", 8) != 0)
{
fprintf (stderr, "Invalid/corrupted comments\n");
@@ -250,7 +250,7 @@
if (audio_fd<0)
{
perror("Cannot open /dev/dsp");
- exit(1);
+ exit(1);
}
format=AFMT_S16_NE;
@@ -287,7 +287,7 @@
#elif defined HAVE_SYS_AUDIOIO_H
audio_info_t info;
int audio_fd;
-
+
audio_fd = open("/dev/audio", O_WRONLY);
if (audio_fd<0)
{
@@ -303,7 +303,7 @@
info.play.precision = 16;
info.play.input_sample_rate = rate;
info.play.channels = *channels;
-
+
if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0)
{
perror ("AUDIO_SETINFO");
@@ -331,7 +331,7 @@
#endif
fout=stdout;
}
- else
+ else
{
fout = fopen(outFile, "wb");
if (!fout)
@@ -355,13 +355,13 @@
printf ("input_file can be:\n");
printf (" filename.oga regular Opus file\n");
printf (" - stdin\n");
- printf ("\n");
+ printf ("\n");
printf ("output_file can be:\n");
printf (" filename.wav Wav file\n");
printf (" filename.* Raw PCM file (any extension other that .wav)\n");
printf (" - stdout\n");
printf (" (nothing) Will be played to soundcard\n");
- printf ("\n");
+ printf ("\n");
printf ("Options:\n");
printf (" --mono Force decoding in mono\n");
printf (" --stereo Force decoding in stereo\n");
@@ -368,7 +368,7 @@
printf (" --rate n Force decoding at sampling rate n Hz\n");
printf (" --no-dither Do not dither 16-bit output\n");
printf (" --packet-loss n Simulate n %% random packet loss\n");
- printf (" -V Verbose mode (show bit-rate)\n");
+ printf (" -V Verbose mode (show bit-rate)\n");
printf (" -h, --help This help\n");
printf (" -v, --version Version information\n");
printf ("\n");
@@ -388,6 +388,7 @@
static OpusMSDecoder *process_header(ogg_packet *op, opus_int32 *rate, int *channels, int *preskip, float *gain, int quiet)
{
+ int error;
OpusMSDecoder *st;
OpusHeader header;
unsigned char mapping[256] = {0,1};
@@ -397,7 +398,7 @@
fprintf(stderr, "Cannot parse header\n");
return NULL;
}
-
+
if (header.channels>2 || header.channels<1)
{
fprintf (stderr, "Unsupported number of channels: %d\n", header.channels);
@@ -409,10 +410,10 @@
if (!*rate)
*rate = header.input_sample_rate;
*preskip = header.preskip;
- st = opus_multistream_decoder_create(48000, header.channels, 1, header.channels==2 ? 1 : 0, mapping);
+ st = opus_multistream_decoder_create(48000, header.channels, 1, header.channels==2 ? 1 : 0, mapping, &error);
if (!st)
{
- fprintf (stderr, "Decoder initialization failed.\n");
+ fprintf (stderr, "Decoder initialization failed: %s\n", opus_strerror(error));
return NULL;
}
@@ -530,7 +531,7 @@
shapemem.b_buf=0;
shapemem.mute=960;
shapemem.fs=0;
-
+
/*Process options*/
while(1)
{
@@ -538,7 +539,7 @@
long_options, &option_index);
if (c==-1)
break;
-
+
switch(c)
{
case 0:
@@ -613,7 +614,7 @@
#endif
fin=stdin;
}
- else
+ else
{
fin = fopen(inFile, "rb");
if (!fin)
@@ -627,9 +628,9 @@
/*Init Ogg data struct*/
ogg_sync_init(&oy);
-
+
/*Main decoding loop*/
-
+
while (1)
{
char *data;
@@ -637,7 +638,7 @@
/*Get the ogg buffer for writing*/
data = ogg_sync_buffer(&oy, 200);
/*Read bitstream from input file*/
- nb_read = fread(data, sizeof(char), 200, fin);
+ nb_read = fread(data, sizeof(char), 200, fin);
ogg_sync_wrote(&oy, nb_read);
/*Loop for all complete pages we got (most likely only one)*/
@@ -751,7 +752,7 @@
break;
}
-
+
/* Drain the resampler */
if (resampler)
{
@@ -758,7 +759,7 @@
int i;
float zeros[200];
int drain;
-
+
for (i=0;i<200;i++)
zeros[i] = 200;
drain = speex_resampler_get_input_latency(resampler);
@@ -770,7 +771,7 @@
drain -= tmp;
} while (drain>0);
}
-
+
if (fout && wav_format)
{
if (fseek(fout,4,SEEK_SET)==0)
@@ -809,7 +810,7 @@
if (close_in)
fclose(fin);
if (fout != NULL)
- fclose(fout);
+ fclose(fout);
return 0;
}
--- a/src/opusenc.c
+++ b/src/opusenc.c
@@ -67,7 +67,7 @@
int written;
written = fwrite(page->header,1,page->header_len, fp);
written += fwrite(page->body,1,page->body_len, fp);
-
+
return written;
}
@@ -77,7 +77,7 @@
#define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */
/* Convert input audio bits, endians and channels */
-static int read_samples_pcm(FILE *fin,int frame_size, int bits, int channels,
+static int read_samples_pcm(FILE *fin,int frame_size, int bits, int channels,
int lsb, float * input, char *buff, opus_int32 *size,
int *extra_samples)
{
@@ -127,8 +127,8 @@
/* convert to our endian format */
for(i=0;i<frame_size*channels;i++)
{
- if(lsb)
- s[i]=le_short(s[i]);
+ if(lsb)
+ s[i]=le_short(s[i]);
else
s[i]=be_short(s[i]);
}
@@ -157,7 +157,7 @@
return nb_read;
}
-static int read_samples(FILE *fin,int frame_size, int bits, int channels,
+static int read_samples(FILE *fin,int frame_size, int bits, int channels,
int lsb, float * input, char *buff, opus_int32 *size,
SpeexResamplerState *resampler, int *extra_samples)
{
@@ -217,15 +217,15 @@
printf (" filename.wav wav file\n");
printf (" filename.* Raw PCM file (any extension other than .wav)\n");
printf (" - stdin\n");
- printf ("\n");
+ printf ("\n");
printf ("output_file can be:\n");
printf (" filename.oga compressed file\n");
printf (" - stdout\n");
- printf ("\n");
+ printf ("\n");
printf ("Options:\n");
- printf (" --speech Optimize for speech\n");
- printf (" --music Optimize for music\n");
- printf (" --bitrate n Encoding bit-rate in kbit/sec\n");
+ printf (" --speech Optimize for speech\n");
+ printf (" --music Optimize for music\n");
+ printf (" --bitrate n Encoding bit-rate in kbit/sec\n");
printf (" --cbr Use constant bitrate encoding\n");
printf (" --comp n Encoding complexity (0-10)\n");
printf (" --framesize n Frame size (Default: 960)\n");
@@ -235,17 +235,17 @@
printf (" used multiple times\n");
printf (" --author Author of this track\n");
printf (" --title Title for this track\n");
- printf (" -h, --help This help\n");
- printf (" -v, --version Version information\n");
- printf (" -V Verbose mode (show bit-rate)\n");
+ printf (" -h, --help This help\n");
+ printf (" -v, --version Version information\n");
+ printf (" -V Verbose mode (show bit-rate)\n");
printf ("Raw input options:\n");
- printf (" --rate n Sampling rate for raw input\n");
- printf (" --mono Consider raw input as mono\n");
- printf (" --stereo Consider raw input as stereo\n");
- printf (" --le Raw input is little-endian\n");
- printf (" --be Raw input is big-endian\n");
- printf (" --8bit Raw input is 8-bit unsigned\n");
- printf (" --16bit Raw input is 16-bit signed\n");
+ printf (" --rate n Sampling rate for raw input\n");
+ printf (" --mono Consider raw input as mono\n");
+ printf (" --stereo Consider raw input as stereo\n");
+ printf (" --le Raw input is little-endian\n");
+ printf (" --be Raw input is big-endian\n");
+ printf (" --8bit Raw input is 8-bit unsigned\n");
+ printf (" --16bit Raw input is 16-bit signed\n");
printf ("Default raw PCM input is 48kHz, 16-bit, little-endian, stereo\n");
}
@@ -335,7 +335,7 @@
long_options, &option_index);
if (c==-1)
break;
-
+
switch(c)
{
case 0:
@@ -404,13 +404,13 @@
fprintf (stderr, "Comments must be of the form name=value\n");
exit(1);
}
- comment_add(&comments, &comments_length, NULL, optarg);
+ comment_add(&comments, &comments_length, NULL, optarg);
} else if (strcmp(long_options[option_index].name,"author")==0)
{
- comment_add(&comments, &comments_length, "author=", optarg);
+ comment_add(&comments, &comments_length, "author=", optarg);
} else if (strcmp(long_options[option_index].name,"title")==0)
{
- comment_add(&comments, &comments_length, "title=", optarg);
+ comment_add(&comments, &comments_length, "title=", optarg);
}
break;
@@ -456,7 +456,7 @@
#endif
fin=stdin;
}
- else
+ else
{
fin = fopen(inFile, "rb");
if (!fin)
@@ -497,9 +497,14 @@
bitrate=128.0;
}
bytes_per_packet = MAX_FRAME_BYTES;
-
+
/*Initialize OPUS encoder*/
- st = opus_multistream_encoder_create(48000, chan, 1, chan==2, mapping, OPUS_APPLICATION_AUDIO);
+ st = opus_multistream_encoder_create(48000, chan, 1, chan==2, mapping, OPUS_APPLICATION_AUDIO, &ret);
+ if (!st)
+ {
+ fprintf (stderr, "Failed to create the encoder: %s\n", opus_strerror(ret));
+ exit(1);
+ }
opus_multistream_encoder_ctl(st, OPUS_SET_SIGNAL(signal));
header.channels = chan;
opus_multistream_encoder_ctl(st, OPUS_GET_LOOKAHEAD(&lookahead));
@@ -512,7 +517,7 @@
/* 0 dB gain is the recommended unless you know what you're doing */
header.gain = 0;
header.input_sample_rate = rate;
-
+
/* Extra samples that need to be read to compensate for the pre-skip */
extra_samples = (int)header.preskip * (rate/48000.);
{
@@ -570,7 +575,7 @@
#endif
fout=stdout;
}
- else
+ else
{
fout = fopen(outFile, "wb");
if (!fout)
@@ -741,8 +746,8 @@
return 0;
}
-/*
- Comments will be stored in the Vorbis style.
+/*
+ Comments will be stored in the Vorbis style.
It is describled in the "Structure" section of
http://www.xiph.org/ogg/vorbis/doc/v-comment.html