Exemple #1
0
//---------------------------------------------------
void initDrumVoice()
{
	ampSmoothValue = 0.1f;

	int i;
	for(i=0;i<NUM_VOICES;i++)
	{

		SnapEg_init(&voiceArray[i].snapEg);
		setPan(i,0.f);
		voiceArray[i].vol = 0.8f;
		//voiceArray[i].panModifier = 1.f;
		voiceArray[i].fmModAmount = 0.5f;
		transient_init(&voiceArray[i].transGen);
#if ENABLE_DRUM_SVF
		SVF_init(&voiceArray[i].filter);
		voiceArray[i].filterType = 0x01;
#endif
		lfo_init(&voiceArray[i].lfo);

		voiceArray[i].modOsc.freq = 440;
		voiceArray[i].modOsc.waveform = 1;
		voiceArray[i].modOsc.fmMod = 0;
		voiceArray[i].modOsc.midiFreq = 70<<8;
		voiceArray[i].modOsc.pitchMod = 1.0f;
		voiceArray[i].modOsc.modNodeValue = 1;

		voiceArray[i].volumeMod = 1;

		voiceArray[i].osc.freq = 440;
		voiceArray[i].osc.modNodeValue = 1;
		voiceArray[i].osc.waveform = TRI+i; //for testing init to tri,saw,rec
		voiceArray[i].osc.fmMod = 0;
		voiceArray[i].osc.midiFreq = 70<<8;

		DecayEg_init(&voiceArray[i].oscPitchEg);
		voiceArray[i].egPitchModAmount = 0.5f;

		slopeEg2_init(&voiceArray[i].oscVolEg);
		setDistortionShape(&voiceArray[i].distortion, 2.f);

#ifdef USE_AMP_FILTER
		initOnePole(&voiceArray[i].ampFilter);
		setOnePoleCoef(&voiceArray[i].ampFilter,ampSmoothValue);
#endif

#if ENABLE_MIX_OSC
		voiceArray[i].mixOscs = true;
#endif
		voiceArray[i].decimationCnt = 0;
		voiceArray[i].decimationRate = 1;

	}
}
Exemple #2
0
int sample_default(Sample* sample, int rate)
{
    int         frames = rate / 8;
    float*      tmp;
    LFO*        lfo;
    LFOParams   lfopar;
    int         i;
    double      v;

    float const*    lfo_out;

    debug("Creating default sample\n");

    if (!(tmp = malloc(frames * 2 * sizeof(*tmp))))
    {
        pf_error(PF_ERR_SAMPLE_DEFAULT_ALLOC);
        return -1;
    }

    sample->frames = frames;
    sample->sp = tmp;

    lfo = lfo_new();
    lfo_init(lfo);
    lfo_params_init(&lfopar, 523.251, LFO_SHAPE_SAW);
    lfo_trigger(lfo, &lfopar);

    lfo_out = lfo_output(lfo);

    for (i = 0; i < frames; ++i)
    {
        lfo_tick(lfo);

        v = *lfo_out * 0.9;

        *tmp++ = v;
        *tmp++ = v;
    }

    lfo_free(lfo);

    sample->filename = strdup("Default");
    sample->default_sample = true;

    return 0;
}
Exemple #3
0
void Cymbal_init()
{

	SnapEg_init(&cymbalVoice.snapEg);
	Cymbal_setPan(0);
	cymbalVoice.vol = 0.8f;

	//cymbalVoice.panModifier = 1.f;

	transient_init(&cymbalVoice.transGen);

	cymbalVoice.fmModAmount1 = 0.5f;
	cymbalVoice.fmModAmount2 = 0.5f;

	setDistortionShape(&cymbalVoice.distortion, 2.f);

	cymbalVoice.modOsc.freq = 440;
	cymbalVoice.modOsc.waveform = SINE;
	cymbalVoice.modOsc.fmMod = 0;
	cymbalVoice.modOsc.midiFreq = 70<<8;
	cymbalVoice.modOsc.pitchMod = 1.0f;
	cymbalVoice.modOsc.modNodeValue = 1;

	cymbalVoice.modOsc2.freq = 440;
	cymbalVoice.modOsc2.waveform = NOISE;//SINE;
	cymbalVoice.modOsc2.fmMod = 0;
	cymbalVoice.modOsc2.midiFreq = 70<<8;
	cymbalVoice.modOsc2.pitchMod = 1.0f;
	cymbalVoice.modOsc2.modNodeValue = 1;

	cymbalVoice.osc.freq = 440;
	cymbalVoice.osc.waveform = 1;
	cymbalVoice.osc.fmMod = 1;
	cymbalVoice.osc.midiFreq = 70<<8;
	cymbalVoice.osc.pitchMod = 1.0f;
	cymbalVoice.osc.modNodeValue = 1;

	cymbalVoice.volumeMod = 1;

	slopeEg2_init(&cymbalVoice.oscVolEg);

	SVF_init(&cymbalVoice.filter);

	lfo_init(&cymbalVoice.lfo);

}
Exemple #4
0
//---------------------------------------------------
void Snare_init()
{
	SnapEg_init(&snareVoice.snapEg);
	Snare_setPan(0.f);
	snareVoice.vol = 0.8f;

	snareVoice.panModifier = 1.f;

	snareVoice.noiseOsc.freq = 440;
	snareVoice.noiseOsc.waveform = 1;
	snareVoice.noiseOsc.fmMod = 0;
	snareVoice.noiseOsc.midiFreq = 70<<8;
	snareVoice.noiseOsc.pitchMod = 1.0f;
	snareVoice.noiseOsc.modNodeValue = 1;

	snareVoice.osc.freq = 440;
	snareVoice.osc.waveform = 1;
	snareVoice.osc.fmMod = 0;
	snareVoice.osc.midiFreq = 70<<8;
	snareVoice.osc.modNodeValue = 1;

	setDistortionShape(&snareVoice.distortion, 2.f);

	snareVoice.volumeMod = 1;

	transient_init(&snareVoice.transGen);

	DecayEg_init(&snareVoice.oscPitchEg);
	snareVoice.egPitchModAmount = 0.5f;

	slopeEg2_init(&snareVoice.oscVolEg);

	setDistortionShape(&snareVoice.distortion, 2.f);

	SVF_init(&snareVoice.filter);

	lfo_init(&snareVoice.lfo);
}
Exemple #5
0
void sampler_voice_start(struct sampler_voice *v, struct sampler_channel *c, struct sampler_layer_data *l, int note, int vel, int *exgroups, int *pexgroupcount)
{
    struct sampler_module *m = c->module;
    sampler_gen_reset(&v->gen);
    
    v->age = 0;
    if (l->trigger == stm_release)
    {
        // time since last 'note on' for that note
        v->age = m->current_time - c->prev_note_start_time[note];
        double age = v->age *  m->module.srate_inv;
        // if attenuation is more than 84dB, ignore the release trigger
        if (age * l->rt_decay > 84)
            return;
    }
    uint32_t end = l->eff_waveform->info.frames;
    if (l->end != 0)
        end = (l->end == -1) ? 0 : l->end;
    v->last_waveform = l->eff_waveform;
    v->gen.cur_sample_end = end;
    if (end > l->eff_waveform->info.frames)
        end = l->eff_waveform->info.frames;
    
    assert(!v->current_pipe);
    if (end > l->eff_waveform->preloaded_frames)
    {
        if (l->eff_loop_mode == slm_loop_continuous && l->loop_end < l->eff_waveform->preloaded_frames)
        {
            // Everything fits in prefetch, because loop ends in prefetch and post-loop part is not being played
        }
        else
        {
            uint32_t loop_start = -1, loop_end = end;
            // If in loop mode, set the loop over the looped part... unless we're doing sustain-only loop on prefetch area only. Then
            // streaming will only cover the release part, and it shouldn't be looped.
            if (l->eff_loop_mode == slm_loop_continuous || (l->eff_loop_mode == slm_loop_sustain && l->loop_end >= l->eff_waveform->preloaded_frames))
            {
                loop_start = l->loop_start;
                loop_end = l->loop_end;
            }
            // Those are initial values only, they will be adjusted in process function
            v->current_pipe = cbox_prefetch_stack_pop(m->pipe_stack, l->eff_waveform, loop_start, loop_end, l->count);
            if (!v->current_pipe)
            {
                g_warning("Prefetch pipe pool exhausted, no streaming playback will be possible");
                end = l->eff_waveform->preloaded_frames;
                v->gen.cur_sample_end = end;
            }
        }
    }
    
    v->output_pair_no = (l->output + c->output_shift) % m->output_pairs;
    v->serial_no = m->serial_no;
    
    float delay = l->delay;
    if (l->delay_random)
        delay += rand() * (1.0 / RAND_MAX) * l->delay_random;
    if (delay > 0)
        v->delay = (int)(delay * m->module.srate);
    else
        v->delay = 0;
    v->gen.loop_overlap = l->loop_overlap;
    v->gen.loop_overlap_step = l->loop_overlap > 0 ? 1.0 / l->loop_overlap : 0;
    v->gain_fromvel = 1.0 + (l->eff_velcurve[vel] - 1.0) * l->amp_veltrack * 0.01;
    v->gain_shift = 0.0;
    v->note = note;
    v->vel = vel;
    v->pitch_shift = 0;
    v->released = 0;
    v->released_with_sustain = 0;
    v->released_with_sostenuto = 0;
    v->captured_sostenuto = 0;
    v->channel = c;
    v->layer = l;
    v->program = c->program;
    v->amp_env.shape = &l->amp_env_shape;
    v->filter_env.shape = &l->filter_env_shape;
    v->pitch_env.shape = &l->pitch_env_shape;
    
    v->cutoff_shift = vel * l->fil_veltrack / 127.0 + (note - l->fil_keycenter) * l->fil_keytrack;
    v->loop_mode = l->eff_loop_mode;
    v->off_by = l->off_by;
    v->reloffset = l->reloffset;
    int auxes = (m->module.outputs - m->module.aux_offset) / 2;
    if (l->effect1bus >= 1 && l->effect1bus < 1 + auxes)
        v->send1bus = l->effect1bus;
    else
        v->send1bus = 0;
    if (l->effect2bus >= 1 && l->effect2bus < 1 + auxes)
        v->send2bus = l->effect2bus;
    else
        v->send2bus = 0;
    v->send1gain = l->effect1 * 0.01;
    v->send2gain = l->effect2 * 0.01;
    if (l->group >= 1 && *pexgroupcount < MAX_RELEASED_GROUPS)
    {
        gboolean found = FALSE;
        for (int j = 0; j < *pexgroupcount; j++)
        {
            if (exgroups[j] == l->group)
            {
                found = TRUE;
                break;
            }
        }
        if (!found)
        {
            exgroups[(*pexgroupcount)++] = l->group;
        }
    }
    lfo_init(&v->amp_lfo, &l->amp_lfo, m->module.srate, m->module.srate_inv);
    lfo_init(&v->filter_lfo, &l->filter_lfo, m->module.srate, m->module.srate_inv);
    lfo_init(&v->pitch_lfo, &l->pitch_lfo, m->module.srate, m->module.srate_inv);
    
    cbox_biquadf_reset(&v->filter_left);
    cbox_biquadf_reset(&v->filter_right);
    cbox_biquadf_reset(&v->filter_left2);
    cbox_biquadf_reset(&v->filter_right2);
    cbox_onepolef_reset(&v->onepole_left);
    cbox_onepolef_reset(&v->onepole_right);
    // set gain later (it's a less expensive operation)
    if (l->tonectl_freq != 0)
        cbox_onepolef_set_highshelf_tonectl(&v->onepole_coeffs, l->tonectl_freq * M_PI * m->module.srate_inv, 1.0);
    
    GSList *nif = v->layer->nifs;
    while(nif)
    {
        struct sampler_noteinitfunc *p = nif->data;
        p->notefunc(p, v);
        nif = nif->next;
    }
    v->offset = l->offset;
    if (v->reloffset != 0)
    {
        uint32_t maxend = v->current_pipe ? (l->eff_waveform->preloaded_frames >> 1) : l->eff_waveform->preloaded_frames;
        int32_t pos = v->offset + v->reloffset * maxend * 0.01;
        if (pos < 0)
            pos = 0;
        if (pos > maxend)
            pos = maxend;
        v->offset = pos;
    }