MP3 Player without external hardware MP3 Player without external hardware. A software based MP3 player based on a modified version of libmad. Mono output (at the moment) via AnalogOut. Files are read from an USB drive. This is a demo program, it plays only one file at the moment. Documentation is in "main.cpp" and "config.h"

Dependencies:   mbed

Committer:
Gruenfrosch
Date:
Sat Nov 27 17:27:33 2010 +0000
Revision:
2:f28cf0afd021
Parent:
0:7627c79db971
Version 3:
* moved another memory block into AHB RAM, giving more room for
* stereo buffer.
* moved content of decode() to main()
* decoding is now safe to be called multiple times (bug in older versions)
* Output routine now fills stereo buffer, DAC output sums channels,
* just for demonstration that stereo output could go here

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gruenfrosch 0:7627c79db971 1 /*
Gruenfrosch 0:7627c79db971 2 * libmad - MPEG audio decoder library
Gruenfrosch 0:7627c79db971 3 * Copyright (C) 2000-2004 Underbit Technologies, Inc.
Gruenfrosch 0:7627c79db971 4 *
Gruenfrosch 0:7627c79db971 5 * This program is free software; you can redistribute it and/or modify
Gruenfrosch 0:7627c79db971 6 * it under the terms of the GNU General Public License as published by
Gruenfrosch 0:7627c79db971 7 * the Free Software Foundation; either version 2 of the License, or
Gruenfrosch 0:7627c79db971 8 * (at your option) any later version.
Gruenfrosch 0:7627c79db971 9 *
Gruenfrosch 0:7627c79db971 10 * This program is distributed in the hope that it will be useful,
Gruenfrosch 0:7627c79db971 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Gruenfrosch 0:7627c79db971 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Gruenfrosch 0:7627c79db971 13 * GNU General Public License for more details.
Gruenfrosch 0:7627c79db971 14 *
Gruenfrosch 0:7627c79db971 15 * You should have received a copy of the GNU General Public License
Gruenfrosch 0:7627c79db971 16 * along with this program; if not, write to the Free Software
Gruenfrosch 0:7627c79db971 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Gruenfrosch 0:7627c79db971 18 *
Gruenfrosch 0:7627c79db971 19 * $Id: stream.h,v 1.1 2010/11/23 20:12:57 andy Exp $
Gruenfrosch 0:7627c79db971 20 */
Gruenfrosch 0:7627c79db971 21
Gruenfrosch 0:7627c79db971 22 # ifndef LIBMAD_STREAM_H
Gruenfrosch 0:7627c79db971 23 # define LIBMAD_STREAM_H
Gruenfrosch 0:7627c79db971 24
Gruenfrosch 0:7627c79db971 25 # include "bit.h"
Gruenfrosch 0:7627c79db971 26
Gruenfrosch 0:7627c79db971 27 # define MAD_BUFFER_GUARD 8
Gruenfrosch 0:7627c79db971 28 # define MAD_BUFFER_MDLEN (511 + 2048 + MAD_BUFFER_GUARD)
Gruenfrosch 0:7627c79db971 29
Gruenfrosch 0:7627c79db971 30 enum mad_error {
Gruenfrosch 0:7627c79db971 31 MAD_ERROR_NONE = 0x0000, /* no error */
Gruenfrosch 0:7627c79db971 32
Gruenfrosch 0:7627c79db971 33 MAD_ERROR_BUFLEN = 0x0001, /* input buffer too small (or EOF) */
Gruenfrosch 0:7627c79db971 34 MAD_ERROR_BUFPTR = 0x0002, /* invalid (null) buffer pointer */
Gruenfrosch 0:7627c79db971 35
Gruenfrosch 0:7627c79db971 36 MAD_ERROR_NOMEM = 0x0031, /* not enough memory */
Gruenfrosch 0:7627c79db971 37
Gruenfrosch 0:7627c79db971 38 MAD_ERROR_LOSTSYNC = 0x0101, /* lost synchronization */
Gruenfrosch 0:7627c79db971 39 MAD_ERROR_BADLAYER = 0x0102, /* reserved header layer value */
Gruenfrosch 0:7627c79db971 40 MAD_ERROR_BADBITRATE = 0x0103, /* forbidden bitrate value */
Gruenfrosch 0:7627c79db971 41 MAD_ERROR_BADSAMPLERATE = 0x0104, /* reserved sample frequency value */
Gruenfrosch 0:7627c79db971 42 MAD_ERROR_BADEMPHASIS = 0x0105, /* reserved emphasis value */
Gruenfrosch 0:7627c79db971 43
Gruenfrosch 0:7627c79db971 44 MAD_ERROR_BADCRC = 0x0201, /* CRC check failed */
Gruenfrosch 0:7627c79db971 45 MAD_ERROR_BADBITALLOC = 0x0211, /* forbidden bit allocation value */
Gruenfrosch 0:7627c79db971 46 MAD_ERROR_BADSCALEFACTOR = 0x0221, /* bad scalefactor index */
Gruenfrosch 0:7627c79db971 47 MAD_ERROR_BADMODE = 0x0222, /* bad bitrate/mode combination */
Gruenfrosch 0:7627c79db971 48 MAD_ERROR_BADFRAMELEN = 0x0231, /* bad frame length */
Gruenfrosch 0:7627c79db971 49 MAD_ERROR_BADBIGVALUES = 0x0232, /* bad big_values count */
Gruenfrosch 0:7627c79db971 50 MAD_ERROR_BADBLOCKTYPE = 0x0233, /* reserved block_type */
Gruenfrosch 0:7627c79db971 51 MAD_ERROR_BADSCFSI = 0x0234, /* bad scalefactor selection info */
Gruenfrosch 0:7627c79db971 52 MAD_ERROR_BADDATAPTR = 0x0235, /* bad main_data_begin pointer */
Gruenfrosch 0:7627c79db971 53 MAD_ERROR_BADPART3LEN = 0x0236, /* bad audio data length */
Gruenfrosch 0:7627c79db971 54 MAD_ERROR_BADHUFFTABLE = 0x0237, /* bad Huffman table select */
Gruenfrosch 0:7627c79db971 55 MAD_ERROR_BADHUFFDATA = 0x0238, /* Huffman data overrun */
Gruenfrosch 0:7627c79db971 56 MAD_ERROR_BADSTEREO = 0x0239 /* incompatible block_type for JS */
Gruenfrosch 0:7627c79db971 57 };
Gruenfrosch 0:7627c79db971 58
Gruenfrosch 0:7627c79db971 59 # define MAD_RECOVERABLE(error) ((error) & 0xff00)
Gruenfrosch 0:7627c79db971 60
Gruenfrosch 0:7627c79db971 61 struct mad_stream {
Gruenfrosch 0:7627c79db971 62 unsigned char const *buffer; /* input bitstream buffer */
Gruenfrosch 0:7627c79db971 63 unsigned char const *bufend; /* end of buffer */
Gruenfrosch 0:7627c79db971 64 unsigned long skiplen; /* bytes to skip before next frame */
Gruenfrosch 0:7627c79db971 65
Gruenfrosch 0:7627c79db971 66 int sync; /* stream sync found */
Gruenfrosch 0:7627c79db971 67 unsigned long freerate; /* free bitrate (fixed) */
Gruenfrosch 0:7627c79db971 68
Gruenfrosch 0:7627c79db971 69 unsigned char const *this_frame; /* start of current frame */
Gruenfrosch 0:7627c79db971 70 unsigned char const *next_frame; /* start of next frame */
Gruenfrosch 0:7627c79db971 71 struct mad_bitptr ptr; /* current processing bit pointer */
Gruenfrosch 0:7627c79db971 72
Gruenfrosch 0:7627c79db971 73 struct mad_bitptr anc_ptr; /* ancillary bits pointer */
Gruenfrosch 0:7627c79db971 74 unsigned int anc_bitlen; /* number of ancillary bits */
Gruenfrosch 0:7627c79db971 75
Gruenfrosch 0:7627c79db971 76 unsigned char (*main_data)[MAD_BUFFER_MDLEN];
Gruenfrosch 0:7627c79db971 77 /* Layer III main_data() */
Gruenfrosch 0:7627c79db971 78 unsigned int md_len; /* bytes in main_data */
Gruenfrosch 0:7627c79db971 79
Gruenfrosch 0:7627c79db971 80 int options; /* decoding options (see below) */
Gruenfrosch 0:7627c79db971 81 enum mad_error error; /* error code (see above) */
Gruenfrosch 0:7627c79db971 82 };
Gruenfrosch 0:7627c79db971 83
Gruenfrosch 0:7627c79db971 84 enum {
Gruenfrosch 0:7627c79db971 85 MAD_OPTION_IGNORECRC = 0x0001, /* ignore CRC errors */
Gruenfrosch 0:7627c79db971 86 MAD_OPTION_HALFSAMPLERATE = 0x0002 /* generate PCM at 1/2 sample rate */
Gruenfrosch 0:7627c79db971 87 # if 0 /* not yet implemented */
Gruenfrosch 0:7627c79db971 88 MAD_OPTION_LEFTCHANNEL = 0x0010, /* decode left channel only */
Gruenfrosch 0:7627c79db971 89 MAD_OPTION_RIGHTCHANNEL = 0x0020, /* decode right channel only */
Gruenfrosch 0:7627c79db971 90 MAD_OPTION_SINGLECHANNEL = 0x0030 /* combine channels */
Gruenfrosch 0:7627c79db971 91 # endif
Gruenfrosch 0:7627c79db971 92 };
Gruenfrosch 0:7627c79db971 93
Gruenfrosch 0:7627c79db971 94 void mad_stream_init(struct mad_stream *);
Gruenfrosch 0:7627c79db971 95 void mad_stream_finish(struct mad_stream *);
Gruenfrosch 0:7627c79db971 96
Gruenfrosch 0:7627c79db971 97 # define mad_stream_options(stream, opts) \
Gruenfrosch 0:7627c79db971 98 ((void) ((stream)->options = (opts)))
Gruenfrosch 0:7627c79db971 99
Gruenfrosch 0:7627c79db971 100 void mad_stream_buffer(struct mad_stream *,
Gruenfrosch 0:7627c79db971 101 unsigned char const *, unsigned long);
Gruenfrosch 0:7627c79db971 102 void mad_stream_skip(struct mad_stream *, unsigned long);
Gruenfrosch 0:7627c79db971 103
Gruenfrosch 0:7627c79db971 104 int mad_stream_sync(struct mad_stream *);
Gruenfrosch 0:7627c79db971 105
Gruenfrosch 0:7627c79db971 106 char const *mad_stream_errorstr(struct mad_stream const *);
Gruenfrosch 0:7627c79db971 107
Gruenfrosch 0:7627c79db971 108 # endif