I am writing a program in c++ to record audio.
Here are my structure and code snippet.
typedef struct _recorder {
const uint32_t SAMPLE_RATE = 44100;
const uint32_t FRAME_STEP = SAMPLE_RATE / 100;
const uint32_t STEP_BUF_SIZE = sizeof(int16_t) * FRAME_STEP;
int16_t *step_buf;
const uint32_t RECORD_TIME = 10;
const uint32_t NUM_SAMPLE = RECORD_TIME * SAMPLE_RATE;
int16_t *total_buf;
uint32_t sample_counter;
} recorder;
void recorder_init(recorder *r)
{
r->step_buf = new int16_t[r->STEP_BUF_SIZE / sizeof(int16_t)];
r->total_buf = new int16_t[r->NUM_SAMPLE];
}
void recorder_free(recorder *r)
{
delete[] r->step_buf;
delete[] r->total_buf;
}
void main(int argc, char *argv[])
{
recorder rec;
recorder_init(&rec);
// Do something to record audio
recorder_free(&rec);
}
Does using structures and functions make sense to you? Or should I use a class? Or there are better design patterns I can follow?
EDIT -------------------------
I add a further question of this post here.