Changeset 2181:05f340c5ea82 in roaraudio for libroardsp


Ignore:
Timestamp:
07/26/09 18:50:58 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

wrote encoder/decoder functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroardsp/transcode_mualaw.c

    r2179 r2181  
    2525#include "libroardsp.h" 
    2626 
    27 int roar_xcoder_alaw_encode(struct roar_xcoder * state, void * buf, size_t len) { 
     27#define _CHECK() if ( state == NULL || state->info.pcm.bits != 16 || buf == NULL ) return -1 
     28 
     29#define _CHECK_BUF(len) \ 
     30                        void * iobuf; \ 
     31                        size_t outbyte = (len)/2; \ 
     32                        _CHECK();     \ 
     33                        if ( (len) & 0x01 ) return -1; \ 
     34                        if ( provide_buffer(&iobuf, outbyte) == -1 ) \ 
     35                         return -1; 
     36 
     37#define _SEND_RETURN()  if ( roar_vio_write(state->backend, iobuf, outbyte) != outbyte ) \ 
     38                         return -1; \ 
     39                        return 0; 
     40 
     41#define _READ()         if ( roar_vio_read(state->backend, iobuf, outbyte) != outbyte ) \ 
     42                         return -1; 
     43 
     44static int provide_buffer(void ** buf, size_t len) { 
     45 static struct roar_buffer * bufbuf = NULL; 
    2846 return -1; 
    2947} 
    3048 
     49int roar_xcoder_alaw_encode(struct roar_xcoder * state, void * buf, size_t len) { 
     50 _CHECK_BUF(len); 
     51 
     52 if ( roardsp_conv_pcm162alaw(iobuf, buf, outbyte) == -1 ) 
     53  return -1; 
     54 
     55 _SEND_RETURN(); 
     56} 
     57 
    3158int roar_xcoder_alaw_decode(struct roar_xcoder * state, void * buf, size_t len) { 
    32  return -1; 
     59 _CHECK_BUF(len); 
     60 
     61 _READ(); 
     62 
     63 if ( roardsp_conv_alaw2pcm16(buf, iobuf, outbyte) == -1 ) 
     64  return -1; 
     65 
     66 return 0; 
    3367} 
    3468 
    3569int roar_xcoder_mulaw_encode(struct roar_xcoder * state, void * buf, size_t len) { 
    36  return -1; 
     70 _CHECK_BUF(len); 
     71 
     72 if ( roardsp_conv_pcm162mulaw(iobuf, buf, outbyte) == -1 ) 
     73  return -1; 
     74 
     75 _SEND_RETURN(); 
    3776} 
    3877 
    3978int roar_xcoder_mulaw_decode(struct roar_xcoder * state, void * buf, size_t len) { 
    40  return -1; 
     79 _CHECK_BUF(len); 
     80 
     81 _READ(); 
     82 
     83 if ( roardsp_conv_mulaw2pcm16(buf, iobuf, outbyte) == -1 ) 
     84  return -1; 
     85 
     86 return 0; 
    4187} 
    4288 
Note: See TracChangeset for help on using the changeset viewer.