Refactor: move gen_sin to new generators file
parent
7cea04234f
commit
6d40c3876c
2
Makefile
2
Makefile
|
|
@ -5,7 +5,7 @@ OLEVEL = -O2
|
|||
|
||||
CFLAGS = -Wall -std=c++17 $(OLEVEL) -o $(PROJ)
|
||||
|
||||
OBJECTS = src/wtpp.cpp src/wave.cpp src/wavetable.cpp
|
||||
OBJECTS = src/wtpp.cpp src/wave.cpp src/wavetable.cpp src/generators.cpp
|
||||
|
||||
build:
|
||||
$(CC) $(CFLAGS) $(OBJECTS)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
#include "generators.h"
|
||||
|
||||
sample_table_t gen_sin() {
|
||||
// Make the new Wavetable object
|
||||
sample_table_t sin_vals = {0};
|
||||
// Make a place to store calculated value
|
||||
float_t val = 0;
|
||||
|
||||
// Loop through number of samples and set table values
|
||||
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
|
||||
// Calculate the value of sin at position
|
||||
val = std::sin((2 * M_PI * i) / DEFAULT_N_SAMPLES);
|
||||
sin_vals[i] = val;
|
||||
}
|
||||
// Return the completed Wavetable object
|
||||
return sin_vals;
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
/*! @file generators.h
|
||||
@brief Header for wave cycle data generators
|
||||
*/
|
||||
#ifndef GENERATORS_H_
|
||||
#define GENERATORS_H_
|
||||
|
||||
#include "wave.h"
|
||||
|
||||
/*! Generate sine wave data
|
||||
@return a table of values
|
||||
*/
|
||||
sample_table_t gen_sin();
|
||||
|
||||
#endif // GENERATORS_H_
|
||||
16
src/wave.cpp
16
src/wave.cpp
|
|
@ -10,19 +10,3 @@ void Wave::print_head() {
|
|||
std::cout << m_table[i] << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
sample_table_t gen_sin() {
|
||||
// Make the new Wavetable object
|
||||
sample_table_t sin_vals = {0};
|
||||
// Make a place to store calculated value
|
||||
float_t val = 0;
|
||||
|
||||
// Loop through number of samples and set table values
|
||||
for (uint16_t i = 0; i < DEFAULT_N_SAMPLES; i++) {
|
||||
// Calculate the value of sin at position
|
||||
val = std::sin((2 * M_PI * i) / DEFAULT_N_SAMPLES);
|
||||
sin_vals[i] = val;
|
||||
}
|
||||
// Return the completed Wavetable object
|
||||
return sin_vals;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,9 +37,4 @@ public:
|
|||
void print_head();
|
||||
};
|
||||
|
||||
/*! Generate sine wave data
|
||||
@return a table of values
|
||||
*/
|
||||
sample_table_t gen_sin();
|
||||
|
||||
#endif // WAVE_H_
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include <math.h>
|
||||
|
||||
#include "wave.h"
|
||||
#include "generators.h"
|
||||
#include "wavetable.h"
|
||||
|
||||
static const uint32_t DEFAULT_SAMPLE_RATE = 44100; // 44.1 kHz sampling rate
|
||||
|
|
|
|||
Loading…
Reference in New Issue