[BGM] Update placeholder ADSR names to reflect actual function

This commit is contained in:
Luke Hubmayer-Werner 2024-07-17 14:10:16 +09:30
parent 961c1344eb
commit 5babc200f2
5 changed files with 67 additions and 64 deletions

View File

@ -20,10 +20,10 @@ var channel_pan := PoolByteArray() # Reversed from MIDI
var channel_octave := PoolByteArray() var channel_octave := PoolByteArray()
var channel_transpose := PoolByteArray() var channel_transpose := PoolByteArray()
var channel_fine_tuning := PoolRealArray() var channel_fine_tuning := PoolRealArray()
var channel_adsr_attack := PoolByteArray() var channel_adsr_attack_rate := PoolByteArray()
var channel_adsr_decay := PoolByteArray() var channel_adsr_decay_rate := PoolByteArray()
var channel_adsr_sustain := PoolByteArray() var channel_adsr_sustain_level := PoolByteArray()
var channel_adsr_release := PoolByteArray() var channel_adsr_sustain_rate := PoolByteArray()
var channel_noise_freq := PoolByteArray() var channel_noise_freq := PoolByteArray()
var channel_noise_on := PoolByteArray() var channel_noise_on := PoolByteArray()
var channel_pan_lfo_rate := PoolByteArray() var channel_pan_lfo_rate := PoolByteArray()
@ -63,10 +63,10 @@ func _init(tracks: Array, instrument_map: Dictionary):
self.channel_octave.append(5) self.channel_octave.append(5)
self.channel_transpose.append(0) self.channel_transpose.append(0)
self.channel_fine_tuning.append(1.0) self.channel_fine_tuning.append(1.0)
self.channel_adsr_attack.append(0) self.channel_adsr_attack_rate.append(0)
self.channel_adsr_decay.append(0) self.channel_adsr_decay_rate.append(0)
self.channel_adsr_sustain.append(0) self.channel_adsr_sustain_level.append(0)
self.channel_adsr_release.append(0) self.channel_adsr_sustain_rate.append(0)
self.channel_noise_freq.append(0) self.channel_noise_freq.append(0)
self.channel_noise_on.append(0) self.channel_noise_on.append(0)
self.channel_pan_lfo_rate.append(0) self.channel_pan_lfo_rate.append(0)
@ -182,14 +182,14 @@ func play_channel(channel: int, time_offset: float = 0.0) -> int:
self.channel_instrument_idx[channel] = event[1] self.channel_instrument_idx[channel] = event[1]
player.stream = self.inst_map[self.channel_instrument_idx[channel]] player.stream = self.inst_map[self.channel_instrument_idx[channel]]
# TODO - grab instrument envelope # TODO - grab instrument envelope
EventType.ADSR_ATTACK: EventType.ADSR_ATTACK_RATE:
self.channel_adsr_attack[channel] = event[1] self.channel_adsr_attack_rate[channel] = event[1]
EventType.ADSR_DECAY: EventType.ADSR_DECAY_RATE:
self.channel_adsr_decay[channel] = event[1] self.channel_adsr_decay_rate[channel] = event[1]
EventType.ADSR_SUSTAIN: EventType.ADSR_SUSTAIN_LEVEL:
self.channel_adsr_sustain[channel] = event[1] self.channel_adsr_sustain_level[channel] = event[1]
EventType.ADSR_RELEASE: EventType.ADSR_SUSTAIN_RATE:
self.channel_adsr_release[channel] = event[1] self.channel_adsr_sustain_rate[channel] = event[1]
EventType.ADSR_DEFAULT: # TODO - grab instrument envelope EventType.ADSR_DEFAULT: # TODO - grab instrument envelope
pass pass
EventType.TEMPO: EventType.TEMPO:

View File

