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.
@@ -0,0 +1,6 @@
1
+ # lib/ruby_dsp/version.rb
2
+ # frozen_string_literal: true
3
+
4
+ module RubyDSP
5
+ VERSION = '0.0.1'
6
+ end
data/lib/ruby_dsp.rb ADDED
@@ -0,0 +1,10 @@
1
+ # lib/ruby_dsp.rb
2
+ require 'ruby_dsp/version'
3
+ require 'ruby_dsp/ruby_dsp'
4
+
5
+ module RubyDSP
6
+ # In-Ruby code
7
+ class AudioTrack
8
+ # ...
9
+ end
10
+ end
data/ruby_dsp.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/ruby_dsp/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'ruby_dsp'
7
+ s.version = RubyDSP::VERSION
8
+ s.summary = 'Very basic audio/DSP gem with C++ guts for speed'
9
+ s.description = 'Basically just a Ruby wrapper for miniaudio + some audio/DSP features.'
10
+ s.authors = ['Radek C.']
11
+ s.email = 'cichrrad@cvut.cz'
12
+ s.homepage = 'https://github.com/cichrrad/ruby_dsp'
13
+ s.license = 'MIT'
14
+
15
+ s.required_ruby_version = '>= 3.0.0'
16
+
17
+ s.require_paths = ['lib', 'stubs/ruby_dsp']
18
+ s.extensions = ['ext/ruby_dsp/extconf.rb']
19
+
20
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+
22
+ s.add_dependency 'rice', '~> 4.11.2'
23
+
24
+ s.add_development_dependency 'rack', '~> 3.2'
25
+ s.add_development_dependency 'rackup', '~> 2.3'
26
+ s.add_development_dependency 'rake-compiler', '~> 1.3'
27
+ s.add_development_dependency 'webrick', '~> 1.9'
28
+ s.add_development_dependency 'yard', '~> 0.9'
29
+ end
@@ -0,0 +1,131 @@
1
+ # stubs/ruby_dsp/audio_track.rb
2
+
3
+ module RubyDSP
4
+ # A high-performance audio track processor backed by miniaudio.
5
+ class AudioTrack
6
+ # @return [String] the path to the loaded audio file
7
+ attr_reader :file_name
8
+
9
+ # @return [Integer] the number of audio channels
10
+ attr_reader :channels
11
+
12
+ # @return [Integer] the sample rate of the track in Hz
13
+ attr_reader :sample_rate
14
+
15
+ # @return [Boolean] true if the track has exactly 1 channel
16
+ attr_reader :is_mono?
17
+
18
+ # Initializes a new AudioTrack and decodes the given file.
19
+ #
20
+ # @param file_name [String] Path to the audio file.
21
+ # @param target_channels [Integer] Optional. Force a specific number of channels (0 = original).
22
+ # @param target_sample_rate [Integer] Optional. Force a specific sample rate (0 = original).
23
+ # @raise [RuntimeError] if the file cannot be processed or read.
24
+ def initialize(file_name = 'default.wav', target_channels = 0, target_sample_rate = 0)
25
+ end
26
+
27
+ # Saves the audio track to disk.
28
+ #
29
+ # The format can be inferred from the `out_file` extension, or explicitly forced
30
+ # via the `format` argument. If no extension or format is provided, it defaults
31
+ # to saving as a WAV file and will append the `.wav` extension automatically.
32
+ #
33
+ # Note: Currently, only the WAV format (`:wav`) is supported for encoding.
34
+ #
35
+ # @example Save with inferred extension
36
+ # track.save_track("output.wav")
37
+ #
38
+ # @example Save without extension (auto-appends .wav)
39
+ # track.save_track("my_beat")
40
+ #
41
+ # @example Force format on an unknown extension
42
+ # track.save_track("audio.data", :wav)
43
+ #
44
+ # @param out_file [String] The destination path and filename.
45
+ # @param format [Symbol] Optional. Forces a specific format (e.g., `:wav`). Defaults to `:auto`.
46
+ # @return [Boolean] true if the file was successfully written.
47
+ # @raise [RuntimeError] if the track is empty, encoder fails, or an unsupported format is requested.
48
+ def save_track(out_file, format = :auto)
49
+ end
50
+
51
+ # Calculates the total duration of the track.
52
+ #
53
+ # @return [Float] duration in seconds.
54
+ def duration
55
+ end
56
+
57
+ # Finds the maximum absolute amplitude across all channels.
58
+ #
59
+ # @return [Float] the peak amplitude.
60
+ def peak_amp
61
+ end
62
+
63
+ # Destructively converts the track to mono by averaging the channels.
64
+ #
65
+ # @return [Boolean] true if conversion happened, false if already mono.
66
+ # @raise [RuntimeError] if channel count is invalid.
67
+ def to_mono!
68
+ end
69
+
70
+ # Destructively resamples the track to the target rate using linear resampling.
71
+ #
72
+ # @param target_rate [Integer] The new sample rate in Hz.
73
+ # @return [Boolean] true if resampling happened, false if the rate was unchanged.
74
+ # @raise [RuntimeError] if the resampler fails to initialize or process.
75
+ def resample!(target_rate = 0)
76
+ end
77
+
78
+ # Calculates the Root Mean Square (RMS) for the entire track, per channel.
79
+ #
80
+ # @return [Array<Float>] An array containing the RMS value for each channel.
81
+ def rms
82
+ end
83
+
84
+ # Calculates the framed Root Mean Square (RMS) over time.
85
+ #
86
+ # @param frame_length [Integer] The number of samples per frame.
87
+ # @param hop_length [Integer] The number of samples to advance each frame.
88
+ # @return [Array<Array<Float>>] A 2D array of RMS values `[channel][frame]`.
89
+ def framed_rms(frame_length = 2048, hop_length = 512)
90
+ end
91
+
92
+ # Calculates the Zero Crossing Rate (ZCR) for the entire track, per channel.
93
+ #
94
+ # @return [Array<Float>] An array containing the ZCR value for each channel.
95
+ def zcr
96
+ end
97
+
98
+ # Calculates the framed Zero Crossing Rate (ZCR) over time.
99
+ #
100
+ # @param frame_length [Integer] The number of samples per frame.
101
+ # @param hop_length [Integer] The number of samples to advance each frame.
102
+ # @return [Array<Array<Float>>] A 2D array of ZCR values `[channel][frame]`.
103
+ def framed_zcr(frame_length = 2048, hop_length = 512)
104
+ end
105
+
106
+ # Finds the start and end sample indices of non-silent audio.
107
+ #
108
+ # This scans the track's framed RMS energy and compares it against the global peak.
109
+ # Any frame that falls below the top_db threshold relative to the peak is considered silent.
110
+ #
111
+ # @param threshold_db [Float] The threshold in decibels below the peak RMS to consider as silence. Default is -60.0.
112
+ # @param frame_length [Integer] The number of samples per frame. Default is 2048.
113
+ # @param hop_length [Integer] The number of samples to advance each frame. Default is 512.
114
+ # @return [Array<Integer>] A 2-element array containing the [start_sample, end_sample] indices.
115
+ def silence_bounds(threshold_db = -60.0, frame_length = 2048, hop_length = 512)
116
+ end
117
+
118
+ # Destructively trims leading and trailing silence from the track's internal sample array.
119
+ #
120
+ # @param threshold_db [Float] The threshold in decibels below the peak RMS to consider as silence. Default is -60.0.
121
+ # @param frame_length [Integer] The number of samples per frame. Default is 2048.
122
+ # @param hop_length [Integer] The number of samples to advance each frame. Default is 512.
123
+ # @return [Boolean] true if the track was trimmed, false if no trimming occurred.
124
+ def trim_silence!(threshold_db = -60.0, frame_length = 2048, hop_length = 512)
125
+ end
126
+
127
+ # @return [String] a formatted summary of the track.
128
+ def to_s
129
+ end
130
+ end
131
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_dsp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Radek C.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rice
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.11.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.11.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: rack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rackup
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webrick
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: yard
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ description: Basically just a Ruby wrapper for miniaudio + some audio/DSP features.
98
+ email: cichrrad@cvut.cz
99
+ executables: []
100
+ extensions:
101
+ - ext/ruby_dsp/extconf.rb
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - README.md
107
+ - Rakefile
108
+ - ext/ruby_dsp/extconf.rb
109
+ - ext/ruby_dsp/ruby_dsp.cpp
110
+ - ext/ruby_dsp/vendor/miniaudio.h
111
+ - lib/ruby_dsp.rb
112
+ - lib/ruby_dsp/version.rb
113
+ - ruby_dsp.gemspec
114
+ - stubs/ruby_dsp/audio_track.rb
115
+ homepage: https://github.com/cichrrad/ruby_dsp
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ - stubs/ruby_dsp
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: 3.0.0
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubygems_version: 3.5.22
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Very basic audio/DSP gem with C++ guts for speed
139
+ test_files: []