torchaudio 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 354a8636b2a04fd0ed60db93e2667f630f1db04ab047a6eb6e0c3607190c58d5
4
- data.tar.gz: cde6229f8ba416c5a72bbea6d47e26fd987b6f13073f1ca9a1e6239cd62b79c1
3
+ metadata.gz: 2b395ce300252d4d65274f0ddb9d387de1dd836721a8a4f81804c5a888fb5433
4
+ data.tar.gz: 9e98ca9a0e8e945e069957990671bf143edb1240f313f65bf87e97bba4e05106
5
5
  SHA512:
6
- metadata.gz: 76c9c637e4f12700c16bbf343104bb46f5e4f04161a3556cd0600ea236222902ac0ba3b9504f4bdb28a9919317a1b791c8f7b4dbcb48b35ed4c674de39a83277
7
- data.tar.gz: '019d89cd2231c386c3458447358058618a6de78b77ed5b4d6d279ee0e3879946bda03cf339051136069dd552d6eeaed33bf40defa9d6c90c9a07eb27d68fdce2'
6
+ metadata.gz: ab922eef545e50e302f7a72f992f2d6040fb9cd1856c37ff532baed0092783442d649f8c3bc91a4cf92684729d7ce7294cd9a943a8c8a483734bb858e885845f
7
+ data.tar.gz: 414ea85a03b53cf21caef57289551fa88747ad2a5e0c60f0e92cb57a017cd04903b359d8d71ac37cecba50492678bc5d4327a9f340aba8f6006339d9379fed26
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.1.2 (2021-02-06)
2
+
3
+ - Added `amplitude_to_DB` and `DB_to_amplitude` methods
4
+ - Added `AmplitudeToDB` transform
5
+ - Fixed `save` options
6
+
1
7
  ## 0.1.1 (2020-08-26)
2
8
 
3
9
  - Added `save` method
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  BSD 2-Clause License
2
2
 
3
3
  Copyright (c) 2017 Facebook Inc. (Soumith Chintala),
4
- Copyright (c) 2020 Andrew Kane,
4
+ Copyright (c) 2020-2021 Andrew Kane,
5
5
  All rights reserved.
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  :fire: An audio library for Torch.rb
4
4
 
