ruby_dsp 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/README.md +80 -0
- data/Rakefile +31 -0
- data/ext/ruby_dsp/extconf.rb +6 -0
- data/ext/ruby_dsp/ruby_dsp.cpp +627 -0
- data/ext/ruby_dsp/vendor/miniaudio.h +95844 -0
- data/lib/ruby_dsp/version.rb +6 -0
- data/lib/ruby_dsp.rb +10 -0
- data/ruby_dsp.gemspec +29 -0
- data/stubs/ruby_dsp/audio_track.rb +131 -0
- metadata +139 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1e6d776eecb15e90862b43ef2db1be0e05f9e0fc9be930cb7ba50164daf424da
|
|
4
|
+
data.tar.gz: 6c34fdbb2eab40ce50a95df9d2676fc6ba1113e72f3eba4d1988e027da996981
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: be8f2b87ef6dd6b5f0f830379b820778035b13eb89ee6c83660f48e4c02cf70917ed40bdcf5d43740e9ef13d7d746b7edcd24cddc4f690499a50625ab21da7dc
|
|
7
|
+
data.tar.gz: 3f7b06d06f1f7e5b457c044777033b58d123a7c1a8c02b4e35c5fbf76ff732995f6ee905442329283bd6bcc9ce0fe95c64e71cb2bfade703e7c35e345ad0f008
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# RubyDSP
|
|
2
|
+
|
|
3
|
+
> 🚧 **Status:** This project is currently in early development. It is fully functional, but API changes are expected.
|
|
4
|
+
|
|
5
|
+
**RubyDSP** is an audio processing and DSP Ruby gem. Ultimately, it aims to be `librosa`-wannabe for Ruby. It uses C++ under the hood, utilizing [miniaudio](https://miniaud.io/) and [Rice](https://github.com/jasonroelofs/rice)
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
* **Fast:** Basically all of the code is written in C++. While not extremely optimized currently, it still absolutely shreds native Ruby.
|
|
10
|
+
* **Format Agnostic Loading:** Automatically decodes standard audio formats (WAV, MP3, FLAC) via `miniaudio`.
|
|
11
|
+
* **Zero-Dependency Native Build:** No need to install `ffmpeg` or `libsndfile` on your system.
|
|
12
|
+
* **YARD Support:** Includes pure-Ruby stubs (in `stubs`, duh) for IDE autocomplete and inline documentation.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
Since the gem is currently in pre-release, you can install it directly from GitHub by adding this line to your application's `Gemfile`:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
source "https://rubygems.org"
|
|
20
|
+
|
|
21
|
+
gem 'ruby_dsp', github: 'cichrrad/rubyDSP'
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
And then execute:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ bundle install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
*(Note: Installing this gem requires a modern C++ compiler, as it builds the native extensions directly on your machine upon installation. It requires Ruby 3.0+).*
|
|
31
|
+
|
|
32
|
+
After this, you can run your scripts with
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
$ bundle exec ruby script.rb
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quick Start
|
|
39
|
+
|
|
40
|
+
Here is a quick look at what you can do with a loaded `AudioTrack`:
|
|
41
|
+
|
|
42
|
+
```ruby
|
|
43
|
+
require 'ruby_dsp'
|
|
44
|
+
|
|
45
|
+
# Load an audio file
|
|
46
|
+
track = RubyDSP::AudioTrack.new("raw_vocals.wav")
|
|
47
|
+
|
|
48
|
+
puts track
|
|
49
|
+
# => ['raw_vocals.wav', 12.450s duration, 2 channel(s), 48000Hz sample rate]
|
|
50
|
+
|
|
51
|
+
# Do stuff!
|
|
52
|
+
track.to_mono! # Averages channels into mono
|
|
53
|
+
track.resample!(44100) # Linearly resamples to target rate
|
|
54
|
+
track.trim_silence!(-60.0) # Strips leading/trailing silence below -60dB
|
|
55
|
+
|
|
56
|
+
# Analysis & Math
|
|
57
|
+
puts "Peak Amp: #{track.peak_amp}"
|
|
58
|
+
puts "Overall RMS: #{track.rms}"
|
|
59
|
+
puts "Overall ZCR: #{track.zcr}"
|
|
60
|
+
|
|
61
|
+
# You can also get framed analysis for time-series data:
|
|
62
|
+
# framed_rms_data = track.framed_rms(2048, 512) also works
|
|
63
|
+
framed_rms_data = track.framed_rms(frame_length: 2048, hop_length: 512)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
# Save the results
|
|
67
|
+
track.save_track("processed_vocals.wav")
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Development
|
|
71
|
+
|
|
72
|
+
If you want to clone the repo and hack on the C++ guts, we have fully automated the compilation and testing steps.
|
|
73
|
+
|
|
74
|
+
1. Clone the repo and run `bundle install` to grab the development dependencies.
|
|
75
|
+
2. Run `rake test` — this will automatically compile the C++ `extconf.rb` and run the Minitest suite.
|
|
76
|
+
3. Run `rake doc:generate ; rake doc:server` — this will compile the YARD stubs into HTML and boot a live-reloading local web server at `http://localhost:8808` so you can read the docs!
|
|
77
|
+
|
|
78
|
+
## License
|
|
79
|
+
|
|
80
|
+
The gem is available as open source under the terms of the **MIT License**.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Rakefile
|
|
2
|
+
require 'bundler/gem_tasks'
|
|
3
|
+
require 'rake/extensiontask'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
|
|
6
|
+
Rake::ExtensionTask.new('ruby_dsp') do |ext|
|
|
7
|
+
ext.lib_dir = 'lib/ruby_dsp'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
Rake::TestTask.new do |t|
|
|
11
|
+
t.libs << 'test'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
desc 'Run tests'
|
|
15
|
+
task test: :compile
|
|
16
|
+
|
|
17
|
+
namespace :doc do
|
|
18
|
+
desc 'Generate static HTML documentation in the doc/ folder'
|
|
19
|
+
task :generate do
|
|
20
|
+
puts 'Generating YARD documentation...'
|
|
21
|
+
sh 'yard doc'
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
desc 'Start the YARD documentation server with live reload'
|
|
25
|
+
task :server do
|
|
26
|
+
puts 'Starting YARD live server...'
|
|
27
|
+
puts 'Open http://localhost:8808 in your browser.'
|
|
28
|
+
puts 'Press Ctrl+C to stop.'
|
|
29
|
+
exec 'yard server --reload'
|
|
30
|
+
end
|
|
31
|
+
end
|