format_parser 2.9.0 → 2.10.0

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
  SHA256:
3
- metadata.gz: 04b14799c012037cf53b949b0920e0f8e2d5a42e30182363fee0d283d41eade4
4
- data.tar.gz: 78ff4a354e05fb0e67a7b8dd8368768fceb313afc4dd736d5fa41592dfbc7b35
3
+ metadata.gz: 922909c34fc304a86a75f6396bd9627cdacf009aba5191da863064811ca2906f
4
+ data.tar.gz: 864b73aa70b7ec650dab326f677b17f7ed1905d05560deb669a564bb9fdc3d37
5
5
  SHA512:
6
- metadata.gz: e5792c23191b2d4b4d63a5d9dfbfe5a3b28862f9e8ba977c49e39f3ebaf6bd222a31c296f224743a00fc877f8dbbfb6f97cdd19a0b6d712db6e3a00d29dd30d8
7
- data.tar.gz: 6fd2ac968375090928b407afa3234c623c933150a36a00da965e75bb97d01ee2dcb502124e71fa100f0f2321b16a0f268c8a8fa94691cd195fbeb65a1fbab177
6
+ metadata.gz: 5f2527d385f3270f9b11976d478030108787a165e4440825c4ffa8c6a56054e67e5a7fb1a88d18d25dcb945ab6c2befc97156e7a2a5d5ad98f2e11e7c558ce2a
7
+ data.tar.gz: 788254d0f2e40625a6f2fd17c3c7f8959456ad1018fceb62305c5a877a3a8fd52ad5587915b0d3711a8ab68c6dc0ca6d283d9556f68a3234bbd3ecb7a50ece95
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 2.10.0
2
+ * Improve WAV parser by focusing on performance rather than on attempting a best-effort when extracting metadata from files that do not strictly follow the format spec.
3
+
1
4
  ## 2.9.0
2
5
  * Improve WAV parser by performing a best-effort when extracting metadata from files that do not strictly follow the format spec.
3
6
 
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '2.9.0'
2
+ VERSION = '2.10.0'
3
3
  end
@@ -21,30 +21,27 @@ class FormatParser::WAVParser
21
21
  # The specification does not require the Format chunk to be the first chunk
22
22
  # after the RIFF header.
23
23
  # https://www.mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/WAVE.html
24
+ fmt_processed = false
25
+ data_processed = false
24
26
  fmt_data = {}
25
27
  data_size = 0
26
- total_sample_frames = nil
27
28
  loop do
28
29
  chunk_type, chunk_size = safe_read(io, 8).unpack('a4l')
29
30
  case chunk_type
30
31
  when 'fmt ' # watch out: the chunk ID of the format chunk ends with a space
31
32
  fmt_data = unpack_fmt_chunk(io, chunk_size)
33
+ fmt_processed = true
32
34
  when 'data'
33
35
  data_size = chunk_size
34
- when 'fact'
35
- total_sample_frames = safe_read(io, 4).unpack('l').first
36
- safe_skip(io, chunk_size - 4)
36
+ data_processed = true
37
37
  else
38
38
  # Skip this chunk until a known chunk is encountered
39
39
  safe_skip(io, chunk_size)
40
40
  end
41
- rescue FormatParser::IOUtils::InvalidRead
42
- # We've reached EOF, so it's time to make the most out of the metadata we
43
- # managed to parse
44
- break
41
+ break if fmt_processed && data_processed
45
42
  end
46
43
 
47
- file_info(fmt_data, data_size, total_sample_frames)
44
+ file_info(fmt_data, data_size)
48
45
  end
49
46
 
50
47
  def unpack_fmt_chunk(io, chunk_size)
@@ -70,10 +67,10 @@ class FormatParser::WAVParser
70
67
  }
71
68
  end
72
69
 
73
- def file_info(fmt_data, data_size, sample_frames)
70
+ def file_info(fmt_data, data_size)
74
71
  # NOTE: Each sample includes information for each channel
75
- sample_frames ||= data_size / (fmt_data[:channels] * fmt_data[:bits_per_sample] / 8) if fmt_data[:channels] > 0 && fmt_data[:bits_per_sample] > 0
76
- duration_in_seconds = sample_frames / fmt_data[:sample_rate].to_f if fmt_data[:sample_rate] > 0
72
+ sample_frames = data_size / (fmt_data[:channels] * fmt_data[:bits_per_sample] / 8) if fmt_data[:channels] > 0 && fmt_data[:bits_per_sample] > 0
73
+ duration_in_seconds = sample_frames / fmt_data[:sample_rate].to_f if sample_frames && fmt_data[:byte_rate] > 0
77
74
  FormatParser::Audio.new(
78
75
  format: :wav,
79
76
  num_audio_channels: fmt_data[:channels],
@@ -20,8 +20,9 @@ describe FormatParser::WAVParser do
20
20
  expect(parse_result.format).to eq(:wav)
21
21
  expect(parse_result.num_audio_channels).to eq(1)
22
22
  expect(parse_result.audio_sample_rate_hz).to eq(8000)
23
- expect(parse_result.media_duration_frames).to eq(110488)
24
- expect(parse_result.media_duration_seconds).to be_within(0.01).of(13.81)
23
+ # Fixture does not define bits_per_sample in the fmt chunk
24
+ expect(parse_result.media_duration_frames).to be_nil
25
+ expect(parse_result.media_duration_seconds).to be_nil
25
26
  end
26
27
 
27
28
  it 'returns correct info about pcm files with more channels' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-07-09 00:00:00.000000000 Z
12
+ date: 2024-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: exifr