Ignore:
Timestamp:
Mar 24, 2006 8:41:20 PM (18 years ago)
Author:
bennylp
Message:

Added WAVE writer and resample port, and also found out why audio quality is poor with DirectSound?

File:
1 moved

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/file_player.c

    r357 r358  
    3131 
    3232 
    33 #ifndef PJMEDIA_FILE_PORT_BUFSIZE 
    34 #   define PJMEDIA_FILE_PORT_BUFSIZE    4000 
    35 #endif 
    36  
    37  
    38 #define SIGNATURE       ('F'<<24|'I'<<16|'L'<<8|'E') 
     33#define SIGNATURE           ('F'<<24|'P'<<16|'L'<<8|'Y') 
     34#define BYTES_PER_SAMPLE    2 
     35 
    3936 
    4037#if 1 
     
    4542 
    4643#if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 
    47     PJ_INLINE(pj_int16_t) swap16(pj_int16_t val) 
    48     { 
    49         pj_uint8_t *p = (pj_uint8_t*)&val; 
    50         pj_uint8_t tmp = *p; 
    51         *p = *(p+1); 
    52         *(p+1) = tmp; 
    53         return val; 
    54     } 
    55     PJ_INLINE(pj_int32_t) swap32(pj_int32_t val) 
    56     { 
    57         pj_uint8_t *p = (pj_uint8_t*)&val; 
    58         pj_uint8_t tmp = *p; 
    59         *p = *(p+3); 
    60         *(p+3) = tmp; 
    61         tmp = *(p+1); 
    62         *(p+1) = *(p+2); 
    63         *(p+2) = tmp; 
    64         return val; 
    65     } 
    66 #   define SWAP16(val16)        swap16(val16) 
    67 #   define SWAP32(val32)        swap32(val32) 
    6844    static void samples_to_host(pj_int16_t *samples, unsigned count) 
    6945    { 
    7046        unsigned i; 
    7147        for (i=0; i<count; ++i) { 
    72             samples[i] = SWAP16(samples[i]); 
     48            samples[i] = pj_swap16(samples[i]); 
    7349        } 
    7450    } 
    7551#else 
    76 #   define SWAP16(val16)        (val16) 
    77 #   define SWAP32(val32)        (val32) 
    7852#   define samples_to_host(samples,count) 
    7953#endif 
     
    171145 
    172146    /* Convert samples to host rep */ 
    173     samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/2); 
     147    samples_to_host((pj_int16_t*)fport->buf, fport->bufsize/BYTES_PER_SAMPLE); 
    174148 
    175149    return PJ_SUCCESS; 
    176150} 
    177  
    178  
    179 /* 
    180  * Change the endianness of WAVE header fields. 
    181  */ 
    182 void pjmedia_wave_hdr_swap_bytes( pjmedia_wave_hdr *hdr ) 
    183 { 
    184     hdr->riff_hdr.riff              = SWAP32(hdr->riff_hdr.riff); 
    185     hdr->riff_hdr.file_len          = SWAP32(hdr->riff_hdr.file_len); 
    186     hdr->riff_hdr.wave              = SWAP32(hdr->riff_hdr.wave); 
    187      
    188     hdr->fmt_hdr.fmt                = SWAP32(hdr->fmt_hdr.fmt); 
    189     hdr->fmt_hdr.len                = SWAP32(hdr->fmt_hdr.len); 
    190     hdr->fmt_hdr.fmt_tag            = SWAP16(hdr->fmt_hdr.fmt_tag); 
    191     hdr->fmt_hdr.nchan              = SWAP16(hdr->fmt_hdr.nchan); 
    192     hdr->fmt_hdr.sample_rate        = SWAP32(hdr->fmt_hdr.sample_rate); 
    193     hdr->fmt_hdr.bytes_per_sec      = SWAP32(hdr->fmt_hdr.bytes_per_sec); 
    194     hdr->fmt_hdr.block_align        = SWAP16(hdr->fmt_hdr.block_align); 
    195     hdr->fmt_hdr.bits_per_sample    = SWAP16(hdr->fmt_hdr.bits_per_sample); 
    196      
    197     hdr->data_hdr.data              = SWAP32(hdr->data_hdr.data); 
    198     hdr->data_hdr.len               = SWAP32(hdr->data_hdr.len); 
    199 } 
    200  
    201  
    202 #if defined(PJ_IS_BIG_ENDIAN) && PJ_IS_BIG_ENDIAN!=0 
    203 #   define normalize_wave_hdr(hdr)  pjmedia_wave_hdr_swap_bytes(hdr) 
    204 #else 
    205 #   define normalize_wave_hdr(hdr) 
    206 #endif 
    207151 
    208152 
     
    224168 
    225169    PJ_UNUSED_ARG(flags); 
    226     PJ_UNUSED_ARG(buff_size); 
    227170 
    228171    /* Check arguments. */ 
     
    266209    } 
    267210 
    268     /* Normalize WAVE header fields value (only used in big-endian hosts) */ 
    269     normalize_wave_hdr(&wave_hdr); 
     211    /* Normalize WAVE header fields values from little-endian to host 
     212     * byte order. 
     213     */ 
     214    pjmedia_wave_hdr_file_to_host(&wave_hdr); 
    270215     
    271216    /* Validate WAVE file. */ 
     
    292237 
    293238    /* Block align must be 2*nchannels */ 
    294     if (wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan*2) { 
     239    if (wave_hdr.fmt_hdr.block_align != wave_hdr.fmt_hdr.nchan*BYTES_PER_SAMPLE) { 
    295240        pj_file_close(fport->fd); 
    296241        return PJMEDIA_EWAVEUNSUPP; 
     
    327272    /* Create file buffer. 
    328273     */ 
    329     fport->bufsize = PJMEDIA_FILE_PORT_BUFSIZE; 
     274    if (buff_size < 1) buff_size = PJMEDIA_FILE_PORT_BUFSIZE; 
     275    fport->bufsize = buff_size; 
    330276 
    331277 
     
    355301 
    356302    PJ_LOG(4,(THIS_FILE,  
    357               "File port '%.*s' created: clock=%dKHz, bufsize=%uKB, " 
     303              "File player '%.*s' created: samp.rate=%d, ch=%d, bufsize=%uKB, " 
    358304              "filesize=%luKB", 
    359305              (int)fport->base.info.name.slen, 
    360306              fport->base.info.name.ptr, 
    361               fport->base.info.sample_rate/1000, 
     307              fport->base.info.sample_rate, 
     308              fport->base.info.channel_count, 
    362309              fport->bufsize / 1000, 
    363310              (unsigned long)(fport->fsize / 1000))); 
     
    390337    pj_assert(fport->base.info.signature == SIGNATURE); 
    391338 
    392     frame_size = fport->base.info.bytes_per_frame; 
    393     pj_assert(frame->size == frame_size); 
     339    //frame_size = fport->base.info.bytes_per_frame; 
     340    //pj_assert(frame->size == frame_size); 
     341    frame_size = frame->size; 
    394342 
    395343    /* Copy frame from buffer. */ 
Note: See TracChangeset for help on using the changeset viewer.