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
152152 #endif
153153 #endif
154154 #+END_SRC
155−* Struct
155+* Structs
156+The main FM oscillator algorithm is encapsulated in a struct
157+called =sk_fmpair=.
156158 #+NAME: typedefs
157159 #+BEGIN_SRC c
158160 typedef struct sk_fmpair sk_fmpair;
@@ -510,6 +512,126 @@ value. · 351 unmodified lines
510512 fmp->clphs += floor(cfreq * fmp->maxlens);
511513 fmp->mlphs += floor(mfreq * fmp->maxlens);
512514 #+END_SRC
515+* Feedback FM Variation
516+The original FM pair algorithm can be slightly modified to
517+include =feedback=. To do this, the =sk_fmpair= struct is
518+encapsulated in a new struct called =sk_fmpair_fdbk=.
519+
520+Feedback FM is based on the Two-oscillator feedback FM
521+design outlined on page 248 of the Computer Music Tutorial
522+by Curtis Roads.
523+
524+#+NAME: typedefs
525+#+BEGIN_SRC c
526+typedef struct sk_fmpair_fdbk sk_fmpair_fdbk;
527+#+END_SRC
528+
529+Appenended to the new struct are two new values: =feedback=,
530+and =prev=. The =feedback= variable controls the feedback
531+amount, while the =prev= variable stores the state of the
532+last oscillator.
533+
534+#+NAME: structs
535+#+BEGIN_SRC c
536+struct sk_fmpair_fdbk {
537+ sk_fmpair fmpair;
538+ SKFLT prev;
539+ SKFLT feedback;
540+};
541+#+END_SRC
542+
543+It is initialized with =sk_fmpair_fdbk_init= just like
544+=sk_fmpair_init=.
545+
546+#+NAME: funcdefs
547+#+BEGIN_SRC c
548+void 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
555+void 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+
567+The feedback amount can be set with =sk_fmpair_fdbk_amt=.
568+
569+#+NAME: funcdefs
570+#+BEGIN_SRC c
571+void sk_fmpair_fdbk_amt(sk_fmpair_fdbk *f, SKFLT amt);
572+#+END_SRC
573+
574+#+NAME: funcs
575+#+BEGIN_SRC c
576+void sk_fmpair_fdbk_amt(sk_fmpair_fdbk *f, SKFLT amt)
577+{
578+ f->feedback = amt;
579+}
580+#+END_SRC
581+
582+Computation of the FM pair feedback is done with
583+=sk_fmpair_fdbk_tick=.
584+
585+#+NAME: funcdefs
586+#+BEGIN_SRC c
587+SKFLT sk_fmpair_fdbk_tick(sk_fmpair_fdbk *fmp);
588+#+END_SRC
589+
590+This 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
599+SKFLT 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+
625+In this function, feedback is added right after the
626+modulator is scaled.
627+
628+This modulated value is then stored in the =prev= sample.
629+
630+#+NAME: apply_feedback
631+#+BEGIN_SRC c
632+modout += f->prev * f->feedback;
633+f->prev = modout;
634+#+END_SRC
513635 * C:M Ratio tips
514636 Some suggestions to get started with picking out good C,M
515637 and 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