Пример #1
0
//Static function
static void _remove_if_exists(libconfig::Setting &setting,
			      const std::string& alias)
{
  if(setting.exists(alias))
    setting.remove(alias);
}
Пример #2
0
void output_ao::setup(libconfig::Setting& setting)
{
    int channels;
    int rate;
    int bps;
    std::string driver;
    
    if (setting.lookupValue("channels", channels)) {
        setting.remove("channels");
        format.channels = channels;
    }
    else {
        format.channels = DEFAULT_GLOBAL_CHANNELS;
    }
    
    if (setting.lookupValue("rate", rate)) {
        setting.remove("rate");
        format.rate = rate;
    }
    else {
        format.rate = 44100;
    }
    
    if (setting.lookupValue("bps", bps)) {
        setting.remove("bps");
        format.bits = bps;
    }
    else {
        format.bits = 16;
    }
    
    format.byte_format = AO_FMT_LITTLE;
    
    if (setting.lookupValue("driver", driver)) {
        setting.remove("driver");
        driver = ao_driver_id(driver.c_str());
    }
    else {
        driver = ao_default_driver_id();
    }
    
    int length = setting.getLength();

    ao_option *current = NULL;
    
    for (int i = 0; i < length; i++) {
        libconfig::Setting& s = setting[i];

        if (current == NULL) {
            current = new ao_option;
            options = current;
        }
        else {
            current->next = new ao_option;
        }

        std::string key = s.getName();
        std::string value = s;

        current->key = new char[key.size() + 1];
        current->value = new char[value.size() + 1];

        ::strncpy(current->key, key.c_str(), key.size());
        ::strncpy(current->value, value.c_str(), value.size());
    }
}