dancasimiro/WAV.jl

wavread with subrange of step >1 gives wrong result

Opened this issue · 4 comments

See the following example, where I have overloaded getindex on a LazyWAVFile to do wavread(path, format="native", ind)

julia> f[1:10] # Correct
10-element Array{Int16,1}:
 -15
  -8
  -4
 -19
  -3
  -4
 -12
  -2
 -17
  -4

julia> f[1:2:10] # Incorrect, but no error message
5-element Array{Int16,1}:
 -15
  -8
  -4
 -19
  -3

julia> f[collect(1:2:10)] # If range is collected to an array, result is correct
5-element Array{Int16,1}:
 -15
  -4
  -3
 -12
 -17

How many channels are in the WAV file?

Single channel

The wavread docstring now says:

  • subrange controls which samples are returned.
    The default (:) returns all samples in the file.
    Passing an integer N (or equivalently the range 1:N) returns
    the first N samples of each channel.
    Passing a unitrange I:J returns length(I:J) consecutive
    samples from each channel, starting with the I-th sample.

There is no support for StepRange.

We could assert subrange::Union{Colon, Real, UnitRange{<:Real}} if you want a compiler error.

While testing a patch for this issue, I stumbled over JuliaLang/julia#37169