[PATCH] wmix: Fix for inaccurate volume adjustments

11 views
Skip to first unread message

Torrance, Douglas

unread,
Oct 13, 2021, 9:35:26 PM10/13/21
to wmake...@googlegroups.com, Torrance, Douglas, Dan Pascu
This has been applied to the Debian package since version 3.1 in 2006.

Authored-By: Dan Pascu <d...@ag-projects.com>
---
wmix/mixer-oss.c | 4 ++--
wmix/ui_x.c | 16 ++++++++--------
2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/wmix/mixer-oss.c b/wmix/mixer-oss.c
index 0c0e03f..28409f5 100644
--- a/wmix/mixer-oss.c
+++ b/wmix/mixer-oss.c
@@ -179,8 +179,8 @@ static void set_mixer_state(void)
vb_to_lr(mixer[cur_channel].volume,
mixer[cur_channel].balance, &left, &right);

- dev_left_volume = (int) (100.0 * left);
- dev_right_volume = (int) (100.0 * right);
+ dev_left_volume = (int) (100.0 * left + 0.5);
+ dev_right_volume = (int) (100.0 * right + 0.5);
dev_lr_volume = (dev_right_volume << 8) | dev_left_volume;
ioctl(mixer_fd, MIXER_WRITE(mixer[cur_channel].dev), &dev_lr_volume);
}
diff --git a/wmix/ui_x.c b/wmix/ui_x.c
index ffc3add..40b479d 100644
--- a/wmix/ui_x.c
+++ b/wmix/ui_x.c
@@ -93,7 +93,7 @@ static Cursor create_null_cursor(Display *x_display);
static void draw_stereo_led(void);
static void draw_rec_led(void);
static void draw_mute_led(void);
-static void draw_percent(void);
+static void draw_percent(float volume);
static void draw_knob(float volume);
static void draw_slider(float offset);

@@ -590,16 +590,16 @@ static void draw_mute_led(void)
copy_xpm_area(65, 21, 20, 7, 39, 14); /* turn off LCD */
}

-static void draw_percent(void)
+static void draw_percent(float volume)
{
- int volume = (int)(mixer_get_volume() * 100);
+ int vol = (int)(volume*100 + 0.5);

copy_xpm_area(0, 87, 18, 9, 41, 22); /* clear percentage */

- if (volume < 100) {
- if (volume >= 10)
- copy_xpm_area((volume / 10) * 6, 67, 6, 9, 47, 22);
- copy_xpm_area((volume % 10) * 6, 67, 6, 9, 53, 22);
+ if (vol < 100) {
+ if (vol >= 10)
+ copy_xpm_area((vol / 10) * 6, 67, 6, 9, 47, 22);
+ copy_xpm_area((vol % 10) * 6, 67, 6, 9, 53, 22);
} else {
copy_xpm_area(6, 67, 6, 9, 41, 22);
copy_xpm_area(0, 67, 6, 9, 47, 22);
@@ -631,7 +631,7 @@ static void draw_knob(float volume)

XCopyArea(display, led_pixmap, dockapp.pixmap, dockapp.gc,
0, 0, LED_WIDTH, LED_HEIGHT, led_topleft_x, led_topleft_y);
- draw_percent();
+ draw_percent(volume);
}

static void draw_slider(float offset)
--
2.30.2
Reply all
Reply to author
Forward
0 new messages