ref: ffe16b59b7ae8c2e00dffa7bba7c9d7b9238c9f5
parent: f6d97317c22b5d2e703844728a3f41b6bc3a74a4
author: Paul Batchelor <[email protected]>
date: Sat Jan 30 05:51:12 EST 2021
reworked phasor to use sndkit phasor
--- a/config.def.mk
+++ b/config.def.mk
@@ -97,6 +97,7 @@
tangled/peakeq.o \
tangled/modalres.o \
tangled/phasewarp.o \
+tangled/phasor.o \
NO_LIBSNDFILE=1
CFLAGS += -DNO_LIBSNDFILE
--- a/h/phasor.h
+++ b/h/phasor.h
@@ -1,6 +1,10 @@
+#ifndef SK_PHASOR_H
+typedef struct sk_phasor sk_phasor;
+#endif
+
typedef struct sp_phasor{
- SPFLOAT freq, phs;
- SPFLOAT onedsr;
+ sk_phasor *phasor;
+ SPFLOAT freq;
} sp_phasor;
int sp_phasor_create(sp_phasor **p);
--- a/modules/phasor.c
+++ b/modules/phasor.c
@@ -4,9 +4,13 @@
* A phasor produces a non-bandlimited sawtooth wave,
* normalized to be in range 0-1. Phasors are most
* frequently used to create table-lookup oscillators.
+ *
+ * This code is placed in the public domain.
*/
#include <stdlib.h>
+#define SK_PHASOR_PRIV
+#include "tangled/phasor.h"
#include "soundpipe.h"
int sp_phasor_create(sp_phasor **p)
@@ -17,6 +21,9 @@
int sp_phasor_destroy(sp_phasor **p)
{
+ sp_phasor *pp;
+ pp = *p;
+ free(pp->phasor);
free(*p);
return SP_OK;
}
@@ -23,30 +30,16 @@
int sp_phasor_init(sp_data *sp, sp_phasor *p, SPFLOAT iphs)
{
+ p->phasor = malloc(sizeof(sk_phasor));
p->freq = 440;
- p->phs = iphs;
- p->onedsr = 1.0 / sp->sr;
+ sk_phasor_init(p->phasor, sp->sr, iphs);
+ sk_phasor_freq(p->phasor, p->freq);
return SP_OK;
}
int sp_phasor_compute(sp_data *sp, sp_phasor *p, SPFLOAT *in, SPFLOAT *out)
{
- SPFLOAT phs;
- SPFLOAT incr;
-
- phs = p->phs;
- incr = p->freq * p->onedsr;
-
- *out = phs;
-
- phs += incr;
-
- if (phs >= 1.0) {
- phs -= 1.0;
- } else if (phs < 0.0) {
- phs += 1.0;
- }
-
- p->phs = phs;
+ sk_phasor_freq(p->phasor, p->freq);
+ *out = sk_phasor_tick(p->phasor);
return SP_OK;
}
--- /dev/null
+++ b/tangled/phasor.c
@@ -1,0 +1,40 @@
+#line 49 "phasor.org"
+#define SK_PHASOR_PRIV
+#include "phasor.h"
+#line 84 "phasor.org"
+void sk_phasor_init(sk_phasor *ph, int sr, SKFLT iphs)
+{
+ ph->phs = iphs;
+ ph->onedsr = 1.0 / sr;
+ sk_phasor_freq(ph, 440);
+}
+#line 102 "phasor.org"
+void sk_phasor_freq(sk_phasor *ph, SKFLT freq)
+{
+ ph->freq = freq;
+}
+#line 128 "phasor.org"
+SKFLT sk_phasor_tick(sk_phasor *ph)
+{
+ SKFLT phs;
+ SKFLT incr;
+ SKFLT out;
+
+ phs = ph->phs;
+ incr = ph->freq * ph->onedsr;
+
+ out = phs;
+
+ phs += incr;
+
+ if (phs >= 1.0) {
+ phs -= 1.0;
+ } else if (phs < 0.0) {
+ phs += 1.0;
+ }
+
+ ph->phs = phs;
+
+ return out;
+}
+#line 49 "phasor.org"
--- /dev/null
+++ b/tangled/phasor.h
@@ -1,0 +1,28 @@
+#line 32 "phasor.org"
+#ifndef SK_PHASOR_H
+#define SK_PHASOR_H
+
+#ifndef SKFLT
+#define SKFLT float
+#endif
+
+#line 60 "phasor.org"
+typedef struct sk_phasor sk_phasor;
+#line 32 "phasor.org"
+#line 79 "phasor.org"
+void sk_phasor_init(sk_phasor *ph, int sr, SKFLT iphs);
+#line 97 "phasor.org"
+void sk_phasor_freq(sk_phasor *ph, SKFLT freq);
+#line 113 "phasor.org"
+SKFLT sk_phasor_tick(sk_phasor *ph);
+#line 41 "phasor.org"
+#ifdef SK_PHASOR_PRIV
+#line 70 "phasor.org"
+struct sk_phasor {
+ SKFLT freq;
+ SKFLT phs;
+ SKFLT onedsr;
+};
+#line 43 "phasor.org"
+#endif
+#endif