Skip to content
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

Fix wavplay on linux, and maybe OSX #85

Merged
merged 1 commit into from
Jul 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions src/WAV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,27 @@ import Libdl
using FileIO
using Logging

function __init__()
module_dir = dirname(@__FILE__)
try
# check we haven't already imported this package into the namespace
# this will throw an error otherwise
WAV
catch e
if isa(e, UndefVarError) && e.var == :WAV
if Libdl.find_library(["libpulse-simple", "libpulse-simple.so.0"]) != ""
include(joinpath(module_dir, "wavplay-pulse.jl"))
elseif Libdl.find_library(["AudioToolbox"],
["/System/Library/Frameworks/AudioToolbox.framework/Versions/A"]) != ""
include(joinpath(module_dir, "wavplay-audioqueue.jl"))
else
wavplay(data, fs) = @warn "wavplay is not currently implemented on $(Sys.KERNEL)"
end
else
throw(e)
end
wavplay(fname) = wavplay(wavread(fname)[1:2]...)
module_dir = dirname(@__FILE__)
@static if Sys.islinux()
@static if Libdl.find_library(["libpulse-simple", "libpulse-simple.so.0"]) != ""
include(joinpath(module_dir, "wavplay-pulse.jl"))
else
wavplay(data, fs) = @warn "libpulse-simple not found, wavplay will not work"
end
elseif Sys.isapple()
@static if Libdl.find_library(["AudioToolbox"],
["/System/Library/Frameworks/AudioToolbox.framework/Versions/A"]) != ""
include(joinpath(module_dir, "wavplay-audioqueue.jl"))
else
wavplay(data, fs) = @warn "AudioToolbox.framework not found, wavplay will not work"
end
nothing
else
wavplay(data, fs) = @warn "wavplay is not currently implemented on $(Sys.KERNEL)"
end

include("AudioDisplay.jl")
include("WAVChunk.jl")
wavplay(fname) = wavplay(wavread(fname)[1:2]...)

# The WAV specification states that numbers are written to disk in little endian form.
write_le(stream::IO, value) = write(stream, htol(value))
Expand Down