Example #1
0
int main(int argc, char *argv[])  
{  
    int ret;

    FA_PRINT_INIT(FA_PRINT_ENABLE,
                  FA_PRINT_FILE_ENABLE,FA_PRINT_STDOUT_ENABLE,FA_PRINT_STDERR_ENABLE,
                  /*FA_PRINT_FILE_DISABLE,FA_PRINT_STDOUT_ENABLE,FA_PRINT_STDERR_ENABLE,*/
                  FA_PRINT_PID_ENABLE,
                  "/tmp", "testlog", "TS");

    ret = fa_parseopt(argc, argv);
    if(ret)
        FA_PRINT_ERR("FAIL: now doing the abnormal things\n");
    else
        FA_PRINT("SUCC: now doing the normal thing\n");

    FA_PRINT_DBG("TEST: now test debug info\n");

    FA_PRINT_UNINIT();
    return 0;  
}  
Example #2
0
int main(int argc, char *argv[])
{
    int ret;
    int frame_index = 0;

	FILE  * destfile;
	FILE  * sourcefile;
	fa_wavfmt_t fmt;

	int i;
    int is_last = 0;
    int read_len = 0;
    int write_total_size= 0;

    uintptr_t h_aac_analysis, h_aac_synthesis;
    uintptr_t h_aacpsy;
    int block_type;
    float pe;

	short wavsamples_in[FRAME_SIZE_MAX];
	short wavsamples_out[FRAME_SIZE_MAX];
	float buf_in[FRAME_SIZE_MAX];
    float buf_out[FRAME_SIZE_MAX];
    float mdct_line[FRAME_SIZE_MAX];

    int block_switch_en = 1;

    ret = fa_parseopt(argc, argv);
    if(ret) return -1;

    if ((destfile = fopen(opt_outputfile, "w+b")) == NULL) {
		printf("output file can not be opened\n");
		return 0; 
	}                         

	if ((sourcefile = fopen(opt_inputfile, "rb")) == NULL) {
		printf("input file can not be opened;\n");
		return 0; 
    }

    fmt = fa_wavfmt_readheader(sourcefile);
    fseek(sourcefile,46,0);
    fseek(destfile, 0, SEEK_SET);
    fa_wavfmt_writeheader(fmt, destfile);

    h_aacpsy = fa_aacpsy_init(48000);
    h_aac_analysis = fa_aacfilterbank_init(block_switch_en);
    h_aac_synthesis = fa_aacfilterbank_init(block_switch_en);


    while(1)
    {
        if(is_last)
            break;

        memset(wavsamples_in, 0, 2*opt_framelen);
        read_len = fread(wavsamples_in, 2, opt_framelen, sourcefile);
        if(read_len < opt_framelen)
            is_last = 1;
       
        for(i = 0 ; i < read_len; i++) {
            buf_in[i] = (float)wavsamples_in[i]/32768;
            buf_out[i] = 0;
        }
        
        if(block_switch_en) {
            block_type = fa_get_aacblocktype(h_aac_analysis);
            pe = fa_aacpsy_calculate_pe(h_aacpsy, wavsamples_in, block_type);
            fa_aacblocktype_switch(h_aac_analysis, h_aacpsy, pe);
        }

        fa_aacfilterbank_analysis(h_aac_analysis, buf_in, mdct_line);

        if(block_switch_en) {
            block_type = fa_get_aacblocktype(h_aac_analysis);
            fa_set_aacblocktype(h_aac_synthesis, block_type);
        }
        fa_aacfilterbank_synthesis(h_aac_synthesis, mdct_line, buf_out);

        for(i = 0 ; i < opt_framelen; i++) {
            float temp;
            temp = buf_out[i] * 32768;

            if (temp >= 32767)
                temp = 32767;
            if (temp < -32768)
                temp = -32768;

            wavsamples_out[i] = temp;
        }

        fwrite(wavsamples_out, 2, opt_framelen, destfile);

        write_total_size += 2 * opt_framelen;

        frame_index++;
        fprintf(stderr,"\rthe frame = [%d]", frame_index);
    }

    fmt.data_size=write_total_size/fmt.block_align;
    fseek(destfile, 0, SEEK_SET);
    fa_wavfmt_writeheader(fmt,destfile);

    fclose(sourcefile);
    fclose(destfile);

    /*fa_aacfilterbank_uninit();*/
    printf("\n");

    return 0;
}
Example #3
0
int main(int argc, char *argv[])
{
    int ret;
    int is_last = 0;
    int read_len = 0;
    int read_total_size = 0;
		
	unsigned char buf[BUF_MAX_SIZE];
	fa_wavfmt_t fmt;

	FILE  * destfile;
	FILE  * sourcefile;

    ret = fa_parseopt(argc, argv);
    if(ret < 0) return -1;

    if ((destfile   = fopen(opt_outputfile, "w+b")) == NULL) {
		printf("FAIL: output file can not be opened\n");
		return -1; 
	}                         

	if ((sourcefile = fopen(opt_inputfile, "rb"))   == NULL) {
		printf("FAIL: input file can not be opened;\n");
		return -1; 
    }

    fmt = fa_wavfmt_readheader(sourcefile);

    printf("NOTE: the sourcefile fmt is below:\n");
    printf("NOTE: wav fmt         : %u\n"  , fmt.format);
    printf("NOTE: total file size : %lu\n" , fmt.data_size*fmt.block_align+36);
    printf("NOTE: channels        : %u\n"  , fmt.channels);
    printf("NOTE: samplerate      : %lu\n" , fmt.samplerate);
    printf("NOTE: bytes per sample: %u\n"  , fmt.bytes_per_sample);
    printf("NOTE: block align     : %u\n"  , fmt.block_align);
    printf("NOTE: wav data size   : %lu\n" , fmt.data_size);


    fseek(sourcefile, 44, SEEK_SET);
    fseek(destfile  ,  0, SEEK_SET);
    fa_wavfmt_writeheader(fmt, destfile);

    while(1)
    {
        if(is_last)
            break;

        read_len = fread(buf, 1, opt_framelen, sourcefile); 
        if(read_len < opt_framelen)
            is_last = 1;

        read_total_size += read_len;
        fwrite(buf, 1, read_len, destfile);
    }

    fmt.data_size = read_total_size / fmt.block_align;
    
    fseek(destfile  ,  0, SEEK_SET);
    fa_wavfmt_writeheader(fmt, destfile);

    fclose(sourcefile);
    fclose(destfile);

    printf("SUCC: copy wav fmt data successfully\n");

    return 0;
}