本文整理汇总了C++中speex_bits_reset函数的典型用法代码示例。如果您正苦于以下问题:C++ speex_bits_reset函数的具体用法?C++ speex_bits_reset怎么用?C++ speex_bits_reset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了speex_bits_reset函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: speex_bits_reset
JNIEXPORT jint Java_com_audio_Speex_encode
(JNIEnv *env, jobject obj, jshortArray lin, jint offset, jbyteArray encoded, jint size) {
jshort buffer[enc_frame_size];
jbyte output_buffer[enc_frame_size];
int nsamples = (size-1)/enc_frame_size + 1;
int i, tot_bytes = 0, encode_bytes = 0;
if (!codec_open)
return 0;
//LOGI("jni_encode size:%d, times:%d", size, nsamples);
speex_bits_reset(&ebits);
for (i = 0; i < nsamples; i++) {
env->GetShortArrayRegion(lin, offset + i*enc_frame_size, enc_frame_size, buffer);
speex_bits_reset(&ebits);
speex_encode_int(enc_state, buffer, &ebits);
//env->GetShortArrayRegion(lin, offset, enc_frame_size, buffer);
//speex_encode_int(enc_state, buffer, &ebits);
encode_bytes = speex_bits_write(&ebits, (char *)output_buffer,
enc_frame_size);
env->SetByteArrayRegion(encoded, tot_bytes, encode_bytes,
output_buffer);
tot_bytes += encode_bytes;
}
return (jint)tot_bytes;
}
开发者ID:winwincoder,项目名称:Documents,代码行数:29,代码来源:speex_jni.cpp
示例2: decodeSPEEX
signed 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,代码来源:codec.c
示例3: while
bool NetworkSoundRecorder::onProcessSamples(const cpp3ds::Int16 *samples, std::size_t sampleCount)
{
m_samples.insert(m_samples.end(), samples, samples + sampleCount);
std::vector<char> encodedSamples;
char out[m_frameSize*2];
int size = m_samples.size();
int i = 0;
while (size >= m_frameSize)
{
spx_int16_t* audioFrame = &m_samples[0] + i * m_frameSize;
speex_preprocess_run(m_speexPreprocessState, audioFrame);
speex_bits_reset(&m_speexBits);
speex_encode_int(m_speexState, audioFrame, &m_speexBits);
char bytes = speex_bits_write(&m_speexBits, out, sizeof(out));
encodedSamples.push_back(bytes);
encodedSamples.insert(encodedSamples.end(), out, out + bytes);
i++;
size -= m_frameSize;
}
std::vector<cpp3ds::Int16>(m_samples.end() - size, m_samples.end()).swap(m_samples);
std::cout << "size: " << sampleCount * sizeof(cpp3ds::Int16) << std::endl;
m_context->client.sendVoiceData(m_context->name.toAnsiString(), &encodedSamples[0], encodedSamples.size());
return true;
}
开发者ID:Cruel,项目名称:DrawAttack,代码行数:34,代码来源:NetworkSoundRecorder.cpp
示例4: SpeexEncode
//*****************************************************************************
//
//! Encode a single frame of speex encoded audio.
//!
//! \param pui16InBuffer is the buffer that contains the raw PCM audio.
//! \param ui32InSize is the number of valid bytes in the \e pui16InBuffer
//! buffer.
//! \param pui8OutBuffer is a pointer to the buffer to store the encoded audio.
//! \param ui32OutSize is the size of the buffer pointed to by the
//! \e pui8OutBuffer pointer.
//!
//! This function will take a buffer of PCM audio and encode it into a frame
//! of speex compressed audio. The \e pui16InBuffer parameter should contain
//! a single frame of PCM audio. The \e pui8OutBuffer will contain the encoded
//! audio after returning from this function.
//!
//! \return This function returns the number of encoded bytes in the
//! \e pui8OutBuffer parameter.
//
//*****************************************************************************
int32_t
SpeexEncode(int16_t *pui16InBuffer, uint32_t ui32InSize,
uint8_t *pui8OutBuffer, uint32_t ui32OutSize)
{
int32_t i32Bytes;
//
// Reset the bit stream before encoding a new frame.
//
speex_bits_reset(&g_sSpeexEncoder.sBits);
//
// Encode a single frame.
//
speex_encode_int(g_sSpeexEncoder.pvState, pui16InBuffer,
&g_sSpeexEncoder.sBits);
//
// Read the PCM data from the encoded bit stream.
//
i32Bytes = speex_bits_write(&g_sSpeexEncoder.sBits, (char *)pui8OutBuffer,
ui32OutSize);
//
// Return the number of bytes in the PCM data.
//
return(i32Bytes);
}
开发者ID:GuillaumeGalasso,项目名称:Embedded_Systems--Shape_The_World,代码行数:48,代码来源:speexlib.c
示例5: Pcm16_2_Speex
int Pcm16_2_Speex( 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*) in_buf;
char* buffer = (char*)out_buf;
div_t blocks;
ss = (SpeexState*) h_codec;
if (!ss || channels!=1)
return -1;
blocks = div(size>>1, ss->frame_size);
if (blocks.rem) {
ERROR("Pcm16_2_Speex: not integral number of blocks %d.%d\n",
blocks.quot, blocks.rem);
return -1;
}
/* For each chunk of ss->frame_size bytes, encode a single frame */
speex_bits_reset(&ss->encoder.bits);
while (blocks.quot--) {
speex_encode_int(ss->encoder.state, pcm, &ss->encoder.bits);
pcm += ss->frame_size;
}
buffer += speex_bits_write(&ss->encoder.bits, buffer, AUDIO_BUFFER_SIZE);
return buffer - (char*)out_buf;
}
开发者ID:Chocolatbuddha,项目名称:sems,代码行数:31,代码来源:speex.c
示例6: spx_encode_frame
int spx_encode_frame(int handle ,short *const pcm_data ,char *speex_data){
// char cbits[200];
float input[FRAME_SIZE];
speex_encode_union_t * speex_encode_u = (speex_encode_union_t *)handle;
/*Flush all the bits in the struct so we can encode a new frame*/
speex_bits_reset(&speex_encode_u->bits);
/*Encode the frame*/
// memcpy(input,pcm_data,FRAME_SIZE*2);
int i;
for (i = 0; i < FRAME_SIZE; i++)
input[i] = pcm_data[i];
speex_encode(speex_encode_u->state, input, &speex_encode_u->bits);
////write rtp packet header!!!!!RTP HEADER
//memcpy(speex_data ,&speex_encode_u->rtp_header ,RTP_HEADER_SIZE);
///*Copy the bits to an array of char that can be written*/
//int nbBytes = speex_bits_write(&speex_encode_u->bits, &speex_data[RTP_HEADER_SIZE], 38);
//fwrite(&speex_data[RTP_HEADER_SIZE] ,1 ,38 ,fp_speex_send);
int nbBytes = speex_bits_write(&speex_encode_u->bits, speex_data, 38);
fwrite(speex_data ,1 ,38 ,fp_speex_send);
printf("after speex_encode ,write nbBytes = %d to file !\n" ,nbBytes);
return 0;
}
开发者ID:chris-magic,项目名称:voice_processing,代码行数:27,代码来源:speex_encode.cpp
示例7: encode
//function encodes input buffer, stores in output buffer, return number of compressed bytes
int encode(char* in, char* out, int max_bytes){
int nbBytes; //track the size of compressed buffer
speex_bits_reset(&enc_bits); //Flush the struct's bits and prepare for next frame
speex_encode_int(enc_state, (short*)in, &enc_bits); //encode the input
int num_bytes = speex_bits_write(&enc_bits, out, max_bytes); //copy the encoded bytes to output stream
return num_bytes; //return the length of the compressed buffer
}
开发者ID:jpanikulam,项目名称:visar,代码行数:8,代码来源:encode.c
示例8: Java_com_haitou_xiaoyoupai_imservice_support_audio_Speex_encode
extern "C" JNIEXPORT jint JNICALL Java_com_haitou_xiaoyoupai_imservice_support_audio_Speex_encode(
JNIEnv *env, jobject obj, jshortArray lin, jint offset,
jbyteArray encoded, jint size) {
jshort buffer[enc_frame_size];
jbyte output_buffer[enc_frame_size];
int nsamples = (size - 1) / enc_frame_size + 1;
int i, tot_bytes = 0;
if (!codec_open)
return 0;
speex_bits_reset(&ebits);
for (i = 0; i < nsamples; i++) {
env->GetShortArrayRegion(lin, offset + i * enc_frame_size,
enc_frame_size, buffer);
speex_encode_int(enc_state, buffer, &ebits);
}
//env->GetShortArrayRegion(lin, offset, enc_frame_size, buffer);
//speex_encode_int(enc_state, buffer, &ebits);
tot_bytes = speex_bits_write(&ebits, (char *) output_buffer,
enc_frame_size);
env->SetByteArrayRegion(encoded, 0, tot_bytes, output_buffer);
return (jint) tot_bytes;
}
开发者ID:treejames,项目名称:FreshMAn-Task,代码行数:28,代码来源:speex_jni.cpp
示例9: encode_speex
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;
}
开发者ID:Youx,项目名称:soliloque-client,代码行数:29,代码来源:encoder.c
示例10: ms_speex_dec_process
void ms_speex_dec_process(MSSpeexDec *obj)
{
MSFifo *outf=obj->outf[0];
MSQueue *inq=obj->inq[0];
gint16 *output;
gint gran=obj->frame_size*2;
gint i;
MSMessage *m;
g_return_if_fail(inq!=NULL);
g_return_if_fail(outf!=NULL);
m=ms_queue_get(inq);
g_return_if_fail(m!=NULL);
speex_bits_reset(&obj->bits);
ms_fifo_get_write_ptr(outf,gran,(void**)&output);
g_return_if_fail(output!=NULL);
if (m->data!=NULL){
speex_bits_read_from(&obj->bits,m->data,m->size);
/* decode */
speex_decode_int(obj->speex_state,&obj->bits,(short*)output);
}else{
/* we have a missing packet */
speex_decode_int(obj->speex_state,NULL,(short*)output);
}
ms_message_destroy(m);
}
开发者ID:serghei,项目名称:kde3-kdenetwork,代码行数:29,代码来源:msspeexdec.c
示例11: speex_bits_nbytes
void AudioInput::flushCheck() {
if (bPreviousVoice && iFrames < g.s.iFramesPerPacket)
return;
int flags = 0;
if (g.iAltSpeak > 0)
flags += MessageSpeex::AltSpeak;
if (g.s.lmLoopMode == Settings::Server)
flags += MessageSpeex::LoopBack;
if (! bPreviousVoice)
flags += MessageSpeex::EndSpeech;
flags += (iFrames - 1) << 4;
int len = speex_bits_nbytes(&sbBits);
QByteArray qba(len + 1, 0);
qba[0] = static_cast<unsigned char>(flags);
speex_bits_write(&sbBits, qba.data() + 1, len);
MessageSpeex msPacket;
msPacket.qbaSpeexPacket = qba;
msPacket.iSeq = iFrameCounter;
if (g.s.lmLoopMode == Settings::Local) {
LoopPlayer::lpLoopy.addFrame(qba, msPacket.iSeq);
} else if (g.sh) {
g.sh->sendMessage(&msPacket);
}
iFrames = 0;
speex_bits_reset(&sbBits);
}
开发者ID:ArminW,项目名称:re-whisper,代码行数:34,代码来源:AudioInput.cpp
示例12: Java_org_thoughtcrime_redphone_codec_SpeexCodec_encode
JNIEXPORT jint JNICALL Java_org_thoughtcrime_redphone_codec_SpeexCodec_encode (JNIEnv *env, jobject obj, jshortArray decArr, jbyteArray encArr, jint rawLen ){
if( !initialized ) {
logv( env, "tried to encode without initializing" );
return -1;
}
// logv( env, "entered encode %d", rawLen );
// logv( env, "encoding %d samples", rawLen );
jshort *raw_stream = env->GetShortArrayElements( decArr, NULL );
speex_bits_reset( &enc_bits );
// logv( env, "bits reset" );
// speex_preprocess_run( prepState, (spx_int16_t *)raw_stream );
speex_encode_int( enc, (spx_int16_t *)raw_stream, &enc_bits );
// logv( env, "encode complete" );
env->ReleaseShortArrayElements( decArr, raw_stream, JNI_ABORT );
// logv( env, "writing up to %d bytes to buffer", enc_frame_size );
int nbytes = speex_bits_write( &enc_bits, enc_buffer, enc_frame_size );
// logv( env, "wrote %d bytes to buffer", nbytes );
env->SetByteArrayRegion( encArr, 0, nbytes, (jbyte*)enc_buffer );
// logv( env, "wrote back to java buffer" );
return (jint)nbytes;
}
开发者ID:3141592653589793,项目名称:RedPhone,代码行数:31,代码来源:SpeexCodec.cpp
示例13: speex_encode_frame
static int speex_encode_frame(AVCodecContext *avctx,
unsigned char *frame, int buf_size, void *data)
{
SpeexContext *s = avctx->priv_data;
int bytes_written = 0;
if (avctx->channels == 2)
speex_encode_stereo_int(data, avctx->frame_size, &s->bits);
speex_encode_int(s->st, data, &s->bits);
//speex_bits_insert_terminator(&s->bits);
if (!(avctx->flags2 & CODEC_FLAG2_NO_OUTPUT))
{
bytes_written = speex_bits_write(&s->bits, frame, buf_size);
}
speex_bits_reset(&s->bits);
if (avctx->debug & FF_DEBUG_BITSTREAM)
{
av_log(avctx, AV_LOG_DEBUG, "Speex: encoded speex frame (%d bytes total, framesize: %d)\n",
bytes_written, avctx->frame_size);
}
return bytes_written;
}
开发者ID:paranojik,项目名称:multitv,代码行数:28,代码来源:speex.c
示例14: tdav_codec_speex_encode
tsk_size_t tdav_codec_speex_encode(tmedia_codec_t* self, const void* in_data, tsk_size_t in_size, void** out_data, tsk_size_t* out_max_size)
{
tdav_codec_speex_t* speex = (tdav_codec_speex_t*)self;
tsk_size_t outsize = 0;
if(!self || !in_data || !in_size || !out_data){
TSK_DEBUG_ERROR("Invalid parameter");
return 0;
}
speex_bits_reset(&speex->encoder.bits);
speex_encode_int(speex->encoder.state, (spx_int16_t*)in_data, &speex->encoder.bits);
if(*out_max_size <speex->encoder.size){
if((*out_data = tsk_realloc(*out_data, speex->encoder.size))){
*out_max_size = speex->encoder.size;
}
else{
*out_max_size = 0;
return 0;
}
}
outsize = speex_bits_write(&speex->encoder.bits, *out_data, speex->encoder.size/2);
return outsize;
}
开发者ID:SayCV,项目名称:doubango,代码行数:27,代码来源:tdav_codec_speex.c
示例15: while
void* SpeexEncoder::encodingThreadMethod(void)
{
Threads::Thread::setCancelState(Threads::Thread::CANCEL_ENABLE);
// Threads::Thread::setCancelType(Threads::Thread::CANCEL_ASYNCHRONOUS);
while(true)
{
try
{
/* Read raw audio data from the recording PCM device: */
size_t numFrames=read(recordingBuffer,speexFrameSize);
/* Check for possible error conditions: */
if(numFrames==speexFrameSize&&speex_encode_int(speexState,recordingBuffer,&speexBits)>=0)
{
/* Write packed bits into the SPEEX packet queue: */
char* speexPacket=speexPacketQueue.getWriteSegment();
speex_bits_write(&speexBits,speexPacket,speexPacketSize);
speexPacketQueue.pushSegment();
speex_bits_reset(&speexBits);
}
}
catch(Sound::ALSAPCMDevice::OverrunError)
{
/* Restart the recording PCM device: */
prepare();
start();
}
}
return 0;
}
开发者ID:KeckCAVES,项目名称:CollaborationInfrastructure,代码行数:32,代码来源:SpeexEncoder.cpp
示例16: spx_encode_frame
int spx_encode_frame(int handle ,short *pcm_data ,char *speex_data){
// char cbits[200];
float input[FRAME_SIZE];
speex_encode_union_t * speex_encode_u = (speex_encode_union_t *)handle;
/*Flush all the bits in the struct so we can encode a new frame*/
speex_bits_reset(&speex_encode_u->bits);
/*Encode the frame*/
// memcpy(input,pcm_data,FRAME_SIZE*2);
int i;
for (i = 0; i < FRAME_SIZE; i++)
input[i] = pcm_data[i];
speex_encode(speex_encode_u->state, input, &speex_encode_u->bits);
/*Copy the bits to an array of char that can be written*/
// nbBytes = speex_bits_write(&speex_encode_u->bits, cbits, 200);
int nbBytes = speex_bits_write(&speex_encode_u->bits, speex_data, 38);
printf("nbBytes = %d \n" ,nbBytes);
// /*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);
// printf("nbBytes = %d \n" ,nbBytes);
// /*Write the compressed data*/
// //fwrite(cbits, 1, nbBytes, stdout);
}
开发者ID:chris-magic,项目名称:libspeex-study,代码行数:25,代码来源:speex_encode.c
示例17: speex_encoder_encode
int speex_encoder_encode(unsigned char* src, int inlen, unsigned char*dest, int outlen) {
int len = 0;
speex_bits_reset(&bits);
speex_encode_int(speex_encoder, (short*)src, &bits);
len = speex_bits_write(&bits, dest, outlen);
return len;
}
开发者ID:yunzed,项目名称:libflvspx,代码行数:7,代码来源:speexencoder.c
示例18: FUNCSPEEX
JNIEXPORT int JNICALL FUNCSPEEX(encodeSpeex)(JNIEnv* env, jobject obj, jbyteArray in) {
speex_bits_reset(&ebits);
jbyte* ptr = env->GetByteArrayElements(in, 0);
int ret = speex_encode_int(enc_state, (spx_int16_t*)ptr, &ebits);
env->ReleaseByteArrayElements(in, ptr, 0);
return ret;
}
开发者ID:hihua,项目名称:hihuacode,代码行数:7,代码来源:audiorecord.cpp
示例19: SpeexEncode
//*****************************************************************************
//
//! Encode a single frame of speex encoded audio.
//!
//! /param pusInBuffer is the buffer that contains the raw PCM audio.
//! /param ulInSize is the number of valid bytes in the pusInBuffer buffer.
//! /param pucOutBuffer is a pointer to the buffer to store the encoded audio.
//! /param ulOutSize is the size of the buffer pointed to by the pucOutBuffer
//! pointer.
//!
//! This function will take a buffer of PCM audio and encode it into a frame
//! of speex compressed audio. The /e pusInBuffer parameter should contain
//! a single frame of PCM audio. The /e pucOutBuffer will contain the encoded
//! audio after returning from this function.
//!
//! /return This function returns the number of encoded bytes in the
//! /e pucOutBuffer parameter.
//
//*****************************************************************************
int
SpeexEncode(short *pusInBuffer, unsigned long ulInSize,
unsigned char *pucOutBuffer, unsigned long ulOutSize)
{
int iBytes;
//
// Reset the bit stream before encoding a new frame.
//
speex_bits_reset(&g_sSpeexEncoder.sBits);
//
// Encode a single frame.
//
speex_encode_int(g_sSpeexEncoder.State, pusInBuffer,
&g_sSpeexEncoder.sBits);
//
// Read the PCM data from the encoded bit stream.
//
iBytes = speex_bits_write(&g_sSpeexEncoder.sBits, (char *)pucOutBuffer,
ulOutSize);
//
// return the number of bytes in the PCM data.
//
return(iBytes);
}
开发者ID:yangjunjiao,项目名称:Luminary-Micro-Library,代码行数:47,代码来源:speexlib.c
示例20: main
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;
}
开发者ID:kaainet,项目名称:smart_bus_proto,代码行数:59,代码来源:sample.c
注:本文中的speex_bits_reset函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论