浏览代码

Improve GPU phase precision

master
Jan Svabenik 9 小时前
父节点
当前提交
e87633f8a0
共有 2 个文件被更改,包括 12 次插入0 次删除
  1. +4
    -0
      internal/demod/gpudemod/kernels.cu
  2. +8
    -0
      internal/demod/gpudemod/native/exports.cu

+ 4
- 0
internal/demod/gpudemod/kernels.cu 查看文件

@@ -12,6 +12,8 @@ extern "C" __global__ void gpud_freq_shift_kernel(
if (idx >= n) return;

double phase = phase_start + phase_inc * (double)idx;
const double TWO_PI = 6.283185307179586;
phase = phase - rint(phase / TWO_PI) * TWO_PI;
float si, co;
sincosf((float)phase, &si, &co);

@@ -161,6 +163,8 @@ extern "C" __global__ void gpud_ssb_product_kernel(
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= n) return;
double phase = phase_start + phase_inc * (double)idx;
const double TWO_PI = 6.283185307179586;
phase = phase - rint(phase / TWO_PI) * TWO_PI;
float si, co;
sincosf((float)phase, &si, &co);
float2 v = in[idx];


+ 8
- 0
internal/demod/gpudemod/native/exports.cu 查看文件

@@ -41,6 +41,12 @@ __global__ void gpud_freq_shift_kernel(
if (idx >= n) return;

double phase = phase_start + phase_inc * (double)idx;
// Reduce phase to [-pi, pi) BEFORE float cast to preserve precision.
// Without this, phase accumulates to millions of radians and the
// (float) cast loses ~0.03-0.1 rad, causing audible clicks at
// frame boundaries in streaming audio.
const double TWO_PI = 6.283185307179586;
phase = phase - rint(phase / TWO_PI) * TWO_PI;
float si, co;
sincosf((float)phase, &si, &co);

@@ -293,6 +299,8 @@ __global__ void gpud_ssb_product_kernel(
int idx = blockIdx.x * blockDim.x + threadIdx.x;
if (idx >= n) return;
double phase = phase_start + phase_inc * (double)idx;
const double TWO_PI = 6.283185307179586;
phase = phase - rint(phase / TWO_PI) * TWO_PI;
float si, co;
sincosf((float)phase, &si, &co);
float2 v = in[idx];


正在加载...
取消
保存