DSP.jl icon indicating copy to clipboard operation
DSP.jl copied to clipboard

resample should use `similar`

Open ssfrr opened this issue 5 years ago • 2 comments

Currently resample always returns an Array even if the input was some other AbstractArray. It should use similar so that the returned value is the same type as the input.

MWE:

julia> using SampledSignals, DSP

julia> buf = SampleBuf(rand(100), 48000)
100-frame, 1-channel SampleBuf{Float64, 1}
0.0020833333333333333s sampled at 48000.0Hz
▇▇▇▆▆▇▇▆▇▇▇▆▇▇▇▇▇▆▇▆▇▆▇▇▇▆▆▇▇▆▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▆▆

julia> resample(buf, 1.2)
120-element Array{Float64,1}:
 0.8790735553966081
 1.0707055066803346
 0.5417156513066438
 0.9083973585054169
 ⋮
 0.0819987776177565
 0.3151630859175723
 0.16424615564476444
 0.17496872135247912

ssfrr avatar Dec 06 '18 14:12 ssfrr

I'm guessing that's because of this line?

jfsantos avatar Dec 25 '18 00:12 jfsantos

Yes, that should probably be

buffer = similar(x, promote_type(Th,Tx), bufLen)

martinholters avatar Jan 14 '19 13:01 martinholters