Comments (7)
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.
I guess this is hard to do in plain Ruby, anyway. But libsamplerate (http://www.mega-nerd.com/SRC/) looks promising!
from wavefile.
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.
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.
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.
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.
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)
- Possible bug when no block is given to the writer? HOT 2
- No high-level duration info HOT 2
- Example here - https://github.com/jstrait/wavefile/wiki/WaveFile-Tutorial#copying-a-wave-file-to-different-format working correctly? HOT 5
- fyi: ruby-wavefile now packaged for Debian HOT 1
- support reading from a file or stream HOT 5
- Duration does not override equality HOT 2
- UnsupportedFormatError HOT 8
- Method to obtain markers/cue points HOT 6
- each_buffer causes ReaderClosedError HOT 3
- Reference for older methods HOT 4
- examples: how create reverse file? HOT 2
- Mix 2 wav files. HOT 2
- Rewind the IO object HOT 4
- Format Chunks With Extra Bytes at the End Sometimes Cause `InvalidFormatError` to be Raised HOT 1
- `Reader` instances can be created for WAVE_FORMAT_EXTENSIBLE files that have an incomplete/missing format chunk extension HOT 1
- Bufer from bytes & mulaw HOT 2
- WaveFile::Reader doesn't work with pipe IO HOT 2
- Sample Data Can't Be Read From a WAVE_FORMAT_EXTENSIBLE File With an Oversized Format Chunk Extension HOT 1
- How i can play file HOT 1
- Misleading error message if "fmt " chunk extension is too large to fit into chunk HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wavefile.