annotate src/libmad-0.15.1b/stream.c @ 22:b07fe9e906dc

Portaudio: add missed file
author Chris Cannam
date Tue, 26 Mar 2013 12:14:11 +0000
parents c7265573341e
children
rev   line source
Chris@0 1 /*
Chris@0 2 * libmad - MPEG audio decoder library
Chris@0 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
Chris@0 4 *
Chris@0 5 * This program is free software; you can redistribute it and/or modify
Chris@0 6 * it under the terms of the GNU General Public License as published by
Chris@0 7 * the Free Software Foundation; either version 2 of the License, or
Chris@0 8 * (at your option) any later version.
Chris@0 9 *
Chris@0 10 * This program is distributed in the hope that it will be useful,
Chris@0 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@0 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@0 13 * GNU General Public License for more details.
Chris@0 14 *
Chris@0 15 * You should have received a copy of the GNU General Public License
Chris@0 16 * along with this program; if not, write to the Free Software
Chris@0 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Chris@0 18 *
Chris@0 19 * $Id: stream.c,v 1.12 2004/02/05 09:02:39 rob Exp $
Chris@0 20 */
Chris@0 21
Chris@0 22 # ifdef HAVE_CONFIG_H
Chris@0 23 # include "config.h"
Chris@0 24 # endif
Chris@0 25
Chris@0 26 # include "global.h"
Chris@0 27
Chris@0 28 # include <stdlib.h>
Chris@0 29
Chris@0 30 # include "bit.h"
Chris@0 31 # include "stream.h"
Chris@0 32
Chris@0 33 /*
Chris@0 34 * NAME: stream->init()
Chris@0 35 * DESCRIPTION: initialize stream struct
Chris@0 36 */
Chris@0 37 void mad_stream_init(struct mad_stream *stream)
Chris@0 38 {
Chris@0 39 stream->buffer = 0;
Chris@0 40 stream->bufend = 0;
Chris@0 41 stream->skiplen = 0;
Chris@0 42
Chris@0 43 stream->sync = 0;
Chris@0 44 stream->freerate = 0;
Chris@0 45
Chris@0 46 stream->this_frame = 0;
Chris@0 47 stream->next_frame = 0;
Chris@0 48 mad_bit_init(&stream->ptr, 0);
Chris@0 49
Chris@0 50 mad_bit_init(&stream->anc_ptr, 0);
Chris@0 51 stream->anc_bitlen = 0;
Chris@0 52
Chris@0 53 stream->main_data = 0;
Chris@0 54 stream->md_len = 0;
Chris@0 55
Chris@0 56 stream->options = 0;
Chris@0 57 stream->error = MAD_ERROR_NONE;
Chris@0 58 }
Chris@0 59
Chris@0 60 /*
Chris@0 61 * NAME: stream->finish()
Chris@0 62 * DESCRIPTION: deallocate any dynamic memory associated with stream
Chris@0 63 */
Chris@0 64 void mad_stream_finish(struct mad_stream *stream)
Chris@0 65 {
Chris@0 66 if (stream->main_data) {
Chris@0 67 free(stream->main_data);
Chris@0 68 stream->main_data = 0;
Chris@0 69 }
Chris@0 70
Chris@0 71 mad_bit_finish(&stream->anc_ptr);
Chris@0 72 mad_bit_finish(&stream->ptr);
Chris@0 73 }
Chris@0 74
Chris@0 75 /*
Chris@0 76 * NAME: stream->buffer()
Chris@0 77 * DESCRIPTION: set stream buffer pointers
Chris@0 78 */
Chris@0 79 void mad_stream_buffer(struct mad_stream *stream,
Chris@0 80 unsigned char const *buffer, unsigned long length)
Chris@0 81 {
Chris@0 82 stream->buffer = buffer;
Chris@0 83 stream->bufend = buffer + length;
Chris@0 84
Chris@0 85 stream->this_frame = buffer;
Chris@0 86 stream->next_frame = buffer;
Chris@0 87
Chris@0 88 stream->sync = 1;
Chris@0 89
Chris@0 90 mad_bit_init(&stream->ptr, buffer);
Chris@0 91 }
Chris@0 92
Chris@0 93 /*
Chris@0 94 * NAME: stream->skip()
Chris@0 95 * DESCRIPTION: arrange to skip bytes before the next frame
Chris@0 96 */
Chris@0 97 void mad_stream_skip(struct mad_stream *stream, unsigned long length)
Chris@0 98 {
Chris@0 99 stream->skiplen += length;
Chris@0 100 }
Chris@0 101
Chris@0 102 /*
Chris@0 103 * NAME: stream->sync()
Chris@0 104 * DESCRIPTION: locate the next stream sync word
Chris@0 105 */
Chris@0 106 int mad_stream_sync(struct mad_stream *stream)
Chris@0 107 {
Chris@0 108 register unsigned char const *ptr, *end;
Chris@0 109
Chris@0 110 ptr = mad_bit_nextbyte(&stream->ptr);
Chris@0 111 end = stream->bufend;
Chris@0 112
Chris@0 113 while (ptr < end - 1 &&
Chris@0 114 !(ptr[0] == 0xff && (ptr[1] & 0xe0) == 0xe0))
Chris@0 115 ++ptr;
Chris@0 116
Chris@0 117 if (end - ptr < MAD_BUFFER_GUARD)
Chris@0 118 return -1;
Chris@0 119
Chris@0 120 mad_bit_init(&stream->ptr, ptr);
Chris@0 121
Chris@0 122 return 0;
Chris@0 123 }
Chris@0 124
Chris@0 125 /*
Chris@0 126 * NAME: stream->errorstr()
Chris@0 127 * DESCRIPTION: return a string description of the current error condition
Chris@0 128 */
Chris@0 129 char const *mad_stream_errorstr(struct mad_stream const *stream)
Chris@0 130 {
Chris@0 131 switch (stream->error) {
Chris@0 132 case MAD_ERROR_NONE: return "no error";
Chris@0 133
Chris@0 134 case MAD_ERROR_BUFLEN: return "input buffer too small (or EOF)";
Chris@0 135 case MAD_ERROR_BUFPTR: return "invalid (null) buffer pointer";
Chris@0 136
Chris@0 137 case MAD_ERROR_NOMEM: return "not enough memory";
Chris@0 138
Chris@0 139 case MAD_ERROR_LOSTSYNC: return "lost synchronization";
Chris@0 140 case MAD_ERROR_BADLAYER: return "reserved header layer value";
Chris@0 141 case MAD_ERROR_BADBITRATE: return "forbidden bitrate value";
Chris@0 142 case MAD_ERROR_BADSAMPLERATE: return "reserved sample frequency value";
Chris@0 143 case MAD_ERROR_BADEMPHASIS: return "reserved emphasis value";
Chris@0 144
Chris@0 145 case MAD_ERROR_BADCRC: return "CRC check failed";
Chris@0 146 case MAD_ERROR_BADBITALLOC: return "forbidden bit allocation value";
Chris@0 147 case MAD_ERROR_BADSCALEFACTOR: return "bad scalefactor index";
Chris@0 148 case MAD_ERROR_BADMODE: return "bad bitrate/mode combination";
Chris@0 149 case MAD_ERROR_BADFRAMELEN: return "bad frame length";
Chris@0 150 case MAD_ERROR_BADBIGVALUES: return "bad big_values count";
Chris@0 151 case MAD_ERROR_BADBLOCKTYPE: return "reserved block_type";
Chris@0 152 case MAD_ERROR_BADSCFSI: return "bad scalefactor selection info";
Chris@0 153 case MAD_ERROR_BADDATAPTR: return "bad main_data_begin pointer";
Chris@0 154 case MAD_ERROR_BADPART3LEN: return "bad audio data length";
Chris@0 155 case MAD_ERROR_BADHUFFTABLE: return "bad Huffman table select";
Chris@0 156 case MAD_ERROR_BADHUFFDATA: return "Huffman data overrun";
Chris@0 157 case MAD_ERROR_BADSTEREO: return "incompatible block_type for JS";
Chris@0 158 }
Chris@0 159
Chris@0 160 return 0;
Chris@0 161 }