mp3.h 1.9 KB

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