本文整理汇总了C++中snd_mixer_selem_get_playback_volume_range函数的典型用法代码示例。如果您正苦于以下问题:C++ snd_mixer_selem_get_playback_volume_range函数的具体用法?C++ snd_mixer_selem_get_playback_volume_range怎么用?C++ snd_mixer_selem_get_playback_volume_range使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了snd_mixer_selem_get_playback_volume_range函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: elem_set_vol_percent
static void elem_set_vol_percent(snd_mixer_elem_t *elem, int vol_percent)
{
int i;
long pmin, pmax, value;
//sdbg("%s: set mixer element volume\n", __func__);
for (i = 0; i <= SND_MIXER_SCHN_LAST; i++) {
if (snd_mixer_selem_has_playback_channel(elem, i) &&
!snd_mixer_selem_has_common_volume(elem)) {
snd_mixer_selem_get_playback_volume_range(elem, &pmin, &pmax);
/* playback volume */
if (snd_mixer_selem_has_playback_volume(elem)) {
value = (int)rint((double)pmin + 0.01 * vol_percent * ((double)pmax - (double)pmin));
snd_mixer_selem_set_playback_volume(elem, i, value);
}
} else if (snd_mixer_selem_has_capture_channel(elem, i) &&
!snd_mixer_selem_has_common_volume(elem)) {
/* capture volume */
snd_mixer_selem_get_capture_volume_range(elem, &pmin, &pmax);
if (snd_mixer_selem_has_capture_volume(elem)) {
value = (int)rint((double)pmin + 0.01 * vol_percent * ((double)pmax - (double)pmin));
snd_mixer_selem_set_capture_volume(elem, i, value);
}
} else {
/* Misc. ex: Boost */
snd_mixer_selem_get_playback_volume_range(elem, &pmin, &pmax);
value = (int)rint((double)pmin + 0.01 * vol_percent * ((double)pmax - (double)pmin));
snd_mixer_selem_set_playback_volume(elem, i, value);
snd_mixer_selem_get_capture_volume_range(elem, &pmin, &pmax);
value = (int)rint((double)pmin + 0.01 * vol_percent * ((double)pmax - (double)pmin));
snd_mixer_selem_set_capture_volume(elem, i, value);
}
}
}
示例2: elem_get_vol_percent
static int elem_get_vol_percent(snd_mixer_elem_t *elem)
{
int i, percent;
long pmin, pmax, volume;
for (i = 0; i <= SND_MIXER_SCHN_LAST; i++) {
/* playback volume */
if (snd_mixer_selem_has_playback_channel(elem, i) &&
!snd_mixer_selem_has_common_volume(elem)) {
snd_mixer_selem_get_playback_volume_range(elem, &pmin, &pmax);
if (snd_mixer_selem_has_playback_volume(elem))
snd_mixer_selem_get_playback_volume(elem, i, &volume);
}
/* capture volume */
else if (snd_mixer_selem_has_capture_channel(elem, i) &&
!snd_mixer_selem_has_common_volume(elem)) {
snd_mixer_selem_get_capture_volume_range(elem, &pmin, &pmax);
if (snd_mixer_selem_has_capture_volume(elem))
snd_mixer_selem_get_capture_volume(elem, i, &volume);
} else {
/* Misc. ex: Boost */
snd_mixer_selem_get_playback_volume_range(elem, &pmin, &pmax);
snd_mixer_selem_get_playback_volume(elem, i, &volume);
}
}
percent = (int) ((double)(volume - pmin) / (double)(pmax - pmin) * 100);
return percent;
}
示例3: set_volume
void set_volume(GtkAdjustment *adjustment, gpointer user_data)
{
int value = (int) 100 - gtk_adjustment_get_value(adjustment);
g_debug("Setting master volume to: %d", value);
if(value == 0)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(s_mute), TRUE);
else
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(s_mute), FALSE);
long min, max;
snd_mixer_t *mix;
snd_mixer_selem_id_t *sid;
const char *card = "default";
const char *selem_name = "Master";
snd_mixer_open(&mix, 0);
snd_mixer_attach(mix, card);
snd_mixer_selem_register(mix, NULL, NULL);
snd_mixer_load(mix);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(mix, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
snd_mixer_selem_set_playback_volume_all(elem, value * max / 100);
snd_mixer_close(mix);
}
示例4: _j4status_alsa_section_elem_callback
static gint
_j4status_alsa_section_elem_callback(snd_mixer_elem_t *elem, guint mask)
{
J4statusAlsaSection *section = snd_mixer_elem_get_callback_private(elem);
if ( mask == SND_CTL_EVENT_MASK_REMOVE )
return 0;
if ( mask & SND_CTL_EVENT_MASK_INFO )
{
glong min, max;
int error;
error = snd_mixer_selem_get_playback_dB_range(elem, &min, &max);
if ( ( error == 0 ) && ( min < max ) )
section->use_dB = TRUE;
else
{
section->use_dB = FALSE;
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
}
section->min = min;
section->max = max;
}
if ( mask & SND_CTL_EVENT_MASK_VALUE )
_j4status_alsa_section_update(section, elem);
return 0;
}
示例5: get_volume
/**
* @brief Get the Volume for the master channel.
*
* This function uses the Alsa API to get the volume
* for the master channel.
*
* @param [out] ptr pointer to long, output will be between 0 and 99.
* @return Void.
*/
void get_volume(long *ptr){
long min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
const char *card = "default";
//const char *selem_name = "Master";
const char *selem_name = "DAC2 Digital Course";
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, card);
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
printd("Volume range <%lu,%lu>\n", min, max);
snd_mixer_selem_get_playback_volume(elem,0,ptr);
printd("volume val = %lu\n",*ptr);
*ptr /= (max / 100);
snd_mixer_close(handle);
}
示例6: snd_mixer_open
char *getvolume() {
char *buf;
int active;
long volume, min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
snd_mixer_elem_t* elem;
const char *card = "default";
const char *selem_name = "Master";
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, card);
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &volume);
snd_mixer_selem_get_playback_switch(elem, SND_MIXER_SCHN_FRONT_LEFT, &active);
buf = xmalloc(10);
if (active)
snprintf(buf, 10, "%0.f%%", (double) volume / (double) max * 100);
else
snprintf(buf, 10, "off");
snd_mixer_close(handle);
return buf;
}
示例7: volume_up
int volume_up(int vol_min, int vol_max)
{
long min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
const char *card = "default";
const char *selem_name = "Master";
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, card);
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
for (int i = vol_min; i<vol_max; i++) {
int v = i*max /100;
snd_mixer_selem_set_playback_volume_all(elem, v);
//printf("min = %d, max= %d, volume = %d\n", min, max, volume);
usleep(50000);
}
snd_mixer_close(handle);
}
示例8: volume_set
int volume_set(int volume)
{
long min, max;
snd_mixer_t *handle;
snd_mixer_selem_id_t *sid;
const char *card = "default";
//const char *selem_name = "Master";
const char *selem_name = "Digital";
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, card);
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
int v = volume*max /100;
snd_mixer_selem_set_playback_volume_all(elem, v);
snd_mixer_close(handle);
return v;
}
示例9: get_volume_indexed
static PxVolume get_volume_indexed(PxDev *dev, int i, int playback)
{
snd_mixer_elem_t *elem;
long vol, min, max;
if (!dev->handle) {
return 0.0;
}
if (i < 0 || i > dev->numselems) {
return 0.0;
}
elem = dev->selems[i].elem;
if (playback) {
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
if (snd_mixer_selem_has_playback_channel(elem, SND_MIXER_SCHN_FRONT_LEFT)) {
snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &vol);
return (PxVolume) vol / (max - min);
}
}
else {
snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
if (snd_mixer_selem_has_capture_channel(elem, SND_MIXER_SCHN_FRONT_LEFT)) {
snd_mixer_selem_get_capture_volume(elem, SND_MIXER_SCHN_FRONT_LEFT, &vol);
return (PxVolume) vol / (max - min);
}
}
return 0.0;
}
示例10: get_master_volume
static long get_master_volume()
{
snd_mixer_t *handle;
snd_mixer_open(&handle, 0);
snd_mixer_attach(handle, Y50_CTL_NAME);
snd_mixer_selem_register(handle, NULL, NULL);
snd_mixer_load(handle);
snd_mixer_selem_id_t *master_sid;
const char *master_selem_name = "Master";
snd_mixer_selem_id_alloca(&master_sid);
snd_mixer_selem_id_set_index(master_sid, 0);
snd_mixer_selem_id_set_name(master_sid, master_selem_name);
snd_mixer_elem_t* elem = snd_mixer_find_selem(handle, master_sid);
long min, max;
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
long volume;
snd_mixer_selem_get_playback_volume(elem, SND_MIXER_SCHN_MONO, &volume);
snd_mixer_close(handle);
return volume * 100 / max;
}
示例11: min
SIDInfo::SIDInfo(snd_mixer_t* handle, snd_mixer_selem_id_t* sid) :
min(0), max(0), globalMax(0), hasMute(false), hasVolume(false),
_isEmulMuted(false), _lastVol(0), _handle(handle), _sid(sid)
{
if (!_sid) return;
snd_mixer_elem_t *elem;
elem = snd_mixer_find_selem(_handle, _sid);
if (!elem) return;
if (snd_mixer_selem_has_playback_volume(elem))
{
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
if (max > min) hasVolume = true;
else min = max = 0;
}
_lastVol = min;
if (snd_mixer_selem_has_playback_switch(elem))
{
hasMute = true;
}
}
示例12: alsa_mixer_is_muted
static gboolean alsa_mixer_is_muted(snd_mixer_elem_t *elem, gboolean *need_reset) {
int sw;
long Rvol, Lvol, min, max;
if(need_reset)
*need_reset = FALSE;
/**if switch is available, get switch status directly*/
if(snd_mixer_selem_has_playback_switch(elem)) {
snd_mixer_selem_get_playback_switch(elem, 0, &sw);
return sw ? FALSE: TRUE;
} else if(snd_mixer_selem_has_capture_switch(elem)) {
snd_mixer_selem_get_capture_switch(elem, 0, &sw);
return sw ? FALSE: TRUE;
}
if(snd_mixer_selem_has_playback_volume(elem)) {
snd_mixer_selem_get_playback_volume(elem, 0, &Rvol);
snd_mixer_selem_get_playback_volume(elem, 1, &Lvol);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
if(need_reset)
*need_reset = !!(max - Rvol);
return (Rvol + Lvol) ? FALSE: TRUE;
} else if(snd_mixer_selem_has_capture_volume(elem)) {
snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
snd_mixer_selem_get_capture_volume(elem, 0, &Rvol);
snd_mixer_selem_get_capture_volume(elem, 1, &Lvol);
if(need_reset)
*need_reset = !!(max - Rvol);
return (Rvol + Lvol) ? FALSE: TRUE;
}
}
示例13: alsa_mixer_set_muted
static int alsa_mixer_set_muted(snd_mixer_elem_t *elem, gboolean muted) {
long val, min, max;
/**if switch is available, get switch status directly*/
if(snd_mixer_selem_has_playback_switch(elem)) {
snd_mixer_selem_set_playback_switch(elem, 0, !muted);
snd_mixer_selem_set_playback_switch(elem, 1, !muted);
return 0;
} else if(snd_mixer_selem_has_capture_switch(elem)) {
snd_mixer_selem_set_capture_switch(elem, 0, !muted);
snd_mixer_selem_set_capture_switch(elem, 1, !muted);
return 0;
}
if(snd_mixer_selem_has_playback_volume(elem)) {
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
val = muted ? min : max;
snd_mixer_selem_set_playback_volume(elem, 0, val);
snd_mixer_selem_set_playback_volume(elem, 1, val);
return 0;
} else if(snd_mixer_selem_has_capture_volume(elem)) {
snd_mixer_selem_get_capture_volume_range(elem, &min, &max);
val = muted ? min : max;
snd_mixer_selem_set_capture_volume(elem, 0, val);
snd_mixer_selem_set_capture_volume(elem, 1, val);
return 0;
}
return -1;
}
示例14: set_volume
void set_volume(int vol)
{
long min, max;
snd_mixer_t *handlev;
snd_mixer_selem_id_t *sid;
const char *card = "default";
const char *selem_name = "Master";
if (vol < 1 || vol > 100) {
printf("ERROR: Volume out of range [0,100] %%\n");
printf("\tSetting volume to 50%%...\n");
vol = 50;
}
snd_mixer_open(&handlev, 0);
snd_mixer_attach(handlev, card);
snd_mixer_selem_register(handlev, NULL, NULL);
snd_mixer_load(handlev);
snd_mixer_selem_id_alloca(&sid);
snd_mixer_selem_id_set_index(sid, 0);
snd_mixer_selem_id_set_name(sid, selem_name);
snd_mixer_elem_t *elem = snd_mixer_find_selem(handlev, sid);
snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
snd_mixer_selem_set_playback_volume_all(elem, vol * max / 100 + min);
snd_mixer_close(handlev);
}
示例15: toggle_volume
/* Volume toggler between 0 <--> element default volume.
* Now excepts new_vol to be in default hardware range of the sound card in use. */
void toggle_volume(
struct sound_profile* sp,
long int const new_vol, // If INT_MAX or negative then toggle to sound
// profiles default volume
enum Volume_type volume_type)
{
// TODO: USE "avolt" SEMAPHORE
long int current_vol;
get_vol(sp->volume_cntrl_mixer_element, hardware, ¤t_vol);
long int min, _;
snd_mixer_selem_get_playback_volume_range(sp->volume_cntrl_mixer_element, &min, &_);
// If current volume is lowest possible
if (current_vol == min) {
if (new_vol > 0 && new_vol != INT_MAX)
set_vol(sp->volume_cntrl_mixer_element, volume_type, new_vol, 0);
else
set_vol(sp->volume_cntrl_mixer_element, sp->volume_type, sp->default_volume, 0);
}
else {
// Else zero current volume
set_vol(sp->volume_cntrl_mixer_element, hardware_percentage, 0, 0);
}
return;
}