Class: GBTiles::GBT::Export::ASM::Channels::Wav

Inherits:
GBTiles::GBT::Export::ASM::Channel show all
Defined in:
lib/gbtiles/gbt/export/asm/channels/wav.rb

Constant Summary

Constants inherited from GBTiles::GBT::Export::ASM::Channel

GBTiles::GBT::Export::ASM::Channel::NOTES

Instance Attribute Summary

Attributes inherited from GBTiles::GBT::Export::ASM::Channel

#channel_number

Instance Method Summary collapse

Methods inherited from GBTiles::GBT::Export::ASM::Channel

#convert_effect, #convert_speed, #data, #data=, #effect_number, #effect_param, #effect_param_1, #effect_param_2, #effect_param_as_bcd, #is_empty_effect?, #is_noise?, #is_pulse?, #note_index, #sample_number, #sample_period

Methods included from Effects

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

Constructor Details

#initializeWav

Returns a new instance of Wav.



12
13
14
# File 'lib/gbtiles/gbt/export/asm/channels/wav.rb', line 12

def initialize
  super(3)
end

Instance Method Details

#convertObject



35
36
37
38
39
40
41
# File 'lib/gbtiles/gbt/export/asm/channels/wav.rb', line 35

def convert
  if sample_period == 0 then
    convert_note_not_new
  else
    convert_note_new
  end
end

#convert_note_newObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gbtiles/gbt/export/asm/channels/wav.rb', line 71

def convert_note_new
  instrument = (sample_number - 8) & 15

  # Volume effect
  if effect_number == 0xC then
    return [
        (1 << 7) | note_index,
        (convert_volume << 4) | instrument
    ]
  end

  # Other effects
  begin
    converted = convert_effect

    if (converted[:number] > 7) then
      throw "Invalid command: only 0-7 allowed in this mode"
    end

    return [
        (1 << 7) | note_index,
        (1 << 7) | (converted_num << 4) | instrument,
        converted_params
    ]
  rescue Exception => e
    throw "Wav - Invalid command: #{e}"
  end
end

#convert_note_not_newObject



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
# File 'lib/gbtiles/gbt/export/asm/channels/wav.rb', line 43

def convert_note_not_new
  if is_empty_effect? then
    return [0]
  end

  # Volume effect
  if effect_number == 0xC then
    return [
      (1 << 5) | convert_volume
    ]
  end

  # Other effects
  begin
    converted = convert_effect

    return [
      (1 << 6) | converted[:number],
      converted[:params]
    ]

  rescue Exception => e
    # Silence
  end

  return [0]
end

#convert_volumeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/gbtiles/gbt/export/asm/channels/wav.rb', line 20

def convert_volume
  case super
  when 0..3
    return 0
  when 4..7
    return 3
  when 8..11
    return 2
  when 12..15
    return 1
  else
    return 1
  end
end

#is_wav?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/gbtiles/gbt/export/asm/channels/wav.rb', line 16

def is_wav?
  true
end