开发者

How can i adapt speex echo canceller to process a float samples?

Good day! how сan i use float samples for echo cancellation processing? I tried to change interface and body of central function:

from

void speex_echo_cancellation(SpeexEchoState *st, const spx_int16_t *rec, const spx_int16_t *play, spx_int16_t *out);

to

void float_speex_echo_cancellation(SpeexEchoState *st, const float rec[], const float play[], float out[]);

and from

...
       for (i=0;i<st->frame_size;i++)
      {
         spx_word32_t tmp_out;
         tmp_out = SUB32(EXTEND32(st->input[chan*st->frame_size+i]), EXTEND32(st->e[chan*N+i+st->frame_size]));
         tmp_out = ADD32(tmp_out, EXTEND32(MULT16_16_P15(st->preemph, st->memE[chan])));

         if (in[i*C+chan] <= -32000 || in[i*C+chan] >= 32000)
         {
         if (st->saturated == 0)
            st->saturated = 1;
         }

         **out[i*C+chan] = (spx_int16_t)WORD2INT(tmp_out);**

         st->memE[chan] = tmp_out;
      }
...

to

  ...

     for (i=0;i<st->frame_size;i++)
          {
             spx_word32_t tmp_out;
             tmp_out = SUB32(EXTEND32(st->input[chan*st->frame_size+i]), EXTEND32(st->e[chan*N+i+st->fram开发者_StackOverflow社区e_size]));
             tmp_out = ADD32(tmp_out, EXTEND32(MULT16_16_P15(st->preemph, st->memE[chan])));

             if (in[i*C+chan] <= -32000 || in[i*C+chan] >= 32000)
             {
             if (st->saturated == 0)
                st->saturated = 1;
             }

             **out[i*C+chan] = /*(spx_int16_t)WORD2INT(*/tmp_out*/)*/;**

             st->memE[chan] = tmp_out;
          }
    ...

and from

static inline void filter_dc_notch16(const spx_int16_t *in, spx_word16_t radius, spx_word16_t *out, int len, spx_mem_t *mem, int stride)
{
   int i;
   spx_word16_t den2;
   den2 = (spx_word16_t)(radius*radius + .7f*(1.f-radius)*(1.f-radius));
   for (i=0;i<len;i++)
   {
      spx_int16_t vin = in[i*stride];
      spx_word32_t vout = mem[0] + SHL32(EXTEND32(vin),15);
      mem[0] = mem[1] + 2*(-vin + radius*vout);
      mem[1] = SHL32(EXTEND32(vin),15) - MULT16_32_Q15(den2,vout);
      out[i] = SATURATE32(PSHR32(MULT16_32_Q15(radius,vout),15),32767);
   }
}

to

 static inline void float_filter_dc_notch16(const /*spx_int16_t*/spx_word16_t *in, spx_word16_t radius, spx_word16_t *out, int len, spx_mem_t *mem, int stride)
{
   int i;
   spx_word16_t den2;
   den2 = /*(spx_word16_t)*/(radius*radius + .7f*(1.f-radius)*(1.f-radius));
   for (i=0;i<len;i++)
   {
      /*spx_int16_t*/spx_word16_t vin = in[i*stride];
      spx_word32_t vout = mem[0] + SHL32(EXTEND32(vin),15);
      mem[0] = mem[1] + 2*(-vin + radius*vout);
      mem[1] = SHL32(EXTEND32(vin),15) - MULT16_32_Q15(den2,vout);
      out[i] = /*SATURATE32(*/PSHR32(MULT16_32_Q15(radius,vout),15)/*,32767)*/;
   }
}

So, i prevented conversion from float type output result to short int, but now i get a warning:

speex_warning("The echo canceller started acting funny and got slapped (reset). It swears it will behave now.");

that points to st->screwed_up parameter having 50 values and it signs of setting to zero all out samples:

...

 if (!(Syy>=0 && Sxx>=0 && See >= 0)
   || !(Sff < N*1e9 && Syy < N*1e9 && Sxx < N*1e9)
  )

{ st->screwed_up += 50; for (i=0;iframe_size*C;i++) out[i] = 0; }

...

What can i do?

enter code here


Why do you want to use float samples? Standard linear PCM audio is represented as integer samples according to the chosen bitrate - 8 bit, 16 bit and so on.

Where do you get that input from?

If I were you I would just convert whatever you got to shorts and provide it to Speex so it can work with it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