Files
2026-05-18 04:02:59 -04:00

53 lines
2.0 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#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);