예제 #1
0
uintptr_t fa_aacenc_init(int sample_rate, int bit_rate, int chn_num,
                         int mpeg_version, int aac_objtype, int lfe_enable,
                         int band_width,
                         int speed_level)
{

    int ms_enable;
    int tns_enable;
    int block_switch_enable;
    int blockswitch_method;
    int quantize_method;
    int psy_enable;

    uintptr_t handle;

    int bit_rate_max, bit_rate_min;
    int bit_rate_chn;


    int speed_index;

    if (speed_level > SPEED_LEVEL_MAX || speed_level < 1)
        return 0;

    speed_index = speed_level - 1;

    ms_enable            = speed_level_tab[speed_index][0];
    tns_enable           = speed_level_tab[speed_index][1];
    block_switch_enable  = speed_level_tab[speed_index][2];
    psy_enable           = speed_level_tab[speed_index][3];
    blockswitch_method   = speed_level_tab[speed_index][4];
    quantize_method      = speed_level_tab[speed_index][5];

    bit_rate_min = 16;
    bit_rate_max = 160;
    bit_rate_chn = bit_rate/chn_num;

    if ((bit_rate_chn > bit_rate_max) || (bit_rate_chn < bit_rate_min)) {
        printf("total bitrate=%d, per chn = %d\n", bit_rate, bit_rate_chn);
        printf("bitrate not support, only suporrt [16~160]kbps per chn\n");
        exit(0);
    }

    handle = aacenc_init(sample_rate, bit_rate*1000, chn_num,
                         mpeg_version, aac_objtype, band_width*1000, speed_level,
                         ms_enable, lfe_enable, tns_enable, block_switch_enable, psy_enable,
                         blockswitch_method, quantize_method);

    return handle;

}
예제 #2
0
파일: main.c 프로젝트: John-He-928/fdkaac
int main(int argc, char **argv)
{
    static m4af_io_callbacks_t m4af_io = {
        read_callback, write_callback, seek_callback, tell_callback
    };
    aacenc_param_ex_t params = { 0 };

    int result = 2;
    char *output_filename = 0;
    pcm_reader_t *reader = 0;
    HANDLE_AACENCODER encoder = 0;
    AACENC_InfoStruct aacinfo = { 0 };
    m4af_ctx_t *m4af = 0;
    const pcm_sample_description_t *sample_format;
    int frame_count = 0;
    int sbr_mode = 0;
    unsigned scale_shift = 0;

    setlocale(LC_CTYPE, "");
    setbuf(stderr, 0);

    if (parse_options(argc, argv, &params) < 0)
        return 1;

    if ((reader = open_input(&params)) == 0)
        goto END;

    sample_format = pcm_get_format(reader);

    sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)&params);
    if (sbr_mode && !aacenc_is_sbr_ratio_available()) {
        fprintf(stderr, "WARNING: Only dual-rate SBR is available "
                        "for this version\n");
        params.sbr_ratio = 2;
    }
    scale_shift = aacenc_is_dual_rate_sbr((aacenc_param_t*)&params);
    params.sbr_signaling =
        (params.transport_format == TT_MP4_LOAS) ? 2 :
        (params.transport_format == TT_MP4_RAW)  ? 1 : 0;
    if (sbr_mode && !scale_shift)
        params.sbr_signaling = 2;

    if (aacenc_init(&encoder, (aacenc_param_t*)&params, sample_format,
                    &aacinfo) < 0)
        goto END;

    if (!params.output_filename) {
        const char *ext = params.transport_format ? ".aac" : ".m4a";
        output_filename = generate_output_filename(params.input_filename, ext);
        params.output_filename = output_filename;
    }

    if ((params.output_fp = aacenc_fopen(params.output_filename, "wb+")) == 0) {
        aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.output_filename,
                       strerror(errno));
        goto END;
    }
    handle_signals();

    if (!params.transport_format) {
        uint32_t scale;
        unsigned framelen = aacinfo.frameLength;
        scale = sample_format->sample_rate >> scale_shift;
        if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io,
                                params.output_fp)) < 0)
            goto END;
        m4af_set_decoder_specific_info(m4af, 0,
                                       aacinfo.confBuf, aacinfo.confSize);
        m4af_set_fixed_frame_duration(m4af, 0,
                                      framelen >> scale_shift);
        m4af_set_vbr_mode(m4af, 0, params.bitrate_mode);
        m4af_set_priming_mode(m4af, params.gapless_mode + 1);
        m4af_begin_write(m4af);
    }
