Changeset 1012:e0923fe24fa9 in roaraudio for roard/codecfilter_sndfile.c


Ignore:
Timestamp:
12/20/08 22:48:23 (15 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for writeing wave files, ha!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • roard/codecfilter_sndfile.c

    r928 r1012  
    3939 obj->stream = info; 
    4040 
     41 ROAR_STREAM(info)->info.codec = ROAR_CODEC_DEFAULT; 
     42 
    4143 *inst = (CODECFILTER_USERDATA_T) obj; 
    4244 
     
    4547 s->info.codec = ROAR_CODEC_DEFAULT; 
    4648*/ 
     49 
     50 ROAR_WARN("cf_sndfile_open(*) = 0"); 
    4751 
    4852 return 0; 
     
    8589   return -1; 
    8690  } 
     91  ROAR_WARN("cf_sndfile_read(*): obj->info={.format=0x%.8x, .samplerate=%i, .channels=%i}", obj->info.format, obj->info.samplerate, obj->info.channels); 
    8792 
    8893  s->info.codec    = ROAR_CODEC_DEFAULT; 
     
    106111 
    107112int cf_sndfile_write(CODECFILTER_USERDATA_T   inst, char * buf, int len) { 
    108  return -1; 
     113 struct codecfilter_sndfile_inst * obj = (struct codecfilter_sndfile_inst *) inst; 
     114 struct roar_stream * s = ROAR_STREAM(obj->stream); 
     115 int ret; 
     116 
     117 ROAR_WARN("cf_sndfile_write(*): obj->opened=%i", obj->opened); 
     118 
     119 if ( !obj->opened ) { 
     120  if ( s->fh == -1 ) { 
     121   errno = EAGAIN; 
     122   return -1; 
     123  } 
     124 
     125  switch (s->info.codec) { 
     126   case ROAR_CODEC_PCM_S_LE: 
     127   case ROAR_CODEC_PCM_S_BE: 
     128     switch (s->info.bits) { 
     129      case  8: 
     130        obj->info.format = SF_FORMAT_PCM_S8; 
     131       break; 
     132      case 16: 
     133        obj->info.format = SF_FORMAT_PCM_16; 
     134       break; 
     135      case 24: 
     136        obj->info.format = SF_FORMAT_PCM_24; 
     137       break; 
     138      case 32: 
     139        obj->info.format = SF_FORMAT_PCM_32; 
     140       break; 
     141     } 
     142     //obj->info.format |= s->info.codec == ROAR_CODEC_PCM_S_LE ? SF_ENDIAN_LITTLE : SF_ENDIAN_BIG; 
     143     obj->info.format |= SF_ENDIAN_FILE; 
     144     obj->info.format |= SF_FORMAT_WAV; 
     145    break; 
     146   default: 
     147     ROAR_ERR("cf_sndfile_write(*): codec(%s) not supported!", roar_codec2str(s->info.bits)); 
     148     return -1; 
     149    break; 
     150  } 
     151 
     152  obj->info.samplerate = s->info.rate; 
     153  obj->info.channels   = s->info.channels; 
     154  obj->info.sections   = 1; 
     155  obj->info.frames     = 182592; // 2147483647; 
     156  obj->info.seekable   = 1; 
     157  obj->info.format     = 0x00010002; 
     158 
     159  if ( (obj->state = sf_open_fd(s->fh, SFM_WRITE, &(obj->info), 0)) == NULL ) { 
     160   ROAR_ERR("cf_sndfile_write(*): can not sf_open_fd(*)!"); 
     161   ROAR_ERR("cf_sndfile_write(*): s->fh=%i", s->fh); 
     162   ROAR_ERR("cf_sndfile_write(*): obj->info={.format=0x%.8x, .samplerate=%i, .channels=%i}", obj->info.format, obj->info.samplerate, obj->info.channels); 
     163   return -1; 
     164  } 
     165 
     166  obj->opened = 1; 
     167//  errno = EAGAIN; 
     168 } 
     169 
     170 ROAR_WARN("cf_sndfile_write(*): obj->opened=%i", obj->opened); 
     171 ret = sf_write_raw(obj->state, (void*) buf, len); 
     172 ROAR_WARN("cf_sndfile_write(inst=%p, buf=%p, len=%i) = %i", inst, buf, len, ret); 
     173 return ret; 
    109174} 
    110175 
Note: See TracChangeset for help on using the changeset viewer.