Skip to content

Commit

Permalink
move WAVPlay module near end, so it can include wavwrite
Browse files Browse the repository at this point in the history
  • Loading branch information
mgkuhn committed Aug 1, 2020
1 parent dffe839 commit 18af523
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
54 changes: 30 additions & 24 deletions src/WAV.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,6 @@ import Libdl
using FileIO
using Logging

"""
wavplay(data, fs)
wavplay(filename)
Plays the audio waveform `data` at sampling frequency `fs`, or read
both from the WAV file named `filename`.
The supported backends are:
* AudioQueue (macOS)
* PulseAudio (Linux, libpulse-simple)
* PlaySound (Windows)
"""
function wavplay end
wavplay(fname) = wavplay(wavread(fname)[1:2]...)
@static if Sys.islinux()
include("wavplay-pulse.jl")
elseif Sys.isapple()
include("wavplay-audioqueue.jl")
elseif Sys.iswindows()
include("wavplay-win32.jl")
else
wavplay(data, fs) = @warn "wavplay is not currently implemented on $(Sys.KERNEL)"
end

include("AudioDisplay.jl")
include("WAVChunk.jl")

Expand Down Expand Up @@ -1071,4 +1047,34 @@ save(s::Stream{format"WAV"}, data; kwargs...) = wavwrite(data, s.io; kwargs...)
load(f::File{format"WAV"}; kwargs...) = wavread(f.filename; kwargs...)
save(f::File{format"WAV"}, data; kwargs...) = wavwrite(data, f.filename; kwargs...)

"""
wavplay(data, fs)
wavplay(filename::AbstractString)
Plays the audio waveform `data` at sampling frequency `fs` (in hertz).
To play a stereo signal, provide two columns in array `data` (left and
right channel), as in [`wavwrite`](@ref).
The `filename` form reads both waveform data and sampling frequency
from the named WAV file to play it.
The supported backends are:
* AudioQueue (macOS)
* PulseAudio (Linux, libpulse-simple)
* PlaySound (Windows)
See also: [`wavwrite`](@ref)
"""
function wavplay end
wavplay(fname::AbstractString) = wavplay(wavread(fname)[1:2]...)
@static if Sys.islinux()
include("wavplay-pulse.jl")
elseif Sys.isapple()
include("wavplay-audioqueue.jl")
elseif Sys.iswindows()
include("wavplay-win32.jl")
else
wavplay(data, fs) = @warn "wavplay is not currently implemented on $(Sys.KERNEL)"
end

end # module
2 changes: 1 addition & 1 deletion src/wavplay-win32.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- mode: julia; -*-
module WAVPlay
import ..wavplay
import WAV: wavplay, wavwrite

# some standard Win32 API types and constants, see [MS-DTYP]
const BOOL = Cint
Expand Down

0 comments on commit 18af523

Please sign in to comment.