Changeset 2308:44151407644f in roaraudio
- Timestamp:
- 08/05/09 15:09:27 (15 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/codecfilter_speex.c
r668 r2308 38 38 */ 39 39 40 #define _FS (_16BIT * (self->stereo ? 2 : 1)) 41 40 42 int cf_speex_open(CODECFILTER_USERDATA_T * inst, int codec, 41 43 struct roar_stream_server * info, … … 49 51 return -1; 50 52 53 s->info.codec = ROAR_CODEC_DEFAULT; 54 s->info.bits = 16; // speex hardcoded 55 56 switch (s->info.channels) { 57 case 1: self->stereo = 0; break; 58 case 2: self->stereo = 1; break; 59 default: 60 free(self); 61 return -1; 62 } 63 64 // do as much to preper the startup of stereo encoder as possible 65 if ( self->stereo ) { 66 self->stereo_callback.callback_id = SPEEX_INBAND_STEREO; 67 self->stereo_callback.func = speex_std_stereo_request_handler; 68 self->stereo_callback.data = &(self->stereo_state); 69 } 70 51 71 self->encoder = NULL; 52 72 self->decoder = NULL; … … 62 82 63 83 speex_bits_init(&(self->bits)); 64 65 s->info.codec = ROAR_CODEC_DEFAULT;66 s->info.bits = 16; // speex hardcoded67 s->info.channels = 1; // only mono support at the moment68 84 69 85 *inst = (void*) self; … … 106 122 uint16_t ui; 107 123 int tmp; 108 int still_todo = len / 2 /* 16 bit */;124 int still_todo = len / _FS; 109 125 int ret = 0; 110 int fs2; // = self->frame_size * 2;126 int fs2; // = self->frame_size * _16BIT * channels; 111 127 char magic[ROAR_SPEEX_MAGIC_LEN]; 128 SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT; 112 129 113 130 ROAR_DBG("cf_speex_read(inst=%p, buf=%p, len=%i) = ?", inst, buf, len); … … 140 157 speex_decoder_ctl(self->decoder, SPEEX_SET_ENH, &tmp); 141 158 159 if ( self->stereo ) { 160 memcpy(&(self->stereo_state), &stereo, sizeof(self->stereo_state)); 161 speex_decoder_ctl(self->decoder, SPEEX_SET_HANDLER, &(self->stereo_callback)); 162 } 163 164 142 165 speex_decoder_ctl(self->decoder, SPEEX_GET_FRAME_SIZE, &(self->frame_size)); 143 166 144 fs2 = self->frame_size * 2;167 fs2 = self->frame_size * _FS; 145 168 146 169 ROAR_DBG("cf_speex_read(*): frame_size=%i (%i bytes)", self->frame_size, fs2); … … 158 181 } 159 182 } 160 fs2 = self->frame_size * 2;183 fs2 = self->frame_size * _FS; 161 184 162 185 ROAR_DBG("cf_speex_read(*): Have a working decoder!"); … … 167 190 168 191 if ( self->fi_rest ) { 169 if ( self->fi_rest > (still_todo* 2) ) {192 if ( self->fi_rest > (still_todo*_FS) ) { 170 193 ROAR_DBG("cf_speex_read(*): using data from input rest buffer: len=%i (no need to read new data)", self->fi_rest); 171 still_todo *= 2; // we will set this to zero one way or another,172 // so we don't need to care about soring a 'warong' value here.194 still_todo *= _FS; // we will set this to zero one way or another, 195 // so we don't need to care about soring a 'wrong' value here. 173 196 memcpy(buf, self->i_rest, still_todo); 174 197 memmove(self->i_rest, self->i_rest + still_todo, self->fi_rest - still_todo); … … 180 203 memcpy(buf, self->i_rest, self->fi_rest); 181 204 buf += self->fi_rest; 182 still_todo -= self->fi_rest/ 2;205 still_todo -= self->fi_rest/_FS; 183 206 ret += self->fi_rest; 184 207 self->fi_rest = 0; … … 203 226 speex_decode_int(self->decoder, &(self->bits), self->cd); 204 227 228 if ( self->stereo) { 229 speex_decode_stereo_int(self->cd, self->frame_size, &(self->stereo_state)); 230 } 231 205 232 if ( self->frame_size > still_todo ) { 206 memcpy(buf, self->cd, still_todo* 2);207 ret += still_todo* 2;208 self->fi_rest = (self->frame_size - still_todo)* 2;209 ROAR_DBG("cf_speex_read(*): self->fi_rest=%i, off=%i", self->fi_rest, still_todo* 2);210 memcpy(self->i_rest, (self->cd)+(still_todo* 2), self->fi_rest);233 memcpy(buf, self->cd, still_todo*_FS); 234 ret += still_todo*_FS; 235 self->fi_rest = (self->frame_size - still_todo)*_FS; 236 ROAR_DBG("cf_speex_read(*): self->fi_rest=%i, off=%i", self->fi_rest, still_todo*_FS); 237 memcpy(self->i_rest, (self->cd)+(still_todo*_FS), self->fi_rest); 211 238 still_todo = 0; 212 239 } else { … … 219 246 220 247 if ( still_todo ) { 221 ROAR_DBG("cf_speex_read(*): could not read all reqquested data, returning %i byte less", still_todo* 2);248 ROAR_DBG("cf_speex_read(*): could not read all reqquested data, returning %i byte less", still_todo*_FS); 222 249 } 223 250
Note: See TracChangeset
for help on using the changeset viewer.