Changeset 4592:e51aef50fe8c in roaraudio


Ignore:
Timestamp:
11/07/10 05:56:17 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added metadata support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/codecfilter_flac.c

    r4590 r4592  
    102102 
    103103void cf_flac_cb_metadata(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data) { 
     104 struct codecfilter_flac_inst * self = client_data; 
     105 const FLAC__StreamMetadata_VorbisComment * vc; 
     106 FLAC__uint32 i; 
     107 const char * key, * value; 
     108 char keycopy[ROAR_META_MAX_NAMELEN]; 
     109 int type; 
     110 float rpg_track = 0, rpg_album = 0; 
     111 
     112 if ( metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT ) { 
     113  ROAR_DBG("cf_flac_cb_metadata(decoder=%p, metadata=%p, client_data=%p): have METADATA_TYPE_VORBIS_COMMENT", decoder, metadata, client_data); 
     114 
     115  stream_meta_clear(ROAR_STREAM(self->ss)->id); 
     116 
     117  vc = &(metadata->data.vorbis_comment); 
     118 
     119  for (i = 0; i < vc->num_comments; i++) { 
     120   //printf("c='%s'\n", vc->comments[i].entry); 
     121   key = (const char *)vc->comments[i].entry; 
     122   value = strstr(key, "="); 
     123   if ( value == NULL ) 
     124    continue; 
     125 
     126   if ( (value - key + 1) > sizeof(keycopy) ) 
     127    continue; 
     128 
     129   memcpy(keycopy, key, value - key); 
     130   keycopy[sizeof(keycopy)-1] = 0; 
     131   keycopy[value - key] = 0; 
     132 
     133   value++; 
     134 
     135   //printf("keycopy='%s', value='%s'\n", keycopy, value); 
     136 
     137   type = roar_meta_inttype(keycopy); 
     138   if ( type == -1 ) 
     139    continue; 
     140 
     141   stream_meta_add(ROAR_STREAM(self->ss)->id, type, "", value); 
     142 
     143    if ( strcmp(keycopy, "REPLAYGAIN_TRACK_PEAK") == 0 ) { 
     144     rpg_track = 1/atof(value); 
     145/* 
     146    } else if ( strcmp(key, "REPLAYGAIN_TRACK_GAIN") == 0 ) { 
     147     rpg_track = powf(10, atof(value)/20); 
     148*/ 
     149    } else if ( strcmp(keycopy, "REPLAYGAIN_ALBUM_PEAK") == 0 ) { 
     150     rpg_album = 1/atof(value); 
     151/* 
     152    } else if ( strcmp(key, "REPLAYGAIN_ALBUM_GAIN") == 0 ) { 
     153     rpg_album = powf(10, atof(value)/20); 
     154*/ 
     155    } 
     156 
     157  } 
     158 
     159 if ( rpg_album ) { 
     160  self->ss->mixer.rpg_div = 2718;  // = int(exp(1)*1000) 
     161  self->ss->mixer.rpg_mul = (float)rpg_album*2718; 
     162 } else if ( rpg_track ) { 
     163  self->ss->mixer.rpg_div = 2718; 
     164  self->ss->mixer.rpg_mul = (float)rpg_track*2718; 
     165 } 
     166 
     167  stream_meta_finalize(ROAR_STREAM(self->ss)->id); 
     168 } 
     169 
    104170 ROAR_DBG("cf_flac_cb_metadata(decoder=%p, metadata=%p, client_data=%p) = (void)", decoder, metadata, client_data); 
    105171} 
     
    138204 FLAC__stream_decoder_set_error_callback(self->decoder.decoder, cf_flac_cb_error); 
    139205 FLAC__stream_decoder_set_client_data(self->decoder.decoder, self); 
     206 
     207 FLAC__stream_decoder_set_metadata_respond(self->decoder.decoder, FLAC__METADATA_TYPE_VORBIS_COMMENT); 
    140208 
    141209 FLAC__stream_decoder_init(self->decoder.decoder); 
Note: See TracChangeset for help on using the changeset viewer.