From 59237ab37598e3bbb51961c1e2f2d73c278496ce Mon Sep 17 00:00:00 2001 From: Ruslan Isaev Date: Wed, 20 May 2026 15:24:01 +0300 Subject: [PATCH] sb16: cleanup and add stereo support --- Makefile | 1 + src/drivers/sb16.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 2968175..5723283 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ iso: cp grubshit/statx katauos/katau/statx cp grubshit/kplayer katauos/katau/kplr cp grubshit/iosys.wav katauos/katau/io.wav + cp grubshit/iosys_stereo.wav katauos/katau/ios.wav sudo umount tmp/ grub-mkrescue -o boot.iso katauos/ diff --git a/src/drivers/sb16.c b/src/drivers/sb16.c index 78c04e6..50e454e 100644 --- a/src/drivers/sb16.c +++ b/src/drivers/sb16.c @@ -27,6 +27,8 @@ static bool is_playing = false; static size_t slot_sizes[2]; +static bool stereo = true; + #define min(a, b) ((a) < (b) ? (a) : (b)) void sb16_enable_irq() { @@ -103,9 +105,6 @@ void sb16_program_dma(uint32_t buf_size) int buffer_pos = (uint32_t)buffer_phys + (current_slot << 15); int count = buf_size; - //printf("buffer_pos: %x buffer: %x\n", buffer_pos, buffer_phys); - //printf("buffer: 0x%x\n", ((uint32_t)buffer_phys >> 16) & 0xFF); - outb(0x0A, 0x4 + channel);//0x4 + channel number (1 in this case) outb(0x0C, 1);//flip flop outb(0x0B, transfer_mode + channel); @@ -124,16 +123,21 @@ void sb16_program_dma(uint32_t buf_size) void sb16_program(uint32_t buf_size) { - const int samples_count = buf_size; + const int samples_count = stereo ? buf_size / 2 : buf_size; outb(DSP_WRITE, 0x41);//sample rate const int sample_rate = 44100; outb(DSP_WRITE, (sample_rate >> 8) & 0xff); outb(DSP_WRITE, (sample_rate) & 0xff); + uint8_t mode = 0x0; + if(stereo) + { + mode |= (1 << 5);//set the 5th bit to 1 if stereo + } outb(DSP_WRITE, 0xC0);//8-bit sound - outb(DSP_WRITE, 0x00);//mono unsigned + outb(DSP_WRITE, mode); outb(DSP_WRITE, (samples_count - 1) & 0xFF); outb(DSP_WRITE, ((samples_count - 1) >> 8) & 0xFF); } @@ -235,7 +239,4 @@ void sb16_init() outb(MIXER, 0x80); printf("SB16 raw irq_code: 0x%X\n", inb(MIXER_DATA)); - - //sb16_program_dma(); - //sb16_program(); } \ No newline at end of file