1 #ifndef __MP3_H 2 #define __MP3_H 3 4 /* 5 * Praat wrappers for libMAD (MPEG Audio Decoder) 6 * Copyright 2007 Erez Volk 7 * 8 * This code is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation; either version 2 of the License, or (at 11 * your option) any later version. 12 * 13 * This code is distributed in the hope that it will be useful, but 14 * WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 16 * See the GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this work. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #include "../../melder/melder.h" // for integer 23 24 /* The following function is used to identify MP3 files */ 25 int mp3_recognize (int nread, const char *data); 26 27 /* Actual decoding is done with an MP3_FILE object */ 28 typedef struct _MP3_FILE *MP3_FILE; 29 30 typedef int MP3F_SAMPLE; 31 #if defined (_OFF_T) || defined (__off_t_defined) 32 typedef off_t MP3F_OFFSET; 33 #else 34 typedef unsigned long MP3F_OFFSET; 35 #endif 36 37 #define MP3F_MAX_CHANNELS 2 38 #define MP3F_MAX_SAMPLES 1152 /* Per callback */ 39 40 typedef void (*MP3F_CALLBACK) ( 41 const MP3F_SAMPLE *channels [MP3F_MAX_CHANNELS], 42 integer num_samples, 43 void *context); 44 45 MP3_FILE mp3f_new (); 46 void mp3f_delete (MP3_FILE mp3f); 47 48 void mp3f_set_file (MP3_FILE mp3f, FILE *f); 49 50 int mp3f_analyze (MP3_FILE mp3f); 51 unsigned mp3f_channels (MP3_FILE mp3f); 52 unsigned mp3f_frequency (MP3_FILE mp3f); 53 MP3F_OFFSET mp3f_samples (MP3_FILE mp3f); 54 55 void mp3f_set_callback (MP3_FILE mp3f, 56 MP3F_CALLBACK callback, void *context); 57 int mp3f_seek (MP3_FILE mp3f, MP3F_OFFSET sample); 58 int mp3f_read (MP3_FILE mp3f, MP3F_OFFSET num_samples); 59 60 #define mp3f_sample_to_float(s) ((float)((s) / (float)(1L << 28))) 61 short mp3f_sample_to_short (MP3F_SAMPLE sample); 62 63 #endif /* __MP3_H */ 64 65