* [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control
2011-09-21 16:10 ` [Qemu-devel] [PATCH 00/11] RFC: apply volume on client stream Marc-André Lureau
@ 2011-09-21 16:11 ` Marc-André Lureau
2011-10-13 12:26 ` [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl Marc-André Lureau
2012-03-01 14:28 ` Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2011-09-21 16:11 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau
---
hw/ac97.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/hw/ac97.c b/hw/ac97.c
index ba94835..4a7c4ed 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -431,6 +431,63 @@ static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX])
AUD_set_active_in (s->voice_mc, active[MC_INDEX]);
}
+static void get_volume (uint16_t vol, uint16_t mask, int inverse,
+ int *mute, uint8_t *lvol, uint8_t *rvol)
+{
+ *mute = (vol >> MUTE_SHIFT) & 1;
+ *rvol = (255 * (vol & mask)) / mask;
+ *lvol = (255 * ((vol >> 8) & mask)) / mask;
+ if (inverse) {
+ *rvol = 255 - *rvol;
+ *lvol = 255 - *lvol;
+ }
+}
+
+static void update_combined_volume_out (AC97LinkState *s)
+{
+ uint8_t lvol, rvol, plvol, prvol;
+ int mute, pmute;
+
+ get_volume (mixer_load (s, AC97_Master_Volume_Mute), 0x3f, 1,
+ &mute, &lvol, &rvol);
+ /* FIXME: should be 1f according to spec */
+ get_volume (mixer_load (s, AC97_PCM_Out_Volume_Mute), 0x3f, 1,
+ &pmute, &plvol, &prvol);
+
+ mute = mute | pmute;
+ lvol = (lvol * plvol) / 255;
+ rvol = (rvol * prvol) / 255;
+
+ AUD_set_volume_out (s->voice_po, mute, lvol, rvol);
+}
+
+static void update_volume_in(AC97LinkState *s)
+{
+ uint8_t lvol, rvol;
+ int mute;
+
+ get_volume (mixer_load (s, AC97_Record_Gain_Mute), 0x0f, 0,
+ &mute, &lvol, &rvol);
+
+ AUD_set_volume_in (s->voice_pi, mute, lvol, rvol);
+}
+
+static void set_volume (AC97LinkState *s, int index, uint32_t val)
+{
+ mixer_store (s, index, val);
+ if (index == AC97_Master_Volume_Mute || index == AC97_PCM_Out_Volume_Mute)
+ update_combined_volume_out (s);
+ else if (index == AC97_Record_Gain_Mute)
+ update_volume_in (s);
+}
+
+static void record_select (AC97LinkState *s, uint32_t val)
+{
+ uint8_t rs = val & REC_MASK;
+ uint8_t ls = (val >> 8) & REC_MASK;
+ mixer_store (s, AC97_Record_Select, rs | (ls << 8));
+}
+
static void mixer_reset (AC97LinkState *s)
{
uint8_t active[LAST_INDEX];
@@ -465,6 +522,11 @@ static void mixer_reset (AC97LinkState *s)
mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80);
mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80);
+ record_select (s, 0);
+ set_volume (s, AC97_Master_Volume_Mute, 0x8000);
+ set_volume (s, AC97_PCM_Out_Volume_Mute, 0x8808);
+ set_volume (s, AC97_Line_In_Volume_Mute, 0x8808);
+
reset_voices (s, active);
}
@@ -523,6 +585,15 @@ static void nam_writew (void *opaque, uint32_t addr, uint32_t val)
val |= mixer_load (s, index) & 0xf;
mixer_store (s, index, val);
break;
+ case AC97_PCM_Out_Volume_Mute:
+ case AC97_Master_Volume_Mute:
+ case AC97_Record_Gain_Mute:
+ case AC97_Line_In_Volume_Mute:
+ set_volume (s, index, val);
+ break;
+ case AC97_Record_Select:
+ record_select (s, val);
+ break;
case AC97_Vendor_ID1:
case AC97_Vendor_ID2:
dolog ("Attempt to write vendor ID to %#x\n", val);
@@ -1075,6 +1146,14 @@ static int ac97_post_load (void *opaque, int version_id)
uint8_t active[LAST_INDEX];
AC97LinkState *s = opaque;
+ record_select (s, mixer_load (s, AC97_Record_Select));
+ set_volume (s, AC97_Master_Volume_Mute,
+ mixer_load (s, AC97_Master_Volume_Mute));
+ set_volume (s, AC97_PCM_Out_Volume_Mute,
+ mixer_load (s, AC97_PCM_Out_Volume_Mute));
+ set_volume (s, AC97_Line_In_Volume_Mute,
+ mixer_load (s, AC97_Line_In_Volume_Mute));
+
active[PI_INDEX] = !!(s->bm_regs[PI_INDEX].cr & CR_RPBM);
active[PO_INDEX] = !!(s->bm_regs[PO_INDEX].cr & CR_RPBM);
active[MC_INDEX] = !!(s->bm_regs[MC_INDEX].cr & CR_RPBM);
--
1.7.6.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl
2011-09-21 16:10 ` [Qemu-devel] [PATCH 00/11] RFC: apply volume on client stream Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control Marc-André Lureau
@ 2011-10-13 12:26 ` Marc-André Lureau
2011-10-13 12:26 ` [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control Marc-André Lureau
2012-03-01 14:28 ` Marc-André Lureau
2 siblings, 1 reply; 4+ messages in thread
From: Marc-André Lureau @ 2011-10-13 12:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau, kraxel
---
audio/audio.c | 12 ++++++++++++
audio/audio_int.h | 1 +
2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/audio/audio.c b/audio/audio.c
index 5649075..c759c1f 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -2050,17 +2050,29 @@ void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
void AUD_set_volume_out (SWVoiceOut *sw, int mute, uint8_t lvol, uint8_t rvol)
{
if (sw) {
+ HWVoiceOut *hw = sw->hw;
+
sw->vol.mute = mute;
sw->vol.l = nominal_volume.l * lvol / 255;
sw->vol.r = nominal_volume.r * rvol / 255;
+
+ if (hw->pcm_ops->ctl_out) {
+ hw->pcm_ops->ctl_out (hw, VOICE_VOLUME, sw);
+ }
}
}
void AUD_set_volume_in (SWVoiceIn *sw, int mute, uint8_t lvol, uint8_t rvol)
{
if (sw) {
+ HWVoiceIn *hw = sw->hw;
+
sw->vol.mute = mute;
sw->vol.l = nominal_volume.l * lvol / 255;
sw->vol.r = nominal_volume.r * rvol / 255;
+
+ if (hw->pcm_ops->ctl_in) {
+ hw->pcm_ops->ctl_in (hw, VOICE_VOLUME, sw);
+ }
}
}
diff --git a/audio/audio_int.h b/audio/audio_int.h
index 2003f8b..117f95e 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -231,6 +231,7 @@ void audio_run (const char *msg);
#define VOICE_ENABLE 1
#define VOICE_DISABLE 2
+#define VOICE_VOLUME 3
static inline int audio_ring_dist (int dst, int src, int len)
{
--
1.7.6.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control
2011-10-13 12:26 ` [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl Marc-André Lureau
@ 2011-10-13 12:26 ` Marc-André Lureau
0 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2011-10-13 12:26 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau, kraxel
---
hw/ac97.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/hw/ac97.c b/hw/ac97.c
index ba94835..4a7c4ed 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -431,6 +431,63 @@ static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX])
AUD_set_active_in (s->voice_mc, active[MC_INDEX]);
}
+static void get_volume (uint16_t vol, uint16_t mask, int inverse,
+ int *mute, uint8_t *lvol, uint8_t *rvol)
+{
+ *mute = (vol >> MUTE_SHIFT) & 1;
+ *rvol = (255 * (vol & mask)) / mask;
+ *lvol = (255 * ((vol >> 8) & mask)) / mask;
+ if (inverse) {
+ *rvol = 255 - *rvol;
+ *lvol = 255 - *lvol;
+ }
+}
+
+static void update_combined_volume_out (AC97LinkState *s)
+{
+ uint8_t lvol, rvol, plvol, prvol;
+ int mute, pmute;
+
+ get_volume (mixer_load (s, AC97_Master_Volume_Mute), 0x3f, 1,
+ &mute, &lvol, &rvol);
+ /* FIXME: should be 1f according to spec */
+ get_volume (mixer_load (s, AC97_PCM_Out_Volume_Mute), 0x3f, 1,
+ &pmute, &plvol, &prvol);
+
+ mute = mute | pmute;
+ lvol = (lvol * plvol) / 255;
+ rvol = (rvol * prvol) / 255;
+
+ AUD_set_volume_out (s->voice_po, mute, lvol, rvol);
+}
+
+static void update_volume_in(AC97LinkState *s)
+{
+ uint8_t lvol, rvol;
+ int mute;
+
+ get_volume (mixer_load (s, AC97_Record_Gain_Mute), 0x0f, 0,
+ &mute, &lvol, &rvol);
+
+ AUD_set_volume_in (s->voice_pi, mute, lvol, rvol);
+}
+
+static void set_volume (AC97LinkState *s, int index, uint32_t val)
+{
+ mixer_store (s, index, val);
+ if (index == AC97_Master_Volume_Mute || index == AC97_PCM_Out_Volume_Mute)
+ update_combined_volume_out (s);
+ else if (index == AC97_Record_Gain_Mute)
+ update_volume_in (s);
+}
+
+static void record_select (AC97LinkState *s, uint32_t val)
+{
+ uint8_t rs = val & REC_MASK;
+ uint8_t ls = (val >> 8) & REC_MASK;
+ mixer_store (s, AC97_Record_Select, rs | (ls << 8));
+}
+
static void mixer_reset (AC97LinkState *s)
{
uint8_t active[LAST_INDEX];
@@ -465,6 +522,11 @@ static void mixer_reset (AC97LinkState *s)
mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80);
mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80);
+ record_select (s, 0);
+ set_volume (s, AC97_Master_Volume_Mute, 0x8000);
+ set_volume (s, AC97_PCM_Out_Volume_Mute, 0x8808);
+ set_volume (s, AC97_Line_In_Volume_Mute, 0x8808);
+
reset_voices (s, active);
}
@@ -523,6 +585,15 @@ static void nam_writew (void *opaque, uint32_t addr, uint32_t val)
val |= mixer_load (s, index) & 0xf;
mixer_store (s, index, val);
break;
+ case AC97_PCM_Out_Volume_Mute:
+ case AC97_Master_Volume_Mute:
+ case AC97_Record_Gain_Mute:
+ case AC97_Line_In_Volume_Mute:
+ set_volume (s, index, val);
+ break;
+ case AC97_Record_Select:
+ record_select (s, val);
+ break;
case AC97_Vendor_ID1:
case AC97_Vendor_ID2:
dolog ("Attempt to write vendor ID to %#x\n", val);
@@ -1075,6 +1146,14 @@ static int ac97_post_load (void *opaque, int version_id)
uint8_t active[LAST_INDEX];
AC97LinkState *s = opaque;
+ record_select (s, mixer_load (s, AC97_Record_Select));
+ set_volume (s, AC97_Master_Volume_Mute,
+ mixer_load (s, AC97_Master_Volume_Mute));
+ set_volume (s, AC97_PCM_Out_Volume_Mute,
+ mixer_load (s, AC97_PCM_Out_Volume_Mute));
+ set_volume (s, AC97_Line_In_Volume_Mute,
+ mixer_load (s, AC97_Line_In_Volume_Mute));
+
active[PI_INDEX] = !!(s->bm_regs[PI_INDEX].cr & CR_RPBM);
active[PO_INDEX] = !!(s->bm_regs[PO_INDEX].cr & CR_RPBM);
active[MC_INDEX] = !!(s->bm_regs[MC_INDEX].cr & CR_RPBM);
--
1.7.6.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control
2011-09-21 16:10 ` [Qemu-devel] [PATCH 00/11] RFC: apply volume on client stream Marc-André Lureau
2011-09-21 16:11 ` [Qemu-devel] [PATCH 06/11] hw/ac97: new support for volume control Marc-André Lureau
2011-10-13 12:26 ` [Qemu-devel] [PATCH 01/11] audio: add VOICE_VOLUME ctl Marc-André Lureau
@ 2012-03-01 14:28 ` Marc-André Lureau
2 siblings, 0 replies; 4+ messages in thread
From: Marc-André Lureau @ 2012-03-01 14:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Marc-André Lureau, kraxel
---
hw/ac97.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/hw/ac97.c b/hw/ac97.c
index f7866ed..227233c 100644
--- a/hw/ac97.c
+++ b/hw/ac97.c
@@ -436,6 +436,63 @@ static void reset_voices (AC97LinkState *s, uint8_t active[LAST_INDEX])
AUD_set_active_in (s->voice_mc, active[MC_INDEX]);
}
+static void get_volume (uint16_t vol, uint16_t mask, int inverse,
+ int *mute, uint8_t *lvol, uint8_t *rvol)
+{
+ *mute = (vol >> MUTE_SHIFT) & 1;
+ *rvol = (255 * (vol & mask)) / mask;
+ *lvol = (255 * ((vol >> 8) & mask)) / mask;
+ if (inverse) {
+ *rvol = 255 - *rvol;
+ *lvol = 255 - *lvol;
+ }
+}
+
+static void update_combined_volume_out (AC97LinkState *s)
+{
+ uint8_t lvol, rvol, plvol, prvol;
+ int mute, pmute;
+
+ get_volume (mixer_load (s, AC97_Master_Volume_Mute), 0x3f, 1,
+ &mute, &lvol, &rvol);
+ /* FIXME: should be 1f according to spec */
+ get_volume (mixer_load (s, AC97_PCM_Out_Volume_Mute), 0x3f, 1,
+ &pmute, &plvol, &prvol);
+
+ mute = mute | pmute;
+ lvol = (lvol * plvol) / 255;
+ rvol = (rvol * prvol) / 255;
+
+ AUD_set_volume_out (s->voice_po, mute, lvol, rvol);
+}
+
+static void update_volume_in(AC97LinkState *s)
+{
+ uint8_t lvol, rvol;
+ int mute;
+
+ get_volume (mixer_load (s, AC97_Record_Gain_Mute), 0x0f, 0,
+ &mute, &lvol, &rvol);
+
+ AUD_set_volume_in (s->voice_pi, mute, lvol, rvol);
+}
+
+static void set_volume (AC97LinkState *s, int index, uint32_t val)
+{
+ mixer_store (s, index, val);
+ if (index == AC97_Master_Volume_Mute || index == AC97_PCM_Out_Volume_Mute)
+ update_combined_volume_out (s);
+ else if (index == AC97_Record_Gain_Mute)
+ update_volume_in (s);
+}
+
+static void record_select (AC97LinkState *s, uint32_t val)
+{
+ uint8_t rs = val & REC_MASK;
+ uint8_t ls = (val >> 8) & REC_MASK;
+ mixer_store (s, AC97_Record_Select, rs | (ls << 8));
+}
+
static void mixer_reset (AC97LinkState *s)
{
uint8_t active[LAST_INDEX];
@@ -470,6 +527,11 @@ static void mixer_reset (AC97LinkState *s)
mixer_store (s, AC97_PCM_LR_ADC_Rate , 0xbb80);
mixer_store (s, AC97_MIC_ADC_Rate , 0xbb80);
+ record_select (s, 0);
+ set_volume (s, AC97_Master_Volume_Mute, 0x8000);
+ set_volume (s, AC97_PCM_Out_Volume_Mute, 0x8808);
+ set_volume (s, AC97_Line_In_Volume_Mute, 0x8808);
+
reset_voices (s, active);
}
@@ -528,6 +590,15 @@ static void nam_writew (void *opaque, uint32_t addr, uint32_t val)
val |= mixer_load (s, index) & 0xf;
mixer_store (s, index, val);
break;
+ case AC97_PCM_Out_Volume_Mute:
+ case AC97_Master_Volume_Mute:
+ case AC97_Record_Gain_Mute:
+ case AC97_Line_In_Volume_Mute:
+ set_volume (s, index, val);
+ break;
+ case AC97_Record_Select:
+ record_select (s, val);
+ break;
case AC97_Vendor_ID1:
case AC97_Vendor_ID2:
dolog ("Attempt to write vendor ID to %#x\n", val);
@@ -1080,6 +1151,14 @@ static int ac97_post_load (void *opaque, int version_id)
uint8_t active[LAST_INDEX];
AC97LinkState *s = opaque;
+ record_select (s, mixer_load (s, AC97_Record_Select));
+ set_volume (s, AC97_Master_Volume_Mute,
+ mixer_load (s, AC97_Master_Volume_Mute));
+ set_volume (s, AC97_PCM_Out_Volume_Mute,
+ mixer_load (s, AC97_PCM_Out_Volume_Mute));
+ set_volume (s, AC97_Line_In_Volume_Mute,
+ mixer_load (s, AC97_Line_In_Volume_Mute));
+
active[PI_INDEX] = !!(s->bm_regs[PI_INDEX].cr & CR_RPBM);
active[PO_INDEX] = !!(s->bm_regs[PO_INDEX].cr & CR_RPBM);
active[MC_INDEX] = !!(s->bm_regs[MC_INDEX].cr & CR_RPBM);
--
1.7.7.6
^ permalink raw reply related [flat|nested] 4+ messages in thread