5
- [![Build Status](https://travis-ci.org/ankane/torchaudio.svg?branch=master)](https://travis-ci.org/ankane/torchaudio)
5
+ [![Build Status](https://github.com/ankane/torchaudio/workflows/build/badge.svg?branch=master)](https://github.com/ankane/torchaudio/actions)
6
6
 
7
7
  ## Installation
8
8
 
@@ -56,6 +56,23 @@ Supported transforms are:
56
56
  - MuLawEncoding
57
57
  - Spectrogram
58
58
 
59
+ ## Functional
60
+
61
+ ```ruby
62
+ TorchAudio::Functional.lowpass_biquad(waveform, sample_rate, cutoff_freq)
63
+ ```
64
+
65
+ Supported functions are:
66
+
67
+ - compute_deltas
68
+ - dither
69
+ - gain
70
+ - highpass_biquad
71
+ - lowpass_biquad
72
+ - mu_law_decoding
73
+ - mu_law_encoding
74
+ - spectrogram
75
+
59
76
  ## Datasets
60
77
 
61
78
  Load a dataset
@@ -64,12 +64,12 @@ void Init_ext()
64
64
 
65
65
  Class rb_cSignalInfo = define_class_under<sox_signalinfo_t>(rb_mExt, "SignalInfo")
66
66
  .define_constructor(Constructor<sox_signalinfo_t>())
67
- .define_method("rate", *[](sox_signalinfo_t self) { return self.rate; })
68
- .define_method("channels", *[](sox_signalinfo_t self) { return self.channels; })
69
- .define_method("precision", *[](sox_signalinfo_t self) { return self.precision; })
70
- .define_method("length", *[](sox_signalinfo_t self) { return self.length; })
71
- .define_method("rate=", *[](sox_signalinfo_t self, sox_rate_t rate) { self.rate = rate; })
72
- .define_method("channels=", *[](sox_signalinfo_t self, unsigned channels) { self.channels = channels; })
73
- .define_method("precision=", *[](sox_signalinfo_t self, unsigned precision) { self.precision = precision; })
74
- .define_method("length=", *[](sox_signalinfo_t self, sox_uint64_t length) { self.length = length; });
67
+ .define_method("rate", *[](sox_signalinfo_t& self) { return self.rate; })
68
+ .define_method("channels", *[](sox_signalinfo_t& self) { return self.channels; })
69
+ .define_method("precision", *[](sox_signalinfo_t& self) { return self.precision; })
70
+ .define_method("length", *[](sox_signalinfo_t& self) { return self.length; })
71
+ .define_method("rate=", *[](sox_signalinfo_t& self, sox_rate_t rate) { self.rate = rate; })
72
+ .define_method("channels=", *[](sox_signalinfo_t& self, unsigned channels) { self.channels = channels; })
73
+ .define_method("precision=", *[](sox_signalinfo_t& self, unsigned precision) { self.precision = precision; })
74
+ .define_method("length=", *[](sox_signalinfo_t& self, sox_uint64_t length) { self.length = length; });
75
75
  }
data/lib/torchaudio.rb CHANGED
@@ -20,6 +20,7 @@ require "torchaudio/transforms/mel_spectrogram"
20
20
  require "torchaudio/transforms/mu_law_encoding"
21
21
  require "torchaudio/transforms/mu_law_decoding"
22
22
  require "torchaudio/transforms/spectrogram"
23
+ require "torchaudio/transforms/amplitude_to_db"
23
24
  require "torchaudio/version"
24
25
 
25
26
  module TorchAudio
@@ -227,6 +227,19 @@ module TorchAudio
227
227
  output
228
228
  end
229
229
 
230
+ def amplitude_to_DB(amp, multiplier, amin, db_multiplier, top_db: nil)
231
+ db = Torch.log10(Torch.clamp(amp, min: amin)) * multiplier
232
+ db -= multiplier * db_multiplier
233
+
234
+ db = db.clamp(min: db.max.item - top_db) if top_db
235
+
236
+ db
237
+ end
238
+
239
+ def DB_to_amplitude(db, ref, power)
240
+ Torch.pow(Torch.pow(10.0, db * 0.1), power) * ref
241
+ end
242
+
230
243
  private
231
244
 
232
245
  def _apply_probability_distribution(waveform, density_function: "TPDF")
@@ -0,0 +1,27 @@
1
+ module TorchAudio
2
+ module Transforms
3
+ class AmplitudeToDB < Torch::NN::Module
4
+ def initialize(stype: :power, top_db: nil)
5
+ super()
6
+
7
+ @stype = stype
8
+
9
+ raise ArgumentError, 'top_db must be a positive numerical' if top_db && top_db.negative?
10
+
11
+ @top_db = top_db
12
+ @multiplier = stype == :power ? 10.0 : 20.0
13
+ @amin = 1e-10
14
+ @ref_value = 1.0
15
+ @db_multiplier = Math.log10([@amin, @ref_value].max)
16
+ end
17
+
18
+ def forward(amplitude_spectrogram)
19
+ F.amplitude_to_DB(
20
+ amplitude_spectrogram,
21
+ @multiplier, @amin, @db_multiplier,
22
+ top_db: @top_db
23
+ )
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,3 +1,3 @@
1
1
  module TorchAudio
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torchaudio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2021-02-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: torch-rb
@@ -38,64 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.2'
41
- - !ruby/object:Gem::Dependency
42
- name: bundler
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rake
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rake-compiler
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: minitest
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '5'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '5'
97
- description:
98
- email: andrew@chartkick.com
41
+ description:
42
+ email: andrew@ankane.org
99
43
  executables: []
100
44
  extensions:
101
45
  - ext/torchaudio/extconf.rb
@@ -119,6 +63,7 @@ files:
119
63
  - lib/torchaudio/datasets/utils.rb
120
64
  - lib/torchaudio/datasets/yesno.rb
121
65
  - lib/torchaudio/functional.rb
66
+ - lib/torchaudio/transforms/amplitude_to_db.rb
122
67
  - lib/torchaudio/transforms/mel_scale.rb
123
68
  - lib/torchaudio/transforms/mel_spectrogram.rb
124
69
  - lib/torchaudio/transforms/mu_law_decoding.rb
@@ -129,7 +74,7 @@ homepage: https://github.com/ankane/torchaudio
129
74
  licenses:
130
75
  - BSD-2-Clause
131
76
  metadata: {}
132
- post_install_message:
77
+ post_install_message:
133
78
  rdoc_options: []
134
79
  require_paths:
135
80
  - lib
@@ -144,8 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
89
  - !ruby/object:Gem::Version
145
90
  version: '0'
146
91
  requirements: []
147
- rubygems_version: 3.1.2
148
- signing_key:
92
+ rubygems_version: 3.2.3
93
+ signing_key:
149
94
  specification_version: 4
150
95
  summary: Data manipulation and transformation for audio signal processing
151
96
  test_files: []