Exemplo n.º 1
0
JNIEXPORT void JNICALL FUNCSPEEX(initDecode)(JNIEnv* env, jobject obj) {
	speex_bits_init(&dbits);
	dec_state = speex_decoder_init(speex_lib_get_mode(SPEEX_MODEID_NB));
	speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &dec_frame_size);
	int tmp = 1;
	speex_decoder_ctl(dec_state, SPEEX_SET_ENH, &tmp);
}
Exemplo n.º 2
0
void *ph_speex_dec_init(SpeexMode *mode)
{
  struct speexdec *speex;
  int tmp;

  speex = (struct speexdec *)calloc(sizeof(struct speexdec), 1);
  if (!speex)
  {
    return 0;
  }

  speex->st = speex_decoder_init(mode);


  tmp=0;
  speex_decoder_ctl(speex->st, SPEEX_SET_VBR, &tmp);
  tmp=8;
  speex_decoder_ctl(speex->st, SPEEX_SET_QUALITY, &tmp);
  tmp=1;
  speex_decoder_ctl(speex->st, SPEEX_SET_COMPLEXITY, &tmp);

  speex_bits_init(&speex->bits);

  return speex;
}
Exemplo n.º 3
0
static av_cold int libspeex_decode_init(AVCodecContext *avctx)
{
    LibSpeexContext *s = avctx->priv_data;
    const SpeexMode *mode;

    // defaults in the case of a missing header
    if (avctx->sample_rate <= 8000)
        mode = &speex_nb_mode;
    else if (avctx->sample_rate <= 16000)
        mode = &speex_wb_mode;
    else
        mode = &speex_uwb_mode;

    if (avctx->extradata_size >= 80)
        s->header = speex_packet_to_header(avctx->extradata, avctx->extradata_size);

    avctx->sample_fmt = AV_SAMPLE_FMT_S16;
    if (s->header) {
        avctx->sample_rate = s->header->rate;
        avctx->channels    = s->header->nb_channels;
        s->frame_size      = s->header->frame_size;

        mode = speex_lib_get_mode(s->header->mode);
        if (!mode) {
            av_log(avctx, AV_LOG_ERROR, "Unknown Speex mode %d", s->header->mode);
            return AVERROR_INVALIDDATA;
        }
    } else
        av_log(avctx, AV_LOG_INFO, "Missing Speex header, assuming defaults.\n");

    if (avctx->channels > 2) {
        av_log(avctx, AV_LOG_ERROR, "Only stereo and mono are supported.\n");
        return AVERROR(EINVAL);
    }

    speex_bits_init(&s->bits);
    s->dec_state = speex_decoder_init(mode);
    if (!s->dec_state) {
        av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex decoder.\n");
        return -1;
    }

    if (!s->header) {
        speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &s->frame_size);
    }

    if (avctx->channels == 2) {
        SpeexCallback callback;
        callback.callback_id = SPEEX_INBAND_STEREO;
        callback.func = speex_std_stereo_request_handler;
        callback.data = &s->stereo;
        s->stereo = (SpeexStereoState)SPEEX_STEREO_STATE_INIT;
        speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback);
    }

    avcodec_get_frame_defaults(&s->frame);
    avctx->coded_frame = &s->frame;

    return 0;
}
Exemplo n.º 4
0
/*
 * Open codec.
 */
