mirror of
https://github.com/mattrberry/crab.git
synced 2025-01-19 10:26:44 +01:00
proper dma sound sound control (volume, enable, balance)
This commit is contained in:
parent
df4ce8540e
commit
bf156dc18d
3 changed files with 42 additions and 27 deletions
|
@ -94,24 +94,40 @@ class APU
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_sample : Nil
|
def get_sample : Nil
|
||||||
channel1_amp = @channel1.get_amplitude
|
abort "Prohibited sound 1-4 volume #{@soundcnt_h.sound_volume}" if @soundcnt_h.sound_volume >= 3
|
||||||
channel2_amp = @channel2.get_amplitude
|
psg_master_volume = ((100 >> (2 - @soundcnt_h.sound_volume)) / 100).to_f32
|
||||||
channel3_amp = @channel3.get_amplitude
|
psg_sound = ((@channel1.get_amplitude * @soundcnt_l.channel_1_left) +
|
||||||
channel4_amp = @channel4.get_amplitude
|
(@channel2.get_amplitude * @soundcnt_l.channel_2_left) +
|
||||||
dma_amp = @dma_channels.get_amplitude
|
(@channel3.get_amplitude * @soundcnt_l.channel_3_left) +
|
||||||
@buffer[@buffer_pos] = (@soundcnt_l.left_volume / 7).to_f32 *
|
(@channel4.get_amplitude * @soundcnt_l.channel_4_left)) / 4
|
||||||
((channel4_amp * @soundcnt_l.channel_4_left) +
|
psg_left = psg_master_volume *
|
||||||
(channel3_amp * @soundcnt_l.channel_3_left) +
|
(@soundcnt_l.left_volume / 7) *
|
||||||
(channel2_amp * @soundcnt_l.channel_2_left) +
|
psg_sound
|
||||||
(channel1_amp * @soundcnt_l.channel_1_left) +
|
psg_right = psg_master_volume *
|
||||||
(dma_amp)) / 5
|
(@soundcnt_l.right_volume / 7) *
|
||||||
@buffer[@buffer_pos + 1] = (@soundcnt_l.right_volume).to_f32 *
|
psg_sound
|
||||||
((channel4_amp * @soundcnt_l.channel_4_right) +
|
|
||||||
(channel3_amp * @soundcnt_l.channel_3_right) +
|
dma_a, dma_b = @dma_channels.get_amplitude
|
||||||
(channel2_amp * @soundcnt_l.channel_2_right) +
|
vol_a = ((100 >> (1 - @soundcnt_h.dma_sound_a_volume)) / 100).to_f32
|
||||||
(channel1_amp * @soundcnt_l.channel_1_right) +
|
vol_b = ((100 >> (1 - @soundcnt_h.dma_sound_b_volume)) / 100).to_f32
|
||||||
(dma_amp)) / 5
|
dma_left = ((dma_a * @soundcnt_h.dma_sound_a_left * vol_a) +
|
||||||
abort @buffer[@buffer_pos] if @buffer[@buffer_pos].abs > 1
|
(dma_b * @soundcnt_h.dma_sound_b_left * vol_a)) / 2
|
||||||
|
dma_right = ((dma_a * @soundcnt_h.dma_sound_a_right * vol_a) +
|
||||||
|
(dma_b * @soundcnt_h.dma_sound_b_right * vol_a)) / 2
|
||||||
|
|
||||||
|
@buffer[@buffer_pos] = (psg_left + dma_left) / 2
|
||||||
|
@buffer[@buffer_pos + 1] = (psg_right + dma_right) / 2
|
||||||
|
|
||||||
|
if @buffer[@buffer_pos].abs > 1 || @buffer[@buffer_pos + 1].abs > 1
|
||||||
|
STDERR.puts "Left: #{@buffer[@buffer_pos]}"
|
||||||
|
STDERR.puts " PSG: #{psg_left}"
|
||||||
|
STDERR.puts " DMA: #{dma_right}"
|
||||||
|
STDERR.puts "Right: #{@buffer[@buffer_pos + 1]}"
|
||||||
|
STDERR.puts " PSG: #{psg_right}"
|
||||||
|
STDERR.puts " DMA: #{dma_right}"
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
@buffer_pos += 2
|
@buffer_pos += 2
|
||||||
|
|
||||||
# push to SDL if buffer is full
|
# push to SDL if buffer is full
|
||||||
|
|
|
@ -50,8 +50,7 @@ class DMAChannels
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_amplitude : Float32
|
def get_amplitude : Tuple(Float32, Float32)
|
||||||
# STDERR.puts @latches.sum / 2 #unless -0.001 < @latches.sum / 2 < 0.001
|
{@latches[0], @latches[1]}
|
||||||
@latches.sum / 2
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,15 +20,15 @@ module Reg
|
||||||
class SOUNDCNT_H < BitField(UInt16)
|
class SOUNDCNT_H < BitField(UInt16)
|
||||||
bool dma_sound_b_reset, lock: true
|
bool dma_sound_b_reset, lock: true
|
||||||
num dma_sound_b_timer, 1
|
num dma_sound_b_timer, 1
|
||||||
bool dma_sound_b_left
|
num dma_sound_b_left, 1
|
||||||
bool dma_sound_b_right
|
num dma_sound_b_right, 1
|
||||||
bool dma_sound_a_reset, lock: true
|
bool dma_sound_a_reset, lock: true
|
||||||
num dma_sound_a_timer, 1
|
num dma_sound_a_timer, 1
|
||||||
bool dma_sound_a_left
|
num dma_sound_a_left, 1
|
||||||
bool dma_sound_a_right
|
num dma_sound_a_right, 1
|
||||||
num not_used, 4, lock: true
|
num not_used, 4, lock: true
|
||||||
bool dma_sound_b_volume
|
num dma_sound_b_volume, 1
|
||||||
bool dma_sound_a_volume
|
num dma_sound_a_volume, 1
|
||||||
num sound_volume, 2
|
num sound_volume, 2
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue