Voxia OS
v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
sb16.c
Go to the documentation of this file.
1
// #include "sb16.h"
2
3
// #include <firmw/pci/pci.h>
4
// #include <libk/io.h>
5
// #include <libk/serial.h>
6
// #include <str.h>
7
// #include <libk/timer.h>
8
// #include <type.h>
9
// #include <memory/memory_utils.h>
10
// #include <memory/phys_base_allocator.h>
11
// #include <vfs/vfs.h>
12
13
// uint16_t nam_base = 0;
14
// uint16_t nabm_base = 0;
15
// uint32_t extended_cap = 0;
16
17
// typedef struct
18
// {
19
// uint32_t addr;
20
// uint16_t size;
21
// uint16_t flags;
22
// } bufer_list;
23
24
// bufer_list *buf;
25
26
// void
27
// set_sample_rate(uint32_t rate)
28
// {
29
// if ((extended_cap & 0x1) == 0x1)
30
// {
31
// // set same variable rate on all outputs
32
// outw(nam_base + 0x2c, rate);
33
// outw(nam_base + 0x2e, rate);
34
// outw(nam_base + 0x30, rate);
35
// outw(nam_base + 0x32, rate);
36
// }
37
// }
38
39
// void
40
// sb16_play(const char *name)
41
// {
42
// int fd = vfs_open(name, 0);
43
// if (fd < 0)
44
// {
45
// serial_trace("failed to open ff.pcm\n");
46
// return;
47
// }
48
49
// struct vfs_file_stats stats;
50
// vfs_fstat(fd, &stats);
51
// uint8_t *buf_ = (uint8_t *)VIRT2PHYS(phys_base_alloc((1 + stats.size) / 4096));
52
// vfs_read(fd, buf_, stats.size);
53
54
// outb(nabm_base + 0x04, 0);
55
56
// set_sample_rate(44100);
57
58
// outb(nabm_base + 0x1b, 0x2);
59
// int ticks = 0;
60
// while ((inb(nabm_base + 0x1b) & 0x2) == 0x2)
61
// {
62
// asm("nop");
63
// if (ticks > 50)
64
// { // stream was not reseted after 100 ms
65
// return;
66
// }
67
// ticks++;
68
// }
69
// outb(nabm_base + 0x1b, 0x0);
70
71
// outl(nabm_base + 0x10, (uint32_t)buf);
72
73
// // fill buffer
74
// buf[0].addr = (uint32_t)buf_ + 0x1000;
75
// buf[0].size = 0x1200;
76
77
// for (int i = 1; i < 32; i++)
78
// {
79
// buf[i].addr = (uint32_t)buf_ + 0x2000 + (i * 0x2000);
80
// buf[i].size = 0x2000;
81
// }
82
83
// // clear status
84
// outw(nabm_base + 0x16, 0x1C);
85
86
// // start streaming
87
// outb(nabm_base + 0x1b, 0x1);
88
// serial_trace("streaming started\n");
89
// }
90
91
// void
92
// sb16_init()
93
// {
94
// // AC97
95
// for (int i = 0; i < 32; i++)
96
// {
97
// if (pci_devices[i].class == 0x4 && pci_devices[i].subclass == 0x1)
98
// {
99
// serial_trace("\nFound Intel AC9 device BAR at: 0x%x and 0x%x\n",
100
// pci_devices[i].bar[0],
101
// pci_devices[i].bar[1]);
102
// enable_bus_mastering(pci_devices[i]);
103
// enable_io_space(pci_devices[i]);
104
105
// nam_base = pci_devices[i].bar[0];
106
// nabm_base = pci_devices[i].bar[1];
107
// break;
108
// }
109
// }
110
111
// // resume rom cold reet
112
// outl(nabm_base + 0x2C, (0b00 << 22) | (0b00 << 20) | (0 << 2) | (1 << 1));
113
// usleep(20);
114
115
// outb(nabm_base + 0x0B, 0x2);
116
// outb(nabm_base + 0x1B, 0x2);
117
// outb(nabm_base + 0x2B, 0x2);
118
119
// outw(nam_base + 0x00, 0xFF);
120
121
// outw(nam_base + 0x18, 0x0);
122
123
// buf = (bufer_list *)VIRT2PHYS(phys_base_alloc(1 + (sizeof(bufer_list) * 32) / 4096));
124
125
// extended_cap = inw(nam_base + 0x28);
126
// serial_trace("extended cap : 0x%x\n", extended_cap);
127
// if ((extended_cap & 0x1) == 0x1)
128
// {
129
// outw(nam_base + 0x2A, 0x1);
130
// }
131
132
// // get number of AUX_OUT volume steps
133
// uint32_t ac97_aux_out_number_of_volume_steps = 31;
134
// outw(nam_base + 0x04, 0x2020);
135
// if ((inw(nam_base + 0x04) & 0x2020) == 0x2020)
136
// {
137
// ac97_aux_out_number_of_volume_steps = 63;
138
// }
139
// serial_trace("AC97 AUX_OUT number of volume steps: %d\n",
140
// ac97_aux_out_number_of_volume_steps);
141
142
// serial_trace("AC997 driver initialized\n\n");
143
// }
kernel
hal
sound
sb16.c
Generated on Sat May 30 2026 11:09:57 for Voxia OS by
1.13.2