static int test_vec_copyf(void) { int i; float x[100]; float za[100]; float zb[100]; printf("Testing vec_copyf()\n"); for (i = 0; i < 99; i++) { x[i] = i; za[i] = -1.0f; zb[i] = -1.0f; } vec_copyf_dumb(za + 3, x + 1, 0); vec_copyf(zb + 3, x + 1, 0); for (i = 0; i < 99; i++) { if (za[i] != zb[i]) { printf("vec_copyf() - %d %f %f\n", i, za[i], zb[i]); printf("Tests failed\n"); exit(2); } } vec_copyf_dumb(za + 3, x + 1, 1); vec_copyf(zb + 3, x + 1, 1); for (i = 0; i < 99; i++) { if (za[i] != zb[i]) { printf("vec_copyf() - %d %f %f\n", i, za[i], zb[i]); printf("Tests failed\n"); exit(2); } } vec_copyf_dumb(za + 3, x + 1, 29); vec_copyf(zb + 3, x + 1, 29); for (i = 0; i < 99; i++) { if (za[i] != zb[i]) { printf("vec_copyf() - %d %f %f\n", i, za[i], zb[i]); printf("Tests failed\n"); exit(2); } } return 0; }
void rmlt_coefs_to_samples(float coefs[], float old_samples[], float out_samples[], int dct_length) { int i; int half_dct_length; int last; float new_samples[MAX_DCT_LENGTH]; const float *win; float sum; half_dct_length = dct_length >> 1; /* Perform a Type IV (inverse) DCT on the coefficients */ dct_type_iv(coefs, new_samples, dct_length); win = (dct_length == DCT_LENGTH) ? rmlt_to_samples_window : max_rmlt_to_samples_window; last = half_dct_length - 1; for (i = 0; i < half_dct_length; i++) { /* Get the first half of the windowed samples */ sum = win[i]*new_samples[last - i]; sum += win[dct_length - i - 1]*old_samples[i]; out_samples[i] = sum; /* Get the second half of the windowed samples */ sum = win[half_dct_length + i]*new_samples[i]; sum -= win[last - i]*old_samples[last - i]; out_samples[half_dct_length + i] = sum; } /* Save the second half of the new samples for next time, when they will be the old samples. */ vec_copyf(old_samples, &new_samples[half_dct_length], half_dct_length); }
void samples_to_rmlt_coefs(const float new_samples[], float old_samples[], float coefs[], int dct_length) { int i; int half_dct_length; int last; float sum; float windowed_data[MAX_DCT_LENGTH]; const float *win; half_dct_length = dct_length >> 1; win = (dct_length == DCT_LENGTH) ? samples_to_rmlt_window : max_samples_to_rmlt_window; /* Get the first half of the windowed samples. */ last = half_dct_length - 1; for (i = 0; i < half_dct_length; i++) { sum = win[last - i]*old_samples[last - i]; sum += win[half_dct_length + i]*old_samples[half_dct_length + i]; windowed_data[i] = sum; } /* Get the second half of the windowed samples. */ last = dct_length - 1; for (i = 0; i < half_dct_length; i++) { sum = win[last - i]*new_samples[i]; sum -= win[i]*new_samples[last - i]; windowed_data[half_dct_length + i] = sum; } /* Save the new samples for next time, when they will be the old samples. */ vec_copyf(old_samples, new_samples, dct_length); /* Perform a Type IV DCT on the windowed data to get the coefficients. */ dct_type_iv(windowed_data, coefs, dct_length); }