Ignore:
Timestamp:
01/18/09 18:17:12 (15 years ago)
Author:
radscorpion
Message:

Demuxer updated to 0.4.0.0
Support for APE 2.0 tags
Chapters are now supported

File:
1 edited

Legend:

Unmodified
Added
Removed
  • dsfilters/demux_mpc/src/mpc_file.cpp

    r380 r421  
    3737CMPCFile::~CMPCFile()
    3838{
     39        ClearChapters();
    3940        if (seek_table) { free(seek_table); seek_table = NULL; }
    4041        if (extradata) { free(extradata); extradata = NULL; }
     42}
     43
     44void CMPCFile::ClearChapters()
     45{
     46        for (int i=0; i<chapters.size(); i++) {
     47                CMPCChapter     *chap = chapters[i];
     48                delete chap;
     49        }
     50        chapters.clear();
    4151}
    4252
     
    106116                if (ret < 0) return ret;
    107117
     118                // if there is a sequence of chapters it MUST follow the seeking table
     119                while (true) {
     120                        ret = packet.Load(reader);
     121                        if (ret < 0) break;
     122
     123                        if (packet.key == MPC_KEY('C','T')) {
     124                                CMPCChapter             *chap = new CMPCChapter();
     125                                ret = chap->Load(&packet);
     126                                if (ret < 0) {
     127                                        delete chap;
     128                                } else {                                       
     129                                        if (chap->caption == _T("")) {
     130                                                chap->caption.Format(_T("Chapter %d"), (int)chapters.size() + 1);
     131                                        }
     132                                        chapters.push_back(chap);
     133                                }
     134                        } else {
     135                                break;
     136                        }
     137                }
     138
    108139                // seek back to first AP
    109140                reader->Seek(first_ap_pos);
     
    256287        HRESULT         hr;
    257288        int                     ret;
     289
     290        //-------------------------------------------------------------------------
     291        //
     292        //      Load APE Tag
     293        //
     294        //-------------------------------------------------------------------------
     295
     296        // try to load the APE Tag
     297        __int64         size, avail;
     298        int                     tagsize = 0;
     299        reader->GetSize(&avail, &size);
     300
     301        tag.Clear();
     302        if (size >= 32) {
     303                BYTE            temp[32];
     304
     305                reader->Seek(size - 32);
     306                reader->Read(temp, 32);
     307
     308                ret = tag.ReadFooter(temp, 32, &tagsize);
     309                if (ret == 0 && tagsize > 0) {
     310                        // seek this many bytes back
     311                        reader->Seek(size - 32 - tagsize);
     312                       
     313                        // also load the footer
     314                        tagsize += 32;
     315                        BYTE            *apetag = (BYTE*)malloc(tagsize);
     316                        if (apetag) {
     317                                reader->Read(apetag, tagsize);
     318
     319                                ret = tag.ReadTag(apetag, tagsize);
     320                                if (ret < 0) {
     321                                        tag.Clear();
     322                                }
     323
     324                                free(apetag);
     325                        }
     326                }
     327        }
     328
     329        //-------------------------------------------------------------------------
     330        //
     331        //      Load MPC file
     332        //
     333        //-------------------------------------------------------------------------
    258334
    259335        // keep a local copy of the reader
     
    662738}
    663739
    664 
     740//-----------------------------------------------------------------------------
     741//
     742//      CMPCChapter
     743//
     744//-----------------------------------------------------------------------------
     745
     746CMPCChapter::CMPCChapter()
     747{
     748        sample_offset           = 0;
     749        chapter_gain_db         = 0;
     750        chapter_peak_db         = 0;
     751}
     752
     753CMPCChapter::~CMPCChapter()
     754{
     755}
     756
     757int CMPCChapter::Load(CMPCPacket *packet)
     758{
     759        Bitstream       b(packet->payload);
     760        b.NeedBits();
     761
     762        sample_offset = b.GetMpcSize();
     763
     764        int16   val;
     765        b.NeedBits();   val = b.SGetBits(16);   chapter_gain_db = val / 256.0;
     766        b.NeedBits();   val = b.UGetBits(16);   chapter_peak_db = val;
     767
     768        if (chapter_gain_db != 0) chapter_gain_db = OLD_GAIN_REF - chapter_gain_db;
     769        if (chapter_peak_db != 0) {
     770                chapter_peak_db = pow((double)10.0, (double)(chapter_peak_db / (20*256))) / (double)(1 << 15);
     771        }
     772
     773        BYTE            *buf = b.Position();
     774        BYTE            *end = packet->payload + packet->payload_size;
     775
     776        // let's try to load the APE Tag
     777        APE_Tag         tag;
     778        int ret = tag.ReadTag(buf, end-buf, true);
     779        if (ret == 0) {
     780
     781                CString         title   = tag.FindName(_T("title"));
     782                CString         track   = tag.FindName(_T("track"));
     783               
     784                if (track != _T("")) {
     785                        caption.Format(_T("%s [%s]"), title.GetBuffer(), track.GetBuffer());
     786                } else {
     787                        caption = title;
     788                }
     789                caption.Trim();
     790       
     791        } else {
     792                caption = _T("");
     793        }
     794
     795        return 0;
     796}
     797
     798
Note: See TracChangeset for help on using the changeset viewer.