• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

JuliaAudio/LibSndFile.jl: Julia Interface to libsndfile

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

JuliaAudio/LibSndFile.jl

开源软件地址:

https://github.com/JuliaAudio/LibSndFile.jl

开源编程语言:

Julia 100.0%

开源软件介绍:

LibSndFile.jl

CI codecov.io

LibSndFile.jl is a wrapper for libsndfile, and supports a wide variety of file and sample formats. The package uses the FileIO load and save interface to automatically figure out the file type of the file to be opened, and the file contents are represented as a SampleBuf. For streaming I/O we support FileIO's loadstreaming and savestreaming functions as well. The results are represented as SampleSource (for reading), or SampleSink (for writing) subtypes. These buffer and stream types are defined in the SampledSignals package.

Note that the load/save/etc. interface is exported from FileIO, and LibSndFile registers itself when the loaded, so you should bring in both packages. LibSndFile doesn't export any of its own names.

julia> using FileIO: load, save, loadstreaming, savestreaming
julia> import LibSndFile
julia> load("audiofile.wav")
2938384-frame, 1-channel SampleBuf{FixedPointNumbers.Fixed{Int16,15}, 2}
66.63002267573697s sampled at 44100.0Hz
▆▅▆▆▆▆▆▅▆▆▆▇▇▇▆▆▆▆▆▆▆▆▆▆▆▆▆▆▆▇▆▆▆▆▆▇▆▇▆▇▆▆▆▅▆▆▆▆▆▆▅▆▆▅▆▅▆▆▇▇▇▇▆▆▆▆▆▆▇▆▆▆▆▆▆▆▇▆▇▂

Examples

Read ogg file, write first 1024 samples of the first channel to new wav file

x = load("myfile.ogg")
save("myfile_short.wav", x[1:1024])

Read file, write the first second of all channels to a new file

x = load("myfile.ogg")
save("myfile_short.wav", x[0s..1s, :])

Read stereo file, write mono mix

x = load("myfile.wav")
save("myfile_mono.wav", x[:, 1] + x[:, 2])

Plot the left channel

x = load("myfile.wav")
plot(x[:, 1]) # plots with samples on the x axis
plot(domain(x), x[:, 1]) # plots with time on the x axis

Plot the spectrum of the left channel

x = load("myfile.wav")
f = fft(x) # returns a FrequencySampleBuf
fmin = 0Hz
fmax = 10000Hz
fs = Float32[float(f_i) for f_i in domain(f[fmin..fmax])]
plot(fs, abs.(f[fmin..fmax]).data, xlim=(fs[1],fs[end]), ylim=(0,20000))

Load a long file as a stream and plot the left channel from 2s to 3s

stream = loadstreaming("myfile.ogg")
x = read(stream, 4s)[2s..3s, 1]
close(stream)
plot(domain(x), x)

To handle closing the file automatically (including in the case of unexpected exceptions), we support the do block syntax

data = loadstreaming("data/never_gonna_give_you_up.ogg") do f
    read(f)
end

Supported Formats

See the libsndfile homepage for details, but in summary it supports reading and writing:

  • Microsoft WAV
  • Ogg/Vorbis
  • FLAC
  • SGI / Apple AIFF / AIFC
  • RAW
  • Sound Designer II SD2
  • Sun / DEC / NeXT AU / SND
  • Paris Audio File (PAF)
  • Commodore Amiga IFF / SVX
  • Sphere Nist WAV
  • IRCAM SF
  • Creative VOC
  • Soundforge W64
  • GNU Octave 2.0 MAT4
  • GNU Octave 2.1 MAT5
  • Portable Voice Format PVF
  • Fasttracker 2 XI
  • HMM Tool Kit HTK
  • Apple CAF

Note not all file formats support all samplerates and bit depths. Currently LibSndFile.jl supports WAV, Ogg Vorbis, and FLAC files. Please file an issue if support for other formats would be useful.

Related Packages

  • SampledSignals.jl provides the basic stream and buffer types used by this package.
  • MP3.jl supports reading and writing MP3 files
  • WAV.jl is a pure-julia package supporting the WAV file format.
  • Opus.jl wraps libopus and allows you to read and write Opus audio.
  • PortAudio.jl can be used to interface with your sound card to record and play audio.

A Note on Licensing

libsndfile is licensed under the LGPL, which is very permissive providing that libsndfile is dynamically linked. LibSndFile.jl is licensed under the MIT license, allowing you to statically compile the wrapper into your Julia application. Remember that you must still abide by the terms of the libsndfile license when using this wrapper, in terms of whether libsndfile is statically or dynamically linked.

Note that this is to the best of my understanding, but I am not an attorney and this should not be considered legal advice.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap