mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 14:54:59 +00:00

This is an implementation that tries to follow the spec as closely as possible, and works with Qemu's Intel HDA and some bare metal HDA controllers out there. Compiling with `INTEL_HDA_DEBUG=on` will provide a lot of detailed information that could help us getting this to work on more bare metal controllers as well :^) Output format is limited to `i16` samples for now.
30 lines
906 B
C++
30 lines
906 B
C++
/*
|
|
* Copyright (c) 2023, Jelle Raaijmakers <jelle@gmta.nl>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Error.h>
|
|
#include <AK/Function.h>
|
|
|
|
namespace Kernel::Audio::IntelHDA {
|
|
|
|
// We define an arbitrary controller timeout of 300ms for most actions.
|
|
constexpr size_t controller_timeout_in_microseconds = 300'000;
|
|
|
|
consteval u32 frame_delay_in_microseconds(u32 frames)
|
|
{
|
|
// NOTE: the link operates at this _fixed_ frequency and is independent of the streams' rates.
|
|
constexpr u32 link_frame_frequency_hz = 48'000;
|
|
|
|
// 2.2: Streams and Channels
|
|
// A new frame starts exactly every 20.83 μs, corresponding to the common 48-kHz sample rate.
|
|
VERIFY(frames <= 4294);
|
|
return frames * 1'000'000u / link_frame_frequency_hz + 1u;
|
|
}
|
|
|
|
ErrorOr<void> wait_until(size_t delay_in_microseconds, size_t timeout_in_microseconds, Function<ErrorOr<bool>()> condition);
|
|
|
|
}
|