Author: sayer
Date: 2008-08-25 22:55:09 +0200 (Mon, 25 Aug 2008)
New Revision: 1077

Modified:
   branches/wb/core/AmAudio.cpp
   branches/wb/core/AmAudio.h
   branches/wb/core/AmConferenceChannel.cpp
   branches/wb/core/AmConferenceChannel.h
   branches/wb/core/AmMediaProcessor.cpp
   branches/wb/core/AmPlaylist.cpp
   branches/wb/core/AmPlaylist.h
   branches/wb/core/AmPlayoutBuffer.cpp
   branches/wb/core/AmPlayoutBuffer.h
   branches/wb/core/AmPrecodedFile.cpp
   branches/wb/core/AmRtpAudio.cpp
   branches/wb/core/AmRtpAudio.h
   branches/wb/core/AmRtpStream.cpp
   branches/wb/core/amci/amci.h
   branches/wb/core/plug-in/adpcm/adpcm.c
   branches/wb/core/plug-in/g722/g722.c
   branches/wb/core/plug-in/gsm/gsm.c
   branches/wb/core/plug-in/ilbc/ilbc.c
   branches/wb/core/plug-in/speex/speex.c
   branches/wb/core/plug-in/wav/wav.c
Log:
wideband, take 2: correctly resample at the proper places.
 - AmAudio::get() takes time in millisec instead of # samples
 - AMCI_FMT_FRAME_LENGTH used (frame in millisec) 
 - note: on RTP->input, resampling is done before playout buffer 
  (i.e. playout buffer has SYSTEM_SAMPLERATE)
 - AMCI_ENCODED_FRAME_SIZE removed (unused anyway)



Modified: branches/wb/core/AmAudio.cpp
===================================================================
--- branches/wb/core/AmAudio.cpp        2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmAudio.cpp        2008-08-25 20:55:09 UTC (rev 1077)
@@ -45,7 +45,6 @@
   amci_codec_t *codec;
   int frame_size;
   int frame_length;
-  int frame_encoded_size;
   long h_codec;
 };
 
@@ -97,7 +96,6 @@
        cc->codec = codec;
        cc->frame_size = frame_size;
        cc->frame_length = frame_length;
-       cc->frame_encoded_size = frame_encoded_size;
        cc->h_codec = h_codec;
        m_codecContainerByPayload[payload] = cc;
       }
@@ -107,7 +105,6 @@
       codec = c->second->codec;
       frame_size = c->second->frame_size;
       frame_length = c->second->frame_length;
