static void celt_destroy_encoder(const struct PluginCodec_Definition * codec, void * context) { CELTContext * celt = (CELTContext *)context; celt_encoder_destroy(celt->encoder_state); celt_mode_destroy(celt->mode); free(celt); }
JNIEXPORT void JNICALL Native_NATIVE(celt_1encoder_1destroy) (JNIEnv *env, jclass that, jlong arg0) { Native_NATIVE_ENTER(env, that, Native_celt_1encoder_1destroy_FUNC); celt_encoder_destroy((CELTEncoder *)(intptr_t)arg0); Native_NATIVE_EXIT(env, that, Native_celt_1encoder_1destroy_FUNC); }
SWIGEXPORT void JNICALL Java_com_morlunk_jumble_audio_celt11_CELT11JNI_celt_1encoder_1destroy(JNIEnv *jenv, jclass jcls, jlong jarg1) { CELTEncoder *arg1 = (CELTEncoder *) 0 ; (void)jenv; (void)jcls; arg1 = *(CELTEncoder **)&jarg1; celt_encoder_destroy(arg1); }
CELTEncoder *celt_encoder_create(const CELTMode *mode) { int N, C; CELTEncoder *st; if (check_mode(mode) != CELT_OK) return NULL; N = mode->mdctSize; C = mode->nbChannels; st = celt_alloc(sizeof(CELTEncoder)); if (st==NULL) return NULL; st->marker = ENCODERPARTIAL; st->mode = mode; st->frame_size = N; st->block_size = N; st->overlap = mode->overlap; st->VBR_rate = 0; st->pitch_enabled = 1; st->pitch_permitted = 1; st->pitch_available = 1; st->force_intra = 0; st->delayedIntra = 1; st->tonal_average = QCONST16(1.,8); st->fold_decision = 1; st->in_mem = celt_alloc(st->overlap*C*sizeof(celt_sig_t)); st->out_mem = celt_alloc((MAX_PERIOD+st->overlap)*C*sizeof(celt_sig_t)); st->oldBandE = (celt_word16_t*)celt_alloc(C*mode->nbEBands*sizeof(celt_word16_t)); st->preemph_memE = (celt_word16_t*)celt_alloc(C*sizeof(celt_word16_t)); st->preemph_memD = (celt_sig_t*)celt_alloc(C*sizeof(celt_sig_t)); #ifdef EXP_PSY st->psy_mem = celt_alloc(MAX_PERIOD*sizeof(celt_word16_t)); psydecay_init(&st->psy, MAX_PERIOD/2, st->mode->Fs); #endif if ((st->in_mem!=NULL) && (st->out_mem!=NULL) && (st->oldBandE!=NULL) #ifdef EXP_PSY && (st->psy_mem!=NULL) #endif && (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; }
static void celt_destructor(void *arg) { struct aucodec_st *st = arg; if (st->enc) celt_encoder_destroy(st->enc); if (st->dec) celt_decoder_destroy(st->dec); if (st->mode) celt_mode_destroy(st->mode); mem_deref(st->ac); }
static gboolean gst_celt_enc_set_format (GstAudioEncoder * benc, GstAudioInfo * info) { GstCeltEnc *enc; GstCaps *otherpadcaps; enc = GST_CELT_ENC (benc); enc->channels = GST_AUDIO_INFO_CHANNELS (info); enc->rate = GST_AUDIO_INFO_RATE (info); /* handle reconfigure */ if (enc->state) { celt_encoder_destroy (enc->state); enc->state = NULL; } if (enc->mode) { celt_mode_destroy (enc->mode); enc->mode = NULL; } memset (&enc->header, 0, sizeof (enc->header)); otherpadcaps = gst_pad_get_allowed_caps (GST_AUDIO_ENCODER_SRC_PAD (enc)); if (otherpadcaps) { if (!gst_caps_is_empty (otherpadcaps)) { GstStructure *ps = gst_caps_get_structure (otherpadcaps, 0); gst_structure_get_int (ps, "frame-size", &enc->frame_size); } gst_caps_unref (otherpadcaps); } if (enc->requested_frame_size > 0) enc->frame_size = enc->requested_frame_size; GST_DEBUG_OBJECT (enc, "channels=%d rate=%d frame-size=%d", enc->channels, enc->rate, enc->frame_size); if (!gst_celt_enc_setup (enc)) return FALSE; /* feedback to base class */ gst_audio_encoder_set_latency (benc, gst_celt_enc_get_latency (enc), gst_celt_enc_get_latency (enc)); gst_audio_encoder_set_frame_samples_min (benc, enc->frame_size); gst_audio_encoder_set_frame_samples_max (benc, enc->frame_size); gst_audio_encoder_set_frame_max (benc, 1); return TRUE; }
CeltCodec::~CeltCodec() { if (celtMode) { if (encoder) { celt_encoder_destroy(encoder); encoder = 0; } if (decoder) { celt_decoder_destroy(decoder); decoder = 0; } celt_mode_destroy(const_cast<CELTMode*>(celtMode)); } celtMode = 0; }
static gboolean gst_celt_enc_stop (GstAudioEncoder * benc) { GstCeltEnc *enc = GST_CELT_ENC (benc); GST_DEBUG_OBJECT (enc, "stop"); enc->header_sent = FALSE; if (enc->state) { celt_encoder_destroy (enc->state); enc->state = NULL; } if (enc->mode) { celt_mode_destroy (enc->mode); enc->mode = NULL; } memset (&enc->header, 0, sizeof (enc->header)); gst_tag_setter_reset_tags (GST_TAG_SETTER (enc)); return TRUE; }
void netjack_detach( netjack_driver_state_t *netj ) { JSList * node; for (node = netj->capture_ports; node; node = jack_slist_next (node)) jack_port_unregister (netj->client, ((jack_port_t *) node->data)); jack_slist_free (netj->capture_ports); netj->capture_ports = NULL; for (node = netj->capture_srcs; node; node = jack_slist_next (node)) { #if HAVE_CELT if( netj->bitdepth == CELT_MODE ) { CELTDecoder * decoder = node->data; celt_decoder_destroy(decoder); } else #endif { #if HAVE_SAMPLERATE SRC_STATE * src = node->data; src_delete(src); #endif } } jack_slist_free (netj->capture_srcs); netj->playback_srcs = NULL; for (node = netj->playback_ports; node; node = jack_slist_next (node)) jack_port_unregister (netj->client, ((jack_port_t *) node->data)); jack_slist_free (netj->playback_ports); netj->playback_ports = NULL; for (node = netj->playback_srcs; node; node = jack_slist_next (node)) { #if HAVE_CELT if( netj->bitdepth == CELT_MODE ) { CELTEncoder * encoder = node->data; celt_encoder_destroy(encoder); } else #endif { #if HAVE_SAMPLERATE SRC_STATE * src = node->data; src_delete(src); #endif } } jack_slist_free (netj->playback_srcs); netj->playback_srcs = NULL; #if HAVE_CELT if( netj->bitdepth == CELT_MODE ) celt_mode_destroy(netj->celt_mode); #endif }
int main(int argc, char **argv) { int nb_samples, total_samples=0, nb_encoded; int c; int option_index = 0; char *inFile, *outFile; FILE *fin, *fout; short input[MAX_FRAME_SIZE]; celt_int32 frame_size = 960; int quiet=0; int nbBytes; CELTMode *mode; void *st; unsigned char bits[MAX_FRAME_BYTES]; int with_cbr = 0; int with_cvbr = 0; int with_skeleton = 0; int total_bytes = 0; int peak_bytes = 0; struct option long_options[] = { {"bitrate", required_argument, NULL, 0}, {"cbr",no_argument,NULL, 0}, {"cvbr",no_argument,NULL, 0}, {"comp", required_argument, NULL, 0}, {"nopf", no_argument, NULL, 0}, {"independent", no_argument, NULL, 0}, {"framesize", required_argument, NULL, 0}, {"skeleton",no_argument,NULL, 0}, {"help", no_argument, NULL, 0}, {"quiet", no_argument, NULL, 0}, {"le", no_argument, NULL, 0}, {"be", no_argument, NULL, 0}, {"8bit", no_argument, NULL, 0}, {"16bit", no_argument, NULL, 0}, {"mono", no_argument, NULL, 0}, {"stereo", no_argument, NULL, 0}, {"rate", required_argument, NULL, 0}, {"version", no_argument, NULL, 0}, {"version-short", no_argument, NULL, 0}, {"comment", required_argument, NULL, 0}, {"author", required_argument, NULL, 0}, {"title", required_argument, NULL, 0}, {0, 0, 0, 0} }; int print_bitrate=0; celt_int32 rate=48000; celt_int32 size; int chan=1; int fmt=16; int lsb=1; ogg_stream_state os; ogg_stream_state so; /* ogg stream for skeleton bitstream */ ogg_page og; ogg_packet op; int bytes_written=0, ret, result; int id=-1; CELTHeader header; char vendor_string[64]; char *comments; int comments_length; int close_in=0, close_out=0; int eos=0; float bitrate=-1; char first_bytes[12]; int wave_input=0; celt_int32 lookahead = 0; int bytes_per_packet=-1; int complexity=-127; int prediction=2; /*Process command-line options*/ while(1) { c = getopt_long (argc, argv, "hvV", long_options, &option_index); if (c==-1) break; switch(c) { case 0: if (strcmp(long_options[option_index].name,"bitrate")==0) { bitrate = atof (optarg); } else if (strcmp(long_options[option_index].name,"cbr")==0) { with_cbr=1; } else if (strcmp(long_options[option_index].name,"cvbr")==0) { with_cvbr=1; } else if (strcmp(long_options[option_index].name,"skeleton")==0) { with_skeleton=1; } else if (strcmp(long_options[option_index].name,"help")==0) { usage(); exit(0); } else if (strcmp(long_options[option_index].name,"quiet")==0) { quiet = 1; } else if (strcmp(long_options[option_index].name,"version")==0) { version(); exit(0); } else if (strcmp(long_options[option_index].name,"version-short")==0) { version_short(); exit(0); } else if (strcmp(long_options[option_index].name,"le")==0) { lsb=1; } else if (strcmp(long_options[option_index].name,"be")==0) { lsb=0; } else if (strcmp(long_options[option_index].name,"8bit")==0) { fmt=8; } else if (strcmp(long_options[option_index].name,"16bit")==0) { fmt=16; } else if (strcmp(long_options[option_index].name,"stereo")==0) { chan=2; } else if (strcmp(long_options[option_index].name,"mono")==0) { chan=1; } else if (strcmp(long_options[option_index].name,"rate")==0) { rate=atoi (optarg); } 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,"nopf")==0) { if (prediction>1) prediction=1; } else if (strcmp(long_options[option_index].name,"independent")==0) { prediction=0; } else if (strcmp(long_options[option_index].name,"comment")==0) { if (!strchr(optarg, '=')) { fprintf (stderr, "Invalid comment: %s\n", optarg); fprintf (stderr, "Comments must be of the form name=value\n"); exit(1); } comment_add(&comments, &comments_length, NULL, optarg); } else if (strcmp(long_options[option_index].name,"author")==0) { comment_add(&comments, &comments_length, "author=", optarg); } else if (strcmp(long_options[option_index].name,"title")==0) { comment_add(&comments, &comments_length, "title=", optarg); } break; case 'h': usage(); exit(0); break; case 'v': version(); exit(0); break; case 'V': print_bitrate=1; break; case '?': usage(); exit(1); break; } } if (argc-optind!=2) { usage(); exit(1); } inFile=argv[optind]; outFile=argv[optind+1]; /*Initialize Ogg stream struct*/ srand(time(NULL)); if (ogg_stream_init(&os, rand())==-1) { fprintf(stderr,"Error: stream init failed\n"); exit(1); } if (with_skeleton && ogg_stream_init(&so, rand())==-1) { fprintf(stderr,"Error: stream init failed\n"); exit(1); } if (strcmp(inFile, "-")==0) { #if defined WIN32 || defined _WIN32 _setmode(_fileno(stdin), _O_BINARY); #elif defined OS2 _fsetmode(stdin,"b"); #endif fin=stdin; } else { fin = fopen(inFile, "rb"); if (!fin) { perror(inFile); exit(1); } close_in=1; } { fread(first_bytes, 1, 12, fin); if (strncmp(first_bytes,"RIFF",4)==0 && strncmp(first_bytes,"RIFF",4)==0) { if (read_wav_header(fin, &rate, &chan, &fmt, &size)==-1) exit(1); wave_input=1; lsb=1; /* CHECK: exists big-endian .wav ?? */ } } if (bitrate<=0.005) if (chan==1) bitrate=64.0; else bitrate=128.0; bytes_per_packet = MAX_FRAME_BYTES; mode = celt_mode_create(rate, frame_size, NULL); if (!mode) return 1; snprintf(vendor_string, sizeof(vendor_string), "Encoded with CELT %s\n",CELT_VERSION); comment_init(&comments, &comments_length, vendor_string); /*celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size);*/ celt_header_init(&header, mode, frame_size, chan); header.nb_channels = chan; { char *st_string="mono"; if (chan==2) st_string="stereo"; if (!quiet) if (with_cbr) fprintf (stderr, "Encoding %.0f kHz %s audio in %.0fms packets at %0.3fkbit/sec (%d bytes per packet, CBR)\n", header.sample_rate/1000., st_string, frame_size/(float)header.sample_rate*1000., bitrate, bytes_per_packet); else fprintf (stderr, "Encoding %.0f kHz %s audio in %.0fms packets at %0.3fkbit/sec (%d bytes per packet maximum)\n", header.sample_rate/1000., st_string, frame_size/(float)header.sample_rate*1000., bitrate, bytes_per_packet); } /*Initialize CELT encoder*/ st = celt_encoder_create_custom(mode, chan, NULL); { int tmp = (bitrate*1000); if (celt_encoder_ctl(st, CELT_SET_BITRATE(tmp)) != CELT_OK) { fprintf (stderr, "bitrate request failed\n"); return 1; } } if (!with_cbr) { if (celt_encoder_ctl(st, CELT_SET_VBR(1)) != CELT_OK) { fprintf (stderr, "VBR request failed\n"); return 1; } if (!with_cvbr) { if (celt_encoder_ctl(st, CELT_SET_VBR_CONSTRAINT(0)) != CELT_OK) { fprintf (stderr, "VBR constraint 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; } } if (strcmp(outFile,"-")==0) { #if defined WIN32 || defined _WIN32 _setmode(_fileno(stdout), _O_BINARY); #endif fout=stdout; } else { fout = fopen(outFile, "wb"); if (!fout) { perror(outFile); exit(1); } close_out=1; } if (with_skeleton) { fprintf (stderr, "Warning: Enabling skeleton output may cause some decoders to fail.\n"); } /* first packet should be the skeleton header. */ if (with_skeleton) { add_fishead_packet(&so); if ((ret = flush_ogg_stream_to_file(&so, fout))) { fprintf (stderr,"Error: failed skeleton (fishead) header to output stream\n"); exit(1); } else bytes_written += ret; } /*Write header*/ { unsigned char header_data[100]; int packet_size = celt_header_to_packet(&header, header_data, 100); op.packet = header_data; op.bytes = packet_size; op.b_o_s = 1; op.e_o_s = 0; op.granulepos = 0; op.packetno = 0; ogg_stream_packetin(&os, &op); while((result = ogg_stream_flush(&os, &og))) { if(!result) break; ret = oe_write_page(&og, fout); if(ret != og.header_len + og.body_len) { fprintf (stderr,"Error: failed writing header to output stream\n"); exit(1); } else bytes_written += ret; } op.packet = (unsigned char *)comments; op.bytes = comments_length; op.b_o_s = 0; op.e_o_s = 0; op.granulepos = 0; op.packetno = 1; ogg_stream_packetin(&os, &op); } /* fisbone packet should be write after all bos pages */ if (with_skeleton) { add_fisbone_packet(&so, os.serialno, &header); if ((ret = flush_ogg_stream_to_file(&so, fout))) { fprintf (stderr,"Error: failed writing skeleton (fisbone )header to output stream\n"); exit(1); } else bytes_written += ret; } /* writing the rest of the celt header packets */ while((result = ogg_stream_flush(&os, &og))) { if(!result) break; ret = oe_write_page(&og, fout); if(ret != og.header_len + og.body_len) { fprintf (stderr,"Error: failed writing header to output stream\n"); exit(1); } else bytes_written += ret; } free(comments); /* write the skeleton eos packet */ if (with_skeleton) { add_eos_packet_to_stream(&so); if ((ret = flush_ogg_stream_to_file(&so, fout))) { fprintf (stderr,"Error: failed writing skeleton header to output stream\n"); exit(1); } else bytes_written += ret; } if (!wave_input) { nb_samples = read_samples(fin,frame_size,fmt,chan,lsb,input, first_bytes, NULL); } else { nb_samples = read_samples(fin,frame_size,fmt,chan,lsb,input, NULL, &size); } if (nb_samples==0) eos=1; total_samples += nb_samples; nb_encoded = -lookahead; /*Main encoding loop (one frame per iteration)*/ while (!eos || total_samples>nb_encoded) { id++; /*Encode current frame*/ nbBytes = celt_encode(st, input, frame_size, bits, bytes_per_packet); if (nbBytes<0) { fprintf(stderr, "Got error %d while encoding. Aborting.\n", nbBytes); break; } nb_encoded += frame_size; total_bytes += nbBytes; peak_bytes=IMAX(nbBytes,peak_bytes); if (wave_input) { nb_samples = read_samples(fin,frame_size,fmt,chan,lsb,input, NULL, &size); } else { nb_samples = read_samples(fin,frame_size,fmt,chan,lsb,input, NULL, NULL); } if (nb_samples==0) { eos=1; } if (eos && total_samples<=nb_encoded) op.e_o_s = 1; else op.e_o_s = 0; total_samples += nb_samples; op.packet = (unsigned char *)bits; op.bytes = nbBytes; op.b_o_s = 0; /*Is this redundent?*/ if (eos && total_samples<=nb_encoded) op.e_o_s = 1; else op.e_o_s = 0; op.granulepos = (id+1)*frame_size-lookahead; if (op.granulepos>total_samples) op.granulepos = total_samples; /*printf ("granulepos: %d %d %d %d %d %d\n", (int)op.granulepos, id, nframes, lookahead, 5, 6);*/ op.packetno = 2+id; ogg_stream_packetin(&os, &op); /*Write all new pages (most likely 0 or 1)*/ while (ogg_stream_pageout(&os,&og)) { ret = oe_write_page(&og, fout); if(ret != og.header_len + og.body_len) { fprintf (stderr,"Error: failed writing header to output stream\n"); exit(1); } else bytes_written += ret; } } /*Flush all pages left to be written*/ while (ogg_stream_flush(&os, &og)) { ret = oe_write_page(&og, fout); if(ret != og.header_len + og.body_len) { fprintf (stderr,"Error: failed writing header to output stream\n"); exit(1); } else bytes_written += ret; } if (!with_cbr && !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); celt_encoder_destroy(st); celt_mode_destroy(mode); ogg_stream_clear(&os); if (close_in) fclose(fin); if (close_out) fclose(fout); return 0; }
int main(int argc, char *argv[]) { int err; char *inFile, *outFile; FILE *fin, *fout; CELTMode *mode=NULL; CELTEncoder *enc; CELTDecoder *dec; int len; celt_int32 frame_size, channels; int bytes_per_packet; unsigned char data[MAX_PACKET]; int rate; int complexity; #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH) int i; double rmsd = 0; #endif int count = 0; celt_int32 skip; celt_int16 *in, *out; if (argc != 9 && argc != 8 && argc != 7) { fprintf (stderr, "Usage: testcelt <rate> <channels> <frame size> " " <bytes per packet> [<complexity> [packet loss rate]] " "<input> <output>\n"); return 1; } rate = atoi(argv[1]); channels = atoi(argv[2]); frame_size = atoi(argv[3]); mode = celt_mode_create(rate, frame_size, NULL); if (mode == NULL) { fprintf(stderr, "failed to create a mode\n"); return 1; } bytes_per_packet = atoi(argv[4]); if (bytes_per_packet < 0 || bytes_per_packet > MAX_PACKET) { fprintf (stderr, "bytes per packet must be between 0 and %d\n", MAX_PACKET); return 1; } inFile = argv[argc-2]; fin = fopen(inFile, "rb"); if (!fin) { fprintf (stderr, "Could not open input file %s\n", argv[argc-2]); return 1; } outFile = argv[argc-1]; fout = fopen(outFile, "wb+"); if (!fout) { fprintf (stderr, "Could not open output file %s\n", argv[argc-1]); return 1; } enc = celt_encoder_create_custom(mode, channels, &err); if (err != 0) { fprintf(stderr, "Failed to create the encoder: %s\n", celt_strerror(err)); return 1; } dec = celt_decoder_create_custom(mode, channels, &err); if (err != 0) { fprintf(stderr, "Failed to create the decoder: %s\n", celt_strerror(err)); return 1; } celt_decoder_ctl(dec, CELT_GET_LOOKAHEAD(&skip)); if (argc>7) { complexity=atoi(argv[5]); celt_encoder_ctl(enc,CELT_SET_COMPLEXITY(complexity)); } in = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16)); out = (celt_int16*)malloc(frame_size*channels*sizeof(celt_int16)); while (!feof(fin)) { int ret; err = fread(in, sizeof(short), frame_size*channels, fin); if (feof(fin)) break; len = celt_encode(enc, in, frame_size, data, bytes_per_packet); if (len <= 0) fprintf (stderr, "celt_encode() failed: %s\n", celt_strerror(len)); /* This is for simulating bit errors */ #if 0 int errors = 0; int eid = 0; /* This simulates random bit error */ for (i=0;i<len*8;i++) { if (rand()%atoi(argv[8])==0) { if (i<64) { errors++; eid = i; } data[i/8] ^= 1<<(7-(i%8)); } } if (errors == 1) data[eid/8] ^= 1<<(7-(eid%8)); else if (errors%2 == 1) data[rand()%8] ^= 1<<rand()%8; #endif #if 1 /* Set to zero to use the encoder's output instead */ /* This is to simulate packet loss */ if (argc==9 && rand()%1000<atoi(argv[argc-3])) /*if (errors && (errors%2==0))*/ ret = celt_decode(dec, NULL, len, out, frame_size); else ret = celt_decode(dec, data, len, out, frame_size); if (ret < 0) fprintf(stderr, "celt_decode() failed: %s\n", celt_strerror(ret)); #else for (i=0;i<ret*channels;i++) out[i] = in[i]; #endif #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH) for (i=0;i<ret*channels;i++) { rmsd += (in[i]-out[i])*1.0*(in[i]-out[i]); /*out[i] -= in[i];*/ } #endif count++; fwrite(out+skip*channels, sizeof(short), (ret-skip)*channels, fout); skip = 0; } PRINT_MIPS(stderr); celt_encoder_destroy(enc); celt_decoder_destroy(dec); fclose(fin); fclose(fout); celt_mode_destroy(mode); free(in); free(out); #if !(defined (FIXED_POINT) && !defined(CUSTOM_MODES)) && defined(RESYNTH) if (rmsd > 0) { rmsd = sqrt(rmsd/(1.0*frame_size*channels*count)); fprintf (stderr, "Error: encoder doesn't match decoder\n"); fprintf (stderr, "RMS mismatch is %f\n", rmsd); return 1; } else { fprintf (stderr, "Encoder matches decoder!!\n"); } #endif return 0; }
CELTEncoder *celt_encoder_create(const CELTMode *mode, int channels, int *error) { int N, C; CELTEncoder *st; if (check_mode(mode) != CELT_OK) { if (error) *error = CELT_INVALID_MODE; return NULL; } #ifdef DISABLE_STEREO if (channels > 1) { celt_warning("Stereo support was disable from this build"); if (error) *error = CELT_BAD_ARG; return NULL; } #endif if (channels < 0 || channels > 2) { celt_warning("Only mono and stereo supported"); if (error) *error = CELT_BAD_ARG; return NULL; } N = mode->mdctSize; C = channels; st = celt_alloc(sizeof(CELTEncoder)); if (st==NULL) { if (error) *error = CELT_ALLOC_FAIL; return NULL; } st->marker = ENCODERPARTIAL; st->mode = mode; st->frame_size = N; st->block_size = N; st->overlap = mode->overlap; st->channels = channels; st->vbr_rate = 0; st->pitch_enabled = 1; st->pitch_permitted = 1; st->pitch_available = 1; st->force_intra = 0; st->delayedIntra = 1; st->tonal_average = QCONST16(1.,8); st->fold_decision = 1; st->in_mem = celt_alloc(st->overlap*C*sizeof(celt_sig)); st->out_mem = celt_alloc((MAX_PERIOD+st->overlap)*C*sizeof(celt_sig)); st->pitch_buf = celt_alloc(((MAX_PERIOD>>1)+2)*sizeof(celt_word16)); st->oldBandE = (celt_word16*)celt_alloc(C*mode->nbEBands*sizeof(celt_word16)); st->preemph_memE = (celt_word16*)celt_alloc(C*sizeof(celt_word16)); st->preemph_memD = (celt_sig*)celt_alloc(C*sizeof(celt_sig)); if ((st->in_mem!=NULL) && (st->out_mem!=NULL) && (st->oldBandE!=NULL) && (st->preemph_memE!=NULL) && (st->preemph_memD!=NULL)) { if (error) *error = CELT_OK; st->marker = ENCODERVALID; return st; } /* If the setup fails for some reason deallocate it. */ celt_encoder_destroy(st); if (error) *error = CELT_ALLOC_FAIL; return NULL; }