예제 #1
0
void
ConfigManager::set_master_volume(int v)
{
  log_info("ConfigManager::set_master_volume: %1%", v);
  Sound::PingusSound::set_master_volume(static_cast<float>(v) / 100.0f);

  m_opts.master_volume.set(get_master_volume());
}
예제 #2
0
int main(int argc, char **argv)
{
    int hwdep_fd;
    snd_ctl_t *ctl;

    (void) argc;
    (void) argv;

    // Setup the signal handler
    struct sigaction sa = { 0 };
    sa.sa_handler = &handle_signal;

    // Handle standard signals to quit properly
    sigemptyset(&sa.sa_mask);
    sigaction(SIGINT,  &sa, NULL);
    sigaction(SIGHUP,  &sa, NULL);
    sigaction(SIGTERM, &sa, NULL);

    // Open control and hwdep devices
    if (open_hwdep(Y50_HWDEP_DEVICE, &hwdep_fd) != 0
            || open_ctl(Y50_CTL_NAME, &ctl) != 0) {
        return 1;
    }

    // Initialize subwoofer
    lfe_initialize(hwdep_fd);

    // Set initial values
    set_headphones_plugged(&headphones_plugged);
    set_lfe_volume(hwdep_fd, headphones_plugged ? 0 : get_master_volume());

    // Poll events
    while (!doneflag) {
        struct pollfd fds;
        snd_ctl_poll_descriptors(ctl, &fds, 1);

        if (poll(&fds, 1, -1) <= 0) {
            if (errno == EINTR) {
                continue;
            } else {
                perror("poll");
                break;
            }
        }

        unsigned short revents;
        snd_ctl_poll_descriptors_revents(ctl, &fds, 1, &revents);
        if (revents & POLLIN) {
            handle_event(hwdep_fd, ctl);
        }
    }

    // Close resources
    close(hwdep_fd);
    snd_ctl_close(ctl);

    return EXIT_SUCCESS;
}
예제 #3
0
void master_sound_volume (int dir) {
    int vol, mute, r;

    r = get_master_volume (&vol, &mute);
    if (!r)
            return;
    if (dir == 0)
            mute = mute ? 0 : 1;
    vol += dir * (65536 / 10);
    if (vol < 0)
            vol = 0;
    if (vol > 65535)
            vol = 65535;
    set_master_volume (vol, mute);
    config_changed = 1;
}
예제 #4
0
static int handle_event(int hwdep_fd, snd_ctl_t *ctl)
{
    snd_ctl_event_t *event;
    unsigned int mask;
    int err;

    snd_ctl_event_alloca(&event);
    err = snd_ctl_read(ctl, event);
    if (err < 0) {
        fprintf(stderr, "Cannot read event from ctl %s\n", snd_ctl_name(ctl));
        return err;
    }

    if (snd_ctl_event_get_type(event) != SND_CTL_EVENT_ELEM) {
        return 0;
    }

    // Filter events
    mask = snd_ctl_event_elem_get_mask(event);
    if (mask & SND_CTL_EVENT_MASK_VALUE) {
        const char *event_name = snd_ctl_event_elem_get_name(event);

        if (!strcmp(event_name, HEADPHONE_SWITCH_NAME)) {
            // If headphones were plugged, mute LFE
            set_headphones_plugged(&headphones_plugged);
            if (headphones_plugged) {
                set_lfe_volume(hwdep_fd, 0);
            }
        } else if (!headphones_plugged && !strcmp(event_name, MASTER_VOLUME_NAME)) {
            // If headphones are unplugged and master volume changed, adjust LFE volume
            set_lfe_volume(hwdep_fd, get_master_volume());
        }
    }

    return 0;
}
예제 #5
0
static PxVolume get_output_volume(px_mixer *Px, int i)
{
   return get_master_volume(Px);
}