一个音乐项目,要做编解码,上头的人决定用CELT
有对CELT不熟,园子里有大侠了解CELT,求帖一段代码,网站:http://www.celt-codec.org/小生这里拜谢了

解决方案 »

  1.   

    #include <stdio.h>
    #include <stdlib.h>
    #include "celt.h"extern "C"{
    void __chkstk(){}
    };int main(int argc,const char *argv[])
    {
    unsigned char in[43];
    celt_int16 out[256];
    CELTMode *mode;
    CELTDecoder *dec;
    celt_int32 skip;
    mode=celt_mode_create(48000,256,NULL); //mode=celt_mode_create(48000,1,256,NULL);
    if(mode==NULL)return EXIT_FAILURE;
    celt_mode_info(mode,CELT_GET_LOOKAHEAD,&skip);
    dec=celt_decoder_create(48000,256,NULL);
    if(dec==NULL)
    return EXIT_FAILURE;
    while(fread(in,sizeof(unsigned char),43,stdin)>=43)
    {
    if(celt_decode(dec,in,48000,out,43)<0) //if(celt_decode(dec,in,43,out)<0)
    return EXIT_FAILURE;
    fwrite(out+skip,sizeof(celt_int16),256-skip,stdout);
    skip=0;
    }
    celt_decoder_destroy(dec);
    celt_mode_destroy(mode);
    return EXIT_SUCCESS;
    }
      

  2.   

    #include <stdio.h>
    #include <stdlib.h>
    #include "celt.h"#define maxCompressedBytes 43extern "C"{
    void __chkstk(){}
    };int main(int argc,const char *argv[])
    {
    celt_int16 in[256];
    celt_int32 Fs=48000;
    int frame_size=256;
    int channels=2;
    unsigned char out[43];
    CELTMode *mode; //编码器
    CELTEncoder *enc; //编码器状态
    int error;

    //EXPORT CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error);
    mode=celt_mode_create(Fs,frame_size,&error); //1.采样率 2.每帧的样本 3.错误返回类型
    //返回一个新创建的模式
    if(mode==NULL)
    {
    return EXIT_FAILURE;
    }

    //EXPORT CELTEncoder *celt_encoder_create_custom(const CELTMode *mode, int channels, int *error);
    enc=celt_encoder_create_custom(mode,channels,&error); //enc=celt_encoder_create(mode);1.编码模式 2.通道数 3.错误返回类型

    if(enc==NULL)
    {
    return EXIT_FAILURE;
    }
    while(fread(in,sizeof(celt_int16),256,stdin)>=256)
    {
    //EXPORT int celt_encode(CELTEncoder *st, const celt_int16 *pcm, int frame_size, unsigned char *compressed, int maxCompressedBytes);
    if((celt_encode(enc,in,frame_size,out,maxCompressedBytes))<0) //if(celt_encode(enc,in,NULL,out,43)<0);
    //1.编码状态 2.16位音频格式 3.每帧的样本 4.压缩的数据 5.压缩帧最大字节数
    {
    return EXIT_FAILURE;
    }
    fwrite(out,sizeof(unsigned char),maxCompressedBytes,stdout);
    }

    celt_encoder_destroy(enc); //释放指针
    celt_mode_destroy(mode); //释放指针
    return EXIT_SUCCESS;
    }