这篇教程C++ speex_bits_read_from函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中speex_bits_read_from函数的典型用法代码示例。如果您正苦于以下问题:C++ speex_bits_read_from函数的具体用法?C++ speex_bits_read_from怎么用?C++ speex_bits_read_from使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了speex_bits_read_from函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: decodevoid decode(int header) { FILE * fin = fopen("audiopacket2.spx", "r"); FILE * fout = fopen("decoded_audio.raw", "w"); int i; short out[FRAME_SIZE]; float output[FRAME_SIZE]; char cbits[331-20]; SpeexBits bits; void * state; state = speex_decoder_init(&speex_nb_mode); speex_bits_init(&bits); while(1) { if(feof(fin)) break; /* on lit 307 octets (un paquet) vers cbits */ fread(cbits, 1, 331-20, fin); /* on le copie vers une structure bit-stream */ speex_bits_read_from(&bits, cbits+header, 331-20-header); /* on decode */ speex_decode(state, &bits, output); for(i=0 ; i< FRAME_SIZE ; i++) out[i]= output[i]; fwrite(out, sizeof(short), FRAME_SIZE, fout); }}
开发者ID:Youx,项目名称:soliloque-client,代码行数:31,
示例2: libspeex_decode_framestatic int libspeex_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt){ const uint8_t *buf = avpkt->data; int buf_size = avpkt->size; LibSpeexContext *s = avctx->priv_data; int16_t *output = data, *end; int i, num_samples; num_samples = s->frame_size * avctx->channels; end = output + *data_size / sizeof(*output); speex_bits_read_from(&s->bits, buf, buf_size); for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) { int ret = speex_decode_int(s->dec_state, &s->bits, output); if (ret <= -2) { av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame./n"); return -1; } else if (ret == -1) // end of stream break; if (avctx->channels == 2) speex_decode_stereo_int(output, s->frame_size, &s->stereo); output += num_samples; } avctx->frame_size = s->frame_size * i; *data_size = avctx->channels * avctx->frame_size * sizeof(*output); return buf_size;}
开发者ID:FreddyPulikottil,项目名称:ffmpeg-msvc,代码行数:34,
示例3: voice_playint voice_play(const char *buf, int length, int codec){ if (length <= 0) return 0; if (codec == EKG_CODEC_SPEEX) {#if HAVE_SPEEX spx_int16_t speex_output[320]; speex_bits_read_from(&speex_dec_bits, buf, length); speex_decode_int(voice_speex_dec, &speex_dec_bits, speex_output); /* XXX, != 0 return? */ if (write(voice_fd, speex_output, sizeof(speex_output)) != sizeof(speex_output)) return -1; return 0;#else printf("voice_play() received speex packet, but HAVE_SPEEX/n"); return -1;#endif } if (codec == EKG_CODEC_GSM) {#if HAVE_GSM const int ramki_dwie = 33 + 33; gsm_signal gsm_output[160]; const char *pos = buf; while (pos <= (buf + length - ramki_dwie)) { switch (codec) { case EKG_CODEC_GSM: if (gsm_decode(voice_gsm_dec, (unsigned char *) pos, gsm_output)) return -1; pos += 33; break; } if (write(voice_fd, gsm_output, 320) != 320) return -1; switch (codec) { case EKG_CODEC_GSM: if (gsm_decode(voice_gsm_dec, (unsigned char *) pos, gsm_output)) return -1; pos += 33; break; } if (write(voice_fd, gsm_output, 320) != 320) return -1; } return 0;#else printf("voice_play() received gsm packet, but HAVE_GSM/n"); return -1;#endif } return -1;}
开发者ID:canthar,项目名称:libgadu,代码行数:60,
示例4: decodeSPEEXsigned short* decodeSPEEX(BYTE *data){ speex_bits_read_from(&obits, (char*)data, SPEEX_SIZE); speex_decode_int(pDec, &obits, out_short); speex_bits_reset(&obits); return (signed short*)(&out_short[0]);}
开发者ID:SrgShv,项目名称:speex_stm32,代码行数:7,
示例5: speex_bits_read_from/***************************************************************************** * DecodePacket: decodes a Speex packet. *****************************************************************************/static block_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket ){ decoder_sys_t *p_sys = p_dec->p_sys; if( p_oggpacket->bytes ) { /* Copy Ogg packet to Speex bitstream */ speex_bits_read_from( &p_sys->bits, (char *)p_oggpacket->packet, p_oggpacket->bytes ); p_sys->i_frame_in_packet = 0; } /* Decode one frame at a time */ if( p_sys->i_frame_in_packet < p_sys->p_header->frames_per_packet ) { block_t *p_aout_buffer; if( p_sys->p_header->frame_size == 0 ) return NULL; p_aout_buffer = decoder_NewAudioBuffer( p_dec, p_sys->p_header->frame_size ); if( !p_aout_buffer ) { return NULL; } switch( speex_decode_int( p_sys->p_state, &p_sys->bits, (int16_t *)p_aout_buffer->p_buffer ) ) { case -2: msg_Err( p_dec, "decoding error: corrupted stream?" ); case -1: /* End of stream */ return NULL; } if( speex_bits_remaining( &p_sys->bits ) < 0 ) { msg_Err( p_dec, "decoding overflow: corrupted stream?" ); } if( p_sys->p_header->nb_channels == 2 ) speex_decode_stereo_int( (int16_t *)p_aout_buffer->p_buffer, p_sys->p_header->frame_size, &p_sys->stereo ); /* Date management */ p_aout_buffer->i_pts = date_Get( &p_sys->end_date ); p_aout_buffer->i_length = date_Increment( &p_sys->end_date, p_sys->p_header->frame_size ) - p_aout_buffer->i_pts; p_sys->i_frame_in_packet++; return p_aout_buffer; } else { return NULL; }}
开发者ID:12307,项目名称:VLC-for-VS2010,代码行数:63,
示例6: Speex_2_Pcm16int Speex_2_Pcm16( unsigned char* out_buf, unsigned char* in_buf, unsigned int size, unsigned int channels, unsigned int rate, long h_codec ){ SpeexState* ss; short* pcm = (short*) out_buf; int frames_out = 0; ss = (SpeexState*) h_codec; if (!ss || channels!=1) return -1; speex_bits_read_from(&ss->decoder.bits, (char*)in_buf, size); /* We don't know where frame boundaries are, but the minimum frame size is 43 */ while (speex_bits_remaining(&ss->decoder.bits)>40) { int ret; ret = speex_decode_int(ss->decoder.state, &ss->decoder.bits, pcm); pcm+= ss->frame_size; if (ret==-2) { ERROR("while calling speex_decode/n"); return -1; } if (ret==-1) break; frames_out++; } return frames_out*ss->frame_size*sizeof(short);}
开发者ID:Chocolatbuddha,项目名称:sems,代码行数:34,
示例7: speex_jitter_getint 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;}
开发者ID:SergeStinckwich,项目名称:openqwaq,代码行数:60,
示例8: mainint 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;}
开发者ID:Distrotech,项目名称:speex,代码行数:60,
示例9: switch_speex_decodestatic switch_status_t switch_speex_decode(switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag){ struct speex_context *context = codec->private_info; short *buf; if (!context) { return SWITCH_STATUS_FALSE; } buf = decoded_data; if (*flag & SWITCH_CODEC_FLAG_SILENCE) { speex_decode_int(context->decoder_state, NULL, buf); } else { speex_bits_read_from(&context->decoder_bits, (char *) encoded_data, (int) encoded_data_len); speex_decode_int(context->decoder_state, &context->decoder_bits, buf); } *decoded_data_len = codec->implementation->decoded_bytes_per_packet; return SWITCH_STATUS_SUCCESS;}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:26,
示例10: qSpeexDecodeint qSpeexDecode(QSpeexCodecPtr handle, void* inputBytes, int inputSize, void* outputSamples, int outputSize){ int offset, remaining; short *out = (short*)outputSamples; /* If there is no input to read, we certainly can't read it. */ if (inputBytes != NULL) { speex_bits_read_from(&handle->decBits, inputBytes, inputSize); } for (offset=0; offset<outputSize; offset+=handle->frameSize) { if (inputBytes != NULL) { if (!speex_bits_remaining(&handle->decBits)) { // Ran out of input data return 2; } speex_decode_int(handle->decState, &handle->decBits, out+offset); } else { /* Extrapolate output-buffer based on current decoder state. */ speex_decode_int(handle->decState, NULL, out+offset); } } remaining = speex_bits_remaining(&handle->decBits); if (remaining >= 8) { /* If less than a byte is left over, that's OK. */ fprintf(stderr, "qSpeexDecode(): %d bits left over/n", remaining); return 1; // Still have encoded bits left over } else return 0; // A-OK!!}
开发者ID:JupiterSmalltalk,项目名称:openqwaq,代码行数:31,
示例11: decode_audiostatic 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;}
开发者ID:Gamer125,项目名称:wiibrowser,代码行数:34,
|