/* ** mpganaly.c - Program to analyse MPEG audio files ** ** File created: 6/16/2000 ** Last revision: 8/10/2000 ** ** Copyright (C) 2000 Sean R. Wells ** ** 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 ** */ #include #include "mp3_data.h" #define DEBUG_LONG int FindBitrate ( int version, int layer, int value ); int FindSamplingRate ( float version, int value ); int FindFrameSize ( mpeg_info header ); int ReadHeader ( unsigned int frame_value, mpeg_info *header ); int ReadMPEG ( register FILE *infile ) { unsigned int frame_value; int i; mpeg_info header; float check_ver; int check_lay; int check_bit; int ch = 0; int byte_count = 0; InitializeStruct ( &header ); while ( ch != EOF ) { frame_value = 0; /* Find frame sync */ for ( ch = getc ( infile ), byte_count++, frame_value = ( frame_value << 8 ) + ch; ( ( ch != EOF ) && ( ( ( frame_value >> 21 ) & 0x07ff ) != 0x07ff ) ); ch = getc ( infile ), frame_value = ( frame_value << 8 ) + ch , byte_count++ ); if ( ch == EOF ) { return ( 0 ); } ReadHeader ( frame_value, &header ); if ( byte_count < 8 ) { check_ver = header.MPEG_ver; check_lay = header.MPEG_lay; check_bit = header.MPEG_bitrate; printf ( "Version = %1.1f Layer = %d Bitrate = %d\n", check_ver, check_lay, check_bit ); } /* Check for a valid header (these values /shouldn't/ change) */ if ( ( header.MPEG_ver == check_ver ) && ( header.MPEG_lay == check_lay ) && ( header.MPEG_bitrate == check_bit ) ) { #ifdef DEBUG_LONG printf ( "MPEG Version = %1.1f\n", header.MPEG_ver ); printf ( "MPEG Layer = %d\n", header.MPEG_lay ); printf ( "MPEG Protection = %s\n", header.MPEG_prot ); printf ( "MPEG Bitrate = %d bps\n", header.MPEG_bitrate ); printf ( "MPEG Sampling rate = %d Hz\n", header.MPEG_samp_rate ); printf ( "MPEG Padding bit = %d\n", header.MPEG_pad_bit ); printf ( "MPEG Channel mode = %s\n", header.MPEG_chan_mode ); printf ( "MPEG Mode extension = %d\n", header.MPEG_mode_ext ); printf ( "MPEG Copyright = %s\n", header.MPEG_copyright ); printf ( "MPEG Copy = %s\n", header.MPEG_copy ); printf ( "MPEG Emphasis = %d\n", header.MPEG_emphasis ); printf ( "MPEG Frame size = %d\n\n", header.MPEG_frame_size ); printf ( "MPEG Frame count = %d\n", header.MPEG_frame_count ); printf ( "MPEG Byte count = %d\n\n", byte_count ); #endif for ( i = 0; i < header.MPEG_frame_size - ( 4 + header.MPEG_pad_bit); i++ ) { ch = getc ( infile ); byte_count++; if ( ch == EOF ) { return ( 0 ); } } header.MPEG_frame_count++; } } printf ( "MPEG Version = %1.1f\n", header.MPEG_ver ); printf ( "MPEG Layer = %d\n", header.MPEG_lay ); printf ( "MPEG Protection = %s\n", header.MPEG_prot ); printf ( "MPEG Bitrate = %d bps\n", header.MPEG_bitrate ); printf ( "MPEG Sampling rate = %d Hz\n", header.MPEG_samp_rate ); printf ( "MPEG Padding bit = %d\n", header.MPEG_pad_bit ); printf ( "MPEG Channel mode = %s\n", header.MPEG_chan_mode ); printf ( "MPEG Mode extension = %d\n", header.MPEG_mode_ext ); printf ( "MPEG Copyright = %s\n", header.MPEG_copyright ); printf ( "MPEG Copy = %s\n", header.MPEG_copy ); printf ( "MPEG Emphasis = %d\n", header.MPEG_emphasis ); printf ( "MPEG Frame size = %d\n\n", header.MPEG_frame_size ); printf ( "MPEG Frame count = %d\n\n", header.MPEG_frame_count ); return ( 0 ); } int main ( argc, argv ) int argc; char **argv; { register FILE *infile; if ( argc < 2 ) { fprintf ( stderr, "mpganaly version 1.0b Copyright (C) 2000 Sean R. Wells"); fprintf ( stderr, "\nUsage: mpganaly \n" ); return ( 0 ); } infile = fopen ( argv[1], "rb" ); if ( !infile ) { fprintf ( stderr, "ERROR - Could not open input file.\n" ); return ( 0 ); } ReadMPEG ( infile ); fclose ( infile ); return ( 0 ); }