History

added feedback variation to fmpair

Paul Batchelor committed 6 years ago

Commit dc6fefa1 parent e4685a61 file · +123 −1Browse files

Unified · Split

fmpair.org+123−1
@@ -152,7 +152,9 @@ It contains all the forward declarations. If · 151 unmodified lines
152#endif152#endif
153#endif153#endif
154#+END_SRC154#+END_SRC
155* Struct155* Structs
156The main FM oscillator algorithm is encapsulated in a struct
157called =sk_fmpair=.
156#+NAME: typedefs158#+NAME: typedefs
157#+BEGIN_SRC c159#+BEGIN_SRC c
158typedef struct sk_fmpair sk_fmpair;160typedef struct sk_fmpair sk_fmpair;
@@ -510,6 +512,126 @@ value. · 351 unmodified lines
510fmp->clphs += floor(cfreq * fmp->maxlens);512fmp->clphs += floor(cfreq * fmp->maxlens);
511fmp->mlphs += floor(mfreq * fmp->maxlens);513fmp->mlphs += floor(mfreq * fmp->maxlens);
512#+END_SRC514#+END_SRC
515* Feedback FM Variation
516The original FM pair algorithm can be slightly modified to
517include =feedback=. To do this, the =sk_fmpair= struct is
518encapsulated in a new struct called =sk_fmpair_fdbk=.
519
520Feedback FM is based on the Two-oscillator feedback FM
521design outlined on page 248 of the Computer Music Tutorial
522by Curtis Roads.
523
524#+NAME: typedefs
525#+BEGIN_SRC c
526typedef struct sk_fmpair_fdbk sk_fmpair_fdbk;
527#+END_SRC
528
529Appenended to the new struct are two new values: =feedback=,
530and =prev=. The =feedback= variable controls the feedback
531amount, while the =prev= variable stores the state of the
532last oscillator.
533
534#+NAME: structs
535#+BEGIN_SRC c
536struct sk_fmpair_fdbk {
537 sk_fmpair fmpair;
538 SKFLT prev;
539 SKFLT feedback;
540};
541#+END_SRC
542
543It is initialized with =sk_fmpair_fdbk_init= just like
544=sk_fmpair_init=.
545
546#+NAME: funcdefs
547#+BEGIN_SRC c
548void sk_fmpair_fdbk_init(sk_fmpair_fdbk *fmp, int sr,
549 SKFLT *ctab, int csz, SKFLT ciphs,
550 SKFLT *mtab, int msz, SKFLT miphs);
551#+END_SRC
552
553#+NAME: funcs
554#+BEGIN_SRC c
555void sk_fmpair_fdbk_init(sk_fmpair_fdbk *fmp, int sr,
556 SKFLT *ctab, int csz, SKFLT ciphs,
557 SKFLT *mtab, int msz, SKFLT miphs)
558{
559 sk_fmpair_init(&fmp->fmpair, sr,
560 ctab, csz, ciphs,
561 mtab, msz, miphs);
562 fmp->prev = 0;
563 fmp->feedback = 0;
564}
565#+END_SRC
566
567The feedback amount can be set with =sk_fmpair_fdbk_amt=.
568
569#+NAME: funcdefs
570#+BEGIN_SRC c
571void sk_fmpair_fdbk_amt(sk_fmpair_fdbk *f, SKFLT amt);
572#+END_SRC
573
574#+NAME: funcs
575#+BEGIN_SRC c
576void sk_fmpair_fdbk_amt(sk_fmpair_fdbk *f, SKFLT amt)
577{
578 f->feedback = amt;
579}
580#+END_SRC
581
582Computation of the FM pair feedback is done with
583=sk_fmpair_fdbk_tick=.
584
585#+NAME: funcdefs
586#+BEGIN_SRC c
587SKFLT sk_fmpair_fdbk_tick(sk_fmpair_fdbk *fmp);
588#+END_SRC
589
590This re-uses many named codeblocks seen in the
591=sk_fmpair_tick=: <<calculate_frequencies>>,
592<<table_lookup_for_modulator>>, <<scale_modulator_output>>,
593<<modulate_carrier_frequency>>,
594<<table_lookup_for_modulator>>, and
595<<update_phase_positions>>.
596
597#+NAME: funcs
598#+BEGIN_SRC c
599SKFLT sk_fmpair_fdbk_tick(sk_fmpair_fdbk *f)
600{
601 SKFLT out;
602 SKFLT cfreq, mfreq;
603 SKFLT modout;
604 int ipos;
605 SKFLT frac;
606 SKFLT x[2];
607 sk_fmpair *fmp;
608 out = 0;
609 fmp = &f->fmpair;
610
611 <<calculate_frequencies>>
612 <<table_lookup_for_modulator>>
613 <<scale_modulator_output>>
614
615 /* feedback-oscillator specific */
616 <<apply_feedback>>
617
618 <<modulate_carrier_frequency>>
619 <<table_lookup_for_carrier>>
620 <<update_phase_positions>>
621 return out;
622}
623#+END_SRC
624
625In this function, feedback is added right after the
626modulator is scaled.
627
628This modulated value is then stored in the =prev= sample.
629
630#+NAME: apply_feedback
631#+BEGIN_SRC c
632modout += f->prev * f->feedback;
633f->prev = modout;
634#+END_SRC
513* C:M Ratio tips635* C:M Ratio tips
514Some suggestions to get started with picking out good C,M636Some suggestions to get started with picking out good C,M
515and I parameters. For those starting out, these should help637and I parameters. For those starting out, these should help

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t