Changeset 614:ba67ef04df1e in roaraudio


Ignore:
Timestamp:
08/20/08 01:15:45 (16 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

got cf speex working for reading, freqs are correct now, cleaned up debug code, introused magic and done some small changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/codecfilter_speex.c

    r609 r614  
    2929 s->info.codec    = ROAR_CODEC_DEFAULT; 
    3030 s->info.bits     = 16; // speex hardcoded 
    31  s->info.channels = 1; // only mono support at the moment 
     31 s->info.channels =  1; // only mono support at the moment 
    3232 
    3333 *inst = (void*) self; 
     
    7272 int still_todo = len / 2 /* 16 bit */; 
    7373 int ret = 0; 
    74  
    75  ROAR_WARN("cf_speex_read(inst=%p, buf=%p, len=%i) = ?", inst, buf, len); 
     74 int fs2; // = self->frame_size * 2; 
     75 char magic[ROAR_SPEEX_MAGIC_LEN]; 
     76 
     77 ROAR_DBG("cf_speex_read(inst=%p, buf=%p, len=%i) = ?", inst, buf, len); 
    7678 
    7779 if ( ! self->decoder ) { 
    7880  ROAR_DBG("cf_speex_read(*): no decoder, starting one!"); 
     81 
     82  if ( stream_vio_s_read(self->stream, magic, ROAR_SPEEX_MAGIC_LEN) != ROAR_SPEEX_MAGIC_LEN ) 
     83   return 0; 
     84 
     85  if ( memcmp(magic, ROAR_SPEEX_MAGIC, ROAR_SPEEX_MAGIC_LEN) != 0 ) 
     86   return -1; 
     87 
    7988  if ( stream_vio_s_read(self->stream, &ui, 2) != 2 ) 
    8089   return 0; 
     
    97106  speex_decoder_ctl(self->decoder, SPEEX_GET_FRAME_SIZE, &(self->frame_size)); 
    98107 
    99  
    100  
    101   ROAR_WARN("cf_speex_read(*): frame_size=%i (%i bytes)", self->frame_size, self->frame_size*2); 
     108  fs2 = self->frame_size * 2; 
     109 
     110  ROAR_DBG("cf_speex_read(*): frame_size=%i (%i bytes)", self->frame_size, fs2); 
    102111 
    103112  if ( !self->cd ) { 
    104    self->cd = malloc((self->frame_size)*2); 
     113   self->cd = malloc(fs2); 
    105114   if ( !self->cd ) 
    106115    return 0; 
     
    108117 
    109118  if ( !self->i_rest ) { 
    110    self->i_rest = malloc((self->frame_size)*2); 
     119   self->i_rest = malloc(fs2); 
    111120   if ( !self->i_rest ) 
    112121    return 0; 
    113122  } 
    114123 } 
     124 fs2 = self->frame_size * 2; 
    115125 
    116126 ROAR_DBG("cf_speex_read(*): Have a working decoder!"); 
    117127 
    118  ROAR_DBG("cf_speex_read(*): frame_size=%i (%i bytes)", self->frame_size, self->frame_size*2); 
     128 ROAR_DBG("cf_speex_read(*): frame_size=%i (%i bytes)", self->frame_size, fs2); 
    119129 ROAR_DBG("cf_speex_read(*): i_rest is %i bytes after cd", ((void*)self->i_rest - (void*)self->cd)); 
    120130 
     
    122132 if ( self->fi_rest ) { 
    123133  if ( self->fi_rest > (still_todo*2) ) { 
    124    ROAR_WARN("cf_speex_read(*): discarding input rest data: buffer too long!"); 
    125    self->fi_rest = 0; 
     134   ROAR_DBG("cf_speex_read(*): using data from input rest buffer: len=%i (no need to read new data)", self->fi_rest); 
     135   still_todo *= 2; // we will set this to zero one way or another, 
     136                    // so we don't need to care about soring a 'warong' value here. 
     137   memcpy(buf, self->i_rest, still_todo); 
     138   memmove(self->i_rest, self->i_rest + still_todo, self->fi_rest - still_todo); 
     139   self->fi_rest -= still_todo; 
     140   ret += still_todo; 
     141   still_todo = 0; 
    126142  } else { 
    127    ROAR_WARN("cf_speex_read(*): using data from input rest buffer: len=%i", self->fi_rest); 
     143   ROAR_DBG("cf_speex_read(*): using data from input rest buffer: len=%i", self->fi_rest); 
    128144   memcpy(buf, self->i_rest, self->fi_rest); 
    129145   buf += self->fi_rest; 
     
    135151 
    136152 while (still_todo) { 
    137   ROAR_WARN("cf_speex_read(*): we sill need %i frames", still_todo); 
     153  ROAR_DBG("cf_speex_read(*): we sill need %i frames", still_todo); 
    138154  if ( stream_vio_s_read(self->stream, &ui, 2) != 2 ) 
    139155   return -1; 
     
    155171   ret += still_todo*2; 
    156172   self->fi_rest = (self->frame_size - still_todo)*2; 
    157    ROAR_WARN("cf_speex_read(*): self->fi_rest=%i, off=%i", self->fi_rest, still_todo*2); 
     173   ROAR_DBG("cf_speex_read(*): self->fi_rest=%i, off=%i", self->fi_rest, still_todo*2); 
    158174   memcpy(self->i_rest, (self->cd)+(still_todo*2), self->fi_rest); 
    159175   still_todo = 0; 
    160176  } else { 
    161    memcpy(buf, self->cd, self->frame_size*2); 
    162    buf        += self->frame_size*2; 
    163    ret        += self->frame_size*2; 
     177   memcpy(buf, self->cd, fs2); 
     178   buf        += fs2; 
     179   ret        += fs2; 
    164180   still_todo -= self->frame_size; 
    165181  } 
     
    167183 
    168184 if ( still_todo ) { 
    169   ROAR_WARN("cf_speex_read(*): could not read all reqquested data, returning %i byte less", still_todo*2); 
    170  } 
    171  
    172  ROAR_WARN("cf_speex_read(*) = %i", ret); 
     185  ROAR_DBG("cf_speex_read(*): could not read all reqquested data, returning %i byte less", still_todo*2); 
     186 } 
     187 
     188 ROAR_DBG("cf_speex_read(*) = %i", ret); 
    173189 
    174190 return ret; 
Note: See TracChangeset for help on using the changeset viewer.