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"
fixed.cpp@1:7c923cbe9f1d, 2010-11-26 (annotated)
- Committer:
- Gruenfrosch
- Date:
- Fri Nov 26 13:05:34 2010 +0000
- Revision:
- 1:7c923cbe9f1d
- Parent:
- 0:7627c79db971
Fixed the last warning
Who changed what in which revision?
User | Revision | Line number | New 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: fixed.c,v 1.1 2010/11/23 20:12:57 andy Exp $ |
Gruenfrosch | 0:7627c79db971 | 20 | */ |
Gruenfrosch | 0:7627c79db971 | 21 | |
Gruenfrosch | 0:7627c79db971 | 22 | # include "config.h" |
Gruenfrosch | 0:7627c79db971 | 23 | |
Gruenfrosch | 0:7627c79db971 | 24 | # include "global.h" |
Gruenfrosch | 0:7627c79db971 | 25 | |
Gruenfrosch | 0:7627c79db971 | 26 | # include "fixed.h" |
Gruenfrosch | 0:7627c79db971 | 27 | |
Gruenfrosch | 0:7627c79db971 | 28 | /* |
Gruenfrosch | 0:7627c79db971 | 29 | * NAME: fixed->abs() |
Gruenfrosch | 0:7627c79db971 | 30 | * DESCRIPTION: return absolute value of a fixed-point number |
Gruenfrosch | 0:7627c79db971 | 31 | */ |
Gruenfrosch | 0:7627c79db971 | 32 | mad_fixed_t mad_f_abs(mad_fixed_t x) |
Gruenfrosch | 0:7627c79db971 | 33 | { |
Gruenfrosch | 0:7627c79db971 | 34 | return x < 0 ? -x : x; |
Gruenfrosch | 0:7627c79db971 | 35 | } |
Gruenfrosch | 0:7627c79db971 | 36 | |
Gruenfrosch | 0:7627c79db971 | 37 | /* |
Gruenfrosch | 0:7627c79db971 | 38 | * NAME: fixed->div() |
Gruenfrosch | 0:7627c79db971 | 39 | * DESCRIPTION: perform division using fixed-point math |
Gruenfrosch | 0:7627c79db971 | 40 | */ |
Gruenfrosch | 0:7627c79db971 | 41 | mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y) |
Gruenfrosch | 0:7627c79db971 | 42 | { |
Gruenfrosch | 0:7627c79db971 | 43 | mad_fixed_t q, r; |
Gruenfrosch | 0:7627c79db971 | 44 | unsigned int bits; |
Gruenfrosch | 0:7627c79db971 | 45 | |
Gruenfrosch | 0:7627c79db971 | 46 | q = mad_f_abs(x / y); |
Gruenfrosch | 0:7627c79db971 | 47 | |
Gruenfrosch | 0:7627c79db971 | 48 | if (x < 0) { |
Gruenfrosch | 0:7627c79db971 | 49 | x = -x; |
Gruenfrosch | 0:7627c79db971 | 50 | y = -y; |
Gruenfrosch | 0:7627c79db971 | 51 | } |
Gruenfrosch | 0:7627c79db971 | 52 | |
Gruenfrosch | 0:7627c79db971 | 53 | r = x % y; |
Gruenfrosch | 0:7627c79db971 | 54 | |
Gruenfrosch | 0:7627c79db971 | 55 | if (y < 0) { |
Gruenfrosch | 0:7627c79db971 | 56 | x = -x; |
Gruenfrosch | 0:7627c79db971 | 57 | y = -y; |
Gruenfrosch | 0:7627c79db971 | 58 | } |
Gruenfrosch | 0:7627c79db971 | 59 | |
Gruenfrosch | 0:7627c79db971 | 60 | if (q > mad_f_intpart(MAD_F_MAX) && |
Gruenfrosch | 0:7627c79db971 | 61 | !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0))) |
Gruenfrosch | 0:7627c79db971 | 62 | return 0; |
Gruenfrosch | 0:7627c79db971 | 63 | |
Gruenfrosch | 0:7627c79db971 | 64 | for (bits = MAD_F_FRACBITS; bits && r; --bits) { |
Gruenfrosch | 0:7627c79db971 | 65 | q <<= 1, r <<= 1; |
Gruenfrosch | 0:7627c79db971 | 66 | if (r >= y) |
Gruenfrosch | 0:7627c79db971 | 67 | r -= y, ++q; |
Gruenfrosch | 0:7627c79db971 | 68 | } |
Gruenfrosch | 0:7627c79db971 | 69 | |
Gruenfrosch | 0:7627c79db971 | 70 | /* round */ |
Gruenfrosch | 0:7627c79db971 | 71 | if (2 * r >= y) |
Gruenfrosch | 0:7627c79db971 | 72 | ++q; |
Gruenfrosch | 0:7627c79db971 | 73 | |
Gruenfrosch | 0:7627c79db971 | 74 | /* fix sign */ |
Gruenfrosch | 0:7627c79db971 | 75 | if ((x < 0) != (y < 0)) |
Gruenfrosch | 0:7627c79db971 | 76 | q = -q; |
Gruenfrosch | 0:7627c79db971 | 77 | |
Gruenfrosch | 0:7627c79db971 | 78 | return q << bits; |
Gruenfrosch | 0:7627c79db971 | 79 | } |