예제 #3
0
uintptr_t fa_aacenc_init(int sample_rate, int bit_rate, int chn_num, float quality, int vbr_flag,
                         int mpeg_version, int aac_objtype, int lfe_enable,
                         float band_width,
                         int speed_level,
                         int time_resolution_first)
{

    int ms_enable;
    int tns_enable;
    int block_switch_enable;
    int blockswitch_method;
    int quantize_method;
    int psy_enable;
    int psy_model;

    uintptr_t handle;

    int bit_rate_max, bit_rate_min;
    int bit_rate_chn;

    int speed_index;

    float qcof;

    if (speed_level > SPEED_LEVEL_MAX || speed_level < 1)
        return 0;

    speed_index = speed_level - 1;

    ms_enable            = speed_level_tab[speed_index][0];
    tns_enable           = speed_level_tab[speed_index][1];
    block_switch_enable  = speed_level_tab[speed_index][2];
    psy_enable           = speed_level_tab[speed_index][3];
    /*psy_model            = PSYCH1;*/
    psy_model            = PSYCH2;
    blockswitch_method   = speed_level_tab[speed_index][4];
    quantize_method      = speed_level_tab[speed_index][5];

    bit_rate_min = 16;
    bit_rate_max = 160;
    bit_rate_chn = bit_rate/chn_num;

    qcof = QCOF_MAX - quality;
    if (qcof < QCOF_MIN)
        qcof = QCOF_MIN;
    if (qcof > QCOF_MAX)
        qcof = QCOF_MAX;

    if ((bit_rate_chn > bit_rate_max) || (bit_rate_chn < bit_rate_min)) {
        printf("total bitrate=%d, per chn = %d\n", bit_rate, bit_rate_chn);
        printf("bitrate not support, only suporrt [16~160]kbps per chn\n");
        exit(0);
    }

    //2012-12-02
    fa_logtab_init();

    handle = aacenc_init(sample_rate, bit_rate*1000, chn_num, qcof, vbr_flag,
                         mpeg_version, aac_objtype, band_width*1000, speed_level,
                         ms_enable, lfe_enable, tns_enable, block_switch_enable, psy_enable, psy_model,
                         blockswitch_method, quantize_method, time_resolution_first);

    return handle;

}
예제 #4
0
int main(int argc, char **argv)
{
    wav_io_context_t wav_io = { read_callback, seek_callback, tell_callback };
    m4af_io_callbacks_t
        m4af_io = { read_callback, write_callback, seek_callback, tell_callback };
    aacenc_param_ex_t params = { 0 };

    int result = 2;
    FILE *ifp = 0;
    FILE *ofp = 0;
    char *output_filename = 0;
#ifdef USE_LIBSNDFILE
    SNDFILE* snd = NULL;
    SF_INFO snd_info;
    pcm_sample_description_t snd_desc = { 0 };
#else
    wav_reader_t *wavf = 0;
#endif
    HANDLE_AACENCODER encoder = 0;
    AACENC_InfoStruct aacinfo = { 0 };
    m4af_ctx_t *m4af = 0;
    const pcm_sample_description_t *sample_format;
    int downsampled_timescale = 0;
    int frame_count = 0;
    struct stat stb = { 0 };

    setlocale(LC_CTYPE, "");
    setbuf(stderr, 0);

    if (parse_options(argc, argv, &params) < 0)
        return 1;

#ifdef USE_LIBSNDFILE
    if ((snd = sf_open (params.input_filename, SFM_READ, &snd_info)) == NULL) {
        fprintf(stderr, "ERROR: broken / unsupported input file\n");
        goto END;
    }
#ifdef USE_LIBSAMPLERATE
    if(params.resample) {
        snd_desc.sample_rate = params.resample;
        printf("resampling to %dhz\n", snd_desc.sample_rate);
    } else {
        snd_desc.sample_rate = snd_info.samplerate;
    }
    snd_desc.sample_type = PCM_TYPE_FLOAT; // always -- libsndfile does the conversion for us
    snd_desc.bits_per_channel = sizeof(float)*8;
#else
    snd_desc.sample_rate = snd_info.samplerate;
    snd_desc.sample_type = PCM_TYPE_SINT; // always -- libsndfile does the conversion for us
    snd_desc.bits_per_channel = sizeof(short)*8;
#endif
    snd_desc.channels_per_frame = snd_info.channels;
    snd_desc.bytes_per_frame = snd_info.channels * (snd_desc.bits_per_channel / 8);
    snd_desc.channel_mask = 0;

    sample_format = &snd_desc;
#else
    if ((ifp = aacenc_fopen(params.input_filename, "rb")) == 0) {
        aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.input_filename,
                       strerror(errno));
        goto END;
    }
    
    if (fstat(fileno(ifp), &stb) == 0 && (stb.st_mode & S_IFMT) != S_IFREG) {
        wav_io.seek = 0;
        wav_io.tell = 0;
    }
    
    if (!params.is_raw) {
        if ((wavf = wav_open(&wav_io, ifp, params.ignore_length)) == 0) {
            fprintf(stderr, "ERROR: broken / unsupported input file\n");
            goto END;
        }
    } else {
        int bytes_per_channel;
        pcm_sample_description_t desc = { 0 };
        if (parse_raw_spec(params.raw_format, &desc) < 0) {
            fprintf(stderr, "ERROR: invalid raw-format spec\n");
            goto END;
        }
        desc.sample_rate = params.raw_rate;
        desc.channels_per_frame = params.raw_channels;
        bytes_per_channel = (desc.bits_per_channel + 7) / 8;
        desc.bytes_per_frame = params.raw_channels * bytes_per_channel;
        if ((wavf = raw_open(&wav_io, ifp, &desc)) == 0) {
            fprintf(stderr, "ERROR: failed to open raw input\n");
            goto END;
        }
    }

    sample_format = wav_get_format(wavf);
