File: wavefile_io_test_helper.rb

package info (click to toggle)
ruby-wavefile 1.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,708 kB
  • sloc: ruby: 4,171; makefile: 2
file content (76 lines) | stat: -rw-r--r-- 5,246 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
module WaveFileIOTestHelper
  CHANNEL_ALIAS = {mono: 1, stereo: 2, tri: 3}

  SUPPORTED_BITS_PER_SAMPLE = {
                                pcm: [8, 16, 24, 32].freeze,
                                float: [32, 64].freeze,
                              }.freeze

  SQUARE_WAVE_CYCLE = {}
  SQUARE_WAVE_CYCLE[:mono] = {}

  SQUARE_WAVE_CYCLE[:mono][:pcm_8] =    [88, 88, 88, 88, 167, 167, 167, 167]
  SQUARE_WAVE_CYCLE[:mono][:pcm_16] =   [-10000, -10000, -10000, -10000, 10000, 10000, 10000, 10000]
  SQUARE_WAVE_CYCLE[:mono][:pcm_24] =   [-1000000, -1000000, -1000000, -1000000, 1000000, 1000000, 1000000, 1000000]
  SQUARE_WAVE_CYCLE[:mono][:pcm_32] =   [-1000000000, -1000000000, -1000000000, -1000000000,
                                          1000000000, 1000000000, 1000000000, 1000000000]
  SQUARE_WAVE_CYCLE[:mono][:float] = [-0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5]
  SQUARE_WAVE_CYCLE[:mono][:float_32] = [-0.5, -0.5, -0.5, -0.5, 0.5, 0.5, 0.5, 0.5]
  SQUARE_WAVE_CYCLE[:mono][:float_64] = SQUARE_WAVE_CYCLE[:mono][:float_32]

  SQUARE_WAVE_CYCLE[:stereo] = {}
  SQUARE_WAVE_CYCLE[:stereo][:pcm_8] =  [[88, 88], [88, 88], [88, 88], [88, 88],
                                         [167, 167], [167, 167], [167, 167], [167, 167]]
  SQUARE_WAVE_CYCLE[:stereo][:pcm_16] = [[-10000, -10000], [-10000, -10000], [-10000, -10000], [-10000, -10000],
                                         [10000, 10000], [10000, 10000], [10000, 10000], [10000, 10000]]
  SQUARE_WAVE_CYCLE[:stereo][:pcm_24] = [[-1000000, -1000000], [-1000000, -1000000], [-1000000, -1000000], [-1000000, -1000000],
                                         [1000000, 1000000], [1000000, 1000000], [1000000, 1000000], [1000000, 1000000]]
  SQUARE_WAVE_CYCLE[:stereo][:pcm_32] = [[-1000000000, -1000000000], [-1000000000, -1000000000],
                                         [-1000000000, -1000000000], [-1000000000, -1000000000],
                                         [ 1000000000,  1000000000], [ 1000000000,  1000000000],
                                         [ 1000000000,  1000000000], [ 1000000000,  1000000000]]
  SQUARE_WAVE_CYCLE[:stereo][:float] = [[-0.5, -0.5], [-0.5, -0.5], [-0.5, -0.5], [-0.5, -0.5],
                                        [0.5, 0.5], [0.5, 0.5], [0.5, 0.5], [0.5, 0.5]]
  SQUARE_WAVE_CYCLE[:stereo][:float_32] = [[-0.5, -0.5], [-0.5, -0.5], [-0.5, -0.5], [-0.5, -0.5],
                                         [0.5, 0.5], [0.5, 0.5], [0.5, 0.5], [0.5, 0.5]]
  SQUARE_WAVE_CYCLE[:stereo][:float_64] = SQUARE_WAVE_CYCLE[:stereo][:float_32]

  SQUARE_WAVE_CYCLE[:tri] = {}
  SQUARE_WAVE_CYCLE[:tri][:pcm_8] =    [[88, 88, 88], [88, 88, 88], [88, 88, 88], [88, 88, 88],
                                    [167, 167, 167], [167, 167, 167], [167, 167, 167], [167, 167, 167]]
  SQUARE_WAVE_CYCLE[:tri][:pcm_16] =   [[-10000, -10000, -10000], [-10000, -10000, -10000],
                                        [-10000, -10000, -10000], [-10000, -10000, -10000],
                                        [ 10000,  10000,  10000], [ 10000,  10000,  10000],
                                        [ 10000,  10000,  10000], [ 10000,  10000,  10000]]
  SQUARE_WAVE_CYCLE[:tri][:pcm_24] =   [[-1000000, -1000000, -1000000], [-1000000, -1000000, -1000000],
                                        [-1000000, -1000000, -1000000], [-1000000, -1000000, -1000000],
                                        [ 1000000,  1000000,  1000000], [ 1000000,  1000000,  1000000],
                                        [ 1000000,  1000000,  1000000], [ 1000000,  1000000,  1000000]]
  SQUARE_WAVE_CYCLE[:tri][:pcm_32] =   [[-1000000000, -1000000000, -1000000000],
                                        [-1000000000, -1000000000, -1000000000],
                                        [-1000000000, -1000000000, -1000000000],
                                        [-1000000000, -1000000000, -1000000000],
                                        [ 1000000000,  1000000000,  1000000000],
                                        [ 1000000000,  1000000000,  1000000000],
                                        [ 1000000000,  1000000000,  1000000000],
                                        [ 1000000000,  1000000000,  1000000000]]
  SQUARE_WAVE_CYCLE[:tri][:float] = [[-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5],
                                     [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]]
  SQUARE_WAVE_CYCLE[:tri][:float_32] = [[-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5], [-0.5, -0.5, -0.5],
                                        [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]]
  SQUARE_WAVE_CYCLE[:tri][:float_64] = SQUARE_WAVE_CYCLE[:tri][:float_32]


  # Executes the given block against different combinations of number of channels and sample_format
  def exhaustively_test
    ["", "extensible_"].each do |format_chunk_format|
      [:mono, :stereo, :tri].each do |channels|
        [:pcm, :float].each do |sample_format|
          SUPPORTED_BITS_PER_SAMPLE[sample_format].each do |bits_per_sample|
            yield(format_chunk_format, channels, "#{sample_format}_#{bits_per_sample}".to_sym)
          end
        end
      end
    end
  end
end