sb16: cleanup and add stereo support

This commit is contained in:
2026-05-20 15:24:01 +03:00
parent a77b51699c
commit 59237ab375
2 changed files with 10 additions and 8 deletions
+1
View File
@@ -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/
+9 -8
View File
@@ -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();
}