frame.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * libmad - MPEG audio decoder library
  3. * Copyright (C) 2000-2004 Underbit Technologies, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. * $Id: frame.h,v 1.20 2004/01/23 09:41:32 rob Exp $
  20. */
  21. # ifndef LIBMAD_FRAME_H
  22. # define LIBMAD_FRAME_H
  23. # include "fixed.h"
  24. # include "timer.h"
  25. # include "stream.h"
  26. enum mad_layer {
  27. MAD_LAYER_I = 1, /* Layer I */
  28. MAD_LAYER_II = 2, /* Layer II */
  29. MAD_LAYER_III = 3 /* Layer III */
  30. };
  31. enum mad_mode {
  32. MAD_MODE_SINGLE_CHANNEL = 0, /* single channel */
  33. MAD_MODE_DUAL_CHANNEL = 1, /* dual channel */
  34. MAD_MODE_JOINT_STEREO = 2, /* joint (MS/intensity) stereo */
  35. MAD_MODE_STEREO = 3 /* normal LR stereo */
  36. };
  37. enum mad_emphasis {
  38. MAD_EMPHASIS_NONE = 0, /* no emphasis */
  39. MAD_EMPHASIS_50_15_US = 1, /* 50/15 microseconds emphasis */
  40. MAD_EMPHASIS_CCITT_J_17 = 3, /* CCITT J.17 emphasis */
  41. MAD_EMPHASIS_RESERVED = 2 /* unknown emphasis */
  42. };
  43. struct mad_header {
  44. enum mad_layer layer; /* audio layer (1, 2, or 3) */
  45. enum mad_mode mode; /* channel mode (see above) */
  46. int mode_extension; /* additional mode info */
  47. enum mad_emphasis emphasis; /* de-emphasis to use (see above) */
  48. unsigned long bitrate; /* stream bitrate (bps) */
  49. unsigned int samplerate; /* sampling frequency (Hz) */
  50. unsigned short crc_check; /* frame CRC accumulator */
  51. unsigned short crc_target; /* final target CRC checksum */
  52. int flags; /* flags (see below) */
  53. int private_bits; /* private bits (see below) */
  54. mad_timer_t duration; /* audio playing time of frame */
  55. };
  56. struct mad_frame {
  57. struct mad_header header; /* MPEG audio header */
  58. int options; /* decoding options (from stream) */
  59. mad_fixed_t sbsample[2][36][32]; /* synthesis subband filter samples */
  60. mad_fixed_t (*overlap)[2][32][18]; /* Layer III block overlap data */
  61. };
  62. # define MAD_NCHANNELS(header) ((header)->mode ? 2 : 1)
  63. # define MAD_NSBSAMPLES(header) \
  64. ((header)->layer == MAD_LAYER_I ? 12 : \
  65. (((header)->layer == MAD_LAYER_III && \
  66. ((header)->flags & MAD_FLAG_LSF_EXT)) ? 18 : 36))
  67. enum {
  68. MAD_FLAG_NPRIVATE_III = 0x0007, /* number of Layer III private bits */
  69. MAD_FLAG_INCOMPLETE = 0x0008, /* header but not data is decoded */
  70. MAD_FLAG_PROTECTION = 0x0010, /* frame has CRC protection */
  71. MAD_FLAG_COPYRIGHT = 0x0020, /* frame is copyright */
  72. MAD_FLAG_ORIGINAL = 0x0040, /* frame is original (else copy) */
  73. MAD_FLAG_PADDING = 0x0080, /* frame has additional slot */
  74. MAD_FLAG_I_STEREO = 0x0100, /* uses intensity joint stereo */
  75. MAD_FLAG_MS_STEREO = 0x0200, /* uses middle/side joint stereo */
  76. MAD_FLAG_FREEFORMAT = 0x0400, /* uses free format bitrate */
  77. MAD_FLAG_LSF_EXT = 0x1000, /* lower sampling freq. extension */
  78. MAD_FLAG_MC_EXT = 0x2000, /* multichannel audio extension */
  79. MAD_FLAG_MPEG_2_5_EXT = 0x4000 /* MPEG 2.5 (unofficial) extension */
  80. };
  81. enum {
  82. MAD_PRIVATE_HEADER = 0x0100, /* header private bit */
  83. MAD_PRIVATE_III = 0x001f /* Layer III private bits (up to 5) */
  84. };
  85. void mad_header_init(struct mad_header *);
  86. # define mad_header_finish(header) /* nothing */
  87. int mad_header_decode(struct mad_header *, struct mad_stream *);
  88. void mad_frame_init(struct mad_frame *);
  89. void mad_frame_finish(struct mad_frame *);
  90. int mad_frame_decode(struct mad_frame *, struct mad_stream *);
  91. void mad_frame_mute(struct mad_frame *);
  92. # endif