Giter Site home page Giter Site logo

Enable resampling about wavefile HOT 7 OPEN

jstrait avatar jstrait commented on May 29, 2024 1
Enable resampling

from wavefile.

Comments (7)

jamestunnell avatar jamestunnell commented on May 29, 2024

I agree that some kind of resampling behaviour would be desirable. But I don't think it needs to be tied up in the Reader class. It could be provided by a utility class instead.

Even as a sperate class, sample rate conversion actually seems quite involved (to do it right), just based on a bit of reading on wikipedia.

from wavefile.

padde avatar padde commented on May 29, 2024

I guess this is hard to do in plain Ruby, anyway. But libsamplerate (http://www.mega-nerd.com/SRC/) looks promising!

from wavefile.

jamestunnell avatar jamestunnell commented on May 29, 2024

That does look like a good library, and I bet the code could be ported to Ruby without too much trouble.

Unfortunately, the license is GPL, which is rather restrictive and I think totally incompatible with MIT. Too bad...

from wavefile.

jamestunnell avatar jamestunnell commented on May 29, 2024

This paper looks pretty promising:
"THE QUEST FOR THE PERFECT RESAMPLER" by Laurent de Soras
http://ldesoras.free.fr/doc/articles/resampler-en.pdf

from wavefile.

jamestunnell avatar jamestunnell commented on May 29, 2024

Actually, this one looks even better:
"Polynomial Interpolators for High-Quality Resampling of Oversampled Audio" by Olli Niemitalo
http://www.student.oulu.fi/~oniemita/dsp/deip.pdf

The paper discusses a hybrid solution of first oversampling audio with discrete methods (FIR filter) and then interpolate with a polynomial interpolator.

I think I'll try to get such a hybrid method implemented as part of https://github.com/jamestunnell/spcore

from wavefile.

jamestunnell avatar jamestunnell commented on May 29, 2024

I added resampling functions to my all-ruby signal processing library, spcore (see https://github.com/jamestunnell/spcore). With a little bit of application logic you could add a resampling feature without too much trouble.

from wavefile.

jstrait avatar jstrait commented on May 29, 2024

To celebrate the 10th anniversary of this issue being opened I thought I would chime in! 😉

This issue raises a good point - I agree it's confusing that it's possible to convert the channel count or sample format of a sample buffer, but not the sample rate. However, in my opinion I don't think adding support for resampling would be the right thing to do.

My understanding (not an expert) is that there's not a single canonical way to resample, and that it is somewhat complicated compared to changing the number of channels or sample format. I wouldn't want to make an assumption about what resampling method to use or add the relatively large amount of code that would have to be maintained and that I wouldn't be 100% confident about getting right.

Although a 3rd party library like spcore could be used to handle resampling, I think resampling is something better handled outside of the wavefile gem. I think conceptually this gem is better served focusing on the low level details of shuttling data to/from a *.wav file, and not being involved with anything DSP related. If I had a time machine I might even also go back and not add the existing channel count/sample format conversions. Although it is convenient to be able to transparently convert channel count/sample formats, it leads to a slippery slope toward adding functionality that maybe belongs elsewhere, and has led to an API inconsistency.

That said, that ship has sailed and I don't think it would be a good idea to remove the conversion functionality that already exists. Perhaps in the future a different API could be added that makes it more clear that the sample rate is an informational field (like the Format::speaker_mapping field that was added in v1.0.0) and isn't "convertible". I'm not sure what that API would be though, and it would need to be something that can co-exist alongside the current API. Since the Format class is pretty central to the gem, changing the API in a backwards incompatible way would break the code of a large number of people (most?) already using the gem.

I'll keep this issue open in case anyone has any further comments, and if there is no response after some amount of time will close it.

from wavefile.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.