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 edited

Legend:

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

    r352 r358  
    2929#include <pj/string.h> 
    3030 
     31/* CONF_DEBUG enables detailed operation of the conference bridge. 
     32 * Beware that it prints large amounts of logs (several lines per frame). 
     33 */ 
    3134//#define CONF_DEBUG 
    3235#ifdef CONF_DEBUG 
    3336#   include <stdio.h> 
    34 #   define TRACE_(x)   {printf x; fflush(stdout); } 
     37#   define TRACE_(x)   PJ_LOG(5,x) 
    3538#else 
    3639#   define TRACE_(x) 
     40#endif 
     41 
     42 
     43/* REC_FILE macro enables recording of the samples written to the sound 
     44 * device. The file contains RAW PCM data with no header, and has the 
     45 * same settings (clock rate etc) as the conference bridge. 
     46 * This should only be enabled when debugging audio quality *only*. 
     47 */ 
     48//#define REC_FILE    "confrec.pcm" 
     49#ifdef REC_FILE 
     50static FILE *fhnd_rec; 
    3751#endif 
    3852 
     
    967981    pj_assert(count == conf->samples_per_frame); 
    968982 
     983    TRACE_((THIS_FILE, "read_port %.*s: count=%d",  
     984                       (int)cport->name.slen, cport->name.ptr, 
     985                       count)); 
     986 
    969987    /* If port's samples per frame and sampling rate matches conference 
    970988     * bridge's settings, get the frame directly from the port. 
     
    976994        f.buf = frame; 
    977995        f.size = count * BYTES_PER_SAMPLE; 
     996 
     997        TRACE_((THIS_FILE, "  get_frame %.*s: count=%d",  
     998                   (int)cport->name.slen, cport->name.ptr, 
     999                   count)); 
    9781000 
    9791001        status = (cport->port->get_frame)(cport->port, &f); 
     
    9981020            f.size = cport->samples_per_frame * BYTES_PER_SAMPLE; 
    9991021 
     1022            TRACE_((THIS_FILE, "  get_frame, count=%d",  
     1023                       cport->samples_per_frame)); 
     1024 
    10001025            status = pjmedia_port_get_frame(cport->port, &f); 
    10011026 
     
    10061031 
    10071032            if (f.type != PJMEDIA_FRAME_TYPE_AUDIO) { 
     1033                TRACE_((THIS_FILE, "  get_frame returned non-audio")); 
    10081034                zero_samples( cport->rx_buf + cport->rx_buf_count, 
    10091035                              cport->samples_per_frame); 
     
    10111037 
    10121038            cport->rx_buf_count += cport->samples_per_frame; 
     1039 
     1040            TRACE_((THIS_FILE, "  rx buffer size is now %d", 
     1041                    cport->rx_buf_count)); 
    10131042 
    10141043            pj_assert(cport->rx_buf_count <= cport->rx_buf_cap); 
     
    10231052            unsigned src_count; 
    10241053 
     1054            TRACE_((THIS_FILE, "  resample, input count=%d",  
     1055                    pjmedia_resample_get_input_size(cport->rx_resample))); 
     1056 
    10251057            pjmedia_resample_run( cport->rx_resample,cport->rx_buf, frame); 
    10261058 
     
    10331065            } 
    10341066 
     1067            TRACE_((THIS_FILE, "  rx buffer size is now %d", 
     1068                    cport->rx_buf_count)); 
     1069 
    10351070        } else { 
    10361071 
     
    10681103        frame.size = 0; 
    10691104 
    1070         if (cport->port && cport->port->put_frame) 
     1105        if (cport->port && cport->port->put_frame) { 
    10711106            pjmedia_port_put_frame(cport->port, &frame); 
     1107        } 
    10721108 
    10731109        cport->tx_level = 0; 
     
    11121148        } 
    11131149 
    1114     } else { 
     1150    } else if (cport->sources) { 
    11151151        /* No need to adjust signal level. */ 
    11161152        for (j=0; j<conf->samples_per_frame; ++j) { 
    11171153            buf[j] = unsigned2pcm(cport->mix_buf[j] / cport->sources); 
    11181154        } 
     1155    } else { 
     1156        // Not necessarry. Buffer has been zeroed before. 
     1157        // zero_samples(buf, conf->samples_per_frame); 
     1158        pj_assert(buf[0] == 0); 
    11191159    } 
    11201160 
     
    11551195            frame.timestamp.u64 = timestamp; 
    11561196 
     1197            TRACE_((THIS_FILE, "put_frame %.*s, count=%d",  
     1198                               (int)cport->name.slen, cport->name.ptr, 
     1199                               frame.size / BYTES_PER_SAMPLE)); 
     1200 
    11571201            return pjmedia_port_put_frame(cport->port, &frame); 
    11581202        } else 
     
    11861230        pj_status_t status; 
    11871231 
     1232        TRACE_((THIS_FILE, "write_port %.*s: count=%d",  
     1233                           (int)cport->name.slen, cport->name.ptr, 
     1234                           cport->samples_per_frame)); 
     1235 
    11881236        if (cport->port) { 
    11891237            pjmedia_frame frame; 
     
    11931241            frame.size = cport->samples_per_frame * BYTES_PER_SAMPLE; 
    11941242            frame.timestamp.u64 = timestamp; 
     1243 
     1244            TRACE_((THIS_FILE, "put_frame %.*s, count=%d",  
     1245                               (int)cport->name.slen, cport->name.ptr, 
     1246                               frame.size / BYTES_PER_SAMPLE)); 
    11951247 
    11961248            status = pjmedia_port_put_frame(cport->port, &frame); 
     
    12061258        } 
    12071259 
     1260        TRACE_((THIS_FILE, " tx_buf count now is %d",  
     1261                           cport->tx_buf_count)); 
     1262 
    12081263        return status; 
    12091264    } 
     
    12221277    unsigned ci, cj, i, j; 
    12231278     
     1279    TRACE_((THIS_FILE, "- clock -")); 
     1280 
    12241281    /* Check that correct size is specified. */ 
    12251282    pj_assert(frame->size == conf->samples_per_frame * 
     
    12281285    /* Must lock mutex (must we??) */ 
    12291286    pj_mutex_lock(conf->mutex); 
    1230  
    1231     TRACE_(("p")); 
    12321287 
    12331288    /* Zero all port's temporary buffers. */ 
     
    12451300        mix_buf = conf_port->mix_buf; 
    12461301 
    1247         for (j=0; j<conf->samples_per_frame; ++j) 
    1248             mix_buf[j] = 0; 
     1302        for (j=0; j<conf->samples_per_frame; ++j) mix_buf[j] = 0; 
    12491303    } 
    12501304 
     
    14221476    /* Return sound playback frame. */ 
    14231477    if (conf->ports[0]->sources) { 
     1478        TRACE_((THIS_FILE, "write to audio, count=%d",  
     1479                           conf->samples_per_frame)); 
     1480 
    14241481        copy_samples( frame->buf, (pj_int16_t*)conf->ports[0]->mix_buf,  
    14251482                      conf->samples_per_frame); 
     
    14321489 
    14331490    pj_mutex_unlock(conf->mutex); 
     1491 
     1492#ifdef REC_FILE 
     1493    if (fhnd_rec == NULL) 
     1494        fhnd_rec = fopen(REC_FILE, "wb"); 
     1495    if (fhnd_rec) 
     1496        fwrite(frame->buf, frame->size, 1, fhnd_rec); 
     1497#endif 
    14341498 
    14351499    return PJ_SUCCESS; 
     
    14481512    pj_int16_t *target_snd_buf; 
    14491513    unsigned i; 
    1450  
    1451     TRACE_(("r")); 
    14521514 
    14531515    /* Check for correct size. */ 
Note: See TracChangeset for help on using the changeset viewer.