mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 10:45:08 +00:00

We have 3 new components: 1. The AudioManagement singleton. This class like in other subsystems, is responsible to find hardware audio controllers and keep a reference to them. 2. AudioController class - this class is the parent class for hardware controllers like the Sound Blaster 16 or Intel 82801AA (AC97). For now, this class has simple interface for getting and controlling sample rate of audio channels, as well a write interface for specific audio channel but not reading from it. One AudioController object might have multiple AudioChannel "child" objects to hold with reference counting. 3. AudioChannel class - this is based on the CharacterDevice class, and represents hardware PCM audio channel. It facilitates an ioctl interface which should be consistent across all supported hardware currently. It has a weak reference to a parent AudioController, and when trying to write to a channel, it redirects the data to the parent AudioController. Each audio channel device should be added into a new directory under the /dev filesystem called "audio".
43 lines
1.3 KiB
C++
43 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Kernel/Devices/CharacterDevice.h>
|
|
#include <Kernel/Interrupts/IRQHandler.h>
|
|
#include <Kernel/Memory/PhysicalPage.h>
|
|
#include <Kernel/PhysicalAddress.h>
|
|
#include <Kernel/WaitQueue.h>
|
|
|
|
namespace Kernel {
|
|
|
|
class AudioController;
|
|
class AudioChannel final
|
|
: public CharacterDevice {
|
|
friend class DeviceManagement;
|
|
|
|
public:
|
|
static NonnullRefPtr<AudioChannel> must_create(AudioController const&, size_t channel_index);
|
|
virtual ~AudioChannel() override { }
|
|
|
|
// ^CharacterDevice
|
|
virtual bool can_read(const OpenFileDescription&, u64) const override;
|
|
virtual ErrorOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
|
virtual ErrorOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
|
virtual bool can_write(const OpenFileDescription&, u64) const override { return true; }
|
|
|
|
virtual ErrorOr<void> ioctl(OpenFileDescription&, unsigned, Userspace<void*>) override;
|
|
|
|
private:
|
|
AudioChannel(AudioController const&, size_t channel_index);
|
|
|
|
// ^CharacterDevice
|
|
virtual StringView class_name() const override { return "AudioChannel"sv; }
|
|
|
|
WeakPtr<AudioController> m_controller;
|
|
const size_t m_channel_index;
|
|
};
|
|
}
|