This commit is contained in:
John Alanbrook 2022-07-05 02:44:39 +00:00
parent 434b8be151
commit 7341d8a8cf

View file

@ -34,8 +34,9 @@ struct wav gen_sine(float amp, float freq, int sr, int ch)
short *data = (short*)new.data;
for (int i = 0; i < new.frames; i++) {
short val = amp * sin(2*PI*((float)i / new.frames));
for (int j = 0; j < new.ch; j++) {
data[i+j] =amp * sin(2*PI*((float)i / new.frames));
data[i+j] = val;
}
}
@ -55,15 +56,10 @@ struct wav gen_square(float amp, float freq, int sr, int ch)
short *data = (short*)new.data;
for (int i = 0; i < crossover; i++) {
for (int i = 0; i < new.frames; i++) {
short val = -2 * floor(2 * i / new.frames) + 1;
for (int j = 0; j < new.ch; j++) {
data[i+j] = samp;
}
}
for (int i = crossover; i < new.frames; i++) {
for (int j = 0; j < new.ch; j++) {
data[i+j] = samp * -1;
data[i+j] = val;
}
}
@ -77,11 +73,25 @@ struct wav gen_triangle(float amp, float freq, int sr, int ch)
if (amp > 1) amp = 1;
if (amp < 0) amp = 0;
for (int i = 0; i < new.frames; i++) {
short val = 2 * abs( (i/new.frames) - floor( (i/new.frames) + 0.5));
for (int j = 0; j < new.ch; j++) {
//new.data[i+j] =
new.data[i+j] = val;
}
}
}
struct wav gen_saw(float amp, float freq, int sr, int ch)
{
struct wav new = make_wav(freq, sr, ch);
if (amp > 1) amp = 1;
if (amp < 0) amp = 0;
for (int i = 0; i < new.frames; i++) {
short val = 2 * ( (i/new.frames) - floor( (0.5 + (i/new.frames))));
for (int j = 0; j < new.ch; j++) {
new.data[i+j] = val;
}
}
}