Changeset 34


Ignore:
Timestamp:
02/22/12 19:53:57 (6 years ago)
Author:
shan2
Message:

ForSyDe-SystemC/CoMPSoC: embedded input support added

Location:
ForSyDe-SystemC/branches/CoMPSoC/examples/sdf/mp3decoder
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • ForSyDe-SystemC/branches/CoMPSoC/examples/sdf/mp3decoder/readBitstreamAndExtractFrames.cpp

    r33 r34  
    1414#include "include/MP3_Huffman_Table.c" 
    1515 
    16  
     16#ifdef FORSYDE 
     17 
     18#define SRC FILE 
     19 
     20#else 
     21 
     22#include "include/input.h" 
     23#define SRC unsigned char 
     24 
     25#endif 
    1726 
    1827/* Function Declaration*/ 
    1928char file_name[256]; 
    20 STATUS MPG_Read_Frame (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp); 
    21 UINT32 MPG_Get_Filepos (FILE* fp); 
    22 STATUS MPG_Read_Header (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp); 
    23 UINT32 MPG_Get_Byte (FILE* fp); 
     29STATUS MPG_Read_Frame (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp); 
     30UINT32 MPG_Get_Filepos (SRC*& fp); 
     31STATUS MPG_Read_Header (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp); 
     32UINT32 MPG_Get_Byte (SRC*& fp); 
    2433void MPG_Decode_L3_Init_Song (); 
    25 STATUS MPG_Read_CRC (FILE* fp); 
    26 STATUS MPG_Read_Audio_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp); 
    27 static void MPG_Get_Sideinfo (UINT32 sideinfo_size, FILE* fp); 
    28 STATUS MPG_Get_Bytes (UINT32 no_of_bytes, UINT32 data_vec[], FILE* fp); 
     34STATUS MPG_Read_CRC (SRC*& fp); 
     35STATUS MPG_Read_Audio_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp); 
     36static void MPG_Get_Sideinfo (UINT32 sideinfo_size, SRC*& fp); 
     37STATUS MPG_Get_Bytes (UINT32 no_of_bytes, UINT32 data_vec[], SRC*& fp); 
    2938UINT32 MPG_Get_Side_Bits (UINT32 number_of_bits); 
    30 STATUS MPG_Read_Main_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp); 
     39STATUS MPG_Read_Main_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp); 
    3140UINT32 MPG_Get_Main_Bits (UINT32 number_of_bits); 
    32 static STATUS MPG_Get_Main_Data (UINT32 main_data_size, UINT32 main_data_begin, FILE* fp); 
     41static STATUS MPG_Get_Main_Data (UINT32 main_data_size, UINT32 main_data_begin, SRC*& fp); 
    3342UINT32 MPG_Get_Main_Pos (); 
    3443static STATUS MPG_Huffman_Decode (UINT32 table_num, INT32 *x, INT32 *y, INT32 *v, INT32 *w); 
     
    5261UINT32  g_main_data_top = 0;/* Number of bytes in reservoir (0-1024) */ 
    5362 
    54 static FILE *fp = (FILE *) NULL; 
     63static SRC *fp = (SRC *) NULL; 
    5564 
    5665static UINT32 hsynth_init = 1; 
     
    93102static UINT32  side_info_idx;   /* Index into the current byte (0-7) */ 
    94103 
    95 FILE *pfile; 
     104SRC *pfile; 
    96105 
    97106 
    98107bool readBitstreamAndExtractFrames(char *file_name, FrameHeader *frameHeader, FrameSideInfo *frameSideInfo, FrameMainData *frameMainData){ 
    99108 
    100         /* File open? */ 
    101               if (fp == (FILE *) NULL) { 
    102                 if ((fp = fopen (file_name, "r")) == (FILE *) NULL) { 
    103                   printf ("Cannot open mp3 file \"%s\"\n", file_name); 
    104                   exit (0); 
    105                 } 
    106               } 
    107  
    108             if (MPG_Get_Filepos (fp) != C_MPG_EOF) { 
    109              MPG_Read_Frame(frameHeader, frameSideInfo, frameMainData, fp); 
    110             } 
    111             else{ 
    112               //fclose(fw); 
    113               //exit (0); 
    114                   return false; 
    115             } 
    116  
    117  
    118                 return true; 
    119         } 
    120  
    121 STATUS MPG_Read_Frame (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp) 
     109  /* File open? */ 
     110  if (fp == (SRC *) NULL) { 
     111  #ifdef FORSYDE 
     112    if ((fp = fopen (file_name, "r")) == (SRC *) NULL) { 
     113      printf ("Cannot open mp3 file \"%s\"\n", file_name); 
     114      exit (0); 
     115    } 
     116  #else 
     117    fp = instream; 
     118  #endif 
     119  } 
     120 
     121    if (MPG_Get_Filepos (fp) != C_MPG_EOF) { 
     122     MPG_Read_Frame(frameHeader, frameSideInfo, frameMainData, fp); 
     123    } 
     124    else{ 
     125      //fclose(fw); 
     126      //exit (0); 
     127      return false; 
     128    } 
     129 
     130 
     131    return true; 
     132} 
     133 
     134STATUS MPG_Read_Frame (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp) 
    122135{ 
    123136    UINT32 first = 0; 
     
    169182} 
    170183 
    171 UINT32 MPG_Get_Filepos (FILE* fp) 
     184UINT32 MPG_Get_Filepos (SRC*& fp) 
    172185{ 
    173186 
    174187    /* File open? */ 
    175     if (fp == (FILE *) NULL) { 
     188    if (fp == (SRC *) NULL) { 
    176189        return (0); 
    177190    } 
    178  
     191#ifdef FORSYDE 
    179192    if (feof (fp)) { 
    180193        return (C_MPG_EOF); 
     
    182195        return ((UINT32) ftell (fp)); 
    183196    } 
    184  
    185 } 
    186  
    187 STATUS MPG_Read_Header (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp) 
     197#else 
     198    if (fp-instream >= instream_size) { 
     199        return (C_MPG_EOF); 
     200    } else { 
     201        return ((UINT32) (fp-instream)); 
     202    } 
     203#endif 
     204} 
     205 
     206STATUS MPG_Read_Header (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp) 
    188207{ 
    189208    UINT32 b1, b2, b3, b4, header; 
     
    302321 
    303322 
    304 STATUS MPG_Read_CRC (FILE* fp) 
     323STATUS MPG_Read_CRC (SRC*& fp) 
    305324{ 
    306325    UINT32 b1, b2; 
     
    321340 
    322341 
    323 UINT32 MPG_Get_Byte (FILE* fp) 
     342UINT32 MPG_Get_Byte (SRC*& fp) 
    324343{ 
    325344         UINT32 val; 
    326345 
    327  
     346#ifdef FORSYDE 
    328347 
    329348            /* Get byte */ 
     
    334353                val = C_MPG_EOF; 
    335354            } 
    336  
     355#else 
     356        /* Get byte */ 
     357            val = (*(fp++)) & 0xff; 
     358 
     359            /* EOF? */ 
     360            if (fp-instream >= instream_size) { 
     361                val = C_MPG_EOF; 
     362            } 
     363#endif 
    337364            /* Done */ 
    338365            return (val); 
     
    340367} 
    341368 
    342 STATUS MPG_Read_Audio_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp) 
     369STATUS MPG_Read_Audio_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp) 
    343370{ 
    344371        UINT32 framesize, sideinfo_size, main_data_size; 
     
    466493} 
    467494 
    468 static void MPG_Get_Sideinfo (UINT32 sideinfo_size,FILE* fp) 
     495static void MPG_Get_Sideinfo (UINT32 sideinfo_size,SRC*& fp) 
    469496{ 
    470497    if (MPG_Get_Bytes (sideinfo_size, side_info_vec, fp) != OK) { 
     
    478505} 
    479506 
    480 STATUS MPG_Get_Bytes (UINT32 no_of_bytes, UINT32 data_vec[], FILE* fp) 
     507STATUS MPG_Get_Bytes (UINT32 no_of_bytes, UINT32 data_vec[], SRC*& fp) 
    481508{ 
    482509    int i; 
     
    498525} 
    499526 
    500 STATUS MPG_Read_Main_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, FILE* fp) 
     527STATUS MPG_Read_Main_L3 (FrameHeader* g_frame_header, FrameSideInfo* g_side_info, FrameMainData* g_main_data, SRC*& fp) 
    501528{ 
    502529 
     
    643670} 
    644671 
    645 static STATUS MPG_Get_Main_Data (UINT32 main_data_size, UINT32 main_data_begin, FILE* fp) 
     672static STATUS MPG_Get_Main_Data (UINT32 main_data_size, UINT32 main_data_begin, SRC*& fp) 
    646673{ 
    647674    int i, start_pos; 
     
    821848} 
    822849 
    823 void MPG_Set_Filepos (UINT32 position, FILE* fp) 
    824 { 
    825  
    826     /* File open? */ 
    827     if (fp == (FILE *) NULL) { 
    828         return; 
    829     } 
    830  
    831     fseek (fp, (long) position, SEEK_SET); 
    832  
    833 } 
     850//~ void MPG_Set_Filepos (UINT32 position, SRC* fp) 
     851//~ { 
     852//~  
     853    //~ /* File open? */ 
     854    //~ if (fp == (SRC *) NULL) { 
     855        //~ return; 
     856    //~ } 
     857//~  
     858    //~ fseek (fp, (long) position, SEEK_SET); 
     859//~  
     860//~ } 
    834861 
    835862static STATUS MPG_Huffman_Decode (UINT32 table_num, INT32 *x, INT32 *y, INT32 *v, INT32 *w) 
Note: See TracChangeset for help on using the changeset viewer.