Skip to content

Commit

Permalink
improve read_pcm_samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ymtoo committed Nov 25, 2020
1 parent 249b072 commit bf329e5
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/WAV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ function read_pcm_samples(io::IO, chunk_size, fmt::WAVFormat, subrange)
if isempty(subrange)
return Array{pcm_container_type(nbits), 2}(undef, 0, fmt.nchannels)
end
samples = Array{pcm_container_type(nbits), 2}(undef, length(subrange), fmt.nchannels)
sample_type = eltype(samples)
samples = Array{UInt64, 2}(undef, length(subrange), fmt.nchannels)
sample_type = pcm_container_type(nbits)
nbytes = ceil(Integer, nbits / 8)
bitshift = [0x0, 0x8, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40]
mask = UInt64(0x1) << (nbits - 1)
Expand All @@ -339,11 +339,10 @@ function read_pcm_samples(io::IO, chunk_size, fmt::WAVFormat, subrange)
end
my_sample >>= nbytes * 8 - nbits
# sign extend negative values
my_sample = xor(my_sample, mask) - mask
samples[i, j] = convert(sample_type, signed(my_sample))
samples[i, j] = xor(my_sample, mask) - mask
end
end
samples
convert.(sample_type, signed.(samples))
end

function read_ieee_float_samples(io::IO, chunk_size, fmt::WAVFormat, subrange, ::Type{floatType}) where {floatType}
Expand Down

0 comments on commit bf329e5

Please sign in to comment.