static pj_status_t spx_codec_open( pjmedia_codec *codec, 
				   pjmedia_codec_param *attr )
{
    struct spx_private *spx;
    int id, tmp;

    spx = (struct spx_private*) codec->codec_data;
    id = spx->param_id;

    /* 
     * Create and initialize encoder. 
     */
    spx->enc = speex_encoder_init(spx_factory.speex_param[id].mode);
    if (!spx->enc)
	return PJMEDIA_CODEC_EFAILED;
    speex_bits_init(&spx->enc_bits);

    /* Set the quality*/
    if (spx_factory.speex_param[id].quality != -1) {
	speex_encoder_ctl(spx->enc, SPEEX_SET_QUALITY, 
			  &spx_factory.speex_param[id].quality);
    }

    /* Sampling rate. */
    tmp = attr->info.clock_rate;
    speex_encoder_ctl(spx->enc, SPEEX_SET_SAMPLING_RATE, 
		      &spx_factory.speex_param[id].clock_rate);

    /* VAD */
    tmp = (attr->setting.vad != 0);
    speex_encoder_ctl(spx->enc, SPEEX_SET_VAD, &tmp);
    speex_encoder_ctl(spx->enc, SPEEX_SET_DTX, &tmp);

    /* Complexity */
    if (spx_factory.speex_param[id].complexity != -1) {
	speex_encoder_ctl(spx->enc, SPEEX_SET_COMPLEXITY, 
			  &spx_factory.speex_param[id].complexity);
    }

    /* 
     * Create and initialize decoder. 
     */
    spx->dec = speex_decoder_init(spx_factory.speex_param[id].mode);
    if (!spx->dec) {
	spx_codec_close(codec);
	return PJMEDIA_CODEC_EFAILED;
    }
    speex_bits_init(&spx->dec_bits);

    /* Sampling rate. */
    speex_decoder_ctl(spx->dec, SPEEX_SET_SAMPLING_RATE, 
		      &spx_factory.speex_param[id].clock_rate);

    /* PENH */
    tmp = attr->setting.penh;
    speex_decoder_ctl(spx->dec, SPEEX_SET_ENH, &tmp);

    return PJ_SUCCESS;
}
void init_speex_decoder() {
    if (gDecoderState == NULL) {
        gDecoderState = speex_decoder_init(&speex_nb_mode);
        int tmp = 1;
        speex_decoder_ctl(gDecoderState, SPEEX_SET_ENH, &tmp);
        tmp = kNetworkAudioSampleRate;
        speex_decoder_ctl(gDecoderState, SPEEX_SET_SAMPLING_RATE, &tmp);
        speex_bits_init(&gDecoderBits);
    }
}
Exemplo n.º 6
0
static void *process_header (struct spx_data *data)
{
	void *st;
	const SpeexMode *mode;
	int modeID;
	SpeexCallback callback;
	int enhance = ENHANCE_AUDIO;

	data->header = speex_packet_to_header ((char*)data->op.packet,
			data->op.bytes);
	if (!data->header) {
		decoder_error (&data->error, ERROR_FATAL, 0,
				"Can't open speex file: can't read header");
		return NULL;
	}

	if (data->header->mode >= SPEEX_NB_MODES) {
		decoder_error (&data->error, ERROR_FATAL, 0,
				"Can't open speex file: Mode number %"PRId32
				" does not exist in this version",
				data->header->mode);
		return NULL;
	}

	modeID = data->header->mode;
	mode = speex_mode_list[modeID];

	if (mode->bitstream_version < data->header->mode_bitstream_version) {
		decoder_error (&data->error, ERROR_FATAL, 0,
				"Can't open speex file: The file was encoded "
				"with a newer version of Speex.");
		return NULL;
	}

	if (mode->bitstream_version > data->header->mode_bitstream_version) {
		decoder_error (&data->error, ERROR_FATAL, 0,
				"Can't open speex file: The file was encoded "
				"with an older version of Speex.");
		return NULL;
	}

	st = speex_decoder_init (mode);
	speex_decoder_ctl(st, SPEEX_SET_ENH, &enhance);
	speex_decoder_ctl(st, SPEEX_GET_FRAME_SIZE, &data->frame_size);

	callback.callback_id = SPEEX_INBAND_STEREO;
	callback.func = speex_std_stereo_request_handler;
	callback.data = &data->stereo;
	speex_decoder_ctl(st, SPEEX_SET_HANDLER, &callback);
	speex_decoder_ctl(st, SPEEX_SET_SAMPLING_RATE, &data->header->rate);

	return st;
}
Exemplo n.º 7
0
static int speex_decoder_construct(struct ast_trans_pvt *pvt, const SpeexMode *profile)
{
	struct speex_coder_pvt *tmp = pvt->pvt;
	
	if (!(tmp->speex = speex_decoder_init(profile)))
		return -1;

	speex_bits_init(&tmp->bits);
	speex_decoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
	if (enhancement)
		speex_decoder_ctl(tmp->speex, SPEEX_SET_ENH, &enhancement);

	return 0;
}
Exemplo n.º 8
0
static int speextolin_new(struct ast_trans_pvt *pvt)
{
	struct speex_coder_pvt *tmp = pvt->pvt;
	
	if (!(tmp->speex = speex_decoder_init(&speex_nb_mode)))
		return -1;

	speex_bits_init(&tmp->bits);
	speex_decoder_ctl(tmp->speex, SPEEX_GET_FRAME_SIZE, &tmp->framesize);
	if (enhancement)
		speex_decoder_ctl(tmp->speex, SPEEX_SET_ENH, &enhancement);

	return 0;
}
Exemplo n.º 9
0
int main(int argc, char **argv)
{
   char *outFile;
   FILE *fout;
   /*Holds the audio that will be written to file (16 bits per sample)*/
   short out[FRAME_SIZE];
   /*Speex handle samples as float, so we need an array of floats*/
   float output[FRAME_SIZE];
   char cbits[200];
   int nbBytes;
   /*Holds the state of the decoder*/
   void *state;
   /*Holds bits so they can be read and written to by the Speex routines*/
   SpeexBits bits;
   int i, tmp;

   /*Create a new decoder state in narrowband mode*/
   state = speex_decoder_init(&speex_nb_mode);

   /*Set the perceptual enhancement on*/
   tmp=1;
   speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);

   outFile = argv[1];
   fout = fopen(outFile, "w");

   /*Initialization of the structure that holds the bits*/
   speex_bits_init(&bits);
   while (1)
   {
      /*Read the size encoded by sampleenc, this part will likely be
        different in your application*/
      fread(&nbBytes, sizeof(int), 1, stdin);
      fprintf (stderr, "nbBytes: %d\n", nbBytes);
      if (feof(stdin))
         break;

      /*Read the "packet" encoded by sampleenc*/
      fread(cbits, 1, nbBytes, stdin);
      /*Copy the data into the bit-stream struct*/
      speex_bits_read_from(&bits, cbits, nbBytes);

      /*Decode the data*/
      speex_decode(state, &bits, output);

      /*Copy from float to short (16 bits) for output*/
      for (i=0;i<FRAME_SIZE;i++)
         out[i]=output[i];

      /*Write the decoded audio to file*/
      fwrite(out, sizeof(short), FRAME_SIZE, fout);
   }

   /*Destroy the decoder state*/
   speex_decoder_destroy(state);
   /*Destroy the bit-stream truct*/
   speex_bits_destroy(&bits);
   fclose(fout);
   return 0;
}
Exemplo n.º 10
0
hsBool plSpeex::Init(Mode mode) 
{
    int enh = 1;
    
    // setup speex
    speex_bits_init(fBits);
    fBitsInit = true;

    if(mode == kNarrowband)
    {
        fEncoderState = speex_encoder_init(speex_lib_get_mode(SPEEX_MODEID_NB));                         // narrowband
        fDecoderState = speex_decoder_init(speex_lib_get_mode(SPEEX_MODEID_NB));
    }
    else if(mode == kWideband)
    {
        fEncoderState = speex_encoder_init(speex_lib_get_mode(SPEEX_MODEID_WB));
        fDecoderState = speex_decoder_init(speex_lib_get_mode(SPEEX_MODEID_WB));
    }
    
    speex_encoder_ctl(fEncoderState, SPEEX_GET_FRAME_SIZE, &fFrameSize);            // get frame size
    speex_encoder_ctl(fEncoderState, SPEEX_SET_COMPLEXITY, &fComplexity);           // 3
    speex_encoder_ctl(fEncoderState, SPEEX_SET_SAMPLING_RATE, &fSampleRate);        // 8 khz
    speex_encoder_ctl(fEncoderState, SPEEX_SET_VBR_QUALITY, &fQuality);             // 7
    speex_encoder_ctl(fEncoderState, SPEEX_SET_VBR, &fVBR);                         // use variable bit rate
    speex_encoder_ctl(fEncoderState, SPEEX_SET_ABR, &fAverageBitrate);              // default to 8kb
    
    speex_decoder_ctl(fDecoderState, SPEEX_SET_ENH, &fENH);                         // perceptual enhancement               

    fInitialized = true;

    return true;
}
Exemplo n.º 11
0
AudioDecoderSpeex::AudioDecoderSpeex()
    : _speex_dec_state(speex_decoder_init(&speex_wb_mode)) 
{
    if (!_speex_dec_state) {
        throw MediaException(_("AudioDecoderSpeex: state initialization failed."));
    }

    speex_bits_init(&_speex_bits);

    speex_decoder_ctl(_speex_dec_state, SPEEX_GET_FRAME_SIZE, &_speex_framesize);

#ifdef RESAMPLING_SPEEX
    int err = 0;
    _resampler = speex_resampler_init(1, 16000, 44100,
        SPEEX_RESAMPLER_QUALITY_DEFAULT, &err);

    if (err != RESAMPLER_ERR_SUCCESS) {
        throw MediaException(_("AudioDecoderSpeex: initialization failed."));
    }

    spx_uint32_t num = 0, den = 0;

    speex_resampler_get_ratio (_resampler, &num, &den);
    assert(num && den);

    boost::rational<boost::uint32_t> numsamples(den, num);

    numsamples *= _speex_framesize * 2 /* convert to stereo */;

    _target_frame_size = boost::rational_cast<boost::uint32_t>(numsamples);
#endif
}
//*****************************************************************************
//
//! Initialize the decoder's state to prepare for decoding new frames.
//!
//! This function will initializes the decoder so that it is prepared to start
//! receiving frames to decode.
//!
//! \return This function returns 0.
//
//*****************************************************************************
int32_t
SpeexDecodeInit(void)
{
    int iTemp;

    //
    // Clear out the flags for this instance.
    //
    g_sSpeexDecoder.ui32Flags = 0;

    //
    // Create a new decoder state in narrow band mode.
    //
    g_sSpeexDecoder.pvState = speex_decoder_init(&speex_nb_mode);

    //
    // Disable enhanced decoding to reduce processing requirements.
    //
    iTemp = 0;
    speex_decoder_ctl(g_sSpeexDecoder.pvState, SPEEX_SET_ENH, &iTemp);

    //
    // Initialization of the structure that holds the bits.
    //
    speex_bits_init(&g_sSpeexDecoder.sBits);

    return(0);
}
Exemplo n.º 13
0
extern "C" JNIEXPORT jint JNICALL Java_com_haitou_xiaoyoupai_imservice_support_audio_Speex_open(
    JNIEnv *env, jobject obj, jint compression) {
    int tmp = 0;
    if (codec_open++ != 0)
        return (jint) 0;

    speex_bits_init(&ebits);
    speex_bits_init(&dbits);

    enc_state = speex_encoder_init(&speex_nb_mode);
    dec_state = speex_decoder_init(&speex_nb_mode);

    tmp = compression;
    speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &tmp);
    speex_encoder_ctl(enc_state, SPEEX_GET_FRAME_SIZE, &enc_frame_size);
    speex_decoder_ctl(dec_state, SPEEX_GET_FRAME_SIZE, &dec_frame_size);

    SpeexPreprocessState * m_st;
    m_st = speex_preprocess_state_init(enc_frame_size, 8000);
    int denoise = 1;
    int noiseSuppress = -25;
    speex_preprocess_ctl(m_st, SPEEX_PREPROCESS_SET_DENOISE, &denoise);
    speex_preprocess_ctl(m_st, SPEEX_PREPROCESS_SET_NOISE_SUPPRESS,
                         &noiseSuppress);

    return (jint) 0;
}
Exemplo n.º 14
0
static int decode_audio(sh_audio_t *sh, unsigned char *buf,
                        int minlen, int maxlen) {
  double pts;
  context_t *ctx = sh->context;
  int len, framelen, framesamples;
  char *packet;
  int i, err;
  speex_decoder_ctl(ctx->dec_context, SPEEX_GET_FRAME_SIZE, &framesamples);
  framelen = framesamples * ctx->hdr->nb_channels * sizeof(short);
  if (maxlen < ctx->hdr->frames_per_packet * framelen) {
    mp_msg(MSGT_DECAUDIO, MSGL_V, "maxlen too small in decode_audio\n");
    return -1;
  }
  len = ds_get_packet_pts(sh->ds, (unsigned char **)&packet, &pts);
  if (len <= 0) return -1;
  if (sh->pts == MP_NOPTS_VALUE)
    sh->pts = 0;
  if (pts != MP_NOPTS_VALUE) {
    sh->pts = pts;
    sh->pts_bytes = 0;
  }
  speex_bits_read_from(&ctx->bits, packet, len);
  i = ctx->hdr->frames_per_packet;
  do {
    err = speex_decode_int(ctx->dec_context, &ctx->bits, (short *)buf);
    if (err == -2)
      mp_msg(MSGT_DECAUDIO, MSGL_ERR, "Error decoding file.\n");
    if (ctx->hdr->nb_channels == 2)
      speex_decode_stereo_int((short *)buf, framesamples, &ctx->stereo);
    buf = &buf[framelen];
  } while (--i > 0);
  sh->pts_bytes += ctx->hdr->frames_per_packet * framelen;
  return ctx->hdr->frames_per_packet * framelen;
}
Exemplo n.º 15
0
static void dec_preprocess(MSFilter *f){
	DecState *s=(DecState*)f->data;
	const SpeexMode *mode=NULL;
	int modeid;
	switch(s->rate){
		case 8000:
	        modeid = SPEEX_MODEID_NB;    /* rate = 8000Hz */
			break;
		case 16000:
	        modeid = SPEEX_MODEID_WB;    /* rate = 16000Hz */
			break;
			/* should be supported in the future */
		case 32000:
	        modeid = SPEEX_MODEID_UWB;   /* rate = 32000Hz */
			break;
		default:
			ms_error("Unsupported rate for speex decoder (back to default rate=8000).");
			modeid=SPEEX_MODEID_NB;
	}
	/* warning: speex_lib_get_mode() is not available on speex<1.1.12 */
	mode = speex_lib_get_mode(modeid);
	s->state=speex_decoder_init(mode);
	speex_mode_query(mode,SPEEX_MODE_FRAME_SIZE,&s->frsz);
	if (s->penh==1)
		speex_decoder_ctl (s->state, SPEEX_SET_ENH, &s->penh);
	s->sample_time=0;
}
Exemplo n.º 16
0
int speex_jitter_get(SpeexJitter *jitter, spx_int16_t *out, int *current_timestamp, void** userData)
{
   int i;
   int jbRet;	/* results returned by the JB */
   int ourRet;	/* result that we will return */
   spx_int32_t activity;
   char data[2048];
   JitterBufferPacket packet;
   packet.data = data;
   packet.len = 2048;  /* AAAAARGH: it took a week to find and add this missing line */
   
   if (jitter->valid_bits)
   {
      /* Try decoding last received packet */
      jbRet = speex_decode_int(jitter->dec, &jitter->current_packet, out);
      if (jbRet == 0)
      {
         jitter_buffer_tick(jitter->packets);
         return 1;
      } else {
         jitter->valid_bits = 0;
      }
   }

   jbRet = jitter_buffer_get(jitter->packets, &packet, jitter->frame_size, NULL);
   
   if (jbRet != JITTER_BUFFER_OK)
   {
	  /* no packet found, so no corresponding user-data */
      *userData = NULL;

      /* No packet found... extrapolate one */

      /*fprintf (stderr, "lost/late frame\n");*/
      /*Packet is late or lost*/
      speex_decode_int(jitter->dec, NULL, out);
	  
	  ourRet = 2;
   } else {
	  /* found a packet, so there is corresponding user-data */
	  *userData = (void*)(packet.user_data);
   
      speex_bits_read_from(&jitter->current_packet, packet.data, packet.len);
      /* Decode packet */
      jbRet = speex_decode_int(jitter->dec, &jitter->current_packet, out);
      if (jbRet == 0) {
         ourRet = 0;		
         jitter->valid_bits = 1;
      } else {
         /* Error while decoding */
         ourRet = 3;
         for (i=0;i<jitter->frame_size;i++) out[i]=0;
      }
   }
   speex_decoder_ctl(jitter->dec, SPEEX_GET_ACTIVITY, &activity);
   if (activity < jitter->activity_threshold) 
      jitter_buffer_update_delay(jitter->packets, &packet, NULL); 
   jitter_buffer_tick(jitter->packets);
   return ourRet;
}
Exemplo n.º 17
0
void gviSpursSpeexDecoderInitialize(SpursSpeexTaskOutput *spuTaskOut)
{
	void * decoder = gviSpursSpeexStateBuffer;
	int perceptualEnhancement = 1;

	// create a new decoder state
	if (gviSpursSpeexTaskDesc.mSamplesPerSecond == GVRate_8KHz)
		speex_decoder_init(&speex_nb_mode, decoder);
	else if (gviSpursSpeexTaskDesc.mSamplesPerSecond == GVRate_16KHz)
		speex_decoder_init(&speex_wb_mode, decoder);
	else
	{
		//spuDebugPrintf("[Speex][SPU] Error: invalid sample rate!\n");
		spuTaskOut->mSpeexReturnCode = -1;
	}

	if(!decoder)
	{
		//spuDebugPrintf("[Speex][SPU] Error: initializing decoder failed!\n");
		spuTaskOut->mSpeexReturnCode = -2;
	}

	// turn on the perceptual enhancement
	speex_decoder_ctl(decoder, SPEEX_SET_ENH, &perceptualEnhancement);

	spuTaskOut->mSpeexReturnCode = 0;
}
Exemplo n.º 18
0
int speex_std_enh_request_handler(SpeexBits *bits, void *state, void *data)
{
   int enh;
   enh = speex_bits_unpack_unsigned(bits, 1);
   speex_decoder_ctl(data, SPEEX_SET_ENH, &enh);
   return 0;
}
Exemplo n.º 19
0
uint16 SpeexPlugin::getDecodingSampleRate() const
		throw(OperationNotPerfomedException) {
	if (!decoder)
		throw OperationNotPerfomedException("Decoder not initialized");
	spx_int32_t sample;
	speex_decoder_ctl(decoder->state, SPEEX_GET_SAMPLING_RATE, &sample);
	return sample;
}
Exemplo n.º 20
0
static void decoder_config(void *st)
{
	int ret;

	ret = speex_decoder_ctl(st, SPEEX_SET_ENH, &sconf.enhancement);
	if (ret) {
		warning("speex: SPEEX_SET_ENH: %d\n", ret);
	}
}
Exemplo n.º 21
0
	speex2pcm_int()
	{
		state = speex_decoder_init(&speex_nb_mode);
		int tmp=1;
		speex_decoder_ctl(state, SPEEX_SET_ENH, &tmp);
		speex_bits_init(&bits);
		speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &frame_size);

		out  = new short[ frame_size ];
	}
