Class: AudioStream::Rate

Inherits:
Object
  • Object
show all
Defined in:
lib/audio_stream/rate.rb

Constant Summary collapse

SYNC_64 =
sync(480 * 4 * 64)
SYNC_32 =
sync(480 * 4 * 32)
SYNC_16 =
sync(480 * 4 * 16)
SYNC_8 =
sync(480 * 4 * 8)
SYNC_6 =
sync(480 * 4 * 6)
SYNC_4 =
sync(480 * 4 * 4)
SYNC_3 =
sync(480 * 4 * 3)
SYNC_2 =
sync(480 * 4 * 2)
SYNC_7_4 =
sync(480 * 4 * 7 / 4)
SYNC_6_4 =
sync(480 * 4 * 6 / 4)
SYNC_5_4 =
sync(480 * 4 * 5 / 4)
SYNC_1 =
sync(480 * 4 * 1)
SYNC_3_4 =
sync(480 * 4 * 3 / 4)
SYNC_1_2 =
sync(480 * 4 * 1 / 2)
SYNC_1_4D =
sync(480 * 4 * 1 / 4 * 3 / 2)
SYNC_1_4 =
sync(480 * 4 * 1 / 4)
SYNC_1_4T =
sync(480 * 4 * 1 / 4 * 2 / 3)
SYNC_1_8D =
sync(480 * 4 * 1 / 8 * 3 / 2)
SYNC_1_8 =
sync(480 * 4 * 1 / 8)
SYNC_1_8T =
sync(480 * 4 * 1 / 8 * 2 / 3)
SYNC_1_16D =
sync(480 * 4 * 1 / 16 * 3 / 2)
SYNC_1_16 =
sync(480 * 4 * 1 / 16)
SYNC_1_16T =
sync(480 * 4 * 1 / 16 * 2 / 3)
SYNC_1_32D =
sync(480 * 4 * 1 / 32 * 3 / 2)
SYNC_1_32 =
sync(480 * 4 * 1 / 32)
SYNC_1_32T =
sync(480 * 4 * 1 / 32 * 2 / 3)
SYNC_1_64D =
sync(480 * 4 * 1 / 64 * 3 / 2)
SYNC_1_64 =
sync(480 * 4 * 1 / 64)
SYNC_1_64T =
sync(480 * 4 * 1 / 64 * 2 / 3)
SYNC_1_128D =
sync(480 * 4 * 1 / 128 * 3 / 2)
SYNC_1_128 =
sync(480 * 4 * 1 / 128)
SYNC_1_128T =
sync(480 * 4 * 1 / 128 * 2 / 3)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sec: nil, sample: nil, freq: nil, sync: nil) ⇒ Rate

Returns a new instance of Rate.



3
4
5
6
7
8
# File 'lib/audio_stream/rate.rb', line 3

def initialize(sec: nil, sample: nil, freq: nil, sync: nil)
  @sec = sec
  @sample = sample
  @freq = freq
  @sync = sync
end

Class Method Details

.freq(v) ⇒ Object



99
100
101
102
103
104
105
# File 'lib/audio_stream/rate.rb', line 99

def self.freq(v)
  if self===v
    v
  else
    new(freq: v)
  end
end

.msec(v) ⇒ Object



83
84
85
86
87
88
89
# File 'lib/audio_stream/rate.rb', line 83

def self.msec(v)
  if self===v
    v
  else
    new(sec: v*0.001)
  end
end

.sample(v) ⇒ Object



91
92
93
94
95
96
97
# File 'lib/audio_stream/rate.rb', line 91

def self.sample(v)
  if self===v
    v
  else
    new(sample: v)
  end
end

.sec(v) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/audio_stream/rate.rb', line 75

def self.sec(v)
  if self===v
    v
  else
    new(sec: v)
  end
end

.sync(v) ⇒ Object



107
108
109
110
111
112
113
# File 'lib/audio_stream/rate.rb', line 107

def self.sync(v)
  if self===v
    v
  else
    new(sync: v)
  end
end

Instance Method Details

#*(other) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/audio_stream/rate.rb', line 55

def *(other)
  other = other.to_f

  if @sample
    return self.class.new(sample: @sample * other)
  end

  if @sec
    return self.class.new(sec: @sec * other)
  end

  if @freq
    return self.class.new(freq: @freq / other)
  end

  if @sync
    return self.class.new(sync: @sync * other)
  end
end

#add(other, soundinfo) ⇒ Object



50
51
52
53
# File 'lib/audio_stream/rate.rb', line 50

def add(other, soundinfo)
  other = self.class.sec(other)
  self.class.new(sec: self.sec(soundinfo) + other.sec(soundinfo))
end

#frame(soundinfo) ⇒ Object



15
16
17
# File 'lib/audio_stream/rate.rb', line 15

def frame(soundinfo)
  sample(soundinfo).to_f / soundinfo.window_size
end

#frame_phase(soundinfo) ⇒ Object



42
43
44
# File 'lib/audio_stream/rate.rb', line 42

def frame_phase(soundinfo)
  sample_phase(soundinfo) * soundinfo.window_size
end

#freq(soundinfo) ⇒ Object



37
38
39
40
# File 'lib/audio_stream/rate.rb', line 37

def freq(soundinfo)
  return @freq if @freq
  soundinfo.samplerate.to_f / sample(soundinfo)
end

#sample(soundinfo) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/audio_stream/rate.rb', line 19

def sample(soundinfo)
  if @sample
    return @sample
  end

  if @sec
    return @sec.to_f * soundinfo.samplerate
  end

  if @freq
    return soundinfo.samplerate.to_f / @freq
  end

  if @sync
    return @sync / 480.0 * soundinfo.sync_rate
  end
end

#sample_phase(soundinfo) ⇒ Object



46
47
48
# File 'lib/audio_stream/rate.rb', line 46

def sample_phase(soundinfo)
  2.0 * Math::PI / sample(soundinfo)
end

#sec(soundinfo) ⇒ Object



10
11
12
13
# File 'lib/audio_stream/rate.rb', line 10

def sec(soundinfo)
  return @sec if @sec
  sample(soundinfo).to_f / soundinfo.samplerate
end