本文整理汇总了C++中speex_bits_init函数的典型用法代码示例。如果您正苦于以下问题:C++ speex_bits_init函数的具体用法?C++ speex_bits_init怎么用?C++ speex_bits_init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了speex_bits_init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Java_com_haitou_xiaoyoupai_imservice_support_audio_Speex_open
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;
}
示例2: spx_codec_open
/*
* 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;
}
示例3: init_speex_encoder
void init_speex_encoder() {
if (!gEncoderState) {
gEncoderState = speex_encoder_init(&speex_nb_mode);
int quality = 3; // 8000 bps
speex_encoder_ctl(gEncoderState, SPEEX_SET_QUALITY, &quality);
int complexity = 4; // net play is demanding, ok?
speex_encoder_ctl(gEncoderState, SPEEX_SET_COMPLEXITY, &complexity);
int tmp = kNetworkAudioSampleRate;
speex_encoder_ctl(gEncoderState, SPEEX_SET_SAMPLING_RATE, &tmp);
speex_bits_init(&gEncoderBits);
// set up the preprocessor
int frame_size;
speex_encoder_ctl(gEncoderState, SPEEX_GET_FRAME_SIZE, &frame_size);
gPreprocessState = speex_preprocess_state_init(frame_size, kNetworkAudioSampleRate);
// turn on AGC and denoise
tmp = 1;
speex_preprocess_ctl(gPreprocessState, SPEEX_PREPROCESS_SET_DENOISE, &tmp);
tmp = 1;
speex_preprocess_ctl(gPreprocessState, SPEEX_PREPROCESS_SET_AGC, &tmp);
float agc_level = 32768.0 * 0.7;
speex_preprocess_ctl(gPreprocessState, SPEEX_PREPROCESS_SET_AGC_LEVEL, &agc_level);
}
}
示例4: FUNCSPEEX
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);
}
示例5: _speex_dec_state
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
}
示例6: stopRecorder
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();
}
示例7: SpeexDecodeInit
//*****************************************************************************
//
//! 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);
}
示例8: allocate_slot
JNIEXPORT jint JNICALL Java_com_purplefrog_speexjni_SpeexDecoder_allocate
(JNIEnv *env, jclass cls, jint wideband)
{
int slot = allocate_slot(&slots);
//
slots.slots[slot] = malloc(sizeof(struct Slot));
struct Slot* gob = slots.slots[slot];
//
speex_bits_init(&gob->bits);
const SpeexMode * mode;
switch (wideband) {
case 1:
mode = &speex_wb_mode;
break;
case 2:
mode = &speex_uwb_mode;
break;
default:
mode = &speex_nb_mode;
break;
}
gob->state = speex_decoder_init(mode);
return slot;
}
示例9: speex_init_encoder
static void speex_init_encoder (enix_aenc_t *this_gen, enix_stream_t *stream) {
speex_t *this = (speex_t *) this_gen;
int bitrate, channels, sample_rate;
enix_options_t *options;
int ret;
/*
* gather parameters
*/
options = this->encoder.options;
bitrate = options->get_num_option (options, "bitrate");
channels = stream->get_property (stream, ENIX_STREAM_PROP_AUDIO_CHANNELS);
sample_rate = stream->get_property (stream, ENIX_STREAM_PROP_SAMPLE_RATE);
printf ("acodec_speex: %d audio channels, %d samples/sec\n",
channels, sample_rate);
/*
* speex init
*/
speex_bits_init (&this->bits);
this->enc_state = speex_encoder_init (&speex_nb_mode);
speex_encoder_ctl (this->enc_state, SPEEX_GET_FRAME_SIZE, &this->frame_size);
printf ("acodec_speex: codec init done. frame size is %d\n", this->frame_size);
this->num_samples = 0;
}
示例10: spx_encode_init
int spx_encode_init(){
fp_speex_send = fopen("speex_send.spx" ,"w+");
if(fp_speex_send == NULL){
printf("open sdcard/fp_speex_send.spx file failed");
}
speex_encode_union_t * speex_encode_u = (speex_encode_union_t *)malloc(sizeof(speex_encode_union_t));
if(speex_encode_u == NULL){
printf("speex_encode_union malloc failed ...\n");
exit(1);
}
/*Create a new encoder state in narrowband mode*/
speex_encode_u->state = speex_encoder_init(&speex_nb_mode);
/*Set the quality to 8 (15 kbps)*/
int tmp = 8;
speex_encoder_ctl(speex_encode_u->state, SPEEX_SET_QUALITY, &tmp);
/*Initialization of the structure that holds the bits*/
speex_bits_init(&speex_encode_u->bits);
return (int )speex_encode_u;
}
示例11: main
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;
}
示例12: decoder_error_init
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;
}
示例13: decode
void 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);
}
}
示例14: 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;
}
示例15: stop
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();
}
}