Kernel: Set audio sample rate to 44.1 KHz by default

Ideally, we would want the audio controller to run a channel at a
device's initial sample rate instead of hardcoding 44.1 KHz. However,
most audio is provided at 44.1 KHz and as long as `Audio::Resampler`
introduces significant audio artifacts, let's set a sensible sample
rate that offers a better experience for most users.

This can be removed after someone implements a higher quality
`Audio::Resampler`.
This commit is contained in:
Jelle Raaijmakers 2023-06-19 21:13:39 +02:00 committed by Andreas Kling
parent 2133bae1a4
commit 4a86861a9d
Notes: sideshowbarker 2024-07-17 03:03:15 +09:00
2 changed files with 11 additions and 3 deletions

View file

@ -86,8 +86,6 @@ UNMAP_AFTER_INIT ErrorOr<void> AC97::initialize(Badge<AudioManagement>)
dbgln_if(AC97_DEBUG, "AC97 @ {}: mixer base: {:#04x}", device_identifier().address(), m_mixer_io_window);
dbgln_if(AC97_DEBUG, "AC97 @ {}: bus base: {:#04x}", device_identifier().address(), m_bus_io_window);
m_audio_channel = TRY(AudioChannel::create(*this, 0));
// Read out AC'97 codec revision and vendor
auto extended_audio_id = m_mixer_io_window->read16(NativeAudioMixerRegister::ExtendedAudioID);
m_codec_revision = static_cast<AC97Revision>(((extended_audio_id & ExtendedAudioMask::Revision) >> 10) & 0b11);
@ -133,6 +131,8 @@ UNMAP_AFTER_INIT ErrorOr<void> AC97::initialize(Badge<AudioManagement>)
m_pcm_out_channel->reset();
enable_irq();
m_audio_channel = TRY(AudioChannel::create(*this, 0));
return {};
}

View file

@ -15,7 +15,15 @@ namespace Kernel {
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<AudioChannel>> AudioChannel::create(AudioController const& controller, size_t channel_index)
{
return *TRY(DeviceManagement::try_create_device<AudioChannel>(controller, channel_index));
auto channel = TRY(DeviceManagement::try_create_device<AudioChannel>(controller, channel_index));
// FIXME: Ideally, we would want the audio controller to run a channel at a device's initial sample
// rate instead of hardcoding 44.1 KHz here. However, most audio is provided at 44.1 KHz and as
// long as Audio::Resampler introduces significant audio artifacts, let's set a sensible sample
// rate here. Remove this after implementing a higher quality Audio::Resampler.
TRY(const_cast<AudioController&>(controller).set_pcm_output_sample_rate(channel_index, 44100));
return *channel;
}
AudioChannel::AudioChannel(AudioController const& controller, size_t channel_index)