Ignore:
Timestamp:
10/31/08 00:20:05 (15 years ago)
Author:
r2d
Message:

added chapter gain / peak to libmpcdec and mpcchap as in the spec

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libmpc/trunk/mpcchap/mpcchap.c

    r408 r411  
    3030void    Init_Tags        ( void );
    3131int     FinalizeTags     ( FILE* fp, unsigned int Version, unsigned int flags );
    32 int     addtag           ( const char* key, size_t keylen, const char* value, size_t valuelen, int converttoutf8, int flags );
     32int     addtag           ( const char* key, size_t keylen, const char* value,
     33                           size_t valuelen, int converttoutf8, int flags );
    3334#define TAG_NO_HEADER 1
    3435#define TAG_NO_FOOTER 2
     
    3940#define atoll _atoi64
    4041#endif
     42
     43static const int Ptis[] = {     PTI_TITLE, PTI_PERFORMER, PTI_SONGWRITER, PTI_COMPOSER,
     44                PTI_ARRANGER, PTI_MESSAGE, PTI_GENRE};
     45static char const * const APE_keys[] = {"Title", "Artist", "Songwriter", "Composer",
     46                "Arranger", "Comment", "Genre"};
    4147
    4248static void usage(const char *exename)
     
    7783        int nchap = iniparser_getnsec(dict);
    7884        for (i = 0; i < nchap; i++) {
    79                 Init_Tags();
    80                 int j, nitem, tag_len = 0;
     85                int j, nitem, ntags = 0, tag_len = 0;
     86                mpc_uint16_t gain = 0, peak = 0;
    8187                char * chap_sec = iniparser_getsecname(dict, i);
    8288                mpc_int64_t chap_pos = atoll(chap_sec);
     89
    8390                if (chap_pos > si->samples - si->beg_silence)
    84                         fprintf(stderr, "warning : chapter %i starts @ %lli after the end of the stream (%lli)\n", i + 1, chap_pos, si->samples - si->beg_silence);
     91                        fprintf(stderr, "warning : chapter %i starts @ %lli samples after the end of the stream (%lli)\n",
     92                                i + 1, chap_pos, si->samples - si->beg_silence);
     93
     94                Init_Tags();
     95
    8596                nitem = iniparser_getnkey(dict, i);
    8697                for (j = 0; j < nitem; j++) {
     
    8899                        int key_len, item_len;
    89100                        item_key = iniparser_getkeyname(dict, i, j, & item_value);
    90                         key_len = strlen(item_key);
    91                         item_len = strlen(item_value);
    92                         addtag(item_key, key_len, item_value, item_len, 0, 0);
    93                         tag_len += key_len + item_len;
     101                        if (strcmp(item_key, "gain") == 0)
     102                                gain = atoi(item_value);
     103                        else if (strcmp(item_key, "peak") == 0)
     104                                peak = atoi(item_value);
     105                        else {
     106                                key_len = strlen(item_key);
     107                                item_len = strlen(item_value);
     108                                addtag(item_key, key_len, item_value, item_len, 0, 0);
     109                                tag_len += key_len + item_len;
     110                                ntags++;
     111                        }
    94112                }
    95                 if (nitem > 0) tag_len += 24 + nitem * 9;
     113                if (ntags > 0) tag_len += 24 + ntags * 9;
    96114                char block_header[12] = "CT";
    97115                char sample_offset[10];
    98116                int offset_size = encodeSize(chap_pos, sample_offset, MPC_FALSE);
    99                 tag_len = encodeSize(tag_len + offset_size + 2, block_header + 2, MPC_TRUE);
     117                tag_len = encodeSize(tag_len + 4 + offset_size + 2, block_header + 2, MPC_TRUE);
    100118                fwrite(block_header, 1, tag_len + 2, in_file);
    101119                fwrite(sample_offset, 1, offset_size, in_file);
     120                sample_offset[0] = gain >> 8;
     121                sample_offset[1] = gain & 0xFF;
     122                sample_offset[2] = peak >> 8;
     123                sample_offset[3] = peak & 0xFF;
     124                fwrite(sample_offset, 1, 4, in_file);
    102125                FinalizeTags(in_file, TAG_VERSION, TAG_NO_FOOTER | TAG_NO_PREAMBLE);
    103126        }
     
    115138mpc_status add_chaps_cue(char * mpc_file, char * chap_file, mpc_demux * demux, mpc_streaminfo * si)
    116139{
    117         int Ptis[7] = { PTI_TITLE, PTI_PERFORMER, PTI_SONGWRITER, PTI_COMPOSER,
    118                         PTI_ARRANGER, PTI_MESSAGE, PTI_GENRE};
    119         char * APE_keys[7] = {"Title", "Artist", "Songwriter", "Composer",
    120                         "Arranger", "Comment", "Genre"};
    121 
    122140        Cd *cd = 0;
    123141        int nchap, format = UNKNOWN;
     
    155173
    156174                if (chap_pos > si->samples - si->beg_silence)
    157                         fprintf(stderr, "warning : chapter %i starts @ %lli after the end of the stream (%lli)\n", i, chap_pos, si->samples - si->beg_silence);
     175                        fprintf(stderr, "warning : chapter %i starts @ %lli samples after the end of the stream (%lli)\n",
     176                                i, chap_pos, si->samples - si->beg_silence);
    158177
    159178                Init_Tags();
     
    168187
    169188                for (j = 0; j < (sizeof(Ptis) / sizeof(*Ptis)); j++) {
    170                         char * item_key = APE_keys[j], * item_value;
     189                        char const * item_key = APE_keys[j], * item_value;
    171190                        item_value = cdtext_get (Ptis[j], cdtext);
    172191                        if (item_value != 0) {
     
    183202                char sample_offset[10];
    184203                int offset_size = encodeSize(chap_pos, sample_offset, MPC_FALSE);
    185                 tag_len = encodeSize(tag_len + offset_size + 2, block_header + 2, MPC_TRUE);
     204                tag_len = encodeSize(tag_len + 4 + offset_size + 2, block_header + 2, MPC_TRUE);
    186205                fwrite(block_header, 1, tag_len + 2, in_file);
    187206                fwrite(sample_offset, 1, offset_size, in_file);
     207                fwrite("\0\0\0\0", 1, 4, in_file); // put unknow chapter gain / peak
    188208                FinalizeTags(in_file, TAG_VERSION, TAG_NO_FOOTER | TAG_NO_PREAMBLE);
    189209        }
     
    201221{
    202222        int i;
    203         unsigned int tag_size;
    204223        FILE * out_file;
    205         char * tag;
     224        mpc_chap_info * chap;
    206225
    207226        if (chap_nb <= 0)
     
    213232
    214233        for (i = 0; i < chap_nb; i++) {
    215                 fprintf(out_file, "[%lli]\n", mpc_demux_chap(demux, i, &tag, &tag_size));
    216                 if (tag_size > 0) {
     234                chap = mpc_demux_chap(demux, i);
     235                fprintf(out_file, "[%lli]\ngain=%i\npeak=%i\n", chap->sample, chap->gain, chap->peak);
     236                if (chap->tag_size > 0) {
    217237                        int item_count, j;
     238                        char const * tag = chap->tag;
    218239                        item_count = tag[8] | (tag[9] << 8) | (tag[10] << 16) | (tag[11] << 24);
    219240                        tag += 24;
Note: See TracChangeset for help on using the changeset viewer.