Exemplo n.º 22
0
EXPORT int speex_decode(void *state, SpeexBits *bits, float *out)
{
   int i, ret;
   spx_int32_t N;
   spx_int16_t short_out[MAX_IN_SAMPLES];
   speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
   ret = (*((SpeexMode**)state))->dec(state, bits, short_out);
   for (i=0;i<N;i++)
      out[i] = short_out[i];
   return ret;
}
Exemplo n.º 23
0
void speex_jitter_init(SpeexJitter *jitter, void *decoder, int sampling_rate)
{
   jitter->dec = decoder;
   speex_decoder_ctl(decoder, SPEEX_GET_FRAME_SIZE, &jitter->frame_size);

   jitter->packets = jitter_buffer_init(jitter->frame_size);

   speex_bits_init(&jitter->current_packet);
   jitter->valid_bits = 0;
   jitter->activity_threshold = 0;
}
Exemplo n.º 24
0
static int decode_update(struct audec_state **adsp,
			 const struct aucodec *ac, const char *fmtp)
{
	struct audec_state *st;
	int err = 0;
	(void)fmtp;

	if (!adsp || !ac)
		return EINVAL;
	if (*adsp)
		return 0;

	st = mem_zalloc(sizeof(*st), decode_destructor);
	if (!st)
		return ENOMEM;

	st->frame_size = ac->srate * SPEEX_PTIME / 1000;
	st->channels = ac->ch;

	/* Decoder */
	st->dec = speex_decoder_init(resolve_mode(ac->srate));
	if (!st->dec) {
		err = ENOMEM;
		goto out;
	}

	speex_bits_init(&st->bits);

	if (2 == st->channels) {

		/* Stereo. */
		st->stereo.balance = 1;
		st->stereo.e_ratio = .5f;
		st->stereo.smooth_left = 1;
		st->stereo.smooth_right = 1;

		st->callback.callback_id = SPEEX_INBAND_STEREO;
		st->callback.func = speex_std_stereo_request_handler;
		st->callback.data = &st->stereo;
		speex_decoder_ctl(st->dec, SPEEX_SET_HANDLER,
				  &st->callback);
	}

	decoder_config(st->dec);

 out:
	if (err)
		mem_deref(st);
	else
		*adsp = st;

	return err;
}
Exemplo n.º 25
0
void ms_speex_dec_init_core(MSSpeexDec *obj,const SpeexMode *mode)
{
	int pf=1;
	
	obj->speex_state=speex_decoder_init(mode);
	speex_bits_init(&obj->bits);
	/* enable the perceptual post filter */
	speex_decoder_ctl(obj->speex_state,SPEEX_SET_PF, &pf);
	
	speex_mode_query(mode, SPEEX_MODE_FRAME_SIZE, &obj->frame_size);
	
	obj->initialized=1;
}
Exemplo n.º 26
0
void CASpeexDecoder::BDCReset()
{
    speex_bits_reset(&mSpeexBits);
    if (mSpeexDecoderState != NULL)
        speex_decoder_ctl(mSpeexDecoderState, SPEEX_RESET_STATE, NULL); //??!

    mSpeexFPList.clear();

    mNumFrames = 0;

    mOutBufferUsedSize = 0;
    mOutBufferStart = 0;

    XCACodec::BDCReset();
}
Exemplo n.º 27
0
void CASpeexDecoder::BDCUninitialize()
{
    speex_bits_destroy(&mSpeexBits);
    if (mSpeexDecoderState != NULL)
        speex_decoder_ctl(mSpeexDecoderState, SPEEX_RESET_STATE, NULL); //??!

    mSpeexFPList.clear();

    if (mOutBuffer)
        delete[] mOutBuffer;
    mOutBuffer = NULL;
    mOutBufferSize = 0;
    mOutBufferUsedSize = 0;
    mOutBufferStart = 0;

    XCACodec::BDCUninitialize();
}
//*****************************************************************************
//
//! This function returns the current frame size from the decoder.
//!
//! This function queries the decoder for the current decode frame size in byte
//! and returns it to the caller.
//!
//! \return The current decoder frame size.
//
//*****************************************************************************
int32_t
SpeexDecodeFrameSizeGet(void)
{
    int iFrameSize;

    //
    // Return 0 if the wrong request is made.
    //
    iFrameSize = 0;

    //
    // Query the decoder for the current frame size.
    //
    speex_decoder_ctl(g_sSpeexDecoder.pvState, SPEEX_GET_FRAME_SIZE,
                      &iFrameSize);

    return(iFrameSize);
}
Exemplo n.º 29
0
/*
 * Modify codec settings.
 */
