/* * mp3plot - Bitrate analysis tool * * Copyright (C) 2007 Toni Corvera * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // $Id: mp3_frame.h 746 2007-05-24 00:55:42Z $ #ifndef ONET_MP3FRAME_H #define ONET_MP3FRAME_H #include #include #include "mp3_common.h" #include "mp3_element.h" namespace net_outlyer { namespace mp3 { /*! * \brief MP3 audio frame and associated header. */ struct mp3frame : public mp3element { private: /*! * \brief Offset of the frame start * \see offset() */ std::streampos start; public: /*! * \brief Index of the frame in the file. * \deprecated Only used for debugging purposes */ numframes_t frame_idx; /// Header meta information //! Version of MPEG (1, 2 or 2.5) of the frame mpeg_version_t mpeg_version; //! MPEG Layer (I, II or III) of the frame mpeg_layer_t mpeg_layer; //! true if the frame contains a CRC bool crc; //! Bitrate, in kbps, of the frame bitrate_t bitrate; //! Frequency, in Hz, of the frame uint16_t freq; //! true if the frame has padding bool has_padding; //! Channel mode of the frame channel_mode_t channel_mode; explicit mp3frame() : start(-1), mpeg_version(_version_reserved), mpeg_layer(_layer_reserved), crc(false), bitrate(BAD_BITRATE), freq(-1), has_padding(false), channel_mode(_undefined_channel_mode) {} virtual ~mp3frame() {} /*! * \brief Reads the frame meta data and puts the get pointer in the audio data. * \see skip_data() */ virtual void read(std::ifstream & input) throw (e_error); /*! * \brief Skips the audio data. * \note The amount skipped is based on bitrate, frequency and * known standard values. */ void skip_data(std::ifstream & input) throw (e_read_failure); //! Prints the frame meta information. void dump() const; //! Returns the offset of the frame start in the file. const std::streampos & offset() const { return start; } static const uint16_t FREE_FORM_BITRATE; private: static uint16_t get_bitrate(uint8_t b); }; struct mp3_meta_info { bool is_vbr; uint32_t num_frames; // This is the filesize indicated in the header, if any, or // 0 otherwise, apparently it might differ somewhat from its real size uint32_t file_size; bool has_filesize, has_numframes, has_toc, has_vbr_scale; mp3_meta_info() : is_vbr(false), num_frames(0), file_size(0), has_filesize(false), has_numframes(false), has_toc(false), has_vbr_scale(false) {} }; struct mp3frame_first : public mp3frame { std::streampos xing_offset; uint8_t flags; mp3_meta_info & info; explicit mp3frame_first(mp3_meta_info & meta_info) : mp3frame(), xing_offset(0), flags(0), info(meta_info) {} virtual void read(std::ifstream & input) throw (e_error); private: void check_vbr(std::ifstream & in) throw (e_read_failure); }; } // namespace mp3 } // namespace net_outlyer #endif // ONET_MP3FRAME_H /* vim:set ts=4 et ai: */