/*------------------------------------------------------------------------------

    File    :	mpega.c

    Author  :	Stéphane TAVENARD

    $VER:   mpega.c  1.1  (10/09/1995)

    (C) Copyright 1995-1995 Stéphane TAVENARD
	All Rights Reserved

    #Rev|   Date   |			  Comment
    ----|----------|--------------------------------------------------------
    0	|01/05/1995| Initial revision					  ST
    1	|28/05/1995| First release					  ST
    2	|05/06/1995| Aminet release ? not yet ...			  ST
    3	|23/06/1995| Aminet release					  ST
    4	|10/09/1995| Added Mixing frequency option, Aminet release	  ST

    ------------------------------------------------------------------------

    MPEG I Audio layer I & II fast decoding

------------------------------------------------------------------------------*/

#include <stdio.h>
#include <stdlib.h>
#include "mpega_decode.h"
#include "user_interface.h"

static frame_params *fr_ps;

void main_exit( void )
{
   if( fr_ps ) {
      fr_ps = MPEGA_close( fr_ps );
   }
}

int main( int argc, char **argv )
{
   fr_ps = MPEGA_open();
   if( !fr_ps ) {
      fprintf( stderr, "Not enough memory !\n" );
      exit( 0 );
   }
   atexit( main_exit );

   USIN_get_parameters( argc, argv, fr_ps );

   if( !MPEGA_init_decode( fr_ps ) ) exit( 0 );

   USIN_display_info( fr_ps );

    while( MPEGA_decode_frame( fr_ps ) ) {
       if( fr_ps->out_write_length > fr_ps->out_write_level ) {
	  (void)MPEGA_write_out( fr_ps );
       }
       if( (fr_ps->frame_count & 15) == 0 ) USIN_display_frame_number( fr_ps );
    }
    (void)MPEGA_write_out( fr_ps );
    (void)MPEGA_write_out( fr_ps ); /* Second write for close audio or file */

    USIN_epilog( fr_ps );

    fr_ps = MPEGA_close( fr_ps );

    return 0;
}
