void Transmitter::setup(int srate, int quality, int abr, int vbr, float vbr_quality, int complexity, int vad, int dtx, int txstop) { if (recording) { recorder->end(); stop(); } SpeexMode *mode = NULL; switch (srate) { case 32000: mode = (SpeexMode *) &speex_uwb_mode; speexmode = DRTA_INFO_MODE_ULTRAWIDE; break; case 16000: mode = (SpeexMode *) &speex_wb_mode; speexmode = DRTA_INFO_MODE_WIDE; break; case 8000: mode = (SpeexMode *) &speex_nb_mode; speexmode = DRTA_INFO_MODE_NARROW; break; } if (state) speex_encoder_destroy(state); state = speex_encoder_init(mode); speex_encoder_ctl(state, SPEEX_SET_SAMPLING_RATE, &srate); speex_encoder_ctl(state, SPEEX_SET_COMPLEXITY, &complexity); if (vbr) { speex_encoder_ctl(state, SPEEX_SET_VBR, &vbr); speex_encoder_ctl(state, SPEEX_SET_VBR_QUALITY, &vbr_quality); } else { speex_encoder_ctl(state, SPEEX_SET_QUALITY, &quality); speex_encoder_ctl(state, SPEEX_SET_VAD, &vad); } if (abr) speex_encoder_ctl(state, SPEEX_SET_ABR, &abr); speex_encoder_ctl(state, SPEEX_SET_DTX, &dtx); speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &frame_size); stoptx = (int) ((srate / frame_size)*txstop); speex_bits_init(&bits); rate = srate; if (recording) { initRecorder(); go(); } }
void voice_close() { if (voice_fd != -1) { close(voice_fd); voice_fd = -1; } #if HAVE_GSM if (voice_gsm_dec) { gsm_destroy(voice_gsm_dec); voice_gsm_dec = NULL; } if (voice_gsm_enc) { gsm_destroy(voice_gsm_enc); voice_gsm_enc = NULL; } #endif #if HAVE_SPEEX if (voice_speex_enc) { speex_encoder_destroy(voice_speex_enc); voice_speex_enc = NULL; speex_bits_destroy(&speex_enc_bits); } if (voice_speex_dec) { speex_decoder_destroy(voice_speex_dec); voice_speex_dec = NULL; speex_bits_destroy(&speex_dec_bits); } #endif }
void sb_encoder_destroy(void *state) { SBEncState *st=(SBEncState*)state; speex_encoder_destroy(st->st_low); #if !(defined(VAR_ARRAYS) || defined (USE_ALLOCA)) /*speex_free_scratch(st->stack);*/ #endif speex_free(st->high); speex_free(st->h0_mem); speex_free(st->h1_mem); speex_free(st->old_lsp); speex_free(st->old_qlsp); speex_free(st->interp_qlpc); speex_free(st->pi_gain); speex_free(st->exc_rms); speex_free(st->mem_sp); speex_free(st->mem_sp2); speex_free(st->mem_sw); speex_free(st); }
AudioInput::~AudioInput() { bRunning = false; wait(); if (ceEncoder) { cCodec->celt_encoder_destroy(ceEncoder); } else if (esSpeex) { speex_bits_destroy(&sbBits); speex_encoder_destroy(esSpeex); } foreach(short *buf, qlEchoFrames) delete [] buf; if (sppPreprocess) speex_preprocess_state_destroy(sppPreprocess); if (sesEcho) speex_echo_state_destroy(sesEcho); if (srsMic) speex_resampler_destroy(srsMic); if (srsEcho) speex_resampler_destroy(srsEcho); delete [] psMic; delete [] psClean; delete [] psSpeaker; delete [] pfMicInput; delete [] pfEchoInput; delete [] pfOutput; }
static switch_status_t switch_speex_destroy(switch_codec_t *codec) { int encoding, decoding; struct speex_context *context = codec->private_info; if (!context) { return SWITCH_STATUS_FALSE; } encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE); decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE); if (encoding) { speex_bits_destroy(&context->encoder_bits); speex_encoder_destroy(context->encoder_state); } if (decoding) { speex_bits_destroy(&context->decoder_bits); speex_decoder_destroy(context->decoder_state); } codec->private_info = NULL; return SWITCH_STATUS_SUCCESS; }
void Phone::setup(int mode, int quality, int abr, int vbr, float vbr_quality, int complexity, int vad, int dtx, int txstop, int th, int ring_vol) { bool restart = recording; if (restart) stopRecorder(); if (enc_state) speex_encoder_destroy(enc_state); SpeexMode *spmode = NULL; switch (mode) { case IHU_NARROW: spmode = (SpeexMode *) &speex_nb_mode; break; case IHU_WIDE: spmode = (SpeexMode *) &speex_wb_mode; break; case IHU_ULTRAWIDE: spmode = (SpeexMode *) &speex_uwb_mode; break; } enc_state = speex_encoder_init(spmode); speex_encoder_ctl(enc_state, SPEEX_SET_COMPLEXITY, &complexity); if (vbr) { speex_encoder_ctl(enc_state, SPEEX_SET_VBR, &vbr); speex_encoder_ctl(enc_state, SPEEX_SET_VBR_QUALITY, &vbr_quality); } else { speex_encoder_ctl(enc_state, SPEEX_SET_QUALITY, &quality); speex_encoder_ctl(enc_state, SPEEX_SET_VAD, &vad); } if (abr) speex_encoder_ctl(enc_state, SPEEX_SET_ABR, &abr); speex_encoder_ctl(enc_state, SPEEX_SET_DTX, &dtx); speex_encoder_ctl(enc_state, SPEEX_GET_SAMPLING_RATE, &rate); speex_encoder_ctl(enc_state, SPEEX_GET_FRAME_SIZE, &frame_size); stoptx = txstop; speex_bits_init(&enc_bits); ring_vol = -ring_vol + 1; float vol = 0.0; if (ring_vol <= 0) vol = powf(VOL_FACTOR, (float) (ring_vol)); for (int i=0; i<SIZE_RING_32; i++) ringBuffer[i] = ((float) ring_32[i]) * vol; setThreshold(th); if (restart) startRecorder(); }
static void encode_destructor(void *arg) { struct auenc_state *st = arg; speex_bits_destroy(&st->bits); speex_encoder_destroy(st->enc); }
int AudioInput::getMaxBandwidth() { int audiorate; void *es; float f = static_cast<float>(g.s.iQuality); es = speex_encoder_init(speex_lib_get_mode(SPEEX_MODEID_WB)); speex_encoder_ctl(es,SPEEX_SET_VBR_QUALITY, &f); speex_encoder_ctl(es,SPEEX_GET_BITRATE,&audiorate); speex_encoder_destroy(es); audiorate /= 400/g.s.iFramesPerPacket; // Overhead audiorate += 20 + 8 + 4 + 3 + 1 + 2; if (g.s.bTransmitPosition) audiorate += 12; if (NetworkConfig::TcpModeEnabled()) audiorate += 12; audiorate = (audiorate * 50) / g.s.iFramesPerPacket; return audiorate; }
AudioInput::~AudioInput() { bRunning = false; wait(); speex_bits_destroy(&sbBits); speex_encoder_destroy(esEncState); mumble_drft_clear(&fftTable); jitter_buffer_destroy(jb); if (sppPreprocess) speex_preprocess_state_destroy(sppPreprocess); if (sesEcho) speex_echo_state_destroy(sesEcho); if (srsMic) speex_resampler_destroy(srsMic); if (srsEcho) speex_resampler_destroy(srsEcho); delete [] psMic; delete [] psSpeaker; delete [] psClean; if (pfMicInput) delete [] pfMicInput; if (pfEchoInput) delete [] pfEchoInput; if (pfOutput) delete [] pfOutput; }
int tdav_codec_speex_deinit(tdav_codec_speex_t* self) { if(self){ if(self->decoder.state){ speex_decoder_destroy(self->decoder.state); self->decoder.state = tsk_null; } speex_bits_destroy(&self->decoder.bits); if(self->decoder.buffer){ TSK_FREE(self->decoder.buffer); self->decoder.size = 0; } if(self->encoder.state){ speex_encoder_destroy(self->encoder.state); self->encoder.state = tsk_null; } speex_bits_destroy(&self->encoder.bits); self->encoder.size = 0; return 0; } else{ TSK_DEBUG_ERROR("Invalid parameter"); return -1; } }
int main(int argc, char **argv) { char *inFile; FILE *fin; short in[FRAME_SIZE]; float input[FRAME_SIZE]; char cbits[2000]; int nbBytes; /*Holds the state of the encoder*/ void *state; /*Holds bits so they can be read and written to by the Speex routines*/ SpeexBits bits; int i, tmp; /*Create a new encoder state in narrowband mode*/ state = speex_encoder_init(&speex_nb_mode); //printf("inited\n"); /*Set the quality to 8 (15 kbps)*/ tmp=8; speex_encoder_ctl(state, SPEEX_SET_QUALITY, &tmp); inFile = argv[1]; fin = fopen(inFile, "r"); /*Initialization of the structure that holds the bits*/ speex_bits_init(&bits); while (1) { /*Read a 16 bits/sample audio frame*/ fread(in, sizeof(short), FRAME_SIZE, fin); if (feof(fin)) break; /*Copy the 16 bits values to float so Speex can work on them*/ for (i=0;i<FRAME_SIZE;i++) input[i]=in[i]; /*Flush all the bits in the struct so we can encode a new frame*/ speex_bits_reset(&bits); /*Encode the frame*/ speex_encode(state, input, &bits); /*Copy the bits to an array of char that can be written*/ nbBytes = speex_bits_write(&bits, cbits, 2000); /*Write the size of the frame first. This is what sampledec expects but it's likely to be different in your own application*/ fwrite(&nbBytes, sizeof(int), 1, stdout); /*Write the compressed data*/ fwrite(cbits, 1, nbBytes, stdout); } /*Destroy the encoder state*/ speex_encoder_destroy(state); /*Destroy the bit-packing struct*/ speex_bits_destroy(&bits); fclose(fin); return 0; }
static void codec_drv_stop(ErlDrvData handle) { codec_data *d = (codec_data *) handle; speex_bits_destroy(&d->bits); speex_encoder_destroy(d->estate); speex_decoder_destroy(d->dstate); driver_free((char*)handle); }
void SpeexEncoder::Close() { speex_encoder_destroy(st); speex_bits_destroy(&bits); ogg_stream_clear(&os); fclose(fout); closed = true; }
JNIEXPORT void JNICALL FUNCSPEEX(releaseEncode)(JNIEnv* env, jobject obj) { speex_bits_destroy(&ebits); if (enc_state != NULL) { speex_encoder_destroy(enc_state); enc_state = NULL; } }
static void enc_uninit(MSFilter *f){ SpeexEncState *s=(SpeexEncState*)f->data; if (s==NULL) return; ms_bufferizer_destroy(s->bufferizer); if (s->state!=NULL) speex_encoder_destroy(s->state); ms_free(s); }
static int speex_encode_close(AVCodecContext *avctx) { SpeexContext *s = avctx->priv_data; speex_encoder_destroy(s->st); speex_bits_destroy(&s->bits); return 0; }
void ph_speex_enc_cleanup(void *ctx) { struct speexenc *speex = (struct speexenc *)ctx; speex_bits_destroy(&speex->bits); speex_encoder_destroy(speex->st); free(ctx); }
static void lintospeex_destroy(struct ast_trans_pvt *arg) { struct speex_coder_pvt *pvt = arg->pvt; #ifdef _SPEEX_TYPES_H if (preproc) speex_preprocess_state_destroy(pvt->pp); #endif speex_encoder_destroy(pvt->speex); speex_bits_destroy(&pvt->bits); }
int spx_destroy(int handle ){ speex_encode_union_t * speex_encode_u = (speex_encode_union_t *)handle; /*Destroy the encoder state*/ speex_encoder_destroy(speex_encode_u->state); /*Destroy the bit-packing struct*/ speex_bits_destroy(&speex_encode_u->bits); free(speex_encode_u); }
SpeexEncoder::~SpeexEncoder(void) { /* Stop the audio encoding thread: */ encodingThread.cancel(); encodingThread.join(); /* Release all allocated resources: */ speex_bits_destroy(&speexBits); delete[] recordingBuffer; speex_encoder_destroy(speexState); }
JNIEXPORT void JNICALL Java_com_speex_encode_Speex_close (JNIEnv *env, jobject obj) { if (--codec_open != 0) return; speex_bits_destroy(&ebits); speex_bits_destroy(&dbits); speex_decoder_destroy(dec_state); speex_encoder_destroy(enc_state); }
extern "C" JNIEXPORT void JNICALL Java_com_mogujie_tt_support_audio_Speex_close( JNIEnv *env, jobject obj) { if (--codec_open != 0) return; speex_bits_destroy(&ebits); speex_bits_destroy(&dbits); speex_decoder_destroy(dec_state); speex_encoder_destroy(enc_state); }
extern "C" JNIEXPORT void JNICALL Java_com_haitou_xiaoyoupai_imservice_support_audio_Speex_close( JNIEnv *env, jobject obj) { if (--codec_open != 0) return; speex_bits_destroy(&ebits); speex_bits_destroy(&dbits); speex_decoder_destroy(dec_state); speex_encoder_destroy(enc_state); }
OsStatus MpeSipxSpeexUWb::freeEncode(void) { if (mpEncoderState) { speex_encoder_destroy(mpEncoderState); mpEncoderState = NULL; speex_bits_destroy(&mBits); } return OS_SUCCESS; }
Transmitter::~Transmitter(void) { if (out) free(out); if (buffer) free(buffer); if (prebuffer) free(prebuffer); if (state) speex_encoder_destroy(state); speex_bits_destroy(&bits); }
bool SpeexPlugin::destroyEncoder() throw(OperationNotPerfomedException) { if (!encoder) return false; speex_encoder_destroy(encoder->state); speex_bits_destroy(&encoder->bits); delete encoder; encoder = 0; return true; }
void destroy_speex_encoder() { if (gEncoderState != NULL) { speex_encoder_destroy(gEncoderState); speex_bits_destroy(&gEncoderBits); gEncoderState = NULL; } if (gPreprocessState) { speex_preprocess_state_destroy(gPreprocessState); gPreprocessState = 0; } }
void RakVoice::FreeChannelMemory(unsigned index, bool removeIndex) { VoiceChannel *channel; channel=voiceChannels[index]; speex_encoder_destroy(channel->enc_state); speex_decoder_destroy(channel->dec_state); speex_preprocess_state_destroy((SpeexPreprocessState*)channel->pre_state); rakFree_Ex(channel->incomingBuffer, __FILE__, __LINE__ ); rakFree_Ex(channel->outgoingBuffer, __FILE__, __LINE__ ); RakNet::OP_DELETE(channel, __FILE__, __LINE__); if (removeIndex) voiceChannels.RemoveAtIndex(index); }
void qSpeexDestroyHandle(QSpeexCodecPtr handle) { if (!handle) return; speex_encoder_destroy(handle->encState); speex_decoder_destroy(handle->decState); speex_bits_destroy(&handle->encBits); speex_bits_destroy(&handle->decBits); speex_jitter_destroy(&handle->jitter); free(handle); }
static GstStateChangeReturn gst_speex_enc_change_state (GstElement * element, GstStateChange transition) { GstSpeexEnc *enc = GST_SPEEX_ENC (element); GstStateChangeReturn res; switch (transition) { case GST_STATE_CHANGE_NULL_TO_READY: enc->tags = gst_tag_list_new (); break; case GST_STATE_CHANGE_READY_TO_PAUSED: speex_bits_init (&enc->bits); enc->frameno = 0; enc->frameno_out = 0; enc->samples_in = 0; enc->start_ts = GST_CLOCK_TIME_NONE; enc->next_ts = GST_CLOCK_TIME_NONE; enc->granulepos_offset = 0; break; case GST_STATE_CHANGE_PAUSED_TO_PLAYING: /* fall through */ default: break; } res = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); if (res == GST_STATE_CHANGE_FAILURE) return res; switch (transition) { case GST_STATE_CHANGE_PLAYING_TO_PAUSED: break; case GST_STATE_CHANGE_PAUSED_TO_READY: enc->setup = FALSE; enc->header_sent = FALSE; if (enc->state) { speex_encoder_destroy (enc->state); enc->state = NULL; } speex_bits_destroy (&enc->bits); break; case GST_STATE_CHANGE_READY_TO_NULL: gst_tag_list_free (enc->tags); enc->tags = NULL; default: break; } return res; }