Changeset 2174:19a693a12053 in roaraudio


Ignore:
Timestamp:
07/26/09 17:02:01 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

started with the basic codec, need to do a lot more ;)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroardsp/transcode.c

    r2169 r2174  
    2525#include "libroardsp.h" 
    2626 
     27#define _FUNC(func) (state->entry->func) 
     28#define _CHECK_STATE() (!(state == NULL || state->entry == NULL)) 
     29#define _CHECK_FUNC(func) (_CHECK_STATE() && _FUNC(func) != NULL) 
     30#define _CHECK_BASIC(func) if ( !_CHECK_FUNC(func) ) return -1 
     31#define _CHECK() if ( !_CHECK_STATE() ) return -1 
     32 
     33static struct roar_xcoder_entry g_xcoders[] = { 
     34 {ROAR_CODEC_ALAW,  roar_xcoder_dummy_inituninit, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_packet_size_any, 
     35                     NULL, NULL},  
     36 {ROAR_CODEC_MULAW, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_inituninit, roar_xcoder_dummy_packet_size_any, 
     37                     NULL, NULL},  
     38 {-1, NULL, NULL, NULL, NULL, NULL} 
     39}; 
     40 
     41int roar_xcoder_init(struct roar_xcoder * state, int encoder, struct roar_audio_info * info, struct roar_vio_calls * vio); 
     42int roar_xcoder_set_backend(struct roar_xcoder * state, struct roar_vio_calls * vio) { 
     43 _CHECK(); 
     44 
     45 if ( vio == NULL && state->backend != NULL ) 
     46  return -1; 
     47 
     48 state->backend = vio; 
     49 
     50 return 0; 
     51} 
     52int roar_xcoder_packet_size(struct roar_xcoder * state, int samples) { 
     53 _CHECK_BASIC(packet_size); 
     54 
     55 state->packet_len = state->entry->packet_size(state, samples); 
     56 
     57 if ( state->packet_len == 0 ) { 
     58  if ( samples < 1 ) { 
     59   return ROAR_RATE_DEFAULT/100; 
     60  } else { 
     61   return samples; 
     62  } 
     63 } 
     64 
     65 return state->packet_len; 
     66} 
     67 
     68int roar_xcoder_close      (struct roar_xcoder * state) { 
     69 _CHECK_BASIC(uninit); 
     70 
     71 
     72 if ( state->iobuffer != NULL ) { 
     73  roar_xcoder_proc(state, NULL, 0); // try to flush 
     74  roar_buffer_free(state->iobuffer); 
     75 } 
     76 
     77 return _FUNC(uninit)(state); 
     78} 
     79 
     80int roar_xcoder_proc_packet(struct roar_xcoder * state, void * buf, size_t len); 
     81int roar_xcoder_proc       (struct roar_xcoder * state, void * buf, size_t len) { 
     82 return -1; 
     83} 
     84 
     85int roar_bixcoder_init(struct roar_bixcoder * state, struct roar_audio_info * info, struct roar_vio_calls * vio); 
     86int roar_bixcoder_packet_size (struct roar_bixcoder * state, int samples); 
     87int roar_bixcoder_close       (struct roar_bixcoder * state); 
     88int roar_bixcoder_read_packet (struct roar_bixcoder * state, void * buf, size_t len); 
     89int roar_bixcoder_read        (struct roar_bixcoder * state, void * buf, size_t len); 
     90int roar_bixcoder_write_packet(struct roar_bixcoder * state, void * buf, size_t len); 
     91int roar_bixcoder_write       (struct roar_bixcoder * state, void * buf, size_t len); 
     92 
     93// dummy functions used by some de/encoders: 
     94int roar_xcoder_dummy_inituninit(struct roar_xcoder * state) { 
     95 return 0; 
     96} 
     97 
     98int roar_xcoder_dummy_packet_size_any(struct roar_xcoder * state, int samples) { 
     99 // the case samples=-1/samples!=-1 based things are done in the general func 
     100 return 0; 
     101} 
    27102 
    28103//ll 
Note: See TracChangeset for help on using the changeset viewer.