mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-10-31 22:25:33 -04:00
Merge branch 'master' into lennartsbtfixes
This commit is contained in:
commit
3442d583aa
4 changed files with 360 additions and 5 deletions
|
|
@ -110,12 +110,14 @@ pa_cvolume_channels_equal_to;
|
|||
pa_cvolume_compatible;
|
||||
pa_cvolume_equal;
|
||||
pa_cvolume_get_balance;
|
||||
pa_cvolume_get_fade;
|
||||
pa_cvolume_init;
|
||||
pa_cvolume_max;
|
||||
pa_cvolume_remap;
|
||||
pa_cvolume_scale;
|
||||
pa_cvolume_set;
|
||||
pa_cvolume_set_balance;
|
||||
pa_cvolume_set_fade;
|
||||
pa_cvolume_snprint;
|
||||
pa_cvolume_valid;
|
||||
pa_ext_stream_restore_delete;
|
||||
|
|
|
|||
|
|
@ -341,6 +341,28 @@ static pa_bool_t on_lfe(pa_channel_position_t p) {
|
|||
p == PA_CHANNEL_POSITION_LFE;
|
||||
}
|
||||
|
||||
static pa_bool_t on_front(pa_channel_position_t p) {
|
||||
return
|
||||
p == PA_CHANNEL_POSITION_FRONT_LEFT ||
|
||||
p == PA_CHANNEL_POSITION_FRONT_RIGHT ||
|
||||
p == PA_CHANNEL_POSITION_FRONT_CENTER ||
|
||||
p == PA_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER ||
|
||||
p == PA_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER ||
|
||||
p == PA_CHANNEL_POSITION_TOP_FRONT_LEFT ||
|
||||
p == PA_CHANNEL_POSITION_TOP_FRONT_RIGHT ||
|
||||
p == PA_CHANNEL_POSITION_TOP_FRONT_CENTER;
|
||||
}
|
||||
|
||||
static pa_bool_t on_rear(pa_channel_position_t p) {
|
||||
return
|
||||
p == PA_CHANNEL_POSITION_REAR_LEFT ||
|
||||
p == PA_CHANNEL_POSITION_REAR_RIGHT ||
|
||||
p == PA_CHANNEL_POSITION_REAR_CENTER ||
|
||||
p == PA_CHANNEL_POSITION_TOP_REAR_LEFT ||
|
||||
p == PA_CHANNEL_POSITION_TOP_REAR_RIGHT ||
|
||||
p == PA_CHANNEL_POSITION_TOP_REAR_CENTER;
|
||||
}
|
||||
|
||||
pa_cvolume *pa_cvolume_remap(pa_cvolume *v, const pa_channel_map *from, const pa_channel_map *to) {
|
||||
int a, b;
|
||||
pa_cvolume result;
|
||||
|
|
@ -487,12 +509,12 @@ pa_cvolume* pa_cvolume_set_balance(pa_cvolume *v, const pa_channel_map *map, flo
|
|||
for (c = 0; c < map->channels; c++) {
|
||||
if (on_left(map->map[c])) {
|
||||
if (left == 0)
|
||||
v->values[c] = 0;
|
||||
v->values[c] = nleft;
|
||||
else
|
||||
v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nleft) / (uint64_t) left);
|
||||
} else if (on_right(map->map[c])) {
|
||||
if (right == 0)
|
||||
v->values[c] = 0;
|
||||
v->values[c] = nright;
|
||||
else
|
||||
v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nright) / (uint64_t) right);
|
||||
}
|
||||
|
|
@ -505,7 +527,7 @@ pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) {
|
|||
unsigned c;
|
||||
pa_volume_t t = 0;
|
||||
|
||||
pa_assert(c);
|
||||
pa_assert(v);
|
||||
|
||||
for (c = 0; c < v->channels; c++)
|
||||
if (v->values[c] > t)
|
||||
|
|
@ -519,3 +541,92 @@ pa_cvolume* pa_cvolume_scale(pa_cvolume *v, pa_volume_t max) {
|
|||
|
||||
return v;
|
||||
}
|
||||
|
||||
static void get_avg_fr(const pa_channel_map *map, const pa_cvolume *v, pa_volume_t *f, pa_volume_t *r) {
|
||||
int c;
|
||||
pa_volume_t front = 0, rear = 0;
|
||||
unsigned n_front = 0, n_rear = 0;
|
||||
|
||||
pa_assert(v);
|
||||
pa_assert(map);
|
||||
pa_assert(map->channels == v->channels);
|
||||
pa_assert(f);
|
||||
pa_assert(r);
|
||||
|
||||
for (c = 0; c < map->channels; c++) {
|
||||
if (on_front(map->map[c])) {
|
||||
front += v->values[c];
|
||||
n_front++;
|
||||
} else if (on_rear(map->map[c])) {
|
||||
rear += v->values[c];
|
||||
n_rear++;
|
||||
}
|
||||
}
|
||||
|
||||
if (n_front <= 0)
|
||||
*f = PA_VOLUME_NORM;
|
||||
else
|
||||
*f = front / n_front;
|
||||
|
||||
if (n_rear <= 0)
|
||||
*r = PA_VOLUME_NORM;
|
||||
else
|
||||
*r = rear / n_rear;
|
||||
}
|
||||
|
||||
float pa_cvolume_get_fade(const pa_cvolume *v, const pa_channel_map *map) {
|
||||
pa_volume_t front, rear;
|
||||
|
||||
pa_assert(v);
|
||||
pa_assert(map);
|
||||
pa_assert(map->channels == v->channels);
|
||||
|
||||
get_avg_fr(map, v, &front, &rear);
|
||||
|
||||
if (front == rear)
|
||||
return 0.0f;
|
||||
|
||||
if (rear > front)
|
||||
return -1.0f + ((float) front / (float) rear);
|
||||
else
|
||||
return 1.0f - ((float) rear / (float) front);
|
||||
}
|
||||
|
||||
pa_cvolume* pa_cvolume_set_fade(pa_cvolume *v, const pa_channel_map *map, float new_fade) {
|
||||
pa_volume_t front, nfront, rear, nrear, m;
|
||||
unsigned c;
|
||||
|
||||
pa_assert(map->channels == v->channels);
|
||||
pa_assert(map);
|
||||
pa_assert(v);
|
||||
pa_assert(new_fade >= -1.0f);
|
||||
pa_assert(new_fade <= 1.0f);
|
||||
|
||||
get_avg_fr(map, v, &front, &rear);
|
||||
|
||||
m = PA_MAX(front, rear);
|
||||
|
||||
if (new_fade <= 0) {
|
||||
nfront = (new_fade + 1.0f) * m;
|
||||
nrear = m;
|
||||
} else {
|
||||
nrear = (1.0f - new_fade) * m;
|
||||
nfront = m;
|
||||
}
|
||||
|
||||
for (c = 0; c < map->channels; c++) {
|
||||
if (on_front(map->map[c])) {
|
||||
if (front == 0)
|
||||
v->values[c] = nfront;
|
||||
else
|
||||
v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nfront) / (uint64_t) front);
|
||||
} else if (on_rear(map->map[c])) {
|
||||
if (rear == 0)
|
||||
v->values[c] = nrear;
|
||||
else
|
||||
v->values[c] = (pa_volume_t) (((uint64_t) v->values[c] * (uint64_t) nrear) / (uint64_t) rear);
|
||||
}
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -242,12 +242,27 @@ float pa_cvolume_get_balance(const pa_cvolume *v, const pa_channel_map *map) PA_
|
|||
/** Adjust the 'balance' value for the specified volume with the
|
||||
* specified channel map. v will be modified in place and
|
||||
* returned. The balance is a value between -1.0f and +1.0f. This
|
||||
* operation might not be reversable! Also, after this call
|
||||
* operation might not be reversible! Also, after this call
|
||||
* pa_cvolume_get_balance() is not guaranteed to actually return the
|
||||
* requested balance (e.g. when the input volume was zero anyway for
|
||||
* requested balance value (e.g. when the input volume was zero anyway for
|
||||
* all channels) \since 0.9.15 */
|
||||
pa_cvolume* pa_cvolume_set_balance(pa_cvolume *v, const pa_channel_map *map, float new_balance);
|
||||
|
||||
/** Calculate a 'fade' value (i.e. 'balance' between front and rear)
|
||||
* for the specified volume with the specified channel map. The return
|
||||
* value will range from -1.0f (rear) to +1.0f (left) \since
|
||||
* 0.9.15 */
|
||||
float pa_cvolume_get_fade(const pa_cvolume *v, const pa_channel_map *map) PA_GCC_PURE;
|
||||
|
||||
/** Adjust the 'fade' value (i.e. 'balance' between front and rear)
|
||||
* for the specified volume with the specified channel map. v will be
|
||||
* modified in place and returned. The balance is a value between
|
||||
* -1.0f and +1.0f. This operation might not be reversible! Also,
|
||||
* after this call pa_cvolume_get_fade() is not guaranteed to
|
||||
* actually return the requested fade value (e.g. when the input volume
|
||||
* was zero anyway for all channels) \since 0.9.15 */
|
||||
pa_cvolume* pa_cvolume_set_fade(pa_cvolume *v, const pa_channel_map *map, float new_fade);
|
||||
|
||||
/** Scale the passed pa_cvolume structure so that the maximum volume
|
||||
* of all channels equals max. The proportions between the channel
|
||||
* volumes are kept. \since 0.9.15 */
|
||||
|
|
|
|||
227
src/tests/volume-ui.py
Normal file
227
src/tests/volume-ui.py
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import pygtk, gtk
|
||||
from ctypes import *
|
||||
|
||||
libpulse = cdll.LoadLibrary("../.libs/libpulse.so")
|
||||
|
||||
class ChannelMap(Structure):
|
||||
_fields_ = [("channels", c_ubyte),
|
||||
("map", c_uint * 32)]
|
||||
|
||||
_to_name = libpulse.pa_channel_map_to_name
|
||||
_to_name.restype = c_char_p
|
||||
_to_name.argtypes = [c_void_p]
|
||||
|
||||
_to_pretty_name = libpulse.pa_channel_map_to_pretty_name
|
||||
_to_pretty_name.restype = c_char_p
|
||||
_to_pretty_name.argtypes = [c_void_p]
|
||||
|
||||
_snprint = libpulse.pa_channel_map_snprint
|
||||
_snprint.restype = c_char_p
|
||||
_snprint.argtypes = [c_char_p, c_ulong, c_void_p]
|
||||
|
||||
_position_to_string = libpulse.pa_channel_position_to_string
|
||||
_position_to_string.restype = c_char_p
|
||||
_position_to_string.argtypes = [c_uint]
|
||||
|
||||
_position_to_pretty_string = libpulse.pa_channel_position_to_pretty_string
|
||||
_position_to_pretty_string.restype = c_char_p
|
||||
_position_to_pretty_string.argtypes = [c_uint]
|
||||
|
||||
def to_name(this):
|
||||
return this._to_name(byref(this))
|
||||
|
||||
def to_pretty_name(this):
|
||||
return this._to_pretty_name(byref(this))
|
||||
|
||||
def snprint(this):
|
||||
s = create_string_buffer(336)
|
||||
r = this._snprint(s, len(s), byref(this))
|
||||
|
||||
if r is None:
|
||||
return None
|
||||
else:
|
||||
return s.raw
|
||||
|
||||
def position_to_string(this, pos):
|
||||
return this._position_to_string(pos)
|
||||
|
||||
def position_to_pretty_string(this, pos):
|
||||
return this._position_to_pretty_string(pos)
|
||||
|
||||
class CVolume(Structure):
|
||||
_fields_ = [("channels", c_ubyte),
|
||||
("values", c_uint32 * 32)]
|
||||
|
||||
|
||||
_snprint = libpulse.pa_cvolume_snprint
|
||||
_snprint.restype = c_char_p
|
||||
_snprint.argtypes = [c_char_p, c_ulong, c_void_p]
|
||||
|
||||
_max = libpulse.pa_cvolume_max
|
||||
_max.restype = c_uint32
|
||||
_max.argtypes = [c_void_p]
|
||||
|
||||
_scale = libpulse.pa_cvolume_scale
|
||||
_scale.restype = c_void_p
|
||||
_scale.argtypes = [c_void_p, c_uint32]
|
||||
|
||||
_get_balance = libpulse.pa_cvolume_get_balance
|
||||
_get_balance.restype = c_float
|
||||
_get_balance.argtypes = [c_void_p, c_void_p]
|
||||
|
||||
_get_fade = libpulse.pa_cvolume_get_fade
|
||||
_get_fade.restype = c_float
|
||||
_get_fade.argtypes = [c_void_p, c_void_p]
|
||||
|
||||
_set_balance = libpulse.pa_cvolume_set_balance
|
||||
_set_balance.restype = c_void_p
|
||||
_set_balance.argtypes = [c_void_p, c_void_p, c_float]
|
||||
|
||||
_set_fade = libpulse.pa_cvolume_set_fade
|
||||
_set_fade.restype = c_void_p
|
||||
_set_fade.argtypes = [c_void_p, c_void_p, c_float]
|
||||
|
||||
def snprint(this):
|
||||
s = create_string_buffer(320)
|
||||
r = this._snprint(s, len(s), byref(this))
|
||||
|
||||
if r is None:
|
||||
return None
|
||||
else:
|
||||
return s.raw
|
||||
|
||||
def max(this):
|
||||
return this._max(byref(this))
|
||||
|
||||
def scale(this, v):
|
||||
return this._scale(byref(this), v)
|
||||
|
||||
def get_balance(this, cm):
|
||||
return this._get_balance(byref(this), byref(cm))
|
||||
|
||||
def get_fade(this, cm):
|
||||
return this._get_fade(byref(this), byref(cm))
|
||||
|
||||
def set_balance(this, cm, f):
|
||||
return this._set_balance(byref(this), byref(cm), f)
|
||||
|
||||
def set_fade(this, cm, f):
|
||||
return this._set_fade(byref(this), byref(cm), f)
|
||||
|
||||
|
||||
|
||||
cm = ChannelMap()
|
||||
cm.channels = 6
|
||||
cm.map[0] = 1
|
||||
cm.map[1] = 2
|
||||
cm.map[2] = 3
|
||||
cm.map[3] = 5
|
||||
cm.map[4] = 6
|
||||
cm.map[5] = 7
|
||||
|
||||
print "Channel map name: %s" % cm.to_name()
|
||||
print "Channel map mapping: %s" % cm.snprint()
|
||||
|
||||
v = CVolume()
|
||||
v.channels = cm.channels
|
||||
|
||||
for i in range(cm.channels):
|
||||
v.values[i] = 65536/2
|
||||
|
||||
print v.max()
|
||||
print v.snprint()
|
||||
print v.get_balance(cm)
|
||||
print v.get_fade(cm)
|
||||
|
||||
window = gtk.Window(gtk.WINDOW_TOPLEVEL)
|
||||
window.set_title(cm.to_pretty_name())
|
||||
window.set_border_width(12)
|
||||
|
||||
vbox = gtk.VBox(spacing=6)
|
||||
|
||||
channel_labels = {}
|
||||
channel_scales = {}
|
||||
|
||||
def update_volume(update_channels = True, update_fade = True, update_balance = True, update_scale = True):
|
||||
if update_channels:
|
||||
for i in range(cm.channels):
|
||||
channel_scales[i].set_value(v.values[i])
|
||||
|
||||
if update_scale:
|
||||
value_scale.set_value(v.max())
|
||||
|
||||
if update_balance:
|
||||
balance_scale.set_value(v.get_balance(cm))
|
||||
|
||||
if update_fade:
|
||||
fade_scale.set_value(v.get_fade(cm))
|
||||
|
||||
def fade_value_changed(fs):
|
||||
v.set_fade(cm, fade_scale.get_value())
|
||||
update_volume(update_fade = False)
|
||||
|
||||
def balance_value_changed(fs):
|
||||
v.set_balance(cm, balance_scale.get_value())
|
||||
update_volume(update_balance = False)
|
||||
|
||||
def value_value_changed(fs):
|
||||
v.scale(int(value_scale.get_value()))
|
||||
update_volume(update_scale = False)
|
||||
|
||||
def channel_value_changed(fs, i):
|
||||
v.values[i] = int(channel_scales[i].get_value())
|
||||
update_volume(update_channels = False)
|
||||
|
||||
for i in range(cm.channels):
|
||||
channel_labels[i] = gtk.Label(cm.position_to_pretty_string(cm.map[i]))
|
||||
channel_labels[i].set_alignment(0, 1)
|
||||
vbox.pack_start(channel_labels[i], expand=False, fill=True)
|
||||
|
||||
channel_scales[i] = gtk.HScale()
|
||||
channel_scales[i].set_range(0, 65536)
|
||||
channel_scales[i].set_digits(0)
|
||||
channel_scales[i].set_value_pos(gtk.POS_RIGHT)
|
||||
vbox.pack_start(channel_scales[i], expand=False, fill=True)
|
||||
|
||||
value_label = gtk.Label("Value")
|
||||
value_label.set_alignment(0, .5)
|
||||
vbox.pack_start(value_label, expand=False, fill=True)
|
||||
value_scale = gtk.HScale()
|
||||
value_scale.set_range(0, 65536)
|
||||
value_scale.set_value_pos(gtk.POS_RIGHT)
|
||||
value_scale.set_digits(0)
|
||||
vbox.pack_start(value_scale, expand=False, fill=True)
|
||||
|
||||
balance_label = gtk.Label("Balance")
|
||||
balance_label.set_alignment(0, .5)
|
||||
vbox.pack_start(balance_label, expand=False, fill=True)
|
||||
balance_scale = gtk.HScale()
|
||||
balance_scale.set_range(-1.0, +1.0)
|
||||
balance_scale.set_value_pos(gtk.POS_RIGHT)
|
||||
balance_scale.set_digits(2)
|
||||
vbox.pack_start(balance_scale, expand=False, fill=True)
|
||||
|
||||
fade_label = gtk.Label("Fade")
|
||||
fade_label.set_alignment(0, .5)
|
||||
vbox.pack_start(fade_label, expand=False, fill=True)
|
||||
fade_scale = gtk.HScale()
|
||||
fade_scale.set_range(-1.0, +1.0)
|
||||
fade_scale.set_value_pos(gtk.POS_RIGHT)
|
||||
fade_scale.set_digits(2)
|
||||
vbox.pack_start(fade_scale, expand=False, fill=True)
|
||||
|
||||
window.add(vbox)
|
||||
window.set_default_size(600, 400)
|
||||
|
||||
update_volume()
|
||||
|
||||
for i in range(cm.channels):
|
||||
channel_scales[i].connect("value_changed", channel_value_changed, i)
|
||||
fade_scale.connect("value_changed", fade_value_changed)
|
||||
balance_scale.connect("value_changed", balance_value_changed)
|
||||
value_scale.connect("value_changed", value_value_changed)
|
||||
|
||||
window.show_all()
|
||||
gtk.main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue