From 4e0861182ee76cfeb2c040d204d6b5ff9eeeac5c Mon Sep 17 00:00:00 2001 From: contradict Date: Thu, 11 Jun 2020 21:01:23 -0700 Subject: [PATCH] Fix wavplay on linux, and maybe OSX --- src/WAV.jl | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/WAV.jl b/src/WAV.jl index b3b9908..d3d476a 100644 --- a/src/WAV.jl +++ b/src/WAV.jl @@ -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))