aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmad/layer12.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libmad/layer12.c')
-rw-r--r--src/libmad/layer12.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/libmad/layer12.c b/src/libmad/layer12.c
index d14122a85..6981f9ce1 100644
--- a/src/libmad/layer12.c
+++ b/src/libmad/layer12.c
@@ -1,6 +1,6 @@
/*
* libmad - MPEG audio decoder library
- * Copyright (C) 2000-2003 Underbit Technologies, Inc.
+ * Copyright (C) 2000-2004 Underbit Technologies, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
- * $Id: layer12.c,v 1.1 2003/08/14 03:57:13 shank Exp $
+ * $Id: layer12.c,v 1.17 2004/02/05 09:02:39 rob Exp $
*/
# ifdef HAVE_CONFIG_H
@@ -341,20 +341,44 @@ int mad_layer_II(struct mad_stream *stream, struct mad_frame *frame)
if (header->flags & MAD_FLAG_LSF_EXT)
index = 4;
+ else if (header->flags & MAD_FLAG_FREEFORMAT)
+ goto freeformat;
else {
- switch (nch == 2 ? header->bitrate / 2 : header->bitrate) {
- case 32000:
- case 48000:
- index = (header->samplerate == 32000) ? 3 : 2;
- break;
+ unsigned long bitrate_per_channel;
- case 56000:
- case 64000:
- case 80000:
- index = 0;
- break;
+ bitrate_per_channel = header->bitrate;
+ if (nch == 2) {
+ bitrate_per_channel /= 2;
- default:
+# if defined(OPT_STRICT)
+ /*
+ * ISO/IEC 11172-3 allows only single channel mode for 32, 48, 56, and
+ * 80 kbps bitrates in Layer II, but some encoders ignore this
+ * restriction. We enforce it if OPT_STRICT is defined.
+ */
+ if (bitrate_per_channel <= 28000 || bitrate_per_channel == 40000) {
+ stream->error = MAD_ERROR_BADMODE;
+ return -1;
+ }
+# endif
+ }
+ else { /* nch == 1 */
+ if (bitrate_per_channel > 192000) {
+ /*
+ * ISO/IEC 11172-3 does not allow single channel mode for 224, 256,
+ * 320, or 384 kbps bitrates in Layer II.
+ */
+ stream->error = MAD_ERROR_BADMODE;
+ return -1;
+ }
+ }
+
+ if (bitrate_per_channel <= 48000)
+ index = (header->samplerate == 32000) ? 3 : 2;
+ else if (bitrate_per_channel <= 80000)
+ index = 0;
+ else {
+ freeformat:
index = (header->samplerate == 48000) ? 0 : 1;
}
}