json-waveform 0.2.0 → 0.2.1

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
  SHA1:
3
- metadata.gz: d36b9399da8bc246ec51e20d9ce4f89763cc5443
4
- data.tar.gz: e2c18ef64ce38d2c7121b4db7d2e75d737e3c4ee
3
+ metadata.gz: 5334350a3a74052ba2d9983311f8a7dea5856a22
4
+ data.tar.gz: 850395b17c1603fbc88956be35cb1b40df7f5fa1
5
5
  SHA512:
6
- metadata.gz: c83b0f46eaf8f4140f2dd2f0917fbeea85739c38b87842f96229ed6a7d7c1f13d57d33f1d0b563991430c57482c8941e2a3556c34aee2f345dfff91aac999476
7
- data.tar.gz: 96fc580e294ad1c31ebce0f0fd14212f94617e77244aabed5d72d3b1d54ec64797430262cbbde7c97be549fcddd54968056e7ffe7d0904c5e60eedde63ed68e2
6
+ metadata.gz: 028859a2c897709e158b0a68d6efac492ff0afe0717cbcd597e0d8eb013e2be6da63856caba122435b14f4f881be3eed54dd752c0fd4e5cbd403476a8ced8fc9
7
+ data.tar.gz: f59a3fb472dea0f4ce2a1166724680657ff30d7d2eee3a63761588236eba3a7a8d902a4e1d96515e706a97af74620ab9988faa757d914e6bd312e10c30719df6
@@ -8,7 +8,7 @@ optparse = OptionParser.new do |o|
8
8
  o.banner = "Usage: json-waveform [options] source_audio [output]"
9
9
  o.version = JsonWaveform::VERSION
10
10
 
11
- o.on("-s", "--samples SAMPLES", "Samples generated from the original file (i.e.: waveform width) -- Default #{JsonWaveform::DEFAULT_OPTIONS[:samples]}.") do |samples|
11
+ o.on("-s", "--samples SAMPLES", "Samples generated from the original file (i.e.: waveform width). The result may have ±10% of the samples requested. -- Default #{JsonWaveform::DEFAULT_OPTIONS[:samples]}.") do |samples|
12
12
  options[:samples] = samples.to_i
13
13
  end
14
14
 
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
22
22
  s.executables << "json-waveform"
23
23
 
24
24
  s.add_dependency "ruby-audio", "~> 1.6.0"
25
+ s.add_development_dependency "minitest", "~> 4"
25
26
  end
@@ -29,7 +29,9 @@ class JsonWaveform
29
29
  # Can be :rms or :peak
30
30
  # Default is :peak.
31
31
  #
32
- # :samples => The amount of samples wanted
32
+ # :samples => The amount of samples wanted. The may have ±10% of the
33
+ # samples requested.
34
+ #
33
35
  # Default is 1800.
34
36
  #
35
37
  # :amplitude => The amplitude of the final values
@@ -1,3 +1,3 @@
1
1
  class JsonWaveform
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.2.1".freeze
3
3
  end
data/makefile CHANGED
@@ -1,4 +1,7 @@
1
- .PHONY: console
1
+ .PHONY: console test
2
+
3
+ test:
4
+ ruby test/json_waveform_test.rb
2
5
 
3
6
  console:
4
7
  irb -I./lib -r json-waveform
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "json-waveform"))
2
+
3
+ require "minitest"
4
+ require "minitest/autorun"
5
+ require "fileutils"
6
+ require 'json'
7
+
8
+ module Helpers
9
+ def fixture(file)
10
+ File.join(File.dirname(__FILE__), "fixtures", file)
11
+ end
12
+ end
13
+
14
+ class JsonWaveformTest < Minitest::Test
15
+ include Helpers
16
+ extend Helpers
17
+
18
+ def test_generates_waveform
19
+ result = JsonWaveform.generate(fixture("sample.wav"))
20
+
21
+ assert_equal File.read(fixture("sample.peak.json")), JSON.dump(result)
22
+ end
23
+
24
+ def test_generates_rms_waveform
25
+ result = JsonWaveform.generate(fixture("sample.wav"), method: :rms)
26
+
27
+ assert_equal File.read(fixture("sample.rms.json")), JSON.dump(result)
28
+ end
29
+
30
+ def test_changes_samples
31
+ result = JsonWaveform.generate(fixture("sample.wav"), samples: 100)
32
+
33
+ assert_in_delta 100, result.size, 1
34
+ end
35
+
36
+ def test_changes_amplitude
37
+ result = JsonWaveform.generate(fixture("sample.wav"), amplitude: 100)
38
+
39
+ original = JSON.parse(File.read(fixture("sample.peak.json")))
40
+
41
+ assert_in_delta original.max * 100, result.max, 1
42
+ end
43
+
44
+ def test_has_auto_width
45
+ result = JsonWaveform.generate(fixture("sample.wav"), auto_samples: 10)
46
+
47
+ assert_equal 210, result.size
48
+ end
49
+
50
+ def test_raises_error_if_not_given_readable_audio_source
51
+ assert_raises JsonWaveform::RuntimeError do
52
+ JsonWaveform.generate(fixture("sample.txt"))
53
+ end
54
+ end
55
+
56
+ def test_raises_exception_if_audio_not_exists
57
+ assert_raises JsonWaveform::RuntimeError do
58
+ JsonWaveform.generate(fixture("foo.wav"))
59
+ end
60
+ end
61
+
62
+ #def test_raises_deprecation_exception_if_ruby_audio_fails_to_read_source_file
63
+ # begin
64
+ # Waveform.generate(fixture("sample.txt"), output("shouldnt_exist.png"))
65
+ # rescue Waveform::RuntimeError => e
66
+ # assert_match /Hint: non-WAV files are no longer supported, convert to WAV first using something like ffmpeg/, e.message
67
+ # end
68
+ #end
69
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json-waveform
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esteban Pastorino
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4'
27
41
  description: Generate waveform JSON information from audio files, compatible with
28
42
  http://waveformjs.org/.
29
43
  email:
@@ -40,6 +54,7 @@ files:
40
54
  - lib/json-waveform.rb
41
55
  - lib/json-waveform/version.rb
42
56
  - makefile
57
+ - test/json_waveform_test.rb
43
58
  homepage: http://github.com/kitop/json-waveform
44
59
  licenses: []
45
60
  metadata: {}