Changeset 3178:0882f7dc9b71 in roaraudio


Ignore:
Timestamp:
01/15/10 22:38:58 (12 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

added support for SNDCTL_DSP_GETOPTR and SNDCTL_DSP_GETIPTR!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libroaross/libroaross.c

    r3177 r3178  
    109109 int                   stream_dir; 
    110110 int                   stream_opened; 
     111 size_t                stream_buffersize; 
     112 size_t                readc, writec; 
    111113}; 
    112114 
     
    688690 
    689691// ------------------------------------- 
     692// buffer size calculation: 
     693// ------------------------------------- 
     694 
     695static size_t _get_stream_buffersize (struct handle * handle) { 
     696 if ( handle->stream_buffersize ) 
     697  return handle->stream_buffersize; 
     698 
     699 return handle->stream_buffersize = handle->stream.info.rate     * 
     700                                    handle->stream.info.channels * 
     701                                    handle->stream.info.bits     / 800; 
     702} 
     703 
     704// ------------------------------------- 
    690705// emulated functions follow: 
    691706// ------------------------------------- 
     
    734749ssize_t write(int fd, const void *buf, size_t count) { 
    735750 struct pointer * pointer; 
     751 ssize_t ret; 
    736752 
    737753 _init(); 
     
    745761    } 
    746762   } 
    747    return roar_vio_write(&(pointer->handle->stream_vio), (char*)buf, count); 
     763   ret = roar_vio_write(&(pointer->handle->stream_vio), (char*)buf, count); 
     764   if ( ret > 0 ) 
     765    pointer->handle->writec += ret; 
     766   return ret; 
    748767  } else { 
    749768   errno = EINVAL; 
     
    757776ssize_t read(int fd, void *buf, size_t count) { 
    758777 struct pointer * pointer; 
     778 ssize_t ret; 
    759779 
    760780 _init(); 
     
    768788    } 
    769789   } 
    770    return roar_vio_read(&(pointer->handle->stream_vio), buf, count); 
     790   ret = roar_vio_read(&(pointer->handle->stream_vio), buf, count); 
     791   if ( ret > 0 ) 
     792    pointer->handle->writec += ret; 
     793   return ret; 
    771794  } else { 
    772795   errno = EINVAL; 
     
    784807 int * ip = NULL; 
    785808 audio_buf_info * bi; 
     809 count_info     * ci; 
    786810#ifdef va_argp 
    787811 va_list args; 
     
    824848       break; 
    825849      case SNDCTL_DSP_GETBLKSIZE: 
    826          *ip = handle->stream.info.rate * handle->stream.info.channels * handle->stream.info.bits / 800; 
     850        *ip = _get_stream_buffersize(handle); 
    827851        return 0; 
    828852       break; 
     
    839863        bi = argp; 
    840864        memset(bi, 0, sizeof(*bi)); 
    841         bi->bytes      = handle->stream.info.rate * handle->stream.info.channels * handle->stream.info.bits / 800; 
     865        bi->bytes      = _get_stream_buffersize(handle); 
    842866        bi->fragments  = 1; 
    843867        bi->fragsize   = bi->bytes; 
    844868        bi->fragstotal = 1; 
     869        return 0; 
     870       break; 
     871      case SNDCTL_DSP_GETOPTR: 
     872        ci = argp; 
     873        memset(ci, 0, sizeof(*ci)); 
     874        ci->bytes  = handle->writec; 
     875        ci->blocks = ci->bytes / _get_stream_buffersize(handle); 
     876        ci->ptr    = 0; 
     877        return 0; 
     878       break; 
     879      case SNDCTL_DSP_GETIPTR: 
     880        ci = argp; 
     881        memset(ci, 0, sizeof(*ci)); 
     882        ci->bytes  = handle->readc; 
     883        ci->blocks = ci->bytes / _get_stream_buffersize(handle); 
     884        ci->ptr    = 0; 
    845885        return 0; 
    846886       break; 
Note: See TracChangeset for help on using the changeset viewer.