コード例 #1
0
ファイル: opus_sm_demo.c プロジェクト: jzombi/opus_sm
/* Init Opus encoder, return it on success. Print error to stdout, release wave resource and return NULL on error. */
OpusSM* init_opus(WAVE* wave) {
	OpusSM* sm = sm_init(wave->header.SampleRate, wave->header.NumChannels);

	if (sm_error(sm) != SM_OK) {
		fprintf(stderr, "Opus encoder returned error on opus_encoder_create(). Error code: %d\n", sm_error(sm));
		sm = sm_destroy(sm);
		return NULL;
	}

	return sm;
}
コード例 #2
0
ファイル: opus_sm_demo.c プロジェクト: jzombi/opus_sm
/* Main program. */
int main(int argc, char* argv[]) {

	const int verbose = 0;

	if ((argc < 2) || (argc > 6)) {
		print_syntax(argv[0]);
		return 1;
	}

	const char* infile  = argv[1];
	const char* out_pmusic = NULL;
	const char* out_labels = NULL;
	double sm_segment_min_dur = 4.0f;
	double b_segment_min_dur = 4.0f;

	if (argc >= 3) {
		out_pmusic = argv[2];
	}

	if (argc >= 4) {
		out_labels = argv[3];
	}

	if (argc >= 5) {
		sm_segment_min_dur = atof(argv[4]);
	}

	if (argc >= 6) {
		b_segment_min_dur = atof(argv[5]);
	}

	/* Load file */
	
	WAVE* wave = open_wav(infile, verbose);
	
	if (wave == NULL) {
		return 1;
	}

	/* Init Opus encoder */

	OpusSM* sm = init_opus(wave);

	if (sm == NULL) {
		wclose(wave);
		return 1;
	}

	/* Open output files */

	FILE* ofp_pmusic = open_output_file(out_pmusic);
	if (ofp_pmusic == NULL) {
		wclose(wave);
		sm_destroy(sm);
		return 1;
	}

	FILE* ofp_labels = open_output_file(out_labels);
	if (ofp_labels == NULL) {
		wclose(wave);
		sm_destroy(sm);
		fclose(ofp_pmusic);
		return 1;
	}

	/* Processing */
	
	int error = process(infile,
	                    wave,
	                    sm,
	                    ofp_pmusic,
	                    ofp_labels,
	                    sm_segment_min_dur,
	                    b_segment_min_dur
	                   );

	/* Clean up */

	sm = sm_destroy(sm);
	wave = wclose(wave);
	fclose(ofp_pmusic);
	fclose(ofp_labels);

	return error;
}
コード例 #3
0
ファイル: main.c プロジェクト: FI-Lab/OCC-benchmarks
int main(int argc, char **argv)
{
    int ret;
    ret = odp_init_global(NULL, NULL);
    if(ret < 0)
    {
        fprintf(stderr, "global init failure!\n");
        exit(EXIT_FAILURE);
    }
    ret = odp_init_local(ODP_THREAD_CONTROL);
    if(ret < 0)
    {
        fprintf(stderr, "local init failure!\n");
        exit(EXIT_FAILURE);
    }

    parse_param(argc, argv);

    packet_classifier_init(glb_param.rule_file, glb_param.fib_file);
    hash_env_init();
    sm_hdl = sm_build(glb_param.pat_file);

    hs_tbl = create_hash_table();

    odp_pool_t pkt_pool;
    pkt_pool = create_pkt_pool("PACKET_POOL",PACKET_POOL_OBJ_SZ,
            PACKET_POOL_MAX_ELT_NUM);
    if(pkt_pool == ODP_POOL_INVALID)
    {
        fprintf(stderr, "create packet pool failure!\n");
        exit(EXIT_FAILURE);
    }

    if(init_all_if(pkt_pool) == -1)
    {
        fprintf(stderr, "init nic faliure!\n");
        exit(EXIT_FAILURE);
    }
    
    odph_linux_pthread_t thr_tbl[ODP_CONFIG_PKTIO_ENTRIES];
    int thr_num;
    thr_num = odph_linux_pthread_create(thr_tbl, &glb_param.cpu_mask, thread_fwd_routine, NULL);
    if(thr_num != glb_param.nic.num)
    {
        fprintf(stderr, "some nic thread start failure!\n");
        exit(EXIT_FAILURE);
    }

    odph_linux_pthread_t thr_stat_hdl;
    odp_cpumask_t thr_stat_mask;
    
    odp_cpumask_zero(&thr_stat_mask);
    odp_cpumask_set(&thr_stat_mask, glb_param.nic.num);
    if(odph_linux_pthread_create(&thr_stat_hdl, &thr_stat_mask, thread_stat_routine, NULL) != 1)
    {
        fprintf(stderr, "stat thread start failure!\n");
        exit(EXIT_FAILURE);
    }

    odph_linux_pthread_join(thr_tbl, thr_num);
    odph_linux_pthread_join(&thr_stat_hdl, 1);
 

    int nic_id;
    for(nic_id = 0; nic_id < glb_param.nic.num; nic_id++)
    {
        odp_pktio_close(thr_data.nic_hdl[nic_id]);
    }
    sm_destroy(sm_hdl);
    odph_hash_free(hs_tbl);
    odp_pool_destroy(pkt_pool);

    odp_term_local();
    odp_term_global();

    return 0;
}