void mage_hts_engine_impl::do_initialize() { configure_for_sample_rate(); std::string bpf_path(path::join(model_path,"bpf.txt")); if(!bpf_load(&bpf,bpf_path.c_str())) throw initialization_error(); arg_list args; model_file_list dur_files(model_path,"dur"); append_model_args(args,dur_files,"-td","-md"); model_file_list mgc_files(model_path,"mgc",3); append_model_args(args,mgc_files,"-tm","-mm","-dm"); model_file_list lf0_files(model_path,"lf0",3); append_model_args(args,lf0_files,"-tf","-mf","-df"); model_file_list ap_files(model_path,"bap",3); append_model_args(args,ap_files,"-tl","-ml","-dl"); args.push_back(arg("-s",str::to_string(sample_rate.get()))); args.push_back(arg("-p",str::to_string(frame_shift))); args.push_back(arg("-a",str::to_string(alpha))); args.push_back(arg("-b",str::to_string(beta.get()))); args.push_back(arg("-u","0.5")); std::vector<char*> c_args; char name[]="RHVoice"; c_args.push_back(name); for(arg_list::const_iterator it=args.begin();it!=args.end();++it) { c_args.push_back(const_cast<char*>(it->first.c_str())); c_args.push_back(const_cast<char*>(it->second.c_str())); } mage.reset(new MAGE::Mage("default",c_args.size(),&c_args[0])); vocoder.reset(new HTS_Vocoder); }
static inline int bpf_open(pcap_t *p, char *errbuf) { int fd; int n = 0; char device[sizeof "/dev/bpf0000000000"]; #ifdef _AIX /* * Load the bpf driver, if it isn't already loaded, * and create the BPF device entries, if they don't * already exist. */ if (bpf_load(errbuf) == -1) return (-1); #endif /* * Go through all the minors and find one that isn't in use. */ do { (void)snprintf(device, sizeof(device), "/dev/bpf%d", n++); /* * Initially try a read/write open (to allow the inject * method to work). If that fails due to permission * issues, fall back to read-only. This allows a * non-root user to be granted specific access to pcap * capabilities via file permissions. * * XXX - we should have an API that has a flag that * controls whether to open read-only or read-write, * so that denial of permission to send (or inability * to send, if sending packets isn't supported on * the device in question) can be indicated at open * time. */ fd = open(device, O_RDWR); if (fd == -1 && errno == EACCES) fd = open(device, O_RDONLY); } while (fd < 0 && errno == EBUSY); /* * XXX better message for all minors used */ if (fd < 0) snprintf(errbuf, PCAP_ERRBUF_SIZE, "(no devices found) %s: %s", device, pcap_strerror(errno)); return (fd); }
void std_hts_engine_impl::do_initialize() { engine.reset(new HTS_Engine); HTS_Engine_initialize(engine.get()); engine->audio.audio_interface=this; std::string voice_path(path::join(model_path,"voice.data")); char* c_voice_path=const_cast<char*>(voice_path.c_str()); if(!HTS_Engine_load(engine.get(),&c_voice_path,1)) { HTS_Engine_clear(engine.get()); throw initialization_error(); } std::string bpf_path(path::join(model_path,"bpf.txt")); if(bpf_load(&engine->bpf,bpf_path.c_str())==0) { HTS_Engine_clear(engine.get()); throw initialization_error(); } HTS_Engine_set_beta(engine.get(),beta); HTS_Engine_set_audio_buff_size(engine.get(),HTS_Engine_get_fperiod(engine.get())); }
struct plum *bpf_dp_register_plum(struct bpf_image *image, struct plum *old_plum, bool alloc_tbl) { int ret; struct bpf_program *bpf_prog; struct plum *plum; struct hlist_head *replicators = NULL; int i; int tsize; union table_priv { struct plum_hash_table htable; struct plum_lpm_table ltable; }; ret = bpf_load(image, &bpf_plum_cb, &bpf_prog); if (ret < 0) { pr_err("BPF load failed %d\n", ret); return ERR_PTR(ret); } if (old_plum && !alloc_tbl && compare_tables(old_plum, bpf_prog)) { ret = -EINVAL; goto err_free_bpf_prog; } ret = -ENOMEM; plum = kzalloc(sizeof(*plum), GFP_KERNEL); if (!plum) goto err_free_bpf_prog; plum->bpf_prog = bpf_prog; plum->num_tables = bpf_prog->table_cnt; if (!old_plum) { alloc_tbl = true; replicators = kzalloc(PLUM_MAX_REPLICATORS * sizeof(struct hlist_head), GFP_KERNEL); if (!replicators) goto err_free_plum; plum->replicators = replicators; for (i = 0; i < PLUM_MAX_REPLICATORS; i++) INIT_HLIST_HEAD(&plum->replicators[i]); } else { if (!alloc_tbl) plum->tables = old_plum->tables; plum->replicators = old_plum->replicators; memcpy(&plum->ports[0], &old_plum->ports[0], sizeof(old_plum->ports[0]) * PLUM_MAX_PORTS); memcpy(&plum->stats[0], &old_plum->stats[0], sizeof(old_plum->stats[0]) * PLUM_MAX_PORTS); } if (alloc_tbl) { if (bpf_prog->table_cnt) { plum->tables = kzalloc(bpf_prog->table_cnt * sizeof(*plum->tables), GFP_KERNEL); if (!plum->tables) goto err_free_replicators; tsize = sizeof(struct plum_table); tsize += ALIGN(sizeof(struct plum_table), PLUM_TABLE_ALIGN); tsize += sizeof(union table_priv); for (i = 0; i < bpf_prog->table_cnt; i++) { plum->tables[i] = kzalloc(tsize, GFP_KERNEL); if (!plum->tables[i]) goto err_free_tables; memcpy(&plum->tables[i]->info, &bpf_prog->tables[i], sizeof(struct bpf_table)); } if (init_plum_tables(plum) < 0) goto err_free_table_array; } } if (bpf_prog->jit_image) plum->run = (void (*)(struct bpf_dp_context *ctx))bpf_prog->jit_image; else plum->run = bpf_run_wrap; return plum; err_free_tables: for (i = 0; i < bpf_prog->table_cnt; i++) kfree(plum->tables[i]); err_free_table_array: kfree(plum->tables); err_free_replicators: kfree(replicators); err_free_plum: kfree(plum); err_free_bpf_prog: bpf_free(bpf_prog); return ERR_PTR(ret); }