Ticket #9134: hda_driver.diff

File hda_driver.diff, 5.4 KB (added by Pete, 8 years ago)

Patch to add settings file to HDA driver

  • src/add-ons/kernel/drivers/audio/hda/device.cpp

    diff --git a/src/add-ons/kernel/drivers/audio/hda/device.cpp b/src/add-ons/kernel/drivers/audio/hda/device.cpp
    index aeb0996..5966a92 100644
    a b hda_open(const char* name, uint32 flags, void** cookie)  
    3535    atomic_add(&controller->opened, 1);
    3636
    3737    *cookie = controller;
     38
     39    get_settings_from_file();   // optional user-settable sample rate, buffer frames and count
     40
    3841    return B_OK;
    3942}
    4043
  • src/add-ons/kernel/drivers/audio/hda/driver.h

    diff --git a/src/add-ons/kernel/drivers/audio/hda/driver.h b/src/add-ons/kernel/drivers/audio/hda/driver.h
    index 6152903..64eaa77 100644
    a b void hda_codec_delete(hda_codec* codec);  
    348348
    349349/* hda_multi_audio.c */
    350350status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t length);
     351void get_settings_from_file();
    351352
    352353/* hda_controller.c: Basic controller support */
    353354status_t hda_hw_init(hda_controller* controller);
  • src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp

    diff --git a/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp b/src/add-ons/kernel/drivers/audio/hda/hda_multi_audio.cpp
    index 0c50f8b..5f372fd 100644
    a b  
    88 */
    99
    1010
     11#include <driver_settings.h>
     12
    1113#include "hmulti_audio.h"
    1214#include "driver.h"
    1315
    format2size(uint32 format)  
    6971}
    7072
    7173
     74#define HDA_SETTINGS "hda.settings"
     75
     76static struct {
     77    int32 play_sample_rate;
     78    int32 play_buffer_frames;
     79    int32 play_buffer_count;
     80    int32 record_sample_rate;
     81    int32 record_buffer_frames;
     82    int32 record_buffer_count;
     83} requested_settings;
     84
     85
     86static uint32
     87fps_to_ratecode(uint32 fps)
     88{
     89    switch (fps) {
     90    case 8000:
     91        return B_SR_8000;
     92    case 11025:
     93        return B_SR_11025;
     94    case 16000:
     95        return B_SR_16000;
     96    case 22050:
     97        return B_SR_22050;
     98    case 32000:
     99        return B_SR_32000;
     100    case 44100:
     101        return B_SR_44100;
     102    case 48000:
     103        return B_SR_48000;
     104    case 88200:
     105        return B_SR_88200;
     106    case 96000:
     107        return B_SR_96000;
     108    case 176400:
     109        return B_SR_176400;
     110    case 192000:
     111        return B_SR_192000;
     112    case 384000:
     113        return B_SR_384000;
     114    }
     115    return 0;
     116}
     117
     118
     119void
     120get_settings_from_file()
     121{
     122    const char *item;
     123    char       *end;
     124    uint32      value;
     125   
     126    memset(&requested_settings, 0, sizeof(requested_settings));
     127    dprintf("looking for settings file\n");
     128   
     129    void *settings_handle = load_driver_settings(HDA_SETTINGS);
     130    if (settings_handle == NULL)
     131        return;
     132
     133    item = get_driver_parameter (settings_handle, "play_sample_rate", "0", "192000");
     134    if (item) {
     135    value = strtoul (item, &end, 0);
     136    if (*end == '\0')
     137        requested_settings.play_sample_rate = value ? fps_to_ratecode(value) : 0;
     138    }
     139
     140    item = get_driver_parameter (settings_handle, "play_buffer_frames", "0", "10240");
     141    if (item) {
     142    value = strtoul (item, &end, 0);
     143    if (*end == '\0')
     144        requested_settings.play_buffer_frames = value;
     145    }
     146
     147    item = get_driver_parameter (settings_handle, "play_buffer_count", "0", "4");
     148    value = strtoul (item, &end, 0);
     149    if (*end == '\0')
     150        requested_settings.play_buffer_count = value;
     151
     152    item = get_driver_parameter (settings_handle, "record_sample_rate", "0", "192000");
     153    value = strtoul (item, &end, 0);
     154    if (*end == '\0')
     155        requested_settings.record_sample_rate = value ? fps_to_ratecode(value) : 0;
     156
     157    item = get_driver_parameter (settings_handle, "record_buffer_frames", "0", "10240");
     158    value = strtoul (item, &end, 0);
     159    if (*end == '\0')
     160        requested_settings.record_buffer_frames = value;
     161
     162    item = get_driver_parameter (settings_handle, "record_buffer_count", "0", "4");
     163    value = strtoul (item, &end, 0);
     164    if (*end == '\0')
     165        requested_settings.record_buffer_count = value;
     166
     167    unload_driver_settings(settings_handle);
     168}
     169
     170
    72171static status_t
    73172get_description(hda_audio_group* audioGroup, multi_description* data)
    74173{
    get_description(hda_audio_group* audioGroup, multi_description* data)  
    107206        data->output_rates = 0;
    108207        data->output_formats = 0;
    109208    }
     209   
     210    if (requested_settings.play_sample_rate != 0)
     211        data->output_rates = requested_settings.play_sample_rate;
    110212
    111213    if (audioGroup->record_stream != NULL) {
    112214        data->input_rates = audioGroup->record_stream->sample_rate;
    get_description(hda_audio_group* audioGroup, multi_description* data)  
    116218        data->input_formats = 0;
    117219    }
    118220
     221    if (requested_settings.record_sample_rate != 0)
     222        data->input_rates = requested_settings.record_sample_rate;
     223
    119224    // force existance of 48kHz if variable rates are not supported
    120225    if (data->output_rates == 0)
    121226        data->output_rates = B_SR_48000;
    default_buffer_length_for_rate(uint32 rate)  
    865970static status_t
    866971get_buffers(hda_audio_group* audioGroup, multi_buffer_list* data)
    867972{
     973    if (requested_settings.play_buffer_frames != 0)
     974        data->request_playback_buffer_size = requested_settings.play_buffer_frames;
     975
     976    if (requested_settings.play_buffer_count != 0)
     977        data->request_playback_buffers = requested_settings.play_buffer_count;
     978
     979    if (requested_settings.record_buffer_frames != 0)
     980        data->request_record_buffer_size = requested_settings.record_buffer_frames;
     981
     982    if (requested_settings.record_buffer_count != 0)
     983        data->request_record_buffers = requested_settings.record_buffer_count;
     984
    868985    TRACE("playback: %ld buffers, %ld channels, %ld samples\n",
    869986        data->request_playback_buffers, data->request_playback_channels,
    870987        data->request_playback_buffer_size);