#define CELT_SIG_SCALE 32768. #define MIN16(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 16-bit value. */ #define MIN32(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum 32-bit value. */ #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ #define SCALEIN(a) (a) #define SCALEOUT(a) (a) #define SCALEIN(a) ((a)*CELT_SIG_SCALE) #define SCALEOUT(a) ((a)*(1/CELT_SIG_SCALE)) #ifndef GLOBAL_STACK_SIZE #ifdef FIXED_POINT #else #endif #endif while (remaining_bits < 0 && q > 0) q--; remaining_bits -= curr_bits; b = IMIN(remaining_bits+1,pulses[i]+curr_balance); b = IMIN(remaining_bits+1,pulses[i]+curr_balance); #define ENCODERVALID 0x4c434554 #define ENCODERPARTIAL 0x5445434c #define ENCODERFREED 0x4c004500 int pitch_enabled; /* Complexity level is allowed to use pitch */ int pitch_permitted; /* Use of the LTP is permitted by the user */ int pitch_available; /* Amount of pitch buffer available */ int force_intra; { if (st==NULL) { celt_warning("NULL passed as an encoder structure"); return CELT_INVALID_STATE; } if (st->marker == ENCODERVALID) return CELT_OK; if (st->marker == ENCODERFREED) celt_warning("Referencing an encoder that has already been freed"); else celt_warning("This is not a valid CELT encoder structure"); return CELT_INVALID_STATE; } st->marker = ENCODERPARTIAL; st->pitch_permitted = 1; st->pitch_available = 1; st->force_intra = 0; st->delayedIntra = 1; if ((st->in_mem!=NULL) && (st->out_mem!=NULL) && (st->oldBandE!=NULL) && (st->preemph_memE!=NULL) && (st->preemph_memD!=NULL)) { st->marker = ENCODERVALID; return st; } /* If the setup fails for some reason deallocate it. */ celt_encoder_destroy(st); return NULL; if (st->marker == ENCODERFREED) { celt_warning("Freeing an encoder which has already been freed"); return; } if (st->marker != ENCODERVALID && st->marker != ENCODERPARTIAL) { celt_warning("This is not a valid CELT encoder structure"); return; } /*Check_mode is non-fatal here because we can still free the encoder memory even if the mode is bad, although calling the free functions in this order is a violation of the API.*/ check_mode(st->mode); st->marker = ENCODERFREED; x = x*CELT_SIG_SCALE; } { x = PSHR32(x, SIG_SHIFT); x = MAX32(x, -32768); x = MIN32(x, 32767); CELT_MEMSET(x+N4, 0, N2); #ifdef FIXED_POINT #else { #endif if (check_encoder(st) != CELT_OK) return CELT_INVALID_STATE; if (nbCompressedBytes<0 || pcm==NULL) return CELT_BAD_ARG; st->preemph_memE[c] = SCALEIN(*pcmp); if (has_pitch) ec_enc_uint(&enc, pitch_index, MAX_PERIOD-(2*N-2*N4)); coarse_needed = ((coarse_needed*3-1)>>3)+1; /* Variable bitrate */ { /* The target rate in 16th bits per frame */ if (shortBlocks) target*=2; else if (st->mode->nbShortMdcts > 1) /* In VBR mode the frame size must not be reduced so much that it would result in the coarse energy busting its budget */ target=IMAX(coarse_needed,(target+64)/128); } if (st->pitch_available>0 || optional_synthesis!=NULL) if (st->pitch_available>0 && st->pitch_availablepitch_available+=st->frame_size; if (optional_synthesis != NULL) { #ifdef FIXED_POINT #ifndef DISABLE_FLOAT_API int celt_encode_float(CELTEncoder * restrict st, const float * pcm, float * optional_synthesis, unsigned char *compressed, int nbCompressedBytes) { int j, ret, C, N; if (check_encoder(st) != CELT_OK) return CELT_INVALID_STATE; if (check_mode(st->mode) != CELT_OK) return CELT_INVALID_MODE; if (pcm==NULL) return CELT_BAD_ARG; N = st->block_size; for (j=0;jmode) != CELT_OK) return CELT_INVALID_MODE; if (pcm==NULL) return CELT_BAD_ARG; N=st->block_size; for (j=0;jmode) != CELT_OK)) goto bad_mode; case CELT_GET_MODE_REQUEST: { const CELTMode ** value = va_arg(ap, const CELTMode**); if (value==0) goto bad_arg; *value=st->mode; } break; if (value<=2) { st->pitch_enabled = 0; st->pitch_available = 0; } else { st->pitch_enabled = 1; if (st->pitch_available<1) st->pitch_available = 1; } } break; case CELT_SET_PREDICTION_REQUEST: { if (value<0 || value>2) goto bad_arg; if (value==0) { st->force_intra = 1; st->pitch_permitted = 0; } else if (value==1) { st->force_intra = 0; st->pitch_permitted = 0; } else { st->force_intra = 0; st->pitch_permitted = 1; } case CELT_SET_VBR_RATE_REQUEST: { if (value<0) goto bad_arg; if (value>3072000) value = 3072000; } break; bad_mode: va_end(ap); return CELT_INVALID_MODE; #define DECODERVALID 0x4c434454 #define DECODERPARTIAL 0x5444434c #define DECODERFREED 0x4c004400 int check_decoder(const CELTDecoder *st) { if (st==NULL) { celt_warning("NULL passed a decoder structure"); return CELT_INVALID_STATE; } if (st->marker == DECODERVALID) return CELT_OK; if (st->marker == DECODERFREED) celt_warning("Referencing a decoder that has already been freed"); else celt_warning("This is not a valid CELT decoder structure"); return CELT_INVALID_STATE; } if (st==NULL) return NULL; st->marker = DECODERPARTIAL; if ((st->decode_mem!=NULL) && (st->out_mem!=NULL) && (st->oldBandE!=NULL) && (st->preemph_memD!=NULL)) { st->marker = DECODERVALID; return st; } /* If the setup fails for some reason deallocate it. */ celt_decoder_destroy(st); return NULL; celt_warning("NULL passed to celt_decoder_destroy"); if (st->marker == DECODERFREED) { celt_warning("Freeing a decoder which has already been freed"); return; } if (st->marker != DECODERVALID && st->marker != DECODERPARTIAL) { celt_warning("This is not a valid CELT decoder structure"); return; } /*Check_mode is non-fatal here because we can still free the encoder memory even if the mode is bad, although calling the free functions in this order is a violation of the API.*/ check_mode(st->mode); celt_free(st->decode_mem); celt_free(st->oldBandE); st->marker = DECODERFREED; #ifdef FIXED_POINT #else { #endif if (check_decoder(st) != CELT_OK) return CELT_INVALID_STATE; if (pcm==NULL) return CELT_BAD_ARG; if (len<0) { RESTORE_STACK; return CELT_BAD_ARG; } if (shortBlocks) { transient_time = ec_dec_uint(&dec, N+st->mode->overlap); transient_time = 0; } else { #ifdef FIXED_POINT #ifndef DISABLE_FLOAT_API { int j, ret, C, N; if (check_decoder(st) != CELT_OK) return CELT_INVALID_STATE; if (check_mode(st->mode) != CELT_OK) return CELT_INVALID_MODE; if (pcm==NULL) return CELT_BAD_ARG; N = st->block_size; ret=celt_decode(st, data, len, out); for (j=0;jmode) != CELT_OK) return CELT_INVALID_MODE; if (pcm==NULL) return CELT_BAD_ARG; N = st->block_size; ret=celt_decode_float(st, data, len, out); for (j=0;jmode) != CELT_OK)) goto bad_mode; case CELT_GET_MODE_REQUEST: { const CELTMode ** value = va_arg(ap, const CELTMode**); if (value==0) goto bad_arg; *value=st->mode; } break; bad_mode: va_end(ap); return CELT_INVALID_MODE; #define _celt_check_mode_ptr_ptr(ptr) ((ptr) + ((ptr) - (CELTMode**)(ptr))) #define CELT_INVALID_STATE -6 #define CELT_GET_MODE_REQUEST 1 /** Get the CELTMode used by an encoder or decoder */ #define CELT_GET_MODE(x) CELT_GET_MODE_REQUEST, _celt_check_mode_ptr_ptr(x) #define CELT_SET_PREDICTION_REQUEST 4 /** Controls the use of interframe prediction. 0=Independent frames 1=Short term interframe prediction allowed 2=Long term prediction allowed */ #define CELT_SET_PREDICTION(x) CELT_SET_PREDICTION_REQUEST, _celt_check_int(x) #define CELT_SET_VBR_RATE_REQUEST 6 #define CELT_SET_VBR_RATE(x) CELT_SET_VBR_RATE_REQUEST, _celt_check_int(x) /** GET the sample rate used in the current mode */ #define CELT_GET_SAMPLE_RATE 1003 @param Fs Sampling rate (32000 to 96000 Hz) @param pcm PCM audio in float format, with a normal range of ±1.0. * frame_size samples per channel. @param compressed The compressed data is written here. This may not alias pcm or @param nbCompressedBytes Maximum number of bytes to use for compressing the frame @return Number of bytes written to "compressed". Will be the same as * "nbCompressedBytes" unless the stream is VBR and will never be larger. * If negative, an error has occurred (see error codes). It is IMPORTANT that * the length returned be somehow transmitted to the decoder. Otherwise, no * decoding is possible. EXPORT int celt_encode_float(CELTEncoder *st, const float *pcm, float *optional_synthesis, unsigned char *compressed, int nbCompressedBytes); * exactly frame_size samples per channel. * This may alias pcm. @param compressed The compressed data is written here. This may not alias pcm or * optional_synthesis. @param nbCompressedBytes Maximum number of bytes to use for compressing the frame @return Number of bytes written to "compressed". Will be the same as * "nbCompressedBytes" unless the stream is VBR and will never be larger. * If negative, an error has occurred (see error codes). It is IMPORTANT that * the length returned be somehow transmitted to the decoder. Otherwise, no * decoding is possible. /* A binary search on U(5,K) avoids the need for 64-bit arithmetic */ { int kl=0; int kr=_k; for(;;){ _k=kl+kr>>1; p=ucwrs5(_k); if(p<_i){ if(_k>=kr)break; kl=_k+1; } else if(p>_i)kr=_k-1; else break; } } RESTORE_STACK; #if !defined(__LITTLE_ENDIAN__) && ( defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__) ) if (check_mode(m) != CELT_OK) return CELT_INVALID_MODE; if (header==NULL) return CELT_BAD_ARG; return CELT_OK; if ((size < 56) || (header==NULL) || (packet==NULL)) return CELT_BAD_ARG; /* FAIL */ *h = _le_32 (header->extra_headers); if ((size < 56) || (header==NULL) || (packet==NULL)) return CELT_BAD_ARG; /* FAIL */ CELT_MEMSET((unsigned char*)header, 0, sizeof(*header)); /* FIXME: Do it in an alignment-safe manner */ /* Copy ident and version */ CELT_COPY((unsigned char*)header, packet, 28); /* Copy the int32 fields */ header->version_id = _le_32(*h++); header->header_size = _le_32(*h++); header->sample_rate = _le_32(*h++); header->nb_channels = _le_32(*h++); header->frame_size = _le_32(*h++); header->overlap = _le_32(*h++); header->bytes_per_packet = _le_32(*h++); header->extra_headers = _le_32(*h); #define kiss_fftr_inplace SUF(kiss_fftr_inplace,KF_SUFFIX) #define celt_log2(x) (1.442695040888963387*log(x)) #define celt_exp2(x) (exp(0.6931471805599453094*(x))) if (l->kfft==NULL) return; if (l->trig==NULL) return; #define MODEVALID 0xa110ca7e #define MODEPARTIAL 0x7eca10a1 #define MODEFREED 0xb10cf8ee if (check_mode(mode) != CELT_OK) return CELT_INVALID_MODE; case CELT_GET_SAMPLE_RATE: *value = mode->Fs; break; /* Find the number of critical bands supported by our sampling rate */ for (nBark=1;nBark= Fs) break; for (lin=0;lin= mode->Fs) break; if (allocVectors==NULL) return; int eband = 0; for (j=0;jnbEBands+eband] = (current+low+128)/256; current=0; current += alloc-low; current += alloc; } allocVectors[i*mode->nbEBands+eband] = (current+128)/256; #if !defined(VAR_ARRAYS) && !defined(USE_ALLOCA) if (global_stack==NULL) { celt_free(global_stack); goto failure; } #endif if (mode==NULL) goto failure; mode->marker_start = MODEPARTIAL; CELTMode *mode=NULL; #if !defined(VAR_ARRAYS) && !defined(USE_ALLOCA) if (global_stack==NULL) { celt_free(global_stack); goto failure; } #endif if (Fs < 32000 || Fs > 96000) celt_warning("Sampling rate must be between 32 kHz and 96 kHz"); if (mode==NULL) goto failure; mode->marker_start = MODEPARTIAL; { mode->nbShortMdcts = 4; } else if (frame_size > 384 && (frame_size%10)==0) { mode->nbShortMdcts = 5; } else if (frame_size > 256 && (frame_size%6)==0) { mode->nbShortMdcts = 3; } else if (frame_size > 256 && (frame_size%8)==0) mode->nbShortMdcts = 4; } else if (frame_size > 64 && (frame_size%4)==0) mode->nbShortMdcts = 2; } else if (frame_size > 128 && (frame_size%6)==0) mode->nbShortMdcts = 3; } else { mode->nbShortMdcts = 1; mode->overlap = (frame_size>>3)<<2; if (mode->allocVectors==NULL) goto failure; if (window==NULL) goto failure; if (mode->bits==NULL) goto failure; goto failure; mode->marker_start = MODEVALID; mode->marker_end = MODEVALID; failure: if (error) *error = CELT_INVALID_MODE; if (mode!=NULL) celt_mode_destroy(mode); return NULL; if (mode == NULL) { celt_warning("NULL passed to celt_mode_destroy"); return; } if (mode->marker_start == MODEFREED || mode->marker_end == MODEFREED) { celt_warning("Freeing a mode which has already been freed"); return; } if (mode->marker_start != MODEVALID && mode->marker_start != MODEPARTIAL) { celt_warning("This is not a valid CELT mode structure"); return; } mode->marker_start = MODEFREED; if (mode->bits!=NULL) for (i=0;inbEBands;i++) if (mode->bits[i] != prevPtr) { prevPtr = mode->bits[i]; celt_free((int*)mode->bits[i]); } } mode->marker_end = MODEFREED; if (mode==NULL) return CELT_INVALID_MODE; decay->decayR = decayR; if (decayR==NULL) return; if (prob==NULL) return NULL; unsigned bits_used = 0; return bits_used; int error = 0; if (bits==NULL) return NULL; if (bits[i]!=NULL) { } else { error=1; } if (error) { if (bits!=NULL) { for (i=0;inbEBands;i++) { if (bits[i] != prevPtr) { prevPtr = bits[i]; celt_free((int*)bits[i]); } } free(bits); bits=NULL; } } #ifdef CELT_C char *global_stack=0; #else extern char *global_stack; #endif /*CELT_C*/ #ifdef CELT_C char *global_stack_top=0; #else extern char *global_stack_top; #endif /*CELT_C*/ #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1)) #define PUSH(stack, size, type) (VALGRIND_MAKE_MEM_NOACCESS(stack, global_stack_top-stack),ALIGN((stack),sizeof(type)/sizeof(char)),VALGRIND_MAKE_MEM_UNDEFINED(stack, ((size)*sizeof(type)/sizeof(char))),(stack)+=(2*(size)*sizeof(type)/sizeof(char)),(type*)((stack)-(2*(size)*sizeof(type)/sizeof(char)))) #define RESTORE_STACK ((global_stack = _saved_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)) #define ALLOC_STACK ((global_stack = (global_stack==0) ? ((global_stack_top=celt_alloc_scratch(GLOBAL_STACK_SIZE*2)+(GLOBAL_STACK_SIZE*2))-(GLOBAL_STACK_SIZE*2)) : global_stack),VALGRIND_MAKE_MEM_NOACCESS(global_stack, global_stack_top-global_stack)) #else #define ALLOC_STACK (global_stack = (global_stack==0) ? celt_alloc_scratch(GLOBAL_STACK_SIZE) : global_stack) #endif /*ENABLE_VALGRIND*/ #endif /*VAR_ARRAYS*/ #endif /*STACK_ALLOC_H*/ #define MAX_PACKET 1024 unsigned char data[MAX_PACKET]; int complexity; if (argc != 9 && argc != 8 && argc != 7) if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET) inFile = argv[argc-2]; fprintf (stderr, "Could not open input file %s\n", argv[argc-2]); outFile = argv[argc-1]; fprintf (stderr, "Could not open output file %s\n", argv[argc-1]); if (argc>7) { complexity=atoi(argv[5]); celt_encoder_ctl(enc,CELT_SET_COMPLEXITY(complexity)); } len = celt_encode(enc, in, in, data, bytes_per_packet); #define CELT_C #include "../libcelt/stack_alloc.h" ALLOC_STACK; #define CELT_C #include "../libcelt/stack_alloc.h" #ifdef FIXED_DEBUG long long celt_mips=0; #endif ALLOC_STACK; #include unsigned int seed; if (_argc > 2) { fprintf(stderr, "Usage: %s []\n", _argv[0]); return 1; } if (_argc > 1) seed = atoi(_argv[1]); else srand(seed); fprintf(stderr,"Testing random streams... Random seed: %u (%.4X)\n", seed, rand() % 65536); fprintf (stderr, "tell() lied, there's %li bytes instead of %d (Random seed: %u)\n", ec_byte_bytes(&buf), (tell_bits+7)/8,seed); "Decoded %i instead of %i with ft of %i at position %i of %i (Random seed: %u).\n", sym,data[j],ft,j,sz,seed); #define CELT_C #include "../libcelt/stack_alloc.h" #ifdef FIXED_DEBUG long long celt_mips=0; #endif #ifndef FIXED_POINT void testlog2(void) { float x; for (x=0.001;x<1677700.0;x+=(x/8.0)) { float error = fabs((1.442695040888963387*log(x))-celt_log2(x)); { fprintf (stderr, "celt_log2 failed: fabs((1.442695040888963387*log(x))-celt_log2(x))>0.001 (x = %f, error = %f)\n", x,error); ret = 1; } } } void testexp2(void) { float x; for (x=-11.0;x<24.0;x+=0.0007) { float error = fabs(x-(1.442695040888963387*log(celt_exp2(x)))); { fprintf (stderr, "celt_exp2 failed: fabs(x-(1.442695040888963387*log(celt_exp2(x))))>0.0005 (x = %f, error = %f)\n", x,error); ret = 1; } } } void testexp2log2(void) { float x; for (x=-11.0;x<24.0;x+=0.0007) { float error = fabs(x-(celt_log2(celt_exp2(x)))); if (error>0.001) { fprintf (stderr, "celt_log2/celt_exp2 failed: fabs(x-(celt_log2(celt_exp2(x))))>0.001 (x = %f, error = %f)\n", x,error); ret = 1; } } } #else void testilog2(void) { for (x=1;x<=268435455;x+=127) { if (error!=0) { printf("celt_ilog2 failed: celt_ilog2(x)!=floor(log2(x)) (x = %d, error = %d)\n",x,error); ret = 1; } } } #endif testlog2(); testexp2(); testexp2log2(); testilog2(); #endif #define CELT_C #include "../libcelt/stack_alloc.h" #ifdef FIXED_DEBUG long long celt_mips=0; #endif #define CELT_C #include "../libcelt/stack_alloc.h" #ifdef FIXED_DEBUG long long celt_mips=0; #endif ALLOC_STACK; #define PACKETSIZE 43 #define CHANNELS 1 #define HAS_SPEEX_AEC #if CHANNELS == 2 /* FIXME: The Speex AEC has multichannel support; but that API isn't being used here yet. */ #undef HAS_SPEEX_AEC #endif #ifdef HAS_SPEEX_AEC #include #endif fprintf(stderr, "Usage %s plughw:0,0 remote_host local_udp_port remote_udp_port\n",argv[0]); fprintf(stderr, "%s: unknown host '%s' \n", argv[0], argv[2]); audio_dev = alsa_device_open(argv[1], SAMPLING_RATE, CHANNELS, FRAME_SIZE); CELTMode *mode = celt_mode_create(SAMPLING_RATE, CHANNELS, FRAME_SIZE, NULL); #ifdef HAS_SPEEX_AEC #endif short pcm[FRAME_SIZE*CHANNELS]; packet.len = MAX_MSG; jitter_buffer_tick(jitter); if (packet.len==0) packet.data=NULL; for (i=0;iend) if (len < 0 || c+len>end) printf ("celtenc (CELT %s encoder)\n",CELT_VERSION); printf ("celtenc (CELT %s encoder)\n",CELT_VERSION); int bitstream; celt_mode_info(*mode, CELT_GET_BITSTREAM_VERSION, &bitstream); if (bitstream!=header.version_id) fprintf(stderr, "WARNING: Input was encoded with a CELT bitstream version %d. This decoder uses %d. Output will probably be corrupted.\n",header.version_id,bitstream); while (!eos && ogg_stream_packetout(&os, &op) == 1 && op.bytes>=8) #define IMIN(a,b) ((a) < (b) ? (a) : (b)) /**< Minimum int value. */ #define IMAX(a,b) ((a) > (b) ? (a) : (b)) /**< Maximum int value. */ unsigned char in[MAX_FRAME_SIZE*2]; printf ("celtenc (CELT %s encoder)\n",CELT_VERSION); printf ("celtenc (CELT %s encoder)\n",CELT_VERSION); printf (" --bitrate n Encoding bit-rate in kbit/sec\n"); printf (" --vbr Use variable bitrate encoding\n"); printf (" --comp n Encoding complexity (0-10)\n"); printf (" --framesize n Frame size (Default: 256)\n"); printf (" --noltp Do not use long-term prediction\n"); printf (" --independent Encode frames independently (implies noltp)\n"); int with_vbr = 0; int total_bytes = 0; int peak_bytes = 0; {"vbr",no_argument,NULL, 0}, {"comp", required_argument, NULL, 0}, {"noltp", no_argument, NULL, 0}, {"independent", no_argument, NULL, 0}, {"framesize", required_argument, NULL, 0}, float bitrate=-1; int complexity=-127; int prediction=2; int bitstream; bitrate = atof (optarg); } else if (strcmp(long_options[option_index].name,"vbr")==0) { with_vbr=1; } else if (strcmp(long_options[option_index].name,"comp")==0) { complexity=atoi (optarg); } else if (strcmp(long_options[option_index].name,"framesize")==0) { frame_size=atoi (optarg); } else if (strcmp(long_options[option_index].name,"noltp")==0) { if (prediction>1) prediction=1; } else if (strcmp(long_options[option_index].name,"independent")==0) { prediction=0; if (bitrate<=0.005) if (chan==1) bitrate=64.0; else bitrate=128.0; bytes_per_packet = (bitrate*1000*frame_size/rate+4)/8; if (bytes_per_packet < 8) { bytes_per_packet=8; fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too low. Setting CELT to 8 bytes/frame.\n",bitrate); } else if (bytes_per_packet > MAX_FRAME_BYTES) { bytes_per_packet=MAX_FRAME_BYTES; fprintf (stderr, "Warning: Requested bitrate (%0.3fkbit/sec) is too high. Setting CELT to %d bytes/frame.\n",bitrate,MAX_FRAME_BYTES); if (with_vbr) { /*In VBR mode the bytes_per_packet argument becomes a hard maximum. 3x the average rate is just a random choice.*/ bytes_per_packet=IMIN(bytes_per_packet*3,MAX_FRAME_BYTES); } else { bitrate = ((rate/(float)frame_size)*8*bytes_per_packet)/1000.0; } celt_mode_info(mode,CELT_GET_BITSTREAM_VERSION,&bitstream); snprintf(vendor_string, sizeof(vendor_string), "Encoded with CELT %s (bitstream: %d)\n",CELT_VERSION,bitstream); comment_init(&comments, &comments_length, vendor_string); celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size); if (with_vbr) fprintf (stderr, "Encoding %d Hz %s audio in %d sample packets at %0.3fkbit/sec (%d maximum bytes per packet) with bitstream version %d\n", header.sample_rate, st_string, frame_size, bitrate, bytes_per_packet,bitstream); else fprintf (stderr, "Encoding %d Hz %s audio in %d sample packets at %0.3fkbit/sec (%d bytes per packet) with bitstream version %d\n", header.sample_rate, st_string, frame_size, bitrate, bytes_per_packet,bitstream); if (with_vbr) { int tmp = (bitrate*1000); if (celt_encoder_ctl(st, CELT_SET_VBR_RATE(tmp)) != CELT_OK) { fprintf (stderr, "VBR request failed\n"); return 1; } } if (celt_encoder_ctl(st, CELT_SET_PREDICTION(prediction)) != CELT_OK) { fprintf (stderr, "Prediction request failed\n"); return 1; } if (complexity!=-127) { if (celt_encoder_ctl(st, CELT_SET_COMPLEXITY(complexity)) != CELT_OK) { fprintf (stderr, "Only complexity 0 through 10 is supported\n"); return 1; } } nbBytes = celt_encode(st, input, NULL, bits, bytes_per_packet); total_bytes += nbBytes; peak_bytes=IMAX(nbBytes,peak_bytes); if (with_vbr && !quiet) fprintf (stderr, "Average rate %0.3fkbit/sec, %d peak bytes per packet\n", (total_bytes*8.0/((float)nb_encoded/header.sample_rate))/1000.0, peak_bytes);