From d03f3c8feee393b170beebf6ce5d46d2f8dcfcc5 Mon Sep 17 00:00:00 2001 From: martii Date: Fri, 13 Jul 2012 16:24:18 +0200 Subject: [PATCH] spark audio: add support for channel specific volume --- libspark/audio.cpp | 40 +++++++++++++++++++++++++++++++++++++++- libspark/audio_lib.h | 7 +++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/libspark/audio.cpp b/libspark/audio.cpp index 74521ba..482b62a 100644 --- a/libspark/audio.cpp +++ b/libspark/audio.cpp @@ -37,6 +37,9 @@ cAudio::cAudio(void *, void *, void *) mixer_fd = -1; openDevice(); Muted = false; +#ifdef MARTII + percent = 100; +#endif } cAudio::~cAudio(void) @@ -108,7 +111,11 @@ int cAudio::setVolume(unsigned int left, unsigned int right) lt_debug("%s(%d, %d)\n", __func__, left, right); volume = (left + right) / 2; +#ifdef MARTII + int v = map_volume((volume * percent)/100); +#else int v = map_volume(volume); +#endif if (clipfd != -1 && mixer_fd != -1) { int tmp = 0; /* not sure if left / right is correct here, but it is always the same anyways ;-) */ @@ -119,11 +126,13 @@ int cAudio::setVolume(unsigned int left, unsigned int right) lt_info("%s: MIXER_WRITE(%d),%04x: %m\n", __func__, mixer_num, tmp); return ret; } +#ifndef MARTII /* compensate for different decoding volume of mpeg and ac3 streams * TODO: check if this is correct for all channels * and if we need to do something with DTS? */ if (StreamType == AUDIO_FMT_MPEG) v = map_volume(volume * 30 / 53); +#endif char str[4]; sprintf(str, "%d", v); @@ -144,10 +153,18 @@ int cAudio::Stop(void) return ioctl(fd, AUDIO_STOP); } +#ifdef MARTII +bool cAudio::Pause(bool Pcm) +{ + ioctl(fd, Pcm ? AUDIO_PAUSE : AUDIO_CONTINUE, 1); + return true; +} +#else bool cAudio::Pause(bool /*Pcm*/) { return true; }; +#endif void cAudio::SetSyncMode(AVSYNC_TYPE Mode) { @@ -167,7 +184,9 @@ void cAudio::SetSyncMode(AVSYNC_TYPE Mode) void cAudio::SetStreamType(AUDIO_FORMAT type) { int bypass = AUDIO_STREAMTYPE_MPEG; +#ifndef MARTII bool update_volume = (StreamType != type); +#endif lt_debug("%s %d\n", __FUNCTION__, type); StreamType = type; @@ -175,7 +194,7 @@ void cAudio::SetStreamType(AUDIO_FORMAT type) { case AUDIO_FMT_DOLBY_DIGITAL: bypass = AUDIO_STREAMTYPE_AC3; - break; + break; case AUDIO_FMT_DTS: bypass = AUDIO_STREAMTYPE_DTS; break; @@ -188,8 +207,10 @@ void cAudio::SetStreamType(AUDIO_FORMAT type) // But as we implemented the behavior to bypass (cause of e2) this is correct here if (ioctl(fd, AUDIO_SET_BYPASS_MODE, bypass) < 0) lt_info("%s: AUDIO_SET_BYPASS_MODE failed (%m)\n", __func__); +#ifndef MARTII if (update_volume) setVolume(volume, volume); +#endif }; int cAudio::setChannel(int channel) @@ -411,3 +432,20 @@ void cAudio::setBypassMode(bool disable) lt_debug("%s %d\n", __func__, disable); proc_put("/proc/stb/audio/ac3", opt[disable], strlen(opt[disable])); } + +#ifdef MARTII +int cAudio::getPercent(void) { + return percent; +} + +int cAudio::setPercent(int perc) { + lt_debug("%s %d (muted: %d)\n", __func__, perc, Muted); + int old_percent = percent; + percent = perc; + if (percent < 0 || percent > 999) + percent = 100; + if(!Muted) + setVolume(volume, volume); + return old_percent; +} +#endif diff --git a/libspark/audio_lib.h b/libspark/audio_lib.h index 74dce1a..69d69c0 100644 --- a/libspark/audio_lib.h +++ b/libspark/audio_lib.h @@ -56,6 +56,9 @@ class cAudio int do_mute(bool enable, bool remember); void setBypassMode(bool disable); +#ifdef MARTII + int percent; +#endif public: /* construct & destruct */ cAudio(void *, void *, void *); @@ -91,6 +94,10 @@ class cAudio void SetSpdifDD(bool enable); void ScheduleMute(bool On); void EnableAnalogOut(bool enable); +#ifdef MARTII + int getPercent(void); + int setPercent(int perc); +#endif }; #endif