Skip to content

Commit

Permalink
Merge pull request #89071 from DeeJayLSP/cubicres
Browse files Browse the repository at this point in the history
WAV importer: Use cubic interpolation on resampler
  • Loading branch information
akien-mga committed Mar 4, 2024
2 parents 0064370 + 7fa3431 commit b811e9a
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions editor/import/resource_importer_wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
int ipos = 0;

for (int i = 0; i < new_data_frames; i++) {
//simple cubic interpolation should be enough.
// Cubic interpolation should be enough.

float mu = frac;

Expand All @@ -337,15 +337,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
float y2 = data[MIN(frames - 1, ipos + 1) * format_channels + c];
float y3 = data[MIN(frames - 1, ipos + 2) * format_channels + c];

float mu2 = mu * mu;
float a0 = y3 - y2 - y0 + y1;
float a1 = y0 - y1 - a0;
float a2 = y2 - y0;
float a3 = y1;

float res = (a0 * mu * mu2 + a1 * mu2 + a2 * mu + a3);

new_data.write[i * format_channels + c] = res;
new_data.write[i * format_channels + c] = Math::cubic_interpolate(y1, y2, y0, y3, mu);

// update position and always keep fractional part within ]0...1]
// in order to avoid 32bit floating point precision errors
Expand Down

0 comments on commit b811e9a

Please sign in to comment.