major refactorings

Signed-off-by: kaguya3311 <kaguya3311@national.shitposting.agency>
This commit is contained in:
kaguya
2026-05-18 04:02:59 -04:00
parent f7aa6f913a
commit b28a6bcf29
211 changed files with 17699 additions and 8107 deletions
+53
View File
@@ -0,0 +1,53 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "hda.h"
/*
* Minimal WAV (RIFF/WAVE) header types.
* pcm_play_file() autodetects RIFF/WAVE and falls back to raw PCM if the
* magic bytes aren't present.
*/
typedef struct __attribute__((packed)) {
char chunk_id[4]; /* "RIFF" */
uint32_t chunk_size; /* file size 8 */
char format[4]; /* "WAVE" */
} wav_riff_t;
typedef struct __attribute__((packed)) {
char chunk_id[4]; /* "fmt " */
uint32_t chunk_size; /* 16 for PCM */
uint16_t audio_format; /* 1 = PCM (linear) */
uint16_t channels;
uint32_t sample_rate;
uint32_t byte_rate; /* sample_rate * channels * bits_per_sample / 8 */
uint16_t block_align;
uint16_t bits_per_sample;
} wav_fmt_chunk_t;
/*
* pcm_play_file - read a file from the ext2 root directory and play it via HDA.
*
* Supports:
* • WAV any PCM WAV (no compression): sample rate / channels / bit depth
* are read from the "fmt " chunk automatically.
* • Raw no RIFF header; audio is assumed to be 48 000 Hz, 16-bit, stereo.
* Override with pcm_play_raw() if file has a different format.
*
* The function allocates a physically-contiguous DMA buffer, reads the file,
* starts playback, blocks until complete, then frees the buffer.
*
* @filename : name of the file in the ext2 root directory (e.g. "music.wav").
* Returns : true on success.
*/
bool pcm_play_file(const char *filename);
/*
* pcm_play_raw - same as pcm_play_file but forces the given format instead of
* auto-detecting from a WAV header. Useful for headerless .pcm files.
*
* @filename : file in ext2 root.
* @fmt : sample rate / channels / bit depth.
*/
bool pcm_play_raw(const char *filename, hda_format_t fmt);