F
fl
Hi,
I am new to C++. I got the following snippet on the web. It is similar to my project application. I want to continue write with this code for my project. I find that there is process definition in the template. In the class definition, it has also a process definition. Could you explain what is the difference between them?
Thanks,
....................................
template<int UPSAMPLE_RATE, int TAPS_PER_PHASE, int MAX_INPUT_SAMPLE_COUNT>
class polyphase_upsample_fir_c
{
public:
static const int STATE_SAMPLE_COUNT = TAPS_PER_PHASE-1;
private:
const float (&taps)[UPSAMPLE_RATE][TAPS_PER_PHASE]; // These must be stored flipped left-to-right for simplicity
// float taps[UPSAMPLE_RATE][TAPS_PER_PHASE]; // THIS IS 4x FASTER THAN USING THE REFERENCE
cmplx_float_c state_and_input[STATE_SAMPLE_COUNT + MAX_INPUT_SAMPLE_COUNT];
public:
polyphase_upsample_fir_c(const float (&taps)[UPSAMPLE_RATE][TAPS_PER_PHASE]) :
taps(taps)
{
// Initialize the state to zero
for(int index=0; index<STATE_SAMPLE_COUNT; index++)
{
state_and_input[index].set(0, 0);
}
}
void process(int input_sample_count, cmplx_float_c* output);
// Returns a pointer to the first sample past the state memory, this is where the filter input should be placed.
inline cmplx_float_c* get_input_pointer() { return &state_and_input[STATE_SAMPLE_COUNT]; }
};
class polyphase_upsample_fir_24_c
{
public:
static const int UPSAMPLE_RATE = 24;
static const int TAPS_PER_PHASE = 16;
static const int MAX_INPUT_SAMPLE_COUNT = 48;
private:
polyphase_upsample_fir_c<UPSAMPLE_RATE, TAPS_PER_PHASE, MAX_INPUT_SAMPLE_COUNT> filter;
static const float taps[UPSAMPLE_RATE][TAPS_PER_PHASE];
public:
polyphase_upsample_fir_24_c():
filter(taps)
{}
void process(int input_sample_count, cmplx_float_c* output);
inline cmplx_float_c* get_input_pointer() { return filter.get_input_pointer(); }
};
I am new to C++. I got the following snippet on the web. It is similar to my project application. I want to continue write with this code for my project. I find that there is process definition in the template. In the class definition, it has also a process definition. Could you explain what is the difference between them?
Thanks,
....................................
template<int UPSAMPLE_RATE, int TAPS_PER_PHASE, int MAX_INPUT_SAMPLE_COUNT>
class polyphase_upsample_fir_c
{
public:
static const int STATE_SAMPLE_COUNT = TAPS_PER_PHASE-1;
private:
const float (&taps)[UPSAMPLE_RATE][TAPS_PER_PHASE]; // These must be stored flipped left-to-right for simplicity
// float taps[UPSAMPLE_RATE][TAPS_PER_PHASE]; // THIS IS 4x FASTER THAN USING THE REFERENCE
cmplx_float_c state_and_input[STATE_SAMPLE_COUNT + MAX_INPUT_SAMPLE_COUNT];
public:
polyphase_upsample_fir_c(const float (&taps)[UPSAMPLE_RATE][TAPS_PER_PHASE]) :
taps(taps)
{
// Initialize the state to zero
for(int index=0; index<STATE_SAMPLE_COUNT; index++)
{
state_and_input[index].set(0, 0);
}
}
void process(int input_sample_count, cmplx_float_c* output);
// Returns a pointer to the first sample past the state memory, this is where the filter input should be placed.
inline cmplx_float_c* get_input_pointer() { return &state_and_input[STATE_SAMPLE_COUNT]; }
};
class polyphase_upsample_fir_24_c
{
public:
static const int UPSAMPLE_RATE = 24;
static const int TAPS_PER_PHASE = 16;
static const int MAX_INPUT_SAMPLE_COUNT = 48;
private:
polyphase_upsample_fir_c<UPSAMPLE_RATE, TAPS_PER_PHASE, MAX_INPUT_SAMPLE_COUNT> filter;
static const float taps[UPSAMPLE_RATE][TAPS_PER_PHASE];
public:
polyphase_upsample_fir_24_c():
filter(taps)
{}
void process(int input_sample_count, cmplx_float_c* output);
inline cmplx_float_c* get_input_pointer() { return filter.get_input_pointer(); }
};