static pj_status_t  spx_codec_modify(pjmedia_codec *codec, 
				     const pjmedia_codec_param *attr )
{
    struct spx_private *spx;
    int tmp;

    spx = (struct spx_private*) codec->codec_data;

    /* VAD */
    tmp = (attr->setting.vad != 0);
    speex_encoder_ctl(spx->enc, SPEEX_SET_VAD, &tmp);
    speex_encoder_ctl(spx->enc, SPEEX_SET_DTX, &tmp);

    /* PENH */
    tmp = attr->setting.penh;
    speex_decoder_ctl(spx->dec, SPEEX_SET_ENH, &tmp);

    return PJ_SUCCESS;
}
Exemplo n.º 30
-1
AudioOutputSpeech::AudioOutputSpeech(boost::shared_ptr<ClientUser> user, MessageHandler::UDPMessageType type) : AudioOutputUser(user->qsName) {
	int err;
	p = user;
	umtType = type;

	unsigned int srate = 0;

	cCodec = NULL;
	cdDecoder = NULL;

	if (umtType != MessageHandler::UDPVoiceSpeex) {
		srate = SAMPLE_RATE;
		iFrameSize = srate / 100;

		dsSpeex = NULL;
	} else {
		speex_bits_init(&sbBits);

		dsSpeex = speex_decoder_init(speex_lib_get_mode(SPEEX_MODEID_UWB));
		int iArg=1;
		speex_decoder_ctl(dsSpeex, SPEEX_SET_ENH, &iArg);
		speex_decoder_ctl(dsSpeex, SPEEX_GET_FRAME_SIZE, &iFrameSize);
		speex_decoder_ctl(dsSpeex, SPEEX_GET_SAMPLING_RATE, &srate);
	}

	if (srate != SAMPLE_RATE)
		srs = speex_resampler_init(1, srate, SAMPLE_RATE, 3, &err);
	else
		srs = NULL;

	iOutputSize = static_cast<unsigned int>(ceilf(static_cast<float>(iFrameSize * SAMPLE_RATE) / static_cast<float>(SAMPLE_RATE)));

	iBufferOffset = iBufferFilled = iLastConsume = 0;
	bLastAlive = true;

	iMissCount = 0;
	iMissedFrames = 0;

	ucFlags = 0xFF;

	jbJitter = jitter_buffer_init(iFrameSize);
	int margin = g.s.iJitterBufferSize * iFrameSize;
	jitter_buffer_ctl(jbJitter, JITTER_BUFFER_SET_MARGIN, &margin);

	fFadeIn = new float[iFrameSize];
	fFadeOut = new float[iFrameSize];

	float mul = static_cast<float>(M_PI / (2.0 * static_cast<double>(iFrameSize)));
	for (unsigned int i=0;i<iFrameSize;++i)
		fFadeIn[i] = fFadeOut[iFrameSize-i-1] = sinf(static_cast<float>(i) * mul);
}