Class: GBTiles::GBT::Export::ASM::Channel

Inherits:
Object
  • Object
show all
Includes:
Effects
Defined in:
lib/gbtiles/gbt/export/asm/channel.rb

Constant Summary collapse

NOTES =
[
  1712,1616,1524,1440,1356,1280,1208,1140,1076,1016, 960, 907,
   856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453,
   428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226,
   214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113,
   107, 101,  95,  90,  85,  80,  75,  71,  67,  63,  60,  56,
    53,  50,  47,  45,  42,  40,  37,  35,  33,  31,  30,  28
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Effects

#effect_arpeggio, #effect_break_and_set_step, #effect_cut_note, #effect_jump, #effect_pan, #effect_speed, #effect_volume

Constructor Details

#initialize(channel_number) ⇒ Channel

Returns a new instance of Channel.



41
42
43
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 41

def initialize channel_number
  @channel_number = channel_number
end

Instance Attribute Details

#channel_numberObject

Returns the value of attribute channel_number.



25
26
27
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 25

def channel_number
  @channel_number
end

Instance Method Details

#convert_effectObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 102

def convert_effect
  if effect_number == 0x0 then
    return effect_arpeggio
  end

  if effect_number == 0xB then
    return effect_jump
  end

  if effect_number == 0xC then
    return effect_volume
  end

  if effect_number == 0xD then
    return effect_break_and_set_step
  end

  if effect_number == 0xE && effect_param_1 == 0x8 then
    return effect_pan
  end

  if effect_number == 0xE && effect_param_1 == 0xC then
    return effect_cut_note
  end

  if effect_number == 0xF then
    return effect_speed
  end

  throw "Unsupported effect"
end

#convert_speed(speed) ⇒ Object

Amiga’s 50 Hz to GB’s 60 Hz



98
99
100
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 98

def convert_speed speed
  speed * 60 / 50
end

#convert_volumeObject



93
94
95
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 93

def convert_volume
  (effect_param == 64) ? 0xF : (effect_param >> 2);
end

#dataObject



29
30
31
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 29

def data
  @data
end

#data=(value) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 33

def data=(value)
  if value.kind_of?(Array) then
    @data = value
  else
    @data = value.unpack('CCCC')
  end
end

#effect_numberObject



73
74
75
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 73

def effect_number
  @data[2] & 0xF
end

#effect_paramObject



77
78
79
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 77

def effect_param
  @data[3]
end

#effect_param_1Object



81
82
83
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 81

def effect_param_1
  (@data[3] & 0xF0) >> 4
end

#effect_param_2Object



85
86
87
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 85

def effect_param_2
  @data[3] & 0x0F
end

#effect_param_as_bcdObject



89
90
91
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 89

def effect_param_as_bcd
  (((effect_param & 0xF0) >> 4) * 10) + (effect_param & 0xF)
end

#is_empty_effect?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 69

def is_empty_effect?
  effect_number == 0 && effect_param == 0
end

#is_noise?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 55

def is_noise?
  false
end

#is_pulse?Boolean

Channel information

Returns:

  • (Boolean)


47
48
49
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 47

def is_pulse?
  false
end

#is_wav?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 51

def is_wav?
  false
end

#note_indexObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 134

def note_index
  period = sample_period

  if period <= 0 then
    return -1
  end

  if !is_noise? then
    if !period.between?(NOTES.last, NOTES.first) then
      throw "Note `#{period}` out of bounds"
    end
  end

  NOTES.index(
    NOTES.min_by { |x| (period - x).abs }
  )
end

#sample_numberObject

Data



61
62
63
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 61

def sample_number
  (@data[0] & 0xF0) | ((@data[2] & 0xF0) >> 4)
end

#sample_periodObject



65
66
67
# File 'lib/gbtiles/gbt/export/asm/channel.rb', line 65

def sample_period
  @data[1] | ((@data[0] & 0xF) << 8)
end