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 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 }
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; } }
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); }
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); }
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); }
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 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; }
static struct spx_data *spx_open_internal (struct io_stream *stream) { struct spx_data *data; SpeexStereoState stereo = SPEEX_STEREO_STATE_INIT; data = (struct spx_data *)xmalloc (sizeof(struct spx_data)); decoder_error_init (&data->error); data->stream = stream; data->st = NULL; data->stereo = stereo; data->header = NULL; data->output = NULL; data->comment_packet = NULL; data->bitrate = -1; ogg_sync_init (&data->oy); speex_bits_init (&data->bits); if (!read_speex_header(data)) { ogg_sync_clear (&data->oy); speex_bits_destroy (&data->bits); data->ok = 0; } else data->ok = 1; return data; }
void destroy_speex_decoder() { if (gDecoderState != NULL) { speex_decoder_destroy(gDecoderState); speex_bits_destroy(&gDecoderBits); gDecoderState = NULL; } }
static int encode_speex(int16_t * input_frame, uint8_t nbframes, char * output, int bitrate) { int i, bytesToWrite, nbBytes; SpeexBits bits; void * state; long long total; speex_bits_init(&bits); state = speex_encoder_init(&speex_nb_mode); speex_encoder_ctl(state, SPEEX_SET_QUALITY, &bitrate); speex_bits_reset(&bits); total = 0; for(i=0;i<5*160;i++) { total += input_frame[i]; } total /= (5*160); if(abs(total) < 10) return 0; for(i=0;i<5;i++) { speex_encode_int(state, input_frame + (i*160), &bits); } bytesToWrite = speex_bits_nbytes(&bits); nbBytes = speex_bits_write(&bits, output, bytesToWrite); speex_bits_destroy(&bits); speex_decoder_destroy(state); return nbBytes; }
static void speextolin_destroy(struct ast_trans_pvt *arg) { struct speex_coder_pvt *pvt = arg->pvt; speex_decoder_destroy(pvt->speex); speex_bits_destroy(&pvt->bits); }
static void gst_speex_dec_reset (GstSpeexDec * dec) { dec->packetno = 0; dec->frame_size = 0; dec->frame_duration = 0; dec->mode = NULL; free (dec->header); dec->header = NULL; speex_bits_destroy (&dec->bits); speex_bits_set_bit_buffer (&dec->bits, NULL, 0); gst_buffer_replace (&dec->streamheader, NULL); gst_buffer_replace (&dec->vorbiscomment, NULL); if (dec->stereo) { speex_stereo_state_destroy (dec->stereo); dec->stereo = NULL; } if (dec->state) { speex_decoder_destroy (dec->state); dec->state = NULL; } }
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 void decode_destructor(void *arg) { struct audec_state *st = arg; speex_bits_destroy(&st->bits); speex_decoder_destroy(st->dec); }
static void encode_destructor(void *arg) { struct auenc_state *st = arg; speex_bits_destroy(&st->bits); speex_encoder_destroy(st->enc); }
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; }
void SpeexEncoder::Close() { speex_encoder_destroy(st); speex_bits_destroy(&bits); ogg_stream_clear(&os); fclose(fout); closed = true; }
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); }
JNIEXPORT void JNICALL FUNCSPEEX(releaseDecode)(JNIEnv* env, jobject obj) { speex_bits_destroy(&dbits); if (dec_state != NULL) { speex_decoder_destroy(dec_state); dec_state = NULL; } }
void speex_destroy(long handle) { SpeexState* ss = (SpeexState*) handle; DBG("SpeexDestroy for handle %ld\n", handle); if (!ss) return; speex_encoder_destroy(ss->encoder.state); speex_bits_destroy(&ss->encoder.bits); speex_decoder_destroy(ss->decoder.state); speex_bits_destroy(&ss->decoder.bits); free(ss); }
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; } }
void ph_speex_dec_cleanup(void *ctx) { struct speexdec *speex = (struct speexdec *)ctx; speex_bits_destroy(&speex->bits); speex_decoder_destroy(speex->st); free(ctx); }
static av_cold int libspeex_decode_close(AVCodecContext *avctx) { LibSpeexContext *s = avctx->priv_data; speex_bits_destroy(&s->bits); speex_decoder_destroy(s->dec_state); return 0; }
static int speex_decode_close(AVCodecContext *avctx) { SpeexContext *s = avctx->priv_data; speex_decoder_destroy(s->st); speex_bits_destroy(&s->bits); return 0; }
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); }
static void uninit(sh_audio_t *sh) { context_t *ctx = sh->context; if (ctx) { speex_bits_destroy(&ctx->bits); speex_decoder_destroy(ctx->dec_context); free(ctx->hdr); free(ctx); } ctx = NULL; }
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); }
JNIEXPORT void JNICALL Java_org_thoughtcrime_redphone_codec_SpeexCodec_closeSpeex (JNIEnv *env, jobject obj ){ if( !initialized ) { logv( env, "tried to shut down speex before initialization" ); return; } logv( env, "speex shutdown" ); speex_bits_destroy( &enc_bits ); speex_bits_destroy( &dec_bits ); logv( env, "bits destroyed" ); speex_encoder_destroy( enc ); speex_decoder_destroy( dec ); // jitter_buffer_destroy( jitter ); logv( env, "codecs destroyed" ); }