mirror of
https://github.com/subhobhai943/SUB-OS.git
synced 2026-10-26 00:52:50 +00:00
feat: Massive OS expansion with IPC, Sound & TTS, Block layer, FAT32/ext2/sysfs, Signals, Syscalls, Modules, Drivers & 50+ LazyBox applets
This commit is contained in:
1 parent
5662be29f5
commit
d680335f05
64 files changed
+2370
-166
No files matched your search
@@ -0,0 +1,63 @@
|
||||
#include <sound/ac97.h>
|
||||
#include <sound/sound.h>
|
||||
#include <drivers/pci.h>
|
||||
#include <arch/x86_64/io.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
static uint32_t ac97_nam_bar = 0;
|
||||
static uint32_t ac97_nabm_bar = 0;
|
||||
static bool ac97_present = false;
|
||||
|
||||
static int ac97_play(const void* buffer, size_t length) {
|
||||
(void)buffer; (void)length;
|
||||
return (int)length;
|
||||
}
|
||||
|
||||
static int ac97_set_vol(int volume) {
|
||||
if (ac97_nam_bar) {
|
||||
uint16_t vol_val = (uint16_t)(((100 - volume) * 31 / 100) | (((100 - volume) * 31 / 100) << 8));
|
||||
outw((uint16_t)(ac97_nam_bar + 0x02), vol_val);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static sound_device_t ac97_device = {
|
||||
.name = "Intel 82801AA AC'97 Audio",
|
||||
.sample_rate = 48000,
|
||||
.channels = 2,
|
||||
.bits_per_sample = 16,
|
||||
.volume = 80,
|
||||
.play_sample = ac97_play,
|
||||
.set_volume = ac97_set_vol,
|
||||
.active = true
|
||||
};
|
||||
|
||||
bool ac97_init(void) {
|
||||
pci_device_t* dev = pci_find_device(0x8086, 0x2415);
|
||||
if (!dev) {
|
||||
dev = pci_find_class(0x04, 0x01); // Multimedia Audio
|
||||
}
|
||||
|
||||
if (dev) {
|
||||
ac97_nam_bar = dev->bar[0] & ~1;
|
||||
ac97_nabm_bar = dev->bar[1] & ~1;
|
||||
ac97_present = true;
|
||||
pci_enable_bus_mastering(dev);
|
||||
sound_register_device(&ac97_device);
|
||||
printk(KERN_INFO "AC97: Audio Controller detected at NAM:0x%x, NABM:0x%x (IRQ %d)\n",
|
||||
ac97_nam_bar, ac97_nabm_bar, dev->irq);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ac97_set_master_volume(uint8_t left, uint8_t right) {
|
||||
if (ac97_nam_bar) {
|
||||
outw((uint16_t)(ac97_nam_bar + 0x02), (uint16_t)(left | (right << 8)));
|
||||
}
|
||||
}
|
||||
|
||||
int ac97_play_pcm(const void* samples, size_t length) {
|
||||
return ac97_play(samples, length);
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
#include <sound/pcm.h>
|
||||
#include <sound/sound.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
static pcm_stream_t default_pcm;
|
||||
|
||||
void pcm_init(void) {
|
||||
memset(&default_pcm, 0, sizeof(default_pcm));
|
||||
default_pcm.sample_rate = 44100;
|
||||
default_pcm.channels = 2;
|
||||
default_pcm.bits = 16;
|
||||
}
|
||||
|
||||
int pcm_write(const void* data, size_t len) {
|
||||
sound_device_t* dev = sound_get_default_device();
|
||||
if (dev && dev->play_sample) {
|
||||
return dev->play_sample(data, len);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <sound/sound.h>
|
||||
#include <sound/pcm.h>
|
||||
#include <sound/ac97.h>
|
||||
#include <sound/tts.h>
|
||||
#include <lib/string.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
static sound_device_t* default_sound_dev = NULL;
|
||||
|
||||
void sound_init(void) {
|
||||
pcm_init();
|
||||
ac97_init();
|
||||
tts_init();
|
||||
printk(KERN_INFO "SOUND: Core Audio Architecture & Formant TTS Engine online\n");
|
||||
}
|
||||
|
||||
int sound_register_device(sound_device_t* dev) {
|
||||
if (!dev) return -1;
|
||||
default_sound_dev = dev;
|
||||
printk(KERN_INFO "SOUND: Registered soundcard '%s' (%u Hz, %d-bit)\n",
|
||||
dev->name, dev->sample_rate, dev->bits_per_sample);
|
||||
return 0;
|
||||
}
|
||||
|
||||
sound_device_t* sound_get_default_device(void) {
|
||||
return default_sound_dev;
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
#include <sound/tts.h>
|
||||
#include <drivers/speaker.h>
|
||||
#include <arch/x86_64/pit.h>
|
||||
#include <kernel/printk.h>
|
||||
|
||||
static const tts_phoneme_t phoneme_table[] = {
|
||||
{{"a"}, 730, 1090, 120},
|
||||
{{"b"}, 400, 800, 80},
|
||||
{{"c"}, 600, 1400, 90},
|
||||
{{"d"}, 450, 1600, 80},
|
||||
{{"e"}, 530, 1840, 110},
|
||||
{{"f"}, 300, 1200, 70},
|
||||
{{"g"}, 420, 1300, 80},
|
||||
{{"h"}, 350, 900, 60},
|
||||
{{"i"}, 270, 2290, 100},
|
||||
{{"j"}, 500, 1700, 90},
|
||||
{{"k"}, 650, 1500, 80},
|
||||
{{"l"}, 400, 1100, 90},
|
||||
{{"m"}, 280, 900, 90},
|
||||
{{"n"}, 300, 1400, 90},
|
||||
{{"o"}, 570, 840, 120},
|
||||
{{"p"}, 350, 700, 80},
|
||||
{{"q"}, 600, 1300, 90},
|
||||
{{"r"}, 450, 1200, 90},
|
||||
{{"s"}, 700, 2000, 80},
|
||||
{{"t"}, 500, 1800, 70},
|
||||
{{"u"}, 440, 1020, 110},
|
||||
{{"v"}, 350, 1100, 80},
|
||||
{{"w"}, 320, 800, 90},
|
||||
{{"x"}, 650, 1900, 80},
|
||||
{{"y"}, 300, 2100, 100},
|
||||
{{"z"}, 500, 1600, 80},
|
||||
{{" "}, 0, 0, 60},
|
||||
{{0}, 0, 0, 0}
|
||||
};
|
||||
|
||||
void tts_init(void) {
|
||||
// Initialized
|
||||
}
|
||||
|
||||
void tts_speak_letter(char c) {
|
||||
if (c >= 'A' && c <= 'Z') c = (char)(c + ('a' - 'A'));
|
||||
|
||||
if (c == ' ' || c == ',' || c == '.' || c == '!') {
|
||||
pit_sleep(80);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; phoneme_table[i].phoneme[0] != 0; i++) {
|
||||
if (phoneme_table[i].phoneme[0] == c) {
|
||||
uint32_t freq = phoneme_table[i].freq_f1;
|
||||
uint32_t dur = phoneme_table[i].duration_ms;
|
||||
if (freq > 0) {
|
||||
speaker_beep(freq, dur);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tts_speak(const char* text) {
|
||||
if (!text) return;
|
||||
while (*text) {
|
||||
tts_speak_letter(*text);
|
||||
text++;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user