-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading wav files is extremely slow. #52
Comments
In julia v1.3, io is thread safe. When reading WAV files, a lot of time is taken to lock and unlock the stream lock in the function. function read(s::IOStream, T::Union{Type{Int16},Type{UInt16},Type{Int32},Type{UInt32},Type{Int64},Type{UInt64}})
n = sizeof(T)
lock(s.lock)
if ccall(:jl_ios_buffer_n, Cint, (Ptr{Cvoid}, Csize_t), s.ios, n) != 0
unlock(s.lock)
throw(EOFError())
end
x = ccall(:jl_ios_get_nbyte_int, UInt64, (Ptr{Cvoid}, Csize_t), s.ios, n) % T
unlock(s.lock)
return x
end I suspect it comes from the fact that very small amounts of data is read in every call to read_le(stream::IO, x::Type{T}) where {T} = ltoh(read(stream, T)) reads a single value at a time |
Defining these function mitigates the issue somewhat and reduces readtime by more than 3x, at the expense of not being thread safe read_le(stream::IO, x::Type{T}) where {T} = ltoh(fastread(stream, T))
fastread(s::IOStream, T) = read(s,T)
function fastread(s::IOStream, T::Union{Type{Int16},Type{UInt16},Type{Int32},Type{UInt32},Type{Int64},Type{UInt64}})
n = sizeof(T)
# lock(s.lock)
if ccall(:jl_ios_buffer_n, Cint, (Ptr{Cvoid}, Csize_t), s.ios, n) != 0
# unlock(s.lock)
throw(EOFError())
end
x = ccall(:jl_ios_get_nbyte_int, UInt64, (Ptr{Cvoid}, Csize_t), s.ios, n) % T
# unlock(s.lock)
return x
end
fastread(s::IOStream, ::Type{Float16}) = reinterpret(Float16, fastread(s, Int16))
fastread(s::IOStream, ::Type{Float32}) = reinterpret(Float32, fastread(s, Int32))
fastread(s::IOStream, ::Type{Float64}) = reinterpret(Float64, fastread(s, Int64)) |
Is it possible to read in larger chunks? Surely it is? |
#79 improves the situation by reading larger chunks |
@baggepinnen Do you anticipate making any additional changes? @Ashymad How does the performance (of master) compare now? |
I think the performance should be on par with other readers now, no more changes planned from me |
Thanks for all of your help. I will close this issue as fixed. |
Increment the patch version and prepare for release 1.0.3
Suppose I create a test file. about 3 minutes of 440Hz sine at 48kHz sampling rate
Let's load it.
Now let's load this file into GNU Octave.
Let's try SciPy.
WAV.jl is around 40 times slower than both.
I have Julia 0.6.2 and WAV.jl 0.9.0.
The text was updated successfully, but these errors were encountered: