Project

sndfile

0.0
No commit activity in last 3 years
No release in over 3 years
Ruby wrapper for libsndfile. Reads/writes data as GSL matrices, to allow fast processing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Libsndfile for Ruby

Build Status Dependency Status

sndfile provides a fast and easy way to read, process, and write audio file data. It wraps the libsndfile C library via FFI, reading & writing the sample data as a GSLng matrix.

The author has (so far) fleshed out only the parts needed for his own projects. Please do fork this project and contribute to it.

Libsndfile?

"Libsndfile is a C library for reading and writing files containing sampled sound (such as MS Windows WAV and the Apple/SGI AIFF format) through one standard library interface. It is released in source code format under the Gnu Lesser General Public License."

Installation

To use this Ruby library, you must have libsndfile and GSL on your machine. You can install them via apt-get (linux) or homebrew (OS X) or download them directly from their websites.

That being said:

gem install sndfile

or, in a Gemfile

gem "sndfile-ruby", :require => "sndfile"

Usage

Here's a simple example, that reads an arbitrary source file and produces a WAV file at half the volume:

fin = Sndfile::File.new(inpath)
Sndfile::File.open(outpath, :mode => :WRITE, :format => :WAV, :encoding => :PCM_16, :channels => fin.info.channels, :samplerate => fin.info.samplerate) do |fout|
  while data = fin.read(10000)
    fout.write(data * 0.5)
  end
end

The audio file info, available as Sndfile::File#info as per the above example, is an instance of Sndfile::Info. You can also query it directly for a file:

info = Sndfile::File.info(filepath) #=> an instance of Sndfile::Info
#    => info.format
#    => info.encoding
#    => info.endian
#    => info.frames
#    => info.samplerate
#    => info.channels

See the RDOC for complete details

Compatibility

Known to work with MRI ruby 1.9.3, and 2.0.0

History

Release notes:

  • 1.1.0 - Add detail fields to Sndfile::Error
  • 1.0.0 - Add Sndfile::Info. Deprecate individual accessors. No longer support ruby 1.8.7
  • 0.2.0 - Support ruby 1.8.7. Thanks to youpy
  • 0.1.3 - Back to ruby-gsl-ng: memory leaks fixed
  • 0.1.2 - Use ruby-gsl-ngx to avoid memory leaks
  • 0.1.1 - Clean up vestigial includes in integration test
  • 0.1.0 - Initial public release

Bitdeli Badge