int main(int argc, char **argv)
{
  if( argc < 2 || param_check(argc,argv) < 0 ){
    usage();
    exit(1);
  }

  if( arg_flg_make_torrent ){
    if( !arg_announce ){ fprintf(stderr,"please use -u specify a announce url!\n"); exit(1);}
    if( !arg_save_as ){ fprintf(stderr,"please use -s specify a metainfo file name!\n"); exit(1);}
    if( BTCONTENT.InitialFromFS(arg_metainfo_file, arg_announce,  arg_piece_length) < 0 ||
       BTCONTENT.CreateMetainfoFile(arg_save_as) < 0){
      fprintf(stderr,"create metainfo failed.\n");
      exit(1);
    }
    printf("create metainfo file %s successful.\n", arg_save_as);
    exit(0);
  }

  if( BTCONTENT.InitialFromMI(arg_metainfo_file, arg_save_as) < 0){
    fprintf(stderr,"error,initial meta info failed.\n");
    exit(1);
  }

  if( !arg_flg_exam_only && !arg_flg_check_only){
    if(WORLD.Initial_ListenPort() < 0){
      fprintf(stderr,"warning,you couldn't accept connection.\n");
    }else
      printf("Listen on: %d\n",cfg_listen_port);

    Tracker.Initial();


    Random_init();

#ifndef __OS2__
    signal(SIGPIPE,SIG_IGN);
#endif
    signal(SIGINT,sigint_catch);
    Downloader();
  }

  exit(0);
}
Example #2
0
void Noise_vstate_init(Voice_state* vstate, const Proc_state* proc_state)
{
    rassert(vstate != NULL);
    rassert(proc_state != NULL);

    Noise_vstate* noise_vstate = (Noise_vstate*)vstate;

    for (int i = 0; i < 2; ++i)
    {
        Random* rand = &noise_vstate->rands[i];
        Random_init(rand, "noise");
        Random_set_seed(rand, Random_get_uint64(vstate->rand_p));
    }

    memset(noise_vstate->buf[0], 0, NOISE_MAX * sizeof(double));
    memset(noise_vstate->buf[1], 0, NOISE_MAX * sizeof(double));

    return;
}
Example #3
0
int main(int argc, char **argv)
{
	try {
		if (argc < 2) {
			throw argc;
		}
	} catch (int) {
		usage();
		exit(1);
	}

	char *s;

	Random_init();

	arg_user_agent = new char[MAX_PF_LEN + 1](); // free'd at end param_check()
	//memmove(arg_user_agent, PEER_PFX, MAX_PF_LEN);
	strcpy(arg_user_agent, PEER_PFX);
	cfg_user_agent = new char[strlen(PACKAGE_NAME) + strlen(PACKAGE_VERSION) + 2]();

	if (!cfg_user_agent)
		return -1;

	sprintf(cfg_user_agent, "%s/%s", PACKAGE_NAME, PACKAGE_VERSION);

	do {
		s = strchr(cfg_user_agent, ' ');
		if (s != NULL)
			*s = '-';
	} while (s);

	if (param_check(argc, argv) < 0) {
		if (arg_user_agent)
			delete[] arg_user_agent;
		return -1;
	}

	if (arg_flg_make_torrent) {
		if (!arg_announce) {
			CONSOLE.Warning(1,
				"Please use -u to specify an announce URL!");
			return EXIT_FAILURE;
		}
		if (!arg_save_as) {
			CONSOLE.Warning(1,
				"Please use -s to specify a metainfo file name!");
			return EXIT_FAILURE;
		}
		if (BTCONTENT.InitialFromFS(arg_metainfo_file, arg_announce,
			arg_piece_length) < 0 ||
			BTCONTENT.CreateMetainfoFile(arg_save_as) < 0) {
			CONSOLE.Warning(1, "create metainfo failed.");
			return EXIT_FAILURE;
		}
		CONSOLE.Print("Create metainfo file %s successful.", arg_save_as);
		return EXIT_SUCCESS;
	}

	if (arg_daemon)
		CONSOLE.Daemonize();

	if (!arg_flg_exam_only
		&& (!arg_flg_check_only || arg_flg_force_seed_mode))
		if (arg_ctcs)
			CTCS.Initial();

	if (BTCONTENT.InitialFromMI(arg_metainfo_file, arg_save_as) < 0) {
		CONSOLE.Warning(1, "error, initial meta info failed.");
		exit(1);
	}

	if (!arg_flg_exam_only
		&& (!arg_flg_check_only || arg_flg_force_seed_mode)) {
		if (WORLD.Initial_ListenPort() < 0) {
			CONSOLE.Warning(2,
				"warn, you can't accept connections.");
		}

		if (Tracker.Initial() < 0) {
			CONSOLE.Warning(1, "error, tracker setup failed.");
			return EXIT_FAILURE;
		}

		sig_setup(); // setup signal handling
		CONSOLE.Interact
			("Press 'h' or '?' for help (display/control client options).");
		Downloader();
		if (cfg_cache_size)
			BTCONTENT.FlushCache();
	}
	if (!arg_flg_exam_only)
		BTCONTENT.SaveBitfield();
	WORLD.CloseAll();

	if (arg_verbose)
		CONSOLE.cpu();

	return EXIT_SUCCESS;
}
Example #4
0
bool Event_channel_hit_process(
        Channel* ch,
        Device_states* dstates,
        const Master_params* master_params,
        const Event_params* params)
{
    rassert(ch != NULL);
    rassert(ch->audio_rate > 0);
    rassert(ch->tempo > 0);
    rassert(dstates != NULL);
    rassert(master_params != NULL);
    rassert(params != NULL);
    rassert(params->arg != NULL);
    rassert(params->arg->type == VALUE_TYPE_INT);

    // Move the old Voices to the background
    Event_channel_note_off_process(ch, dstates, master_params, NULL);

    // Find our audio unit
    Audio_unit* au = Module_get_au_from_input(ch->parent.module, ch->au_input);
    if (au == NULL)
        return true;

    init_force_controls(ch, master_params);

    // Don't attempt to hit effects
    if (Audio_unit_get_type(au) != AU_TYPE_INSTRUMENT)
        return true;

    const int hit_index = (int)params->arg->value.int_type;

    if (!Audio_unit_get_hit_existence(au, hit_index))
        return true;

    const Param_proc_filter* hpf = Audio_unit_get_hit_proc_filter(au, hit_index);

    // Generate our next note random seed here so that random generation
    // is consistent even if we run out of voices
    const uint64_t note_rand_seed = Random_get_uint64(&ch->rand);

    // Find reserved voices
    Voice_group* vgroup = VOICE_GROUP_AUTO;

    if (!Voice_group_reservations_get_clear_entry(
                ch->voice_group_res, ch->num, &ch->fg_group_id) ||
            (Voice_pool_get_group(ch->pool, ch->fg_group_id, vgroup) == NULL))
    {
        reset_channel_voices(ch);
        return true;
    }

    int voice_index = 0;

    for (int i = 0; i < KQT_PROCESSORS_MAX; ++i)
    {
        const Processor* proc = Audio_unit_get_proc(au, i);
        if (proc == NULL ||
                !Device_is_existent((const Device*)proc) ||
                !Processor_get_voice_signals(proc))
            continue;

        // Skip processors that are filtered out for this hit index
        if ((hpf != NULL) && !Param_proc_filter_is_proc_allowed(hpf, i))
            continue;

        const Proc_state* proc_state = (Proc_state*)Device_states_get_state(
                dstates, Device_get_id((const Device*)proc));

        Voice_state_get_size_func* get_vstate_size =
            proc_state->parent.device->dimpl->get_vstate_size;
        if ((get_vstate_size != NULL) && (get_vstate_size() == 0))
            continue;

        char context_str[16] = "";
        snprintf(context_str, 16, "np%hd", (short)i);
        Random* random = Random_init(RANDOM_AUTO, context_str);
        Random_set_seed(random, note_rand_seed);
        const uint64_t voice_rand_seed = Random_get_uint64(random);

        Voice* voice = Voice_group_get_voice(vgroup, voice_index);

        const bool voice_allocated = init_voice(
                ch, voice, au, ch->fg_group_id, proc_state, i, voice_rand_seed);
        if (!voice_allocated)
        {
            // Some of our voices were reallocated
            reset_channel_voices(ch);
            return true;
        }

        ++voice_index;

        Voice_state* vs = voice->state;
        vs->hit_index = hit_index;

        if (vs->proc_type == Proc_type_force)
        {
            Force_controls* fc = Force_vstate_get_force_controls_mut(vs);
            Force_controls_copy(fc, &ch->force_controls);
        }
    }

    Channel_reset_test_output(ch);

    init_streams(ch, au);

    return true;
}
Example #5
0
bool Event_channel_note_on_process(
        Channel* ch,
        Device_states* dstates,
        const Master_params* master_params,
        const Event_params* params)
{
    rassert(ch != NULL);
    rassert(ch->audio_rate > 0);
    rassert(ch->tempo > 0);
    rassert(dstates != NULL);
    rassert(master_params != NULL);
    rassert(params != NULL);
    rassert(params->arg != NULL);
    rassert(params->arg->type == VALUE_TYPE_FLOAT);

    // Move the old Voices to the background
    Event_channel_note_off_process(ch, dstates, master_params, NULL);

    // Find our audio unit
    Audio_unit* au = Module_get_au_from_input(ch->parent.module, ch->au_input);
    if (au == NULL)
        return true;

    double pitch_param = params->arg->value.float_type;

    // Retune pitch parameter if a retuner is active
    {
        const int tuning_index = master_params->cur_tuning_state;
        if (0 <= tuning_index && tuning_index < KQT_TUNING_TABLES_MAX)
        {
            Tuning_state* state = master_params->tuning_states[tuning_index];
            const Tuning_table* table =
                Module_get_tuning_table(master_params->parent.module, tuning_index);
            if (state != NULL && table != NULL)
                pitch_param = Tuning_state_get_retuned_pitch(state, table, pitch_param);
        }
    }

    if (ch->carry_pitch)
    {
        if (isnan(ch->pitch_controls.pitch))
            ch->pitch_controls.pitch = pitch_param;
        if (isnan(ch->pitch_controls.orig_carried_pitch))
            ch->pitch_controls.orig_carried_pitch = pitch_param;

        const double pitch_diff = pitch_param - ch->pitch_controls.orig_carried_pitch;
        ch->pitch_controls.pitch_add = pitch_diff;
    }
    else
    {
        Pitch_controls_reset(&ch->pitch_controls);
        ch->pitch_controls.orig_carried_pitch = pitch_param;

        Slider_set_tempo(&ch->pitch_controls.slider, master_params->tempo);
        Slider_set_length(&ch->pitch_controls.slider, &ch->pitch_slide_length);

        LFO_set_tempo(&ch->pitch_controls.vibrato, master_params->tempo);
        LFO_set_speed_slide(&ch->pitch_controls.vibrato, &ch->vibrato_speed_slide);
        LFO_set_depth_slide(&ch->pitch_controls.vibrato, &ch->vibrato_depth_slide);

        ch->pitch_controls.pitch = pitch_param;
        if (isnan(ch->pitch_controls.orig_carried_pitch))
            ch->pitch_controls.orig_carried_pitch = pitch_param;
    }

    init_force_controls(ch, master_params);

    // Don't attempt to play effects
    if (Audio_unit_get_type(au) != AU_TYPE_INSTRUMENT)
        return true;

    // Generate our next note random seed here so that random generation
    // is consistent even if we run out of voices
    const uint64_t note_rand_seed = Random_get_uint64(&ch->rand);

    // Find reserved voices
    Voice_group* vgroup = VOICE_GROUP_AUTO;

    if (!Voice_group_reservations_get_clear_entry(
                ch->voice_group_res, ch->num, &ch->fg_group_id) ||
            (Voice_pool_get_group(ch->pool, ch->fg_group_id, vgroup) == NULL))
    {
        reset_channel_voices(ch);
        return true;
    }

    int voice_index = 0;

    for (int i = 0; i < KQT_PROCESSORS_MAX; ++i)
    {
        const Processor* proc = Audio_unit_get_proc(au, i);
        if (proc == NULL ||
                !Device_is_existent((const Device*)proc) ||
                !Processor_get_voice_signals(proc))
            continue;

        const Proc_state* proc_state = (Proc_state*)Device_states_get_state(
                dstates, Device_get_id((const Device*)proc));

        Voice_state_get_size_func* get_vstate_size =
            proc_state->parent.device->dimpl->get_vstate_size;
        if ((get_vstate_size != NULL) && (get_vstate_size() == 0))
            continue;

        char context_str[16] = "";
        snprintf(context_str, 16, "np%hd", (short)i);
        Random* random = Random_init(RANDOM_AUTO, context_str);
        Random_set_seed(random, note_rand_seed);
        const uint64_t voice_rand_seed = Random_get_uint64(random);

        Voice* voice = Voice_group_get_voice(vgroup, voice_index);

        const bool voice_allocated = init_voice(
                ch, voice, au, ch->fg_group_id, proc_state, i, voice_rand_seed);
        if (!voice_allocated)
        {
            // Some of our voices were reallocated
            reset_channel_voices(ch);
            return true;
        }

        ++voice_index;

        Voice_state* vs = voice->state;

        if (vs->proc_type == Proc_type_pitch)
            Pitch_vstate_set_controls(vs, &ch->pitch_controls);

        if (vs->proc_type == Proc_type_force)
        {
            Force_controls* fc = Force_vstate_get_force_controls_mut(vs);
            Force_controls_copy(fc, &ch->force_controls);
        }
    }

    Channel_reset_test_output(ch);

    init_streams(ch, au);

    return true;
}