-      frame_encoded_size = c->second->frame_encoded_size;
       h_codec = c->second->h_codec;
     }
     if (m_currentPayloadP && codec) {
@@ -130,7 +127,7 @@
 
 AmAudioFormat::AmAudioFormat()
   : channels(-1), rate(-1), codec(NULL),
-    frame_length(20), frame_size(20*SYSTEM_SAMPLERATE/1000), 
frame_encoded_size(320)
+    frame_length(20), frame_size(20*SYSTEM_SAMPLERATE/1000)
 {
 
 }
@@ -152,11 +149,10 @@
 unsigned int AmAudioFormat::calcBytesToRead(unsigned int needed_samples) const
 {
   if (codec && codec->samples2bytes)
-    return codec->samples2bytes(h_codec, needed_samples) * 
-      rate * channels / SYSTEM_SAMPLERATE; // FIXME: channels, system_channels
+    return codec->samples2bytes(h_codec, needed_samples) * channels; // FIXME: 
channels, system_channels
 
   WARN("Cannot convert samples to bytes\n");
-  return needed_samples * channels * rate / SYSTEM_SAMPLERATE;
+  return needed_samples * channels;
 }
 
 unsigned int AmAudioFormat::bytes2samples(unsigned int bytes) const
@@ -201,9 +197,6 @@
        case AMCI_FMT_FRAME_SIZE: {
          frame_size=fmt_i[i].value; 
        } break;
-       case AMCI_FMT_ENCODED_FRAME_SIZE: {
-         frame_encoded_size=fmt_i[i].value; 
-       } break;
        default: {
          DBG("Unknown codec format descriptor: %d\n", fmt_i[i].id);
        } break;
@@ -230,7 +223,6 @@
 
 amci_codec_t* AmAudioFormat::getCodec()
 {
-
   if(!codec){
     int codec_id = getCodecId();
     codec = AmPlugIn::instance()->codec(codec_id);
@@ -252,7 +244,6 @@
   : fmt(new AmAudioSimpleFormat(CODEC_PCM16)),
     max_rec_time(-1),
     rec_time(0)
-
 {
   initSrc();
 }
@@ -294,7 +285,8 @@
 #endif
 }
 
-void AmAudio::setFormat(AmAudioFormat* new_fmt) {
+void AmAudio::setFormat(AmAudioFormat* new_fmt) 
+{
   fmt.reset(new_fmt);
   fmt->resetCodec();
 }
@@ -304,21 +296,23 @@
 }
 
 // returns bytes read, else -1 if error (0 is OK)
-int AmAudio::get(unsigned int user_ts, unsigned char* buffer, unsigned int 
nb_samples)
+int AmAudio::get(unsigned int user_ts, unsigned char* buffer, unsigned int 
time_millisec)
 {
+  unsigned int nb_samples = time_millisec * fmt->rate / 1000;
+  
   int size = calcBytesToRead(nb_samples);
-
   size = read(user_ts,size);
 
-  if(size <= 0) {
+  if (size <= 0)
     return size;
-  }
 
   size = decode(size);
-  if(size < 0) {
+
+  if (size < 0) {
     DBG("decode returned %i\n",size);
     return -1; 
   }
+
   /* into internal format */
   size = downMix(size);
     
@@ -335,7 +329,7 @@
     return 0;
   }
 
-  if(max_rec_time > -1 && rec_time >= max_rec_time)
+  if((max_rec_time > -1) && (rec_time >= max_rec_time))
     return -1;
 
 
@@ -343,8 +337,10 @@
 
   /* from internal format */
   size = upMix(size);
+
   unsigned long wr_ts = user_ts;
-  // unsigned int wr_ts =( (long)user_ts * (long)fmt->rate / 
(long)SYSTEM_SAMPLERATE);
+
+  // wr_ts =( (long)user_ts * (long)fmt->rate / (long)SYSTEM_SAMPLERATE);
   if (fmt->rate != SYSTEM_SAMPLERATE) {
     if (fmt->rate > SYSTEM_SAMPLERATE) {
       unsigned int f = fmt->rate / SYSTEM_SAMPLERATE;
@@ -354,15 +350,12 @@
       wr_ts = wr_ts / f; 
     }
   }
-  //  DBG("wr_ts = %ld\n", wr_ts);
 
   int s = encode(size);
-  if(s>0){
-    //DBG("%s\n",typeid(this).name());
+  if (s>0) {
     incRecordTime(bytes2samples(size));
     return write(wr_ts,(unsigned int)s);
-  }
-  else{
+  } else {
     return s;
   }
 }
@@ -373,7 +366,7 @@
   short* end = (short*)(in_buf + size);
   short* out = (short*)out_buf;
     
-  while(in != end){
+  while (in != end) {
     *(out++) = (*in + *(in+1)) / 2;
     in += 2;
   }
@@ -399,10 +392,10 @@
   //   return -1;
   //     }
 
-  if(codec->decode){
+  if (codec->decode) {
     s = (*codec->decode)(samples.back_buffer(),samples,s,
                         fmt->channels,fmt->rate,h_codec);
-    if(s<0) return s;
+    if (s<0) return s;
     samples.swap();
   }
     
@@ -422,7 +415,7 @@
   amci_codec_t* codec = fmt->getCodec();
   long h_codec = fmt->getHCodec();
 
-  if(codec->encode){
+  if (codec->encode) {
     s = (*codec->encode)(samples.back_buffer(),samples,(unsigned int) size,
                         fmt->channels,fmt->rate,h_codec);
     if(s<0) return s;
@@ -435,14 +428,14 @@
 unsigned int AmAudio::downMix(unsigned int size)
 {
   unsigned int s = size;
-  if(fmt->channels == 2){
+
+  if (fmt->channels == 2) {
     stereo2mono(samples.back_buffer(),(unsigned char*)samples,s);
     samples.swap();
   }
 
 #ifdef USE_LIBSAMPLERATE 
   if (fmt->rate != SYSTEM_SAMPLERATE) {
-//     DBG("downmix %d->%d\n", SYSTEM_SAMPLERATE, fmt->rate);
     s = resample(src_state_in, (double)SYSTEM_SAMPLERATE / (double)fmt->rate, 
size);
   }
 #endif
@@ -453,14 +446,10 @@
 unsigned int AmAudio::upMix(unsigned int size)
 {
   unsigned int s = size;
-//   if(fmt->channels == 2){
-//     stereo2mono(samples.back_buffer(),(unsigned char*)samples,s);
-//     samples.swap();
-//   }
+  // todo: system_channels, convert from/to stereo ? 
 
 #ifdef USE_LIBSAMPLERATE 
   if (fmt->rate != SYSTEM_SAMPLERATE) {
-//     DBG("upmix %d->%d\n", fmt->rate,SYSTEM_SAMPLERATE);
     s = resample(src_state_out, (double)fmt->rate / (double)SYSTEM_SAMPLERATE, 
size);
   }
 #endif
@@ -470,7 +459,8 @@
 
 #ifdef USE_LIBSAMPLERATE 
 
-unsigned int AmAudio::resample(src_state* m_src_state, double factor, unsigned 
int size) {
+unsigned int AmAudio::resample(src_state* m_src_state, double factor, unsigned 
int size) 
+{
   if (!m_src_state)
     return size;
 
@@ -526,13 +516,20 @@
 
 unsigned int AmAudio::getFrameSize()
 {
-
   if (!fmt.get())
     fmt.reset(new AmAudioSimpleFormat(CODEC_PCM16));
 
   return fmt->frame_size;
 }
 
+unsigned int AmAudio::getFrameLength()
+{
+  if (!fmt.get())
+    fmt.reset(new AmAudioSimpleFormat(CODEC_PCM16));
+
+  return fmt->frame_length;
+}
+
 unsigned int AmAudio::calcBytesToRead(unsigned int nb_samples) const
 {
   return fmt->calcBytesToRead(nb_samples);

Modified: branches/wb/core/AmAudio.h
===================================================================
--- branches/wb/core/AmAudio.h  2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmAudio.h  2008-08-25 20:55:09 UTC (rev 1077)
@@ -111,12 +111,10 @@
   int channels;
   /** Sampling rate. */
   int rate;
-  /* frame length in ms (frame based codecs) - unused */
+  /* frame length in ms (frame based codecs)  */
   int frame_length;
   /* frame size in samples */
   int frame_size;
-  /* encoded frame size in bytes - unused */
-  int frame_encoded_size;
 
   string sdp_format_parameters;
     
@@ -300,13 +298,13 @@
   virtual void close();
 
   /** 
-   * Get some samples from input stream.
+   * Get some audio from input stream.
    * @warning For packet based payloads / file formats, use:
    * <pre>           nb_sample = input buffer size / sample size of the 
reference format
    * </pre>           whereby the format with/from which the codec works is 
the reference one.
    * @return # bytes read, else -1 if error (0 is OK) 
    */
-  virtual int get(unsigned int user_ts, unsigned char* buffer, unsigned int 
nb_samples);
+  virtual int get(unsigned int user_ts, unsigned char* buffer, unsigned int 
time_millisec);
 
   /** 
    * Put some samples to the output stream.
@@ -317,8 +315,12 @@
    */
   virtual int put(unsigned int user_ts, unsigned char* buffer, unsigned int 
size);
   
+  /** get frame length in samples */
   unsigned int getFrameSize();
 
+  /** get frame length in ms */
+  unsigned int getFrameLength();
+  
   void setRecordTime(unsigned int ms);
   int  incRecordTime(unsigned int samples);
 

Modified: branches/wb/core/AmConferenceChannel.cpp
===================================================================
--- branches/wb/core/AmConferenceChannel.cpp    2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/AmConferenceChannel.cpp    2008-08-25 20:55:09 UTC (rev 
1077)
@@ -20,9 +20,10 @@
   return size;
 }
 
-int AmConferenceChannel::get(unsigned int user_ts, unsigned char* buffer, 
unsigned int nb_samples)
+int AmConferenceChannel::get(unsigned int user_ts, unsigned char* buffer, 
unsigned int time_millisec)
 {
-  unsigned int size = PCM16_S2B(nb_samples);
+  int size = PCM16_S2B(time_millisec * fmt->rate / 1000);
   status->getMixer()->GetChannelPacket(channel_id,user_ts,buffer,size);
+
   return size;
 }

Modified: branches/wb/core/AmConferenceChannel.h
===================================================================
--- branches/wb/core/AmConferenceChannel.h      2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/AmConferenceChannel.h      2008-08-25 20:55:09 UTC (rev 
1077)
@@ -51,7 +51,7 @@
   int write(unsigned int user_ts, unsigned int size){ return -1; }
 
   // override AmAudio
-  int get(unsigned int user_ts, unsigned char* buffer, unsigned int 
nb_samples);
+  int get(unsigned int user_ts, unsigned char* buffer, unsigned int 
time_millisec);
   int put(unsigned int user_ts, unsigned char* buffer, unsigned int size);
 
  public:

Modified: branches/wb/core/AmMediaProcessor.cpp
===================================================================
--- branches/wb/core/AmMediaProcessor.cpp       2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/AmMediaProcessor.cpp       2008-08-25 20:55:09 UTC (rev 
1077)
@@ -239,10 +239,10 @@
 
     AmSession* s = (*it);
     // todo: get frame size/checkInterval from local audio if local in+out (?)
-    unsigned int f_size = s->rtp_str.getFrameSize(); 
+    unsigned int frame_length = s->rtp_str.getFrameLength(); // ms
 
     // complete frame time reached? 
-    if (s->rtp_str.checkInterval(ts, f_size)) {
+    if (s->rtp_str.checkInterval(ts)) {
       s->lockAudio();
 
       int rcvd_audio_len = -1;
@@ -272,7 +272,7 @@
              break;
            }
          } else {
-           rcvd_audio_len = s->rtp_str.get(ts,buffer,f_size);
+           rcvd_audio_len = s->rtp_str.get(ts,buffer,frame_length);
            
            if (s->isDtmfDetectionEnabled() && rcvd_audio_len > 0)
              s->putDtmfAudio(buffer, rcvd_audio_len, ts);
@@ -282,7 +282,7 @@
        // input is local - get audio from local_in
        AmAudio* local_input = s->getLocalInput(); 
        if (local_input) {
-         rcvd_audio_len = local_input->get(ts,buffer,f_size);
+         rcvd_audio_len = local_input->get(ts,buffer,frame_length);
        }
       }
 
@@ -311,9 +311,9 @@
     AmAudio* output = s->getOutput();
            
     if(output && s->rtp_str.sendIntReached()){
-               
-      int size = output->get(ts,buffer,s->rtp_str.getFrameSize());
-      
+      unsigned int frame_length = s->rtp_str.getFrameLength();
+      int size = output->get(ts,buffer,frame_length);
+
       if(size <= 0){
        DBG("output->get() returned: %i\n",size);
        postRequest(new SchedRequest(AmMediaProcessor::ClearSession,s)); 

Modified: branches/wb/core/AmPlaylist.cpp
===================================================================
--- branches/wb/core/AmPlaylist.cpp     2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmPlaylist.cpp     2008-08-25 20:55:09 UTC (rev 1077)
@@ -64,7 +64,7 @@
   }
 }
 
-int AmPlaylist::get(unsigned int user_ts, unsigned char* buffer, unsigned int 
nb_samples)
+int AmPlaylist::get(unsigned int user_ts, unsigned char* buffer, unsigned int 
time_millisec)
 {
   int ret = -1;
 
@@ -73,13 +73,14 @@
 
   while(cur_item && 
        cur_item->play && 
-       (ret = cur_item->play->get(user_ts,buffer,nb_samples)) <= 0){
+       (ret = cur_item->play->get(user_ts,buffer,time_millisec)) <= 0){
 
     DBG("get: gotoNextItem\n");
     gotoNextItem();
   }
 
   if(!cur_item || !cur_item->play) {
+    unsigned int nb_samples = time_millisec * fmt->rate / 1000;
     ret = calcBytesToRead(nb_samples);
     memset(buffer,0,ret);
   }

Modified: branches/wb/core/AmPlaylist.h
===================================================================
--- branches/wb/core/AmPlaylist.h       2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmPlaylist.h       2008-08-25 20:55:09 UTC (rev 1077)
@@ -76,7 +76,7 @@
   int write(unsigned int user_ts, unsigned int size){ return -1; }
     
   // override AmAudio
-  int get(unsigned int user_ts, unsigned char* buffer, unsigned int 
nb_samples);
+  int get(unsigned int user_ts, unsigned char* buffer, unsigned int 
time_millisec);
   int put(unsigned int user_ts, unsigned char* buffer, unsigned int size);
        
  public:

Modified: branches/wb/core/AmPlayoutBuffer.cpp
===================================================================
--- branches/wb/core/AmPlayoutBuffer.cpp        2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/AmPlayoutBuffer.cpp        2008-08-25 20:55:09 UTC (rev 
1077)
@@ -59,7 +59,6 @@
 void AmPlayoutBuffer::write(u_int32_t ref_ts, u_int32_t rtp_ts, 
                            int16_t* buf, u_int32_t len, bool begin_talk)
 {  
-
   unsigned int mapped_ts;
   if(!recv_offset_i)
     {
@@ -94,6 +93,7 @@
      && (mapped_ts - last_ts <= PLC_MAX_SAMPLES))
     {
       unsigned char tmp[AUDIO_BUFFER_SIZE * 2];
+      DBG("loss - conceal from last_ts %u to mapped_ts %u\n", last_ts, 
mapped_ts);
       int l_size = m_plcbuffer->conceal_loss(mapped_ts - last_ts, tmp);
       if (l_size>0)
         {
@@ -123,7 +123,7 @@
     u_int32_t rlen=0;
     if(ts_less()(r_ts+PCM16_B2S(AUDIO_BUFFER_SIZE),w_ts))
       rlen = PCM16_B2S(AUDIO_BUFFER_SIZE);
-    else
+    else 
       rlen = w_ts - r_ts;
 
     buffer_get(r_ts,buf,rlen);
@@ -140,6 +140,7 @@
 
   if(ts_less()(w_ts,ts+len))
     w_ts = ts + len;
+//   DBG("@%u put %u\n", ts, len);
 }
 
 void AmPlayoutBuffer::buffer_get(unsigned int ts, ShortSample* buf, unsigned 
int len)
@@ -148,6 +149,7 @@
 
   if(ts_less()(r_ts,ts+len))
     r_ts = ts + len;
+//   DBG("@%u get %u\n", ts, len);
 }
 
 //

Modified: branches/wb/core/AmPlayoutBuffer.h
===================================================================
--- branches/wb/core/AmPlayoutBuffer.h  2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmPlayoutBuffer.h  2008-08-25 20:55:09 UTC (rev 1077)
@@ -42,13 +42,13 @@
 #define EXP_THRESHOLD 20
 #define SHR_THRESHOLD 180
 
-#define WSOLA_START_OFF  10 * SYSTEM_SAMPLERATE / 1000
+#define WSOLA_START_OFF  (10 * SYSTEM_SAMPLERATE / 1000)
 #define WSOLA_SCALED_WIN 50
 
 // the maximum packet size that will be processed (80ms)
-#define MAX_PACKET_SAMPLES 80 * SYSTEM_SAMPLERATE / 1000
+#define MAX_PACKET_SAMPLES (80 * SYSTEM_SAMPLERATE / 1000)
 // search segments of size TEMPLATE_SEG samples (10 ms)
-#define TEMPLATE_SEG   10 * SYSTEM_SAMPLERATE / 1000
+#define TEMPLATE_SEG   (10 * SYSTEM_SAMPLERATE / 1000)
 
 // Maximum value: AUDIO_BUFFER_SIZE / 2
 // Note: plc result get stored in our back buffer

Modified: branches/wb/core/AmPrecodedFile.cpp
===================================================================
--- branches/wb/core/AmPrecodedFile.cpp 2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmPrecodedFile.cpp 2008-08-25 20:55:09 UTC (rev 1077)
@@ -64,7 +64,6 @@
   frame_size = precoded_payload.frame_ms * precoded_payload.sample_rate / 1000;
   // fill unused stuff
   frame_length = precoded_payload.frame_ms;
-  frame_encoded_size = precoded_payload.frame_bytes;
 }
 
 AmPrecodedRtpFormat::~AmPrecodedRtpFormat() {

Modified: branches/wb/core/AmRtpAudio.cpp
===================================================================
--- branches/wb/core/AmRtpAudio.cpp     2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmRtpAudio.cpp     2008-08-25 20:55:09 UTC (rev 1077)
@@ -33,7 +33,7 @@
 
 AmRtpAudio::AmRtpAudio(AmSession* _s)
   : AmRtpStream(_s), AmAudio(0), 
-    /*last_ts_i(false),*/ use_default_plc(true),
+    use_default_plc(true),
     send_only(false), playout_buffer(new AmPlayoutBuffer(this)),
     last_check(0),last_check_i(false),send_int(false)
 {
@@ -48,17 +48,31 @@
 #endif // USE_SPANDSP_PLC
 }
 
-bool AmRtpAudio::checkInterval(unsigned int ts, unsigned int frame_size)
+bool AmRtpAudio::checkInterval(unsigned int ts)
 {
+  unsigned int frame_size = getFrameSize();
+
+  unsigned int used_ts = ts;
+
+  if (fmt->rate != SYSTEM_SAMPLERATE) {
+    if (fmt->rate > SYSTEM_SAMPLERATE) {
+      unsigned int f = fmt->rate / SYSTEM_SAMPLERATE;
+      used_ts = used_ts * f; 
+    } else {
+      unsigned int f = SYSTEM_SAMPLERATE / fmt->rate ;
+      used_ts = used_ts / f; 
+    }
+  }
+
   if(!last_check_i){
     send_int     = true;
     last_check_i = true;
-    last_check   = ts;
+    last_check   = used_ts;
   }
   else {
-    if((ts - last_check) >= frame_size){
+    if((used_ts - last_check) >= frame_size){
       send_int = true;
-      last_check = ts;
+      last_check = used_ts;
     }
     else {
       send_int = false;
@@ -90,7 +104,7 @@
     size = AmRtpStream::receive((unsigned char*)samples,
                                (unsigned int)AUDIO_BUFFER_SIZE, rtp_ts,
                                payload);
-    //    DBG("rtp_ts recvd %u\n", rtp_ts);
+
     if(size <= 0)
       break;
 
@@ -114,7 +128,6 @@
     /* into internal format */
     size = downMix(size);
 
-
     // rtp_ts = SYSTEM_SAMPLERATE * rtp_ts / fmt->rate;
     if (fmt->rate && fmt->rate != SYSTEM_SAMPLERATE) {
       if (fmt->rate > SYSTEM_SAMPLERATE) {
@@ -132,9 +145,22 @@
   return size;
 }
 
-int AmRtpAudio::get(unsigned int ref_ts, unsigned char* buffer, unsigned int 
nb_samples)
+int AmRtpAudio::get(unsigned int ref_ts, unsigned char* buffer, unsigned int 
time_millisec)
 {
+  // for resampling before playout buffer (buffer has SYSTEM_SAMPLERATE), 
+  // otherwise fmt->rate
+  unsigned int nb_samples = time_millisec * SYSTEM_SAMPLERATE / 1000;
+
   int size = read(ref_ts,PCM16_S2B(nb_samples));
+
+  if (size < 0) 
+    return size;
+
+  //   /* convert here for sampling in internal format after playout buffer */
+  //   size = downMix(size);
+  //   if (size < 0) 
+  //     return size;
+
   memcpy(buffer,(unsigned char*)samples,size);
   return size;
 }
@@ -146,7 +172,9 @@
     ->read(ref_ts,
           (ShortSample*)((unsigned char*)samples),
           PCM16_B2S(size));
+//   DBG("read ref/@%u want %u got %u samples\n", ref_ts, PCM16_B2S(size), 
rlen);
 
+
   return PCM16_S2B(rlen);
 }
 

Modified: branches/wb/core/AmRtpAudio.h
===================================================================
--- branches/wb/core/AmRtpAudio.h       2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmRtpAudio.h       2008-08-25 20:55:09 UTC (rev 1077)
@@ -96,7 +96,7 @@
   AmRtpAudio(AmSession* _s=0);
   ~AmRtpAudio();
 
-  bool checkInterval(unsigned int ts, unsigned int frame_size);
+  bool checkInterval(unsigned int ts);
   bool sendIntReached();
 
   int setCurrentPayload(int payload);
@@ -113,7 +113,7 @@
   int write(unsigned int user_ts, unsigned int size);
 
   int get(unsigned int user_ts, unsigned char* buffer, 
-         unsigned int nb_samples);
+         unsigned int time_millisec);
 
   // AmRtpStream interface
   void init(const vector<SdpPayload*>& sdp_payloads);

Modified: branches/wb/core/AmRtpStream.cpp
===================================================================
--- branches/wb/core/AmRtpStream.cpp    2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/AmRtpStream.cpp    2008-08-25 20:55:09 UTC (rev 1077)
@@ -335,8 +335,11 @@
 
   memcpy(buffer,rp->getData(),rp->getDataSize());
   ts = rp->timestamp;
+
+#if SYSTEM_SAMPLERATE >=16000
   if (rp->payload == PAYLOAD_ID_G722)
     ts*=2; // G722 rate registered as 8khz due to historical error
+#endif
 
   out_payload = rp->payload;
 

Modified: branches/wb/core/amci/amci.h
===================================================================
--- branches/wb/core/amci/amci.h        2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/amci/amci.h        2008-08-25 20:55:09 UTC (rev 1077)
@@ -67,12 +67,11 @@
 /** @def AMCI_WRONLY Write only mode. */
 #define AMCI_WRONLY   2
 
+  /* todo: change in ptr to structure owned by codec */
   /** @def AMCI_FMT_FRAME_LENGTH  frame length in ms (for framed codecs; must 
be multiple of 10) see codec_init */
 #define AMCI_FMT_FRAME_LENGTH       1
   /** @def AMCI_FMT_FRAME_SIZE frame size in samples */
 #define AMCI_FMT_FRAME_SIZE         2
-  /** @def AMCI_FMT_ENCODED_FRAME_SIZE encoded frame size in bytes */
-#define AMCI_FMT_ENCODED_FRAME_SIZE 3
 
 struct amci_codec_t;
 

Modified: branches/wb/core/plug-in/adpcm/adpcm.c
===================================================================
--- branches/wb/core/plug-in/adpcm/adpcm.c      2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/plug-in/adpcm/adpcm.c      2008-08-25 20:55:09 UTC (rev 
1077)
@@ -116,7 +116,14 @@
   g72x_init_state(&cinst->to_g726);
   g72x_init_state(&cinst->from_g726);
 
-  format_description[0].id = 0;
+  format_description[0].id = AMCI_FMT_FRAME_LENGTH;
+  format_description[0].value = 20;
+  format_description[1].id = AMCI_FMT_FRAME_SIZE;
+  format_description[1].value = 160;
+/*   format_description[2].id =  AMCI_FMT_ENCODED_FRAME_SIZE; */
+/*   format_description[2].value = 160; */
+  format_description[2].id = 0;
+
   return (long) cinst;
 }
 

Modified: branches/wb/core/plug-in/g722/g722.c
===================================================================
--- branches/wb/core/plug-in/g722/g722.c        2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/plug-in/g722/g722.c        2008-08-25 20:55:09 UTC (rev 
1077)
@@ -1,7 +1,7 @@
 /*
   This is a simple interface to the spandsp's g722 implementation.
-  This uses the 8khz compatibility mode - audio is encodec and decoded 
-  in 8khz.
+  In narrowband this uses the 8khz compatibility mode - audio is 
+  encoded and decoded in 8khz.
 
   Copyright (C) 2008 iptego GmbH 
 
@@ -65,7 +65,7 @@
 END_FILE_FORMATS
 
 END_EXPORTS
-
+ 
 typedef struct {
   g722_encode_state_t encode_state;
   g722_decode_state_t decode_state;    
@@ -108,6 +108,16 @@
     return 0;
   }
 
+  format_description[0].id = AMCI_FMT_FRAME_LENGTH;
+  format_description[0].value = 20;
+  format_description[1].id = AMCI_FMT_FRAME_SIZE;
+#if SYSTEM_SAMPLERATE >=16000
+  format_description[1].value = 320; /* 20 ms at 16khz */ 
+#else
+  format_description[1].value = 160;
+#endif
+  format_description[2].id = 0;
+
   return (long)gs;
 }
 

Modified: branches/wb/core/plug-in/gsm/gsm.c
===================================================================
--- branches/wb/core/plug-in/gsm/gsm.c  2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/plug-in/gsm/gsm.c  2008-08-25 20:55:09 UTC (rev 1077)
@@ -83,8 +83,8 @@
   blocks = div(size,320);
 
   if(blocks.rem){
-    ERROR("pcm16_2_gsm: number of blocks should be integral (block size = 
320)\n");
-    return -1;
+    ERROR("pcm16_2_gsm: number of blocks should be integral (block size = 320, 
got %u)\n", size);
+    //    return -1;
   }
 
   for (i=0;i<blocks.quot;i++)
@@ -143,10 +143,9 @@
   format_description[0].value = 20;
   format_description[1].id = AMCI_FMT_FRAME_SIZE;
   format_description[1].value = 160;
-  format_description[2].id =  AMCI_FMT_ENCODED_FRAME_SIZE;
-  format_description[2].value = 33;
-  format_description[3].id = 0;
-
+/*   format_description[2].id =  AMCI_FMT_ENCODED_FRAME_SIZE; */
+/*   format_description[2].value = 33; */
+  format_description[2].id = 0;
     
   return (long)h_codec;
 }

Modified: branches/wb/core/plug-in/ilbc/ilbc.c
===================================================================
--- branches/wb/core/plug-in/ilbc/ilbc.c        2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/plug-in/ilbc/ilbc.c        2008-08-25 20:55:09 UTC (rev 
1077)
@@ -153,9 +153,9 @@
   format_description[0].value = mode;
   format_description[1].id = AMCI_FMT_FRAME_SIZE;
   format_description[1].value = mode==30 ? 240 : 160;
-  format_description[2].id = AMCI_FMT_ENCODED_FRAME_SIZE;
-  format_description[2].value = mode==30 ? 50 : 38;
-  format_description[3].id = 0;
+/*   format_description[2].id = AMCI_FMT_ENCODED_FRAME_SIZE; */
+/*   format_description[2].value = mode==30 ? 50 : 38; */
+  format_description[2].id = 0;
     
   if (format_parameters) {
     DBG("ilbc with format parameters : '%s', mode=%d.\n", format_parameters, 
mode);

Modified: branches/wb/core/plug-in/speex/speex.c
===================================================================
--- branches/wb/core/plug-in/speex/speex.c      2008-08-25 15:59:24 UTC (rev 
1076)
+++ branches/wb/core/plug-in/speex/speex.c      2008-08-25 20:55:09 UTC (rev 
1077)
@@ -233,16 +233,17 @@
   format_description[1].id = AMCI_FMT_FRAME_SIZE;
   format_description[1].value = SPEEX_NB_SAMPLES_PER_FRAME * 
ss->frames_per_packet;
     
-  format_description[2].id = AMCI_FMT_ENCODED_FRAME_SIZE;
-  format_description[2].value = bits/8 + (bits % 8 ? 1 : 0) + 1;
+/*   format_description[2].id = AMCI_FMT_ENCODED_FRAME_SIZE; */
+/*   format_description[2].value = bits/8 + (bits % 8 ? 1 : 0) + 1; */
 
   DBG("set AMCI_FMT_FRAME_LENGTH to %d\n", format_description[0].value);
   DBG("set AMCI_FMT_FRAME_SIZE to %d\n", format_description[1].value);
-  DBG("set AMCI_FMT_ENCODED_FRAME_SIZE to %d\n", format_description[2].value);
+/*   DBG("set AMCI_FMT_ENCODED_FRAME_SIZE to %d\n", 
format_description[2].value); */
     
-  format_description[3].id = 0;
+  format_description[2].id = 0;
     
-  DBG("SpeexState %p inserted with mode %d and %d frames per packet,\n", ss, 
ss->mode, ss->frames_per_packet);
+  DBG("SpeexState %p inserted with mode %d and %d frames per packet,\n", 
+      ss, ss->mode, ss->frames_per_packet);
     
   return (long)ss;
 }

Modified: branches/wb/core/plug-in/wav/wav.c
===================================================================
--- branches/wb/core/plug-in/wav/wav.c  2008-08-25 15:59:24 UTC (rev 1076)
+++ branches/wb/core/plug-in/wav/wav.c  2008-08-25 20:55:09 UTC (rev 1077)
@@ -77,6 +77,8 @@
 /** @def WAV_ULAW subtype declaration. */
 #define WAV_ULAW 7 
 
+static long g711_create(const char* format_parameters, amci_codec_fmt_info_t* 
format_description);
+
 static int ULaw_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, 
unsigned int size,
                         unsigned int channels, unsigned int rate, long h_codec 
);
 
@@ -96,10 +98,10 @@
 
      BEGIN_CODECS
 CODEC( CODEC_ULAW, Pcm16_2_ULaw, ULaw_2_Pcm16, 
-       AMCI_NO_CODEC_PLC, AMCI_NO_CODECCREATE, AMCI_NO_CODECDESTROY, 
+       AMCI_NO_CODEC_PLC, g711_create, AMCI_NO_CODECDESTROY, 
        g711_bytes2samples, g711_samples2bytes )
      CODEC( CODEC_ALAW, Pcm16_2_ALaw, ALaw_2_Pcm16, 
-           AMCI_NO_CODEC_PLC, AMCI_NO_CODECCREATE, AMCI_NO_CODECDESTROY, 
+           AMCI_NO_CODEC_PLC, g711_create, AMCI_NO_CODECDESTROY, 
            g711_bytes2samples, g711_samples2bytes )
      END_CODECS
     
@@ -120,6 +122,18 @@
 
 END_EXPORTS
 
+     /* to set frame size 160 */
+static long g711_create(const char* format_parameters, amci_codec_fmt_info_t* 
format_description)
+{
+  format_description[0].id = AMCI_FMT_FRAME_LENGTH;
+  format_description[0].value = 20;
+  format_description[1].id = AMCI_FMT_FRAME_SIZE;
+  format_description[1].value = 160;
+  format_description[2].id = 0;
+
+  return 1;
+}
+
 static unsigned int g711_bytes2samples(long h_codec, unsigned int num_bytes)
 {
   /* ALAW and ULAW formats has one sample per byte */

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to