[vorbis] selecting driver for ao

rik at kde.org rik at kde.org
Sat Dec 30 07:47:07 PST 2000



I added a couple of functions to my copy of ao.
int ao_get_driver_count(void);
const char * ao_get_driver_name(int index);

With these, I can get a list of drivers and give the user a choice
by using radio buttons, e.g.

[ ] alsa
[*] oss
[ ] esd
[ ] null
[ ] wav

This is a lot nicer than just asking them to enter the name of
the driver.

Here's the code I added to audio_out.c:

const char * ao_get_driver_name(int idx)
{
  int i = 0;
  driver_tree_t * driver = driver_head;

  while (driver)
  {
    if (idx == i)
      return driver->functions->get_driver_info()->short_name;

    ++i;
    driver = driver->next;
  }

  return NULL;
}

int ao_get_driver_count(void)
{
  int i = 0;
  driver_tree_t * driver = driver_head;

  while (driver)
  {
    ++i;
    driver = driver->next;
  }

  return i;
}

Sorry if the API style is not right. I'm used to C++ and Qt.
All this dealing with pointers and linked lists is alien to me,
now that I've been dealing with value-based collections and
implicitly shared string classes for so long :)

It's a shame that C doesn't allow you to make parts of the
driver structures private, so that you can simply give the
user the driver list and be sure that they can't damage it :(

Hmm, I think ao_get_driver_name(int idx) is unnecessary, as
ao_get_driver_info(int driver_id) does what is needed. But
for the user of the API, they can't be sure that 'driver_id'
is actually an index.

It's probably better to just document the fact that driver
indices run from 0...driver_count and let the user use
ao_get_driver_info(). ao_get_driver_count is still necessary,
though.

Rik

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis mailing list