Use floating point for sample offsets.

This commit is contained in:
Themaister 2012-02-25 14:31:36 +01:00
parent 74de5350d2
commit 6643bf3e1c
4 changed files with 13 additions and 8 deletions

View File

@ -30,12 +30,12 @@ struct ssnes_resampler
double r_frac;
};
void resampler_preinit(ssnes_resampler_t *re, double omega, unsigned *samples_offset)
void resampler_preinit(ssnes_resampler_t *re, double omega, double *samples_offset)
{
*samples_offset = 4;
for (unsigned i = 0; i < 4; i++)
*samples_offset = 2.0;
for (int i = 0; i < 4; i++)
{
re->chan_data[0][i] = cos(i * omega);
re->chan_data[0][i] = cos((i - 2) * omega);
re->chan_data[1][i] = re->chan_data[0][i];
}

View File

@ -45,7 +45,7 @@ void resampler_process(ssnes_resampler_t *re, struct resampler_data *data);
void resampler_free(ssnes_resampler_t *re);
// Generate a starting cosine pulse with given frequency for testing (SNR, etc) purposes.
void resampler_preinit(ssnes_resampler_t *re, double omega, unsigned *samples_offset);
void resampler_preinit(ssnes_resampler_t *re, double omega, double *samples_offset);
#endif

View File

@ -65,7 +65,7 @@ struct ssnes_resampler
uint32_t time;
};
void resampler_preinit(ssnes_resampler_t *re, double omega, unsigned *samples_offset)
void resampler_preinit(ssnes_resampler_t *re, double omega, double *samples_offset)
{
*samples_offset = SIDELOBES + 1;
for (int i = 0; i < 2 * SIDELOBES; i++)

View File

@ -22,7 +22,7 @@
#include <math.h>
#include <assert.h>
static void gen_signal(float *out, double freq, double sample_rate, unsigned bias_samples, size_t samples)
static void gen_signal(float *out, double freq, double sample_rate, double bias_samples, size_t samples)
{
double omega = 2.0 * M_PI * freq / sample_rate;
@ -149,7 +149,7 @@ int main(int argc, char *argv[])
for (unsigned i = 0; i < sizeof(freq_list) / sizeof(freq_list[0]) && freq_list[i] < 0.5f * in_rate; i++)
{
double omega = 2.0 * M_PI * freq_list[i] / in_rate;
unsigned sample_offset;
double sample_offset;
resampler_preinit(re, omega, &sample_offset);
gen_signal(input, freq_list[i], in_rate, sample_offset, samples);
@ -171,6 +171,11 @@ int main(int argc, char *argv[])
printf("SNR @ %7.1f Hz: %6.2lf dB, Gain: %6.1f dB\n",
freq_list[i], res.snr, res.gain);
//printf("Generated:\n\t");
//for (unsigned i = 0; i < 10; i++)
// printf("%.4f, ", output[i]);
//printf("\n");
}
resampler_free(re);