求大佬帮帮 一个奇怪的bug

操作系统:Windows 11
Julia: 1.10.3
代码如下

using SampledSignals
using Interpolations
using Unitful
using DSP
using StatsBase: mean

function rotary(x:: SampleBuf, p:: RotaryParams)
    sr = x.samplerate;
    buf = mean(x; dims=2);

    filt_low = SecondOrderSections([Biquad(1, 1, :LP)], 1);
    filt_high = SecondOrderSections([
        Biquad(0, 1, :HP)
        Biquad(0, 2, :LP)
    ], 1);
    weight_low = (1 - p.balance) / 2;
    weight_high = (1 + p.balance) / 2;
    x_low = weight_low * filt(filt_low, buf);
    x_high = weight_high * filt(filt_high, buf);

    # 问题出现在这几行
    x_low = [x_low x_low]
    x_high = [x_high x_high]
    x_low = tremvibsync(x_low, TremVibParams(0.75, 0.003, p.woofer_speed, 0));
    x_high = tremvibsync(x_high, TremVibParams(0.75, 0.003, p.horn_speed, 0));
    # 问题结束
    
    ...
end

如果这四行采用如上写法,会报错

MethodError: no method matching tremvibsync(::Matrix{Float64}, ::TremVibParams)

Closest candidates are:
  tremvibsync(!Matched::SampleBuf, ::TremVibParams)
   @ Main e:\JupyterLab\YAMAHA rot simulation.ipynb:1

但是如果将以上几行改成这样

    x_low = SampleBuf([x_low x_low], sr);
    x_high = SampleBuf([x_high x_high], sr);
    x_low = tremvibsync(x_low, TremVibParams(0.75, 0.003, p.woofer_speed, 0));
    x_high = tremvibsync(x_high, TremVibParams(0.75, 0.003, p.horn_speed, 0));

则会报另外一个错:

MethodError: no method matching SampleBuf(::SampleBuf{Float64, 2}, ::Float64)

Closest candidates are:
  SampleBuf(!Matched::Array{T, N}, ::Float64) where {T, N}
   @ SampledSignals D:\ProgramTemp\Julia\packages\SampledSignals\KYg5Q\src\SampleBuf.jl:12
  SampleBuf(!Matched::Array{T, N}, ::Real) where {T, N}
   @ SampledSignals D:\ProgramTemp\Julia\packages\SampledSignals\KYg5Q\src\SampleBuf.jl:17
  SampleBuf(!Matched::Type, ::Any, !Matched::Quantity)
   @ SampledSignals D:\ProgramTemp\Julia\packages\SampledSignals\KYg5Q\src\SampleBuf.jl:37
  ...

所以在这里的x_low, x_high到底是Matrix还是SampleBuf啊(((

求教大佬们

估计是你这里几个变量名弄混了,你把中间的 x_low x_high 换个其它名字,再重试下,看报错应该就是 SampleBuf

谢谢回复

后来让x_low, x_high一开始的类型变成Matrix就能正常运行了。

    ...
    x_low = weight_low * filt(filt_low, buf);
    x_high = weight_high * filt(filt_high, buf);
    x_low = SampleBuf([x_low x_low], sr);
    x_high = SampleBuf([x_high x_high], sr);
    y_low = tremvibsync(x_low, TremVibParams(0.75, 0.0028*p.drive_low, p.woofer_speed, 0));
    y_high = tremvibsync(x_high, TremVibParams(0.75, 0.0028*p.drive_low, p.horn_speed, 0));
    ...

但是在原来的代码里x_low的类型一直都没变过,一直是SampleBuf,为什么会出现这种错误呢 :thinking: