Skip to content

Commit ac386b6

Browse files
authored
Merge pull request #7 from ssfrr/06_depwarns_windows
Removes units, updates for 0.6 and latest SampledSignals
2 parents 990c96d + 60b5874 commit ac386b6

File tree

10 files changed

+88
-122
lines changed

10 files changed

+88
-122
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ os:
55
- linux
66
- osx
77
julia:
8-
- 0.5
9-
- 0.4
8+
- 0.6
109
notifications:
1110
email: false
1211
# uncomment the following lines to override the default test script

REQUIRE

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
julia 0.4
1+
julia 0.6-
22
BinDeps
33
FileIO
44
FixedPointNumbers
5-
SampledSignals 0.2.0
6-
SIUnits
5+
SampledSignals 1.0.0
76
@osx Homebrew
8-
Compat 0.8.8

appveyor.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
environment:
22
matrix:
3-
- JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
4-
- JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
5-
- JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
6-
- JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
3+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
4+
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
75

86
notifications:
97
- provider: Email
@@ -12,9 +10,10 @@ notifications:
1210
on_build_status_changed: false
1311

1412
install:
13+
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
1514
# Download most recent Julia Windows binary
1615
- ps: (new-object net.webclient).DownloadFile(
17-
$("http://s3.amazonaws.com/"+$env:JULIAVERSION),
16+
$env:JULIA_URL,
1817
"C:\projects\julia-binary.exe")
1918
# Run installer silently, output to C:\projects\julia
2019
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

deps/build.jl

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
using BinDeps
2-
using Compat
32

43
@BinDeps.setup
54

6-
mpg123 = library_dependency("libmpg123")
5+
mpg123 = library_dependency("libmpg123", aliases=["libmpg123", "libmpg123-0"])
76
lame = library_dependency("libmp3lame")
87

98
provides(AptGet, "libmpg123-dev", mpg123)
109
provides(AptGet, "libmp3lame-dev", lame)
1110

11+
provides(Pacman, "mpg123", mpg123)
12+
provides(Pacman, "lame", lame)
13+
1214
@static if is_apple()
1315
if Pkg.installed("Homebrew") === nothing
1416
error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")")
@@ -18,4 +20,24 @@ provides(AptGet, "libmp3lame-dev", lame)
1820
provides(Homebrew.HB, "lame", lame)
1921
end
2022

23+
@static if is_windows()
24+
if Sys.WORD_SIZE == 32
25+
provides(Binaries, URI("http://www.rarewares.org/files/mp3/libmp3lame-3.99.5x86.zip"), lame,
26+
SHA="7bf2a33de715d968e5ef5049b7b18e34b9ae98224842293adcdc6f6f23ad9b76",
27+
unpacked_dir=".")
28+
provides(Binaries, URI("http://www.mpg123.org/download/win32/1.24.0/mpg123-1.24.0-x86.zip"), mpg123,
29+
SHA="331a48db899f6405b7728a4fcd9ee3ef0282f1d27d983bdc8b0738314bb780cb",
30+
unpacked_dir="mpg123-1.24.0-x86")
31+
elseif Sys.WORD_SIZE == 64
32+
provides(Binaries, URI("http://www.rarewares.org/files/mp3/libmp3lame-3.99.5x64.zip"), lame,
33+
SHA="97959980490caa1669b1c4af386c3e23fe4ceed0835c04e328c9a5966e4d2521",
34+
unpacked_dir=".")
35+
provides(Binaries, URI("http://www.mpg123.org/download/win64/1.24.0/mpg123-1.24.0-x86-64.zip"), mpg123,
36+
SHA="d3c21a6f62204a8c93c3f48288f6f7b4d7609394daa966f2d1e6c75b30476f85",
37+
unpacked_dir="mpg123-1.24.0-x86-64")
38+
else
39+
error("System not 32-bit or 64-bit. Something is wrong")
40+
end
41+
end
42+
2143
@BinDeps.install Dict("libmpg123" => :libmpg123, "libmp3lame" => :libmp3lame)

src/MP3.jl

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ isfile(deps)? include(deps) : error("MP3 is not properly installed. Please run:
99
using SampledSignals
1010
using FileIO
1111
using FixedPointNumbers
12-
using SIUnits
13-
using SIUnits.ShortUnits
14-
15-
using Compat
16-
import Compat: UTF8String, view
1712

1813
# methods to override
1914
import SampledSignals: nchannels, nframes, samplerate, unsafe_read!, unsafe_write
@@ -23,13 +18,6 @@ import FileIO: load, save
2318
export load, save
2419
export Hz, kHz, s
2520

26-
# types used for fixed-point 16-bit and 32-bit encoding
27-
typealias PCM16Sample Fixed{Int16, 15}
28-
typealias PCM32Sample Fixed{Int32, 31}
29-
30-
# shortcut to SIQuantity type of Hz
31-
typealias Hertz SIUnits.SIQuantity{Int64,0,0,-1,0,0,0,0,0,0}
32-
3321
type MP3INFO
3422
nframes::Int64
3523
nchannels::Int32
@@ -39,7 +27,7 @@ end
3927

4028
"""create an MP3INFO object from given audio buffer"""
4129
function MP3INFO{T}(buf::SampleBuf{T})
42-
MP3INFO(size(buf, 1), size(buf, 2), buf.samplerate.val, T)
30+
MP3INFO(nframes(buf), nchannels(buf), samplerate(buf), T)
4331
end
4432

4533
include("readers.jl")

src/lame.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# lame wrappers of required functions to write mp3 files
22

33
"""represents the C pointer lame_global_flags*. used by all LAME functions"""
4-
typealias LAME Ptr{Void}
4+
const LAME = Ptr{Void}
55

66
"""meaning of LAME return codes, usually only relevant to lame_encode_buffer families"""
7-
LAME_ERRORS = Dict{Int, UTF8String}(
7+
LAME_ERRORS = Dict{Int, String}(
88
-1 => "mp3buf was too small",
99
-2 => "malloc() problem",
1010
-3 => "lame_init_params() not called",

src/mpg123.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const MPG123_ENC_ANY = ( MPG123_ENC_SIGNED_16 | MPG123_ENC_UNSIGNED_16
2929
| MPG123_ENC_FLOAT_32 | MPG123_ENC_FLOAT_64 )
3030

3131
"""represents the C pointer mpg123_handle*. used by all mpg123 functions"""
32-
typealias MPG123 Ptr{Void}
32+
const MPG123 = Ptr{Void}
3333

3434
const MPG123_DONE = -12
3535
const MPG123_NEW_FORMAT = -11

src/readers.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function initialize_readers()
77
mpg123_init()
88
end
99

10-
type MP3FileSource{T} <: SampleSource
10+
mutable struct MP3FileSource{T} <: SampleSource
1111
path::AbstractString
1212
mpg123::MPG123
1313
info::MP3INFO
@@ -16,12 +16,12 @@ type MP3FileSource{T} <: SampleSource
1616
end
1717

1818
function MP3FileSource(path::AbstractString, mpg123::MPG123, info::MP3INFO, bufsize::Integer)
19-
readbuf = Array(info.datatype, info.nchannels, bufsize)
20-
MP3FileSource(path, mpg123, info, 0, readbuf)
19+
readbuf = Array{info.datatype}(info.nchannels, bufsize)
20+
MP3FileSource(path, mpg123, info, Int64(0), readbuf)
2121
end
2222

2323
@inline nchannels(source::MP3FileSource) = Int(source.info.nchannels)
24-
@inline samplerate(source::MP3FileSource) = quantity(Int, Hz)(source.info.samplerate)
24+
@inline samplerate(source::MP3FileSource) = source.info.samplerate
2525
@inline nframes(source::MP3FileSource) = source.info.nframes
2626
@inline Base.eltype{T}(source::MP3FileSource{T}) = T
2727

@@ -47,7 +47,7 @@ loads an MP3 file as SampledSignals.SampleBuf.
4747
function load(file::File{format"MP3"}; blocksize = -1)
4848
source = loadstream(file; blocksize = blocksize)
4949
buffer = try
50-
readall(source)
50+
read(source)
5151
finally
5252
close(source)
5353
end
@@ -106,9 +106,9 @@ function unsafe_read!(source::MP3FileSource, buf::Array, frameoffset, framecount
106106
nread
107107
end
108108

109-
@inline function Base.readall(source::MP3FileSource)
110-
read(source, nframes(source) - source.pos)
111-
end
109+
# @inline function Base.read(source::MP3FileSource)
110+
# read(source, nframes(source) - source.pos)
111+
# end
112112

113113
@inline function Base.close(source::MP3FileSource)
114114
mpg123_close(source.mpg123)

src/writers.jl

Lines changed: 38 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,22 @@ const MP3_BLOCKFRAMES = 1152
1111
# max size needed to hold the encoded mp3 data for a full block
1212
const MP3_BUFBYTES = ceil(Int, 1.25 * MP3_BLOCKFRAMES + 7200)
1313

14-
type MP3FileSink <: SampleSink
14+
mutable struct MP3FileSink <: SampleSink
1515
lame::LAME
16-
info::MP3INFO
16+
samplerate::Int
17+
nchannels::Int
1718
output::IO
19+
nframes::Int
1820
mp3buf::Vector{UInt8}
21+
end
1922

20-
MP3FileSink(lame, info, output) = new(lame, info, output, Array(UInt8, MP3_BUFBYTES))
23+
function MP3FileSink(lame, samplerate, nchannels, output)
24+
MP3FileSink(lame, samplerate, nchannels, output, 0, Array{UInt8}(MP3_BUFBYTES))
2125
end
2226

23-
@inline nchannels(sink::MP3FileSink) = Int(sink.info.nchannels)
24-
@inline samplerate(sink::MP3FileSink) = quantity(Int, Hz)(sink.info.samplerate)
25-
@inline nframes(sink::MP3FileSink) = sink.info.nframes
27+
@inline nchannels(sink::MP3FileSink) = sink.nchannels
28+
@inline samplerate(sink::MP3FileSink) = sink.samplerate
29+
@inline nframes(sink::MP3FileSink) = sink.nframes
2630
@inline Base.eltype(sink::MP3FileSink) = PCM16Sample
2731

2832
"""
@@ -42,37 +46,13 @@ save an MP3 file, using parameters as specified
4246
* others: ID3v2 tag items to be added
4347
"""
4448
function save(file::File, buf::SampleBuf;
45-
nchannels::Integer = -1,
46-
samplerate::Union{Integer, Hertz} = -1,
47-
bitrate::Integer = 320,
48-
VBR::Bool = false,
49-
quality::Number = 4,
50-
title::AbstractString = "",
51-
artist::AbstractString = "",
52-
album::AbstractString = "",
53-
year::AbstractString = "",
54-
comment::AbstractString = "")
55-
56-
stream = savestream(file, MP3INFO(buf);
57-
nchannels = nchannels,
58-
samplerate = samplerate,
59-
bitrate = bitrate,
60-
VBR = VBR,
61-
quality = quality,
62-
title = title,
63-
artist = artist,
64-
album = album,
65-
year = year,
66-
comment = comment)
67-
68-
try
49+
samplerate=SampledSignals.samplerate(buf), nchannels=SampledSignals.nchannels(buf),
50+
kwargs...)
51+
savestream(file; samplerate=samplerate, nchannels=nchannels, kwargs...) do stream
6952
frameswritten = write(stream, buf)
7053
if frameswritten != nframes(buf)
7154
error("Only wrote $frameswritten frames, expected $(nframes(buf))")
7255
end
73-
finally
74-
# make sure we close the file even if something goes wrong
75-
close(stream)
7656
end
7757

7858
nothing
@@ -90,62 +70,46 @@ function savestream(f::Function, args...; kwargs...)
9070
end
9171
end
9272

93-
function savestream(path::File, info::MP3INFO;
94-
nchannels::Integer = -1,
95-
samplerate::Union{Integer, Hertz} = -1,
96-
bitrate::Integer = 320,
97-
VBR::Bool = false,
98-
quality::Number = 4,
99-
title::AbstractString = "",
100-
artist::AbstractString = "",
101-
album::AbstractString = "",
102-
year::AbstractString = "",
103-
comment::AbstractString = "")
73+
function savestream(path::File;
74+
nchannels = 2,
75+
samplerate = 44100,
76+
bitrate = 320,
77+
VBR = false,
78+
quality = 4,
79+
title = "",
80+
artist = "",
81+
album = "",
82+
year = "",
83+
comment = "")
10484

10585
lame = lame_init()
106-
lame_set_num_samples(lame, info.nframes)
86+
# lame_set_num_samples(lame, info.nframes)
10787

108-
109-
# default to the source channels
110-
if nchannels < 0
111-
nchannels = info.nchannels
112-
end
11388
if nchannels == 1
11489
lame_set_num_channels(lame, 1)
11590
lame_set_mode(lame, LAME_MONO)
116-
info.nchannels = 1
11791
elseif nchannels == 2
11892
lame_set_num_channels(lame, 2)
11993
lame_set_mode(lame, LAME_JOINT_STEREO)
120-
info.nchannels = 2
12194
else
12295
error("the output channels should be either mono (1) or stereo (2)")
12396
end
12497

125-
# default to the source sample rate
126-
if typeof(samplerate) == Hertz
127-
samplerate = samplerate.val
128-
end
129-
if samplerate < 0
130-
samplerate = info.samplerate
131-
else
132-
info.samplerate = samplerate
133-
end
13498
if !(samplerate in [8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000])
13599
error("sample rate $samplerate Hz is not supported")
136100
end
137101
# resampling is handled by SampledSignals
138-
lame_set_in_samplerate(lame, samplerate)
139-
lame_set_out_samplerate(lame, samplerate)
102+
lame_set_in_samplerate(lame, Int(samplerate))
103+
lame_set_out_samplerate(lame, Int(samplerate))
140104

141105
if VBR == false
142106
# CBR mode
143-
lame_set_brate(lame, bitrate)
144-
lame_set_quality(lame, quality)
107+
lame_set_brate(lame, Int(bitrate))
108+
lame_set_quality(lame, Int(quality))
145109
else
146110
# VBR mode
147111
lame_set_VBR(lame)
148-
lame_set_VBR_quality(lame, quality)
112+
lame_set_VBR_quality(lame, Int(quality))
149113
end
150114

151115
id3tag_init(lame)
@@ -161,13 +125,13 @@ function savestream(path::File, info::MP3INFO;
161125
lame_init_params(lame)
162126

163127
id3size = lame_get_id3v2_tag(lame, UInt8[], 0)
164-
id3buffer = Array(UInt8, id3size)
128+
id3buffer = Array{UInt8}(id3size)
165129
lame_get_id3v2_tag(lame, id3buffer, id3size) == id3size || error("failed to get ID3v2 buffer")
166130

167131
output = open(filename(path), "w")
168132
write(output, id3buffer)
169133

170-
MP3FileSink(lame, info, output)
134+
MP3FileSink(lame, samplerate, nchannels, output)
171135
end
172136

173137
function unsafe_write(sink::MP3FileSink, buf::Array, frameoffset, framecount)
@@ -185,23 +149,24 @@ function unsafe_write(sink::MP3FileSink, buf::Array, frameoffset, framecount)
185149

186150
written = 0
187151
while written < framecount
188-
nsamples = min(MP3_BLOCKFRAMES, framecount - written)
152+
nframes = min(MP3_BLOCKFRAMES, framecount - written)
189153
l = left + written * encsize
190154
r = right + written * encsize
191-
bytes = lame_encode_buffer!(lame, l, r, nsamples, mp3buf, MP3_BUFBYTES)
192-
Compat.unsafe_write(sink.output, mp3buf, bytes)
155+
bytes = lame_encode_buffer!(lame, l, r, nframes, mp3buf, MP3_BUFBYTES)
156+
Base.unsafe_write(sink.output, mp3buf, bytes)
193157

194-
written += nsamples
158+
written += nframes
195159
end
196160

161+
sink.nframes += written
197162
written
198163
end
199164

200165
function Base.close(sink::MP3FileSink)
201166
if sink.lame != C_NULL
202167
mp3buf = pointer(sink.mp3buf)
203168
bytes = lame_encode_flush_nogap(sink.lame, mp3buf, MP3_BUFBYTES)
204-
Compat.unsafe_write(sink.output, mp3buf, bytes)
169+
Base.unsafe_write(sink.output, mp3buf, bytes)
205170

206171
err = lame_close(sink.lame)
207172
close(sink.output)

0 commit comments

Comments
 (0)