carrierwave-audio-waveform 1.0.4 → 1.0.5
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cf043df5b38e07639eb6a531706b07163868e36
|
4
|
+
data.tar.gz: 67140c30355b8c621c5d2b2fbe69775cd6c79aa4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69db0a620320c1ecf4b36c5530c45abbe232ec10489410c8c1c0b0452b8dca38e88ffb890877dafe8f0afee5c4bad572761b0eaae48c6059ed1d36e8c80ca41c
|
7
|
+
data.tar.gz: 3787b962fa47074f2cc3c6ccdffd241529c947869a1772717a621a32fd32ee9206af20f6422148b8a46f5fe635842457157cd8c0b2b1fddcfce9e79a24cce3c5
|
@@ -106,7 +106,7 @@ module CarrierWave
|
|
106
106
|
# the larger the frames are, the more "peaky" the waveform should get,
|
107
107
|
# perhaps to the point of inaccurately reflecting the actual sound.
|
108
108
|
samples = frames(source, options[:width], options[:method]).collect do |frame|
|
109
|
-
frame.inject(0.0) { |sum, peak| sum + peak } / frame.size
|
109
|
+
frame.inject(0.0) { |sum, peak| sum + peak } / frame.size
|
110
110
|
end
|
111
111
|
|
112
112
|
@log.timed("\nDrawing...") do
|
@@ -211,15 +211,34 @@ module CarrierWave
|
|
211
211
|
end
|
212
212
|
|
213
213
|
def draw_svg(samples, options)
|
214
|
-
|
215
|
-
if options[:
|
214
|
+
wave_image = ""
|
215
|
+
samples = spaced_samples(samples, options[:sample_width], options[:gap_width]) if options[:sample_width]
|
216
|
+
height_factor = (options[:height] * 0.85 / 2.0)
|
217
|
+
|
218
|
+
bar_pos = 0
|
219
|
+
samples.each_with_index do |sample, pos|
|
220
|
+
next if sample.nil?
|
221
|
+
|
222
|
+
if (pos%3 == 0)
|
223
|
+
amplitude = sample * height_factor
|
224
|
+
top = (0 - amplitude).round
|
225
|
+
bottom = (0 + amplitude).round
|
226
|
+
|
227
|
+
wave_image+= "M#{bar_pos},#{top}V#{bottom}"
|
228
|
+
|
229
|
+
bar_pos += 1
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
image = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3/org/1999/xlink\" viewbox=\"0 0 #{iPos+1} #{options[:height]}\" preserveAspectRatio=\"none\" width=\"100%\" height=\"100%\">"
|
234
|
+
if (options[:hide_style].nil? || options[:hide_style] == false)
|
216
235
|
image+= "<style>"
|
217
236
|
image+= "svg {"
|
218
237
|
image+= "stroke: #000;"
|
219
|
-
image+= "stroke-width:
|
238
|
+
image+= "stroke-width: 0.25;"
|
220
239
|
image+= "}"
|
221
240
|
image+= "use.waveform-progress {"
|
222
|
-
image+= "stroke-width:
|
241
|
+
image+= "stroke-width: 0.25;"
|
223
242
|
image+= "clip-path: polygon(0% 0%, 0% 0%, 0% 100%, 0% 100%);"
|
224
243
|
image+= "}"
|
225
244
|
image+= "svg path {"
|
@@ -239,22 +258,10 @@ module CarrierWave
|
|
239
258
|
end
|
240
259
|
uniqueWaveformID = "waveform-#{SecureRandom.uuid}"
|
241
260
|
image+= "<g id=\"#{uniqueWaveformID}\">"
|
242
|
-
image+=
|
261
|
+
image+= "<g transform=\"translate(0, #{options[:height] / 2.0})\">"
|
243
262
|
image+= '<path stroke="currrentColor" d="'
|
244
263
|
|
245
|
-
|
246
|
-
max = samples.reject {|v| v.nil? }.max
|
247
|
-
height_factor = (options[:height] / 2.0) / max
|
248
|
-
|
249
|
-
samples.each_with_index do |sample, pos|
|
250
|
-
next if sample.nil?
|
251
|
-
|
252
|
-
amplitude = sample * height_factor
|
253
|
-
top = (0 - amplitude).round
|
254
|
-
bottom = (0 + amplitude).round
|
255
|
-
|
256
|
-
image+= " M#{pos},#{top} V#{bottom}"
|
257
|
-
end
|
264
|
+
image+= wave_image
|
258
265
|
|
259
266
|
image+= '"/>'
|
260
267
|
image+= "</g>"
|
@@ -315,7 +322,7 @@ module CarrierWave
|
|
315
322
|
|
316
323
|
def spaced_samples samples, sample_width = 1, gap_width = 1
|
317
324
|
sample_width = sample_width.to_i >= 1 ? sample_width.to_i : 1
|
318
|
-
gap_width = gap_width.to_i >=
|
325
|
+
gap_width = gap_width.to_i >= 0 ? gap_width.to_i : 1
|
319
326
|
width_counter = sample_width
|
320
327
|
current_sample_index = 0
|
321
328
|
spaced_samples = []
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-audio-waveform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Trevor Hinesley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|