#endif

    if (aacenc_init(&encoder, (aacenc_param_t*)&params, sample_format,
                    &aacinfo) < 0)
        goto END;

    if (!params.output_filename) {
        const char *ext = params.transport_format ? ".aac" : ".m4a";
        output_filename = generate_output_filename(params.input_filename, ext);
        params.output_filename = output_filename;
    }

    if ((ofp = aacenc_fopen(params.output_filename, "wb+")) == 0) {
        aacenc_fprintf(stderr, "ERROR: %s: %s\n", params.output_filename,
                       strerror(errno));
        goto END;
    }
    handle_signals();
    if (!params.transport_format) {
        uint32_t scale;
        unsigned framelen = aacinfo.frameLength;
        int sbr_mode = aacenc_is_sbr_active((aacenc_param_t*)&params);
        int sig_mode = aacEncoder_GetParam(encoder, AACENC_SIGNALING_MODE);
        if (sbr_mode && !sig_mode)
            downsampled_timescale = 1;
        scale = sample_format->sample_rate >> downsampled_timescale;
        if ((m4af = m4af_create(M4AF_CODEC_MP4A, scale, &m4af_io, ofp)) < 0)
            goto END;
        m4af_set_decoder_specific_info(m4af, 0, aacinfo.confBuf,
                                       aacinfo.confSize);
        m4af_set_fixed_frame_duration(m4af, 0,
                                      framelen >> downsampled_timescale);
        m4af_set_priming_mode(m4af, params.gapless_mode + 1);
        m4af_begin_write(m4af);
    }