@ -11,10 +11,10 @@ class NoteEvent:
var instrument: int var instrument: int
var pitch: int var pitch: int
var velocity: float var velocity: float
var adsr_attack: int var adsr_attack_rate: int
var adsr_decay: int var adsr_decay_rate: int
var adsr_sustain: int var adsr_sustain_level: int
var adsr_release: int var adsr_sustain_rate: int
class TrackCurve: # built-in Curve class is too restrictive for this class TrackCurve: # built-in Curve class is too restrictive for this
@ -145,10 +145,10 @@ static func render_channels(tracks: Array, inst_map: Array, debug_name := 'none'
var current_octave := 5 var current_octave := 5
var current_transpose := 0 var current_transpose := 0
# var current_velocity := 100 # var current_velocity := 100
var current_adsr_attack := 0 var current_adsr_attack_rate := 0
var current_adsr_decay := 0 var current_adsr_decay_rate := 0
var current_adsr_sustain := 0 var current_adsr_sustain_level := 0
var current_adsr_release := 0 var current_adsr_sustain_rate := 0
# First, check if it ends in a GOTO, then store the program counter of the destination # First, check if it ends in a GOTO, then store the program counter of the destination
var infinite_loop_target_program_counter = -1 var infinite_loop_target_program_counter = -1
@ -194,10 +194,10 @@ static func render_channels(tracks: Array, inst_map: Array, debug_name := 'none'
note_event.instrument = current_instrument note_event.instrument = current_instrument
note_event.pitch = note # pitch_idx #* curve_fine_tuning note_event.pitch = note # pitch_idx #* curve_fine_tuning
note_event.velocity = curve_velocity.get_pulse(p) # current_velocity note_event.velocity = curve_velocity.get_pulse(p) # current_velocity
note_event.adsr_attack = current_adsr_attack note_event.adsr_attack_rate = current_adsr_attack_rate
note_event.adsr_decay = current_adsr_decay note_event.adsr_decay_rate = current_adsr_decay_rate
note_event.adsr_sustain = current_adsr_sustain note_event.adsr_sustain_level = current_adsr_sustain_level
note_event.adsr_release = current_adsr_release note_event.adsr_sustain_rate = current_adsr_sustain_rate
channel_note_events.append(note_event) channel_note_events.append(note_event)
# num_notes += 1 # num_notes += 1
elif note == music.NOTE_IS_TIE: elif note == music.NOTE_IS_TIE:
@ -253,25 +253,25 @@ static func render_channels(tracks: Array, inst_map: Array, debug_name := 'none'
current_instrument = inst_map[event_idx] - 1 current_instrument = inst_map[event_idx] - 1
if current_instrument < len(instrument_adsrs) and current_instrument > 0: if current_instrument < len(instrument_adsrs) and current_instrument > 0:
var adsr = instrument_adsrs[current_instrument] var adsr = instrument_adsrs[current_instrument]
current_adsr_attack = adsr[2] current_adsr_attack_rate = adsr[2]
current_adsr_decay = adsr[3] current_adsr_decay_rate = adsr[3]
current_adsr_sustain = adsr[0] current_adsr_sustain_level = adsr[0]
current_adsr_release = adsr[1] current_adsr_sustain_rate = adsr[1]
EventType.ADSR_DEFAULT: # TODO - Investigate actual scaling and order EventType.ADSR_DEFAULT: # TODO - Investigate actual scaling and order
if current_instrument < len(instrument_adsrs) and current_instrument > 0: if current_instrument < len(instrument_adsrs) and current_instrument > 0:
var adsr = instrument_adsrs[current_instrument] var adsr = instrument_adsrs[current_instrument]
current_adsr_attack = adsr[2] current_adsr_attack_rate = adsr[2]
current_adsr_decay = adsr[3] current_adsr_decay_rate = adsr[3]
current_adsr_sustain = adsr[0] current_adsr_sustain_level = adsr[0]
current_adsr_release = adsr[1] current_adsr_sustain_rate = adsr[1]
EventType.ADSR_ATTACK: EventType.ADSR_ATTACK_RATE:
current_adsr_attack = event[1] current_adsr_attack_rate = event[1]
EventType.ADSR_DECAY: EventType.ADSR_DECAY_RATE:
current_adsr_decay = event[1] current_adsr_decay_rate = event[1]
EventType.ADSR_SUSTAIN: EventType.ADSR_SUSTAIN_LEVEL:
current_adsr_sustain = event[1] current_adsr_sustain_level = event[1]
EventType.ADSR_RELEASE: EventType.ADSR_SUSTAIN_RATE:
current_adsr_release = event[1] current_adsr_sustain_rate = event[1]
EventType.VIBRATO_ON: EventType.VIBRATO_ON:
curve_vibrato_delay.add_point(p, event[1]) curve_vibrato_delay.add_point(p, event[1])
curve_vibrato_rate.add_point(p, event[2]) curve_vibrato_rate.add_point(p, event[2])
@ -390,10 +390,10 @@ static func render_channels(tracks: Array, inst_map: Array, debug_name := 'none'
midi_events_bytes3.put_u8(event.pitch) midi_events_bytes3.put_u8(event.pitch)
midi_events_bytes3.put_u8(int(event.velocity * curve_master_volume.get_pulse(p) * 255.0)) # velocity midi_events_bytes3.put_u8(int(event.velocity * curve_master_volume.get_pulse(p) * 255.0)) # velocity
midi_events_bytes3.put_u8(int((curve_pan.get_pulse(p)+1.0) * 127.5)) # pan midi_events_bytes3.put_u8(int((curve_pan.get_pulse(p)+1.0) * 127.5)) # pan
midi_events_bytes_adsr.put_u8(event.adsr_attack) midi_events_bytes_adsr.put_u8(event.adsr_attack_rate)
midi_events_bytes_adsr.put_u8(event.adsr_decay) midi_events_bytes_adsr.put_u8(event.adsr_decay_rate)
midi_events_bytes_adsr.put_u8(event.adsr_sustain) midi_events_bytes_adsr.put_u8(event.adsr_sustain_level)
midi_events_bytes_adsr.put_u8(event.adsr_release) midi_events_bytes_adsr.put_u8(event.adsr_sustain_rate)
event_ptr += 1 event_ptr += 1
num_notes += 1 num_notes += 1

View File

@ -4,11 +4,11 @@ const NOTE_IS_TIE := -1
const NOTE_IS_REST := -2 const NOTE_IS_REST := -2
enum EventType { enum EventType {
ADSR_ATTACK, ADSR_ATTACK_RATE,
ADSR_DECAY, ADSR_DECAY_RATE,
ADSR_DEFAULT, ADSR_DEFAULT,
ADSR_RELEASE, ADSR_SUSTAIN_RATE,
ADSR_SUSTAIN, ADSR_SUSTAIN_LEVEL,
CPU_CONTROLLED_JUMP, CPU_CONTROLLED_JUMP,
ECHO_FEEDBACK_FIR, ECHO_FEEDBACK_FIR,
ECHO_OFF, ECHO_OFF,
@ -58,11 +58,11 @@ enum OperandType {
} }
const OPERAND_MAP := { const OPERAND_MAP := {
EventType.ADSR_ATTACK: [OperandType.U8], EventType.ADSR_ATTACK_RATE: [OperandType.U8], # Attack Rate, & 0b00001111
EventType.ADSR_DECAY: [OperandType.U8], EventType.ADSR_DECAY_RATE: [OperandType.U8], # Decay Rate, & 0b00000111
EventType.ADSR_DEFAULT: [], EventType.ADSR_DEFAULT: [],
EventType.ADSR_RELEASE: [OperandType.U8], EventType.ADSR_SUSTAIN_RATE: [OperandType.U8], # & 0b00001111
EventType.ADSR_SUSTAIN: [OperandType.U8], EventType.ADSR_SUSTAIN_LEVEL: [OperandType.U8], # & 0b00000111
EventType.CPU_CONTROLLED_JUMP: [OperandType.U16], EventType.CPU_CONTROLLED_JUMP: [OperandType.U16],
EventType.ECHO_FEEDBACK_FIR: [OperandType.U8, OperandType.U8], EventType.ECHO_FEEDBACK_FIR: [OperandType.U8, OperandType.U8],
EventType.ECHO_OFF: [], EventType.ECHO_OFF: [],
@ -91,8 +91,8 @@ const OPERAND_MAP := {
EventType.PROGCHANGE: [OperandType.U8], EventType.PROGCHANGE: [OperandType.U8],
EventType.TEMPO_SLIDE: [OperandType.U8, OperandType.U8], EventType.TEMPO_SLIDE: [OperandType.U8, OperandType.U8],
EventType.TEMPO: [OperandType.U8], EventType.TEMPO: [OperandType.U8],
EventType.TRANSPOSE_ABS: [OperandType.U8], EventType.TRANSPOSE_ABS: [OperandType.S8],
EventType.TRANSPOSE_REL: [OperandType.U8], EventType.TRANSPOSE_REL: [OperandType.S8],
EventType.TREMOLO_OFF: [], EventType.TREMOLO_OFF: [],
EventType.TREMOLO_ON: [OperandType.U8, OperandType.U8, OperandType.U8], EventType.TREMOLO_ON: [OperandType.U8, OperandType.U8, OperandType.U8],
EventType.TUNING: [OperandType.U8], EventType.TUNING: [OperandType.U8],

View File

@ -34,10 +34,10 @@ func _init() -> void:
0xE8: EventType.TRANSPOSE_REL, 0xE8: EventType.TRANSPOSE_REL,
0xE9: EventType.TUNING, 0xE9: EventType.TUNING,
0xEA: EventType.PROGCHANGE, 0xEA: EventType.PROGCHANGE,
0xEB: EventType.ADSR_ATTACK, 0xEB: EventType.ADSR_ATTACK_RATE,
0xEC: EventType.ADSR_DECAY, 0xEC: EventType.ADSR_DECAY_RATE,
0xED: EventType.ADSR_SUSTAIN, 0xED: EventType.ADSR_SUSTAIN_LEVEL,
0xEE: EventType.ADSR_RELEASE, 0xEE: EventType.ADSR_SUSTAIN_RATE,
0xEF: EventType.ADSR_DEFAULT, 0xEF: EventType.ADSR_DEFAULT,
0xF0: EventType.LOOP_START, 0xF0: EventType.LOOP_START,
0xF1: EventType.LOOP_END, 0xF1: EventType.LOOP_END,

View File

@ -214,8 +214,11 @@ highp vec4 render_song(highp sampler2D tex, highp int smp) {
// ====================At some point I'll look back into packing floats==================== // ====================At some point I'll look back into packing floats====================
// TBD = note_event_supplement.zw; - tremolo/vibrato/noise/pan_lfo/pitchbend/echo remain // TBD = note_event_supplement.zw; - tremolo/vibrato/noise/pan_lfo/pitchbend/echo remain
// ====================At some point I'll look back into packing floats==================== // ====================At some point I'll look back into packing floats====================
highp float attack = 1.0 + adsr.x*255.0; //65535.0 + 1.0; // TODO: work out effective resolution for this highp float attack_rate = 1.0 + adsr.x*255.0; //65535.0 + 1.0; // TODO: work out effective resolution for this - it's actually only 4 of 8 bits
highp int smp_attack = int(attack) * 2; // Max value is 131072 samples = 4.096 seconds highp float decay_rate = adsr.y; // TODO: work out effective resolution for this - it's actually only 3 of 8 bits
highp float sustain_level = adsr.z; // TODO: work out effective resolution for this - it's actually only 3 of 8 bits
highp float sustain_rate = adsr.w; // TODO: work out effective resolution for this - it's actually only 4 of 8 bits
highp int smp_attack = int(attack_rate) * 2; // Max value is 131072 samples = 4.096 seconds
// For now, just branch this // For now, just branch this
if (smp_start < smp) { // First sample may not start at zero! if (smp_start < smp) { // First sample may not start at zero!