summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2021-07-12 12:07:30 +0800
committerJSDurand <mmemmew@gmail.com>2021-07-12 12:07:30 +0800
commitd073f301aa94cd7a8278681d8d723d74fa5d5d3f (patch)
treeafb67e8393307c5bec32ac7f8444854a8b3e6cd0
parent75a875116f7060e5a0512b447123253d3c25946a (diff)
Use double instead of float
I thought that a float has more precision than a double. Silly me.
-rw-r--r--instrument.c152
-rw-r--r--main.c56
-rw-r--r--mix.c5
-rw-r--r--parser.c32
-rw-r--r--util.c4
-rw-r--r--util.h24
6 files changed, 137 insertions, 136 deletions
diff --git a/instrument.c b/instrument.c
index 097ede4..fac875d 100644
--- a/instrument.c
+++ b/instrument.c
@@ -8,19 +8,19 @@
/* This is not exposed to other files, as this should be controlled by
individual instruments. */
typedef struct {
- float freq;
- float amp;
+ NUMT freq;
+ NUMT amp;
unsigned char pred; /* if this is 0, then no frequency
modulation is present. */
} FM;
/* By similar reasoning, ADSR is not exposed either. */
typedef struct {
- float attack_p;
- float decay_p;
- float sustain_p;
- float release_p;
- float sustain_level;
+ NUMT attack_p;
+ NUMT decay_p;
+ NUMT sustain_p;
+ NUMT release_p;
+ NUMT sustain_level;
unsigned char pred; /* If this is 0 then the instrument
does not adapt the ADSR model. */
} ADSR;
@@ -32,13 +32,13 @@ typedef struct {
flexibility. */
struct Instrument_s {
- float *sin_coefs; /* coefficients of sin in the Fourier
+ NUMT *sin_coefs; /* coefficients of sin in the Fourier
expansion. */
- float *cos_coefs; /* coefficients of cos in the Fourier
+ NUMT *cos_coefs; /* coefficients of cos in the Fourier
expansion. */
sound_t sound; /* the function to produce sounds. */
merger_t merger; /* the function to merge waves. */
- float reverb; /* The percentage of reverberation. */
+ NUMT reverb; /* The percentage of reverberation. */
FM fm;
ADSR adsr;
};
@@ -61,34 +61,34 @@ merge_waves(Instrument *in, WaveFrag *frags, LENT len, int step)
/* The first is piano */
UH_ATTR
-static float
-smooth_step(float t)
+static NUMT
+smooth_step(NUMT t)
{
- if (t <= 0.0f) {
- return 0.0f;
- } else if (t >= 1.0f) {
- return 1.0f;
+ if (t <= 0.0) {
+ return 0.0;
+ } else if (t >= 1.0) {
+ return 1.0;
} else {
return 6*pow(t, 5)-15*pow(t, 4)+10*pow(t, 3);
}
}
UH_ATTR
-static float
-old_piano_sound_internal(Instrument *piano, float theta)
+static NUMT
+old_piano_sound_internal(Instrument *piano, NUMT theta)
{
- return sin(theta)+1.869*sin(2.0f*theta)+0.042f*sin(3.0f*theta)
- +0.022f*sin(4.0f*theta)+cos(theta);
+ return sin(theta)+1.869*sin(2.0*theta)+0.042*sin(3.0*theta)
+ +0.022*sin(4.0*theta)+cos(theta);
}
UH_ATTR
-static float
-piano_sound_internal(Instrument *piano, float theta)
+static NUMT
+piano_sound_internal(Instrument *piano, NUMT theta)
{
return (*(piano->sin_coefs) * sin(theta)+
- *(piano->sin_coefs+1) * sin(2.0f*theta)+
- *(piano->sin_coefs+2) * sin(3.0f*theta))*
- exp(-0.004f*theta);
+ *(piano->sin_coefs+1) * sin(2.0*theta)+
+ *(piano->sin_coefs+2) * sin(3.0*theta))*
+ exp(-0.004*theta);
}
UH_ATTR
@@ -97,17 +97,17 @@ piano_sound(void * in, Volume v, Hertz h, Seconds s)
{
Instrument *piano = (Instrument *)in;
- float step = (float) (h * 2 * M_PI) / SAMPLE_RATE;
+ NUMT step = (NUMT) (h * 2 * M_PI) / SAMPLE_RATE;
LENT sample_num = (LENT) floor(SAMPLE_RATE * s);
Wave w = MYALLOC(Pulse, sizeof(*w) * sample_num);
- float theta = 0.0f, temp = 0.0f;
+ NUMT theta = 0.0, temp = 0.0;
for (LENT i = 0; i < sample_num; i++, theta += step) {
temp = piano_sound_internal(piano, theta);
temp += temp*temp*temp;
- *(w+i) = (float) v * piano_sound_internal(piano, temp);
+ *(w+i) = (NUMT) v * piano_sound_internal(piano, temp);
}
return (WaveFrag) { w, sample_num };
@@ -153,11 +153,11 @@ Instrument *make_piano()
ins->adsr.pred = 0;
ins->sin_coefs = malloc(sizeof(*(ins->sin_coefs)) * 3);
ins->cos_coefs = malloc(sizeof(*(ins->cos_coefs)) * 1);
- ins->reverb = 0.0f;
+ ins->reverb = 0.0;
- *(ins->sin_coefs) = 0.65f;
- *(ins->sin_coefs+1) = 0.45f;
- *(ins->sin_coefs+2) = 0.1f;
+ *(ins->sin_coefs) = 0.65;
+ *(ins->sin_coefs+1) = 0.45;
+ *(ins->sin_coefs+2) = 0.1;
*(ins->cos_coefs) = 1;
ins->sound = piano_sound;
ins->merger = simple_merger;
@@ -177,36 +177,36 @@ destroy_piano(Instrument *in)
UH_ATTR
Pulse
-violin_sound_internal(Instrument *in, float theta)
+violin_sound_internal(Instrument *in, NUMT theta)
{
- return -1.0f*fmod(theta, 2.0f*M_PI)/M_PI + 1.0f;
+ return -1.0*fmod(theta, 2.0*M_PI)/M_PI + 1.0;
/* return (*(in->sin_coefs)*sin(theta)+
- * *(in->sin_coefs+1)*sin(2.0f*theta)+
- * *(in->sin_coefs+2)*sin(3.0f*theta)+
- * *(in->sin_coefs+3)*sin(4.0f*theta)+
- * *(in->sin_coefs+4)*sin(5.0f*theta)); */
- /* Pulse result = 0.0f;
+ * *(in->sin_coefs+1)*sin(2.0*theta)+
+ * *(in->sin_coefs+2)*sin(3.0*theta)+
+ * *(in->sin_coefs+3)*sin(4.0*theta)+
+ * *(in->sin_coefs+4)*sin(5.0*theta)); */
+ /* Pulse result = 0.0;
* for (int i = 0; i < 4; i++)
- * result += *(in->sin_coefs+i) * sin((float) (i+1)*theta); */
+ * result += *(in->sin_coefs+i) * sin((NUMT) (i+1)*theta); */
/* result = sin(theta); */
/* return result; */
}
UH_ATTR
-float violin_adsr(Instrument *violin, float t)
+NUMT violin_adsr(Instrument *violin, NUMT t)
{
- if (t <= 0.0f || t > 1.0f)
- return 0.0f;
+ if (t <= 0.0 || t > 1.0)
+ return 0.0;
if (t <= violin->adsr.attack_p)
- return log(1.0f + 2.7f*(t / violin->adsr.attack_p));
+ return log(1.0 + 2.7*(t / violin->adsr.attack_p));
else if (t <= violin->adsr.decay_p+violin->adsr.attack_p)
return (t - violin->adsr.attack_p) / violin->adsr.decay_p;
- else if (t <= 1.0f - violin->adsr.release_p)
+ else if (t <= 1.0 - violin->adsr.release_p)
return violin->adsr.sustain_level;
else
- return 1.0f - (1.0f - t) / violin->adsr.release_p;
+ return 1.0 - (1.0 - t) / violin->adsr.release_p;
}
UH_ATTR
@@ -217,45 +217,45 @@ violin_sound(void * in, Volume v, Hertz h, Seconds s)
/* We produce a little more samples so that we can create the effect
of reverberation later on. */
- s *= (1.0f+violin->reverb);
+ s *= (1.0+violin->reverb);
- float step = (float) (h * 2 * M_PI) / SAMPLE_RATE;
+ NUMT step = (NUMT) (h * 2 * M_PI) / SAMPLE_RATE;
LENT sample_num = (LENT) floor(SAMPLE_RATE * s);
- /* float attack_step = 1.0f / (float) (sample_num * violin->adsr.attack_p);
- * float decay_step = 1.0f / (float) (sample_num * violin->adsr.decay_p);
- * float sustain_step = 1.0f / (float) (sample_num * violin->adsr.sustain_p);
- * float release_step = 1.0f / (float) (sample_num * violin->adsr.release_p); */
+ /* NUMT attack_step = 1.0 / (NUMT) (sample_num * violin->adsr.attack_p);
+ * NUMT decay_step = 1.0 / (NUMT) (sample_num * violin->adsr.decay_p);
+ * NUMT sustain_step = 1.0 / (NUMT) (sample_num * violin->adsr.sustain_p);
+ * NUMT release_step = 1.0 / (NUMT) (sample_num * violin->adsr.release_p); */
Wave w = MYALLOC(Pulse, sizeof(*w) * sample_num);
- float theta = 0.0f, temp = 0.0f, adsrcounter = 0.0f;
+ NUMT theta = 0.0, temp = 0.0, adsrcounter = 0.0;
for (LENT i = 0; i < sample_num; i++, theta += step) {
temp = violin_sound_internal(violin, theta);
- adsrcounter = violin_adsr(violin, (float) i / sample_num);
+ adsrcounter = violin_adsr(violin, (NUMT) i / sample_num);
/* temp += temp*temp*temp; */
- /* *(w+i) = (float) v * temp * ((sustain_flag) ? SUSTAIN_LEVEL : adsrcounter); */
- *(w+i) = (float) v * temp * adsrcounter;
+ /* *(w+i) = (NUMT) v * temp * ((sustain_flag) ? SUSTAIN_LEVEL : adsrcounter); */
+ *(w+i) = (NUMT) v * temp * adsrcounter;
/* switch (phase) {
* case 0: /\* attack phase *\/
* adsrcounter += attack_step;
- * if (adsrcounter >= 1.0f) {
- * adsrcounter = 1.0f;
+ * if (adsrcounter >= 1.0) {
+ * adsrcounter = 1.0;
* phase++;
* }
* break;
* case 1: /\* decay phase *\/
* adsrcounter -= decay_step;
* if (adsrcounter <= SUSTAIN_LEVEL) {
- * adsrcounter = 0.0f;
+ * adsrcounter = 0.0;
* sustain_flag = 1;
* phase++;
* }
* break;
* case 2: /\* sustain phase *\/
* adsrcounter += sustain_step;
- * if (adsrcounter >= 1.0f) {
+ * if (adsrcounter >= 1.0) {
* adsrcounter = SUSTAIN_LEVEL;
* sustain_flag = 0;
* phase++;
@@ -263,7 +263,7 @@ violin_sound(void * in, Volume v, Hertz h, Seconds s)
* break;
* default: /\* release phase *\/
* adsrcounter -= release_step;
- * if (adsrcounter <= 0.0f) adsrcounter = 0.0f;
+ * if (adsrcounter <= 0.0) adsrcounter = 0.0;
* break;
* } */
}
@@ -283,7 +283,7 @@ violin_merger(void *in, WaveFrag *frags, LENT len, int step)
LENT total_len = 0;
- float reverb_ratio = 1.0f / (1.0f + violin->reverb);
+ NUMT reverb_ratio = 1.0 / (1.0 + violin->reverb);
for (LENT i = 0; i < len; i += step)
total_len += (LENT) ((frags+i)->n * reverb_ratio);
@@ -355,14 +355,14 @@ make_violin()
violin->fm.pred = 0;
violin->adsr.pred = 1;
- violin->reverb = 0.01f;
+ violin->reverb = 0.01;
violin->adsr.attack_p = 0.09;
violin->adsr.release_p = 0.09;
violin->adsr.decay_p = 0.05;
- violin->adsr.sustain_p = max(1.0f - (violin->adsr.attack_p+
+ violin->adsr.sustain_p = max(1.0 - (violin->adsr.attack_p+
violin->adsr.decay_p+
violin->adsr.release_p),
- 0.0f);
+ 0.0);
violin->adsr.sustain_level = 0.9;
double temp [] = {
@@ -376,19 +376,19 @@ make_violin()
0.002860679, 0.002558108, 0.0, 0.001650392
};
- violin->sin_coefs = malloc(sizeof(float)*26);
+ violin->sin_coefs = malloc(sizeof(NUMT)*26);
for (int i = 0; i < 26; i++)
*(violin->sin_coefs+i) = *(temp+i);
- /* *(violin->sin_coefs) = 1.0f;
- * *(violin->sin_coefs+1) = 0.41f;
- * *(violin->sin_coefs+2) = 0.35f;
- * *(violin->sin_coefs+3) = 0.39f;
- * *(violin->sin_coefs+4) = 0.45f;
- * *(violin->sin_coefs+5) = 0.35f;
- * *(violin->sin_coefs+6) = 0.5f;
- * *(violin->sin_coefs+7) = 0.4f;
- * *(violin->sin_coefs+8) = 0.35f;
- * *(violin->sin_coefs+9) = 0.1f; */
+ /* *(violin->sin_coefs) = 1.0;
+ * *(violin->sin_coefs+1) = 0.41;
+ * *(violin->sin_coefs+2) = 0.35;
+ * *(violin->sin_coefs+3) = 0.39;
+ * *(violin->sin_coefs+4) = 0.45;
+ * *(violin->sin_coefs+5) = 0.35;
+ * *(violin->sin_coefs+6) = 0.5;
+ * *(violin->sin_coefs+7) = 0.4;
+ * *(violin->sin_coefs+8) = 0.35;
+ * *(violin->sin_coefs+9) = 0.1; */
violin->sound = violin_sound;
violin->merger = simple_merger;
diff --git a/main.c b/main.c
index 43bf52b..eb83b58 100644
--- a/main.c
+++ b/main.c
@@ -116,7 +116,7 @@ static inline Pulse
synthesize_wave(float theta)
{
- /* return -1.0f + fmod(theta, 2*M_PI)/M_PI; */
+ /* return -1.0 + fmod(theta, 2*M_PI)/M_PI; */
/* return sin(theta); */
@@ -124,17 +124,17 @@ synthesize_wave(float theta)
/* return pow(theta/2*M_PI, 2); */
- /* return sin(theta)+0.442f*sin(2.0f*theta)+0.315f*sin(3.0f*theta)
- * +0.083f*sin(4.0f*theta)+cos(theta)+0.442f*cos(2.0f*theta); */
+ /* return sin(theta)+0.442*sin(2.0*theta)+0.315*sin(3.0*theta)
+ * +0.083*sin(4.0*theta)+cos(theta)+0.442*cos(2.0*theta); */
/* piano like */
- /* return sin(theta)+1.869*sin(2.0f*theta)+0.042f*sin(3.0f*theta)
- * +0.022f*sin(4.0f*theta)+cos(theta); */
+ /* return sin(theta)+1.869*sin(2.0*theta)+0.042*sin(3.0*theta)
+ * +0.022*sin(4.0*theta)+cos(theta); */
/* excellent piano like */
- return ((0.65f*sin(theta)+0.5f*sin(2.0f*theta))*exp(-0.004f*theta));
+ return ((0.65*sin(theta)+0.5*sin(2.0*theta))*exp(-0.004*theta));
}
@@ -144,7 +144,7 @@ synthesize_wave(float theta)
* oscillator(Volume v, Hertz h, Seconds s, Instrument *ins)
* {
*
- * return 0.0f;
+ * return 0.0;
* } */
UHA_ATTR
@@ -159,10 +159,10 @@ static WaveFrag
hstow(Volume v, Hertz h, Seconds s)
{
LENT sample_num = (LENT) floor(SAMPLE_RATE * s);
- float attack_step = 1.0f / (float) (sample_num * ATTACK_P);
- float decay_step = 1.0f / (float) (sample_num * DECAY_P);
- float sustain_step = 1.0f / (float) (sample_num * SUSTAIN_P);
- float release_step = 1.0f / (float) (sample_num * RELEASE_P);
+ float attack_step = 1.0 / (float) (sample_num * ATTACK_P);
+ float decay_step = 1.0 / (float) (sample_num * DECAY_P);
+ float sustain_step = 1.0 / (float) (sample_num * SUSTAIN_P);
+ float release_step = 1.0 / (float) (sample_num * RELEASE_P);
float step = (float) (h * 2 * M_PI) / SAMPLE_RATE;
@@ -172,8 +172,8 @@ hstow(Volume v, Hertz h, Seconds s)
Wave w = MYALLOC(Pulse, sizeof(*w) * sample_num);
- float adsrcounter = 0.0f, counter = 0.0f, fm_counter = 0.0f;
- float theta = 0.0f, temp = 0.0f;
+ float adsrcounter = 0.0, counter = 0.0, fm_counter = 0.0;
+ float theta = 0.0, temp = 0.0;
for (LENT i = 0; i < sample_num; i++, counter += step, fm_counter += fm_step) {
/* theta = frequency_modulation(counter, (float) h*i/((float) SAMPLE_RATE), fm_counter); */
@@ -181,30 +181,30 @@ hstow(Volume v, Hertz h, Seconds s)
temp = synthesize_wave(theta);
temp += temp*temp*temp;
temp = synthesize_wave(temp);
- temp += theta*exp(-2.0f*theta);
+ temp += theta*exp(-2.0*theta);
*(w+i) = (float) v * temp;
/* (synthesize_wave(temp)/\* +
- * * 0.01*(2.0f*(float)rand()/(float) RAND_MAX - 1.0f) *\/) *//* *
+ * * 0.01*(2.0*(float)rand()/(float) RAND_MAX - 1.0) *\/) *//* *
* ((sustain_flag) ? SUSTAIN_LEVEL : adsrcounter) ;*/
switch (phase) {
case 0: /* attack phase */
adsrcounter += attack_step;
- if (adsrcounter >= 1.0f) {
- adsrcounter = 1.0f;
+ if (adsrcounter >= 1.0) {
+ adsrcounter = 1.0;
phase++;
}
break;
case 1: /* decay phase */
adsrcounter -= decay_step;
if (adsrcounter <= SUSTAIN_LEVEL) {
- adsrcounter = 0.0f;
+ adsrcounter = 0.0;
sustain_flag = 1;
phase++;
}
break;
case 2: /* sustain phase */
adsrcounter += sustain_step;
- if (adsrcounter >= 1.0f) {
+ if (adsrcounter >= 1.0) {
adsrcounter = SUSTAIN_LEVEL;
sustain_flag = 0;
phase++;
@@ -212,7 +212,7 @@ hstow(Volume v, Hertz h, Seconds s)
break;
default: /* release phase */
adsrcounter -= release_step;
- if (adsrcounter <= 0.0f) adsrcounter = 0.0f;
+ if (adsrcounter <= 0.0) adsrcounter = 0.0;
break;
}
}
@@ -296,10 +296,10 @@ read_sb(const char *str, int str_len,
if (nth % 2) {
/* odd */
- PUSH_NODE(b_len, bp, beats, temp, f);
+ PUSH_NODE(b_len, bp, beats, temp, n);
} else {
/* even */
- PUSH_NODE(semi_len, sp, semis, temp, f);
+ PUSH_NODE(semi_len, sp, semis, temp, n);
}
}
@@ -310,15 +310,15 @@ read_sb(const char *str, int str_len,
exit(1);
}
- *len = floor(nth/2.0f);
+ *len = floor(nth/2.0);
*sts = realloc(*sts, sizeof(float) * (*len));
*bs = realloc(*bs, sizeof(float) * (*len));
for (int i = 0; i < *len; i++) {
- POP_NODE(semi_len, temp, semis, sn, f);
+ POP_NODE(semi_len, temp, semis, sn, n);
*(*sts+*len-1-i) = temp;
- POP_NODE(b_len, temp, beats, bn, f);
+ POP_NODE(b_len, temp, beats, bn, n);
*(*bs+*len-1-i) = temp;
}
}
@@ -382,7 +382,7 @@ int main(int argc, char **argv)
/* return 0; */
- /* STD_BASE = (float) pow(2, 1.0f/12.0f); */
+ /* STD_BASE = (float) pow(2, 1.0/12.0); */
UNUSED int notes_len = 0;
@@ -418,10 +418,10 @@ int main(int argc, char **argv)
#endif
/* vs = MYALLOC(Volume, notes_len);
- * for (int i = 0; i < notes_len;) *(vs+i++) = 0.3f; */
+ * for (int i = 0; i < notes_len;) *(vs+i++) = 0.3; */
/* WaveFrag wf = compose(vs, sts, bs, notes_len); */
- WaveFrag wf = play_sheet(psh, 0.3f);
+ WaveFrag wf = play_sheet(psh, 0.3);
destroy_sheet(psh);
diff --git a/mix.c b/mix.c
index ae1c1ab..987993a 100644
--- a/mix.c
+++ b/mix.c
@@ -10,13 +10,12 @@ U_ATTR
Pulse
mix_sound(Wave w, LENT n)
{
- Pulse result = 0.0f;;
+ Pulse result = 0.0;
for (LENT i = 0; i < n;)
result += *(w+i++);
- result /= (float) n;
+ result /= (NUMT) n;
return result;
}
-
diff --git a/parser.c b/parser.c
index 8d34121..3b0d30c 100644
--- a/parser.c
+++ b/parser.c
@@ -38,7 +38,7 @@ struct PUnit_s {
/* Helper macro */
-#define EMPTY_NOTE ((PNote) { NULL, 0.0f, 0, NONE_TYPE, NULL })
+#define EMPTY_NOTE ((PNote) { NULL, 0.0, 0, NONE_TYPE, NULL })
#define EMPTY_UNIT ((PUnit) { NULL, 0 })
/* Helper function */
@@ -157,7 +157,7 @@ read_sheet(const char *str, LENT len)
char current = 0;
- float local = 0.0f;
+ NUMT local = 0.0;
int channel_num = 0, num_chars_read = 0;
int num_channels = 0;
@@ -183,7 +183,7 @@ read_sheet(const char *str, LENT len)
Semitones *st_pointer = NULL;
/* A note without time information will use the previous beats
- information. A first note without time information will use 1.0f
+ information. A first note without time information will use 1.0
as the beats. */
Beats *beats_channel_array = NULL;
@@ -206,7 +206,7 @@ read_sheet(const char *str, LENT len)
beats_channel_array = MYALLOC(Beats, num_channels);
for (int i = 0; i < num_channels; i++) {
- *(beats_channel_array+i) = 1.0f;
+ *(beats_channel_array+i) = 1.0;
}
} else if (note_used) {
@@ -254,7 +254,7 @@ read_sheet(const char *str, LENT len)
for (int i = 0; i < num_channels; i++) {
*(notes_pointer+i) = EMPTY_NOTE;
- *(beats_channel_array+i) = 1.0f;
+ *(beats_channel_array+i) = 1.0;
}
current_unit.notes = notes_pointer;
@@ -276,7 +276,7 @@ read_sheet(const char *str, LENT len)
if (*(str+counter) != '\n' &&
*(str+counter) != 13 &&
- sscanf(str+counter, "%f%n",
+ sscanf(str+counter, "%lf%n",
&local, &num_chars_read) == 1) {
temp_note = (PNote) {
NULL, local,
@@ -298,7 +298,7 @@ read_sheet(const char *str, LENT len)
if (*(str+counter) != '\n' &&
*(str+counter) != 13 &&
- sscanf(str+counter, "%f%n",
+ sscanf(str+counter, "%lf%n",
&local, &num_chars_read) == 1) {
*(beats_channel_array+channel_num) = local;
temp_note = (PNote) {
@@ -326,7 +326,7 @@ read_sheet(const char *str, LENT len)
/* subtract one from the increment so that we don't
unknowingly skip one character. */
increment--;
- } else if (sscanf(str+counter, "%f%n",
+ } else if (sscanf(str+counter, "%lf%n",
&local, &num_chars_read) == 1) {
/* a note consisting of one single semitone */
st_pointer = MYALLOC(Semitones, 1);
@@ -339,7 +339,7 @@ read_sheet(const char *str, LENT len)
if (*(str+counter) != '\n' &&
*(str+counter) != 13 &&
- sscanf(str+counter, "%f%n",
+ sscanf(str+counter, "%lf%n",
&local, &num_chars_read) == 1) {
*(beats_channel_array+channel_num) = local;
temp_note = (PNote) {
@@ -373,7 +373,7 @@ read_sheet(const char *str, LENT len)
st_stack_len = 0;
counter++;
- for (;sscanf(str+counter, "%f %n", &local, &num_chars_read) == 1;
+ for (;sscanf(str+counter, "%lf %n", &local, &num_chars_read) == 1;
counter += num_chars_read) {
*(st_stack+st_stack_len++) = local;
}
@@ -485,7 +485,7 @@ sheet_note_num(const PSheet sh, LENT *nums_per_channel)
H_ATTR
static WaveFrag
-silent_note(Beats b, float dur)
+silent_note(Beats b, NUMT dur)
{
WaveFrag w;
@@ -495,7 +495,7 @@ silent_note(Beats b, float dur)
w.n = sample_num;
for (LENT i = 0; i < sample_num; i++)
- *(w.w+i) = 0.0f;
+ *(w.w+i) = 0.0;
return w;
}
@@ -590,12 +590,12 @@ play_sheet(const PSheet sh, const Volume v)
switch (pn.type) {
case NOTE_TYPE:
for (LENT k = 0; k < pn.len; k++) {
- *(st_temp+k) = make_sound(inst, v * ((k==1) ? 0.3f : 1.0f),
+ *(st_temp+k) = make_sound(inst, v * ((k==1) ? 0.3 : 1.0),
stoh(*(pn.tones+k)), pn.secs * dur);
}
break;
case BEAT_DURATION_TYPE:
- dur = 60.0f / pn.secs;
+ dur = 60.0 / pn.secs;
break;
default:
/* SILENT_TYPE */
@@ -678,12 +678,12 @@ main(int argc, char **argv)
print_sheet(sh);
- WaveFrag wf = play_sheet(sh, 0.3f);
+ WaveFrag wf = play_sheet(sh, 0.3);
destroy_sheet(sh);
printf("w.n = %lu\n", wf.n);
- printf("some sound is %f\n", *(wf.w+10));
+ printf("some sound is %lf\n", *(wf.w+10));
free(wf.w);
diff --git a/util.c b/util.c
index c5921e5..c998930 100644
--- a/util.c
+++ b/util.c
@@ -52,7 +52,7 @@ mix_waves(WaveFrag *frags, LENT len)
LENT max_len = 0;
- Pulse p = 0.0f;
+ Pulse p = 0.0;
for (LENT i = 0; i < len; i++)
max_len = max(max_len, (frags+i)->n);
@@ -61,7 +61,7 @@ mix_waves(WaveFrag *frags, LENT len)
wf.w = MYALLOC(Pulse, max_len);
for (LENT i = 0; i < max_len; i++) {
- p = 0.0f;
+ p = 0.0;
for (LENT j = 0; j < len; j++)
if (i < (frags+j)->n) p += *((frags+j)->w+i);
diff --git a/util.h b/util.h
index 700a8bf..3665ee1 100644
--- a/util.h
+++ b/util.h
@@ -29,10 +29,11 @@
}
/* An empty node. */
-#define EMPTY_NODE (Node_t) { (Node_v) { .f=0 }, NULL }
+#define EMPTY_NODE (Node_t) { (Node_v) { .n=0 }, NULL }
typedef union {
- float f;
+ /* the typedef for NUMT is below, so I cannot use that alias. */
+ double n;
void *v; /* very evil */
} Node_v;
@@ -88,16 +89,17 @@ typedef struct Node {
/* types */
-typedef float Volume;
-typedef float Samples;
-typedef float Hertz;
-typedef float Seconds;
-typedef float Pulse;
-typedef float Beats;
-typedef float Semitones;
-typedef Pulse *Wave;
-
typedef unsigned long LENT;
+typedef double NUMT;
+
+typedef NUMT Volume;
+typedef NUMT Samples;
+typedef NUMT Hertz;
+typedef NUMT Seconds;
+typedef NUMT Pulse;
+typedef NUMT Beats;
+typedef NUMT Semitones;
+typedef Pulse *Wave;
typedef struct {
Wave w;