MCPcopy Create free account
hub / github.com/LabSound/LabSound / SynthSample

Method SynthSample

src/extended/SfxrNode.cpp:422–588  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

420}
421
422void SfxrNode::Sfxr::SynthSample(size_t length, float * buffer, FILE * file)
423{
424 for (int i = 0; i < length; i++)
425 {
426 if (!playing_sample)
427 break;
428
429 rep_time++;
430 if (rep_limit != 0 && rep_time >= rep_limit)
431 {
432 rep_time = 0;
433 ResetSample(true);
434 }
435
436 // frequency envelopes/arpeggios
437 arp_time++;
438 if (arp_limit != 0 && arp_time >= arp_limit)
439 {
440 arp_limit = 0;
441 fperiod *= arp_mod;
442 }
443 fslide += fdslide;
444 fperiod *= fslide;
445 if (fperiod > fmaxperiod)
446 {
447 fperiod = fmaxperiod;
448 if (p_freq_limit > 0.0f)
449 playing_sample = false;
450 }
451 float rfperiod = static_cast<float>(fperiod);
452 if (vib_amp > 0.0f)
453 {
454 vib_phase += vib_speed;
455 rfperiod = static_cast<float>(fperiod * (1.0 + sin(vib_phase) * vib_amp));
456 }
457 period = (int) rfperiod;
458 if (period < 8) period = 8;
459 square_duty += square_slide;
460 if (square_duty < 0.0f) square_duty = 0.0f;
461 if (square_duty > 0.5f) square_duty = 0.5f;
462 // volume envelope
463 env_time++;
464 if (env_time > env_length[env_stage])
465 {
466 env_time = 0;
467 env_stage++;
468 if (env_stage == 3)
469 playing_sample = false;
470 }
471 if (env_stage == 0)
472 env_vol = (float) env_time / env_length[0];
473 if (env_stage == 1)
474 env_vol = 1.0f + pow(1.0f - (float) env_time / env_length[1], 1.0f) * 2.0f * p_env_punch;
475 if (env_stage == 2)
476 env_vol = 1.0f - (float) env_time / env_length[2];
477
478 // phaser step
479 fphase += fdphase;

Callers 1

processMethod · 0.80

Calls 1

frndFunction · 0.85

Tested by

no test coverage detected