real mute volume on lowest volume level .. but not show the mute symbol
[enigma2.git] / lib / dvb / volume.cpp
index c3fc291..fc10480 100644 (file)
@@ -4,7 +4,6 @@
 #include <sys/ioctl.h>
 #include <unistd.h>
 
 #include <sys/ioctl.h>
 #include <unistd.h>
 
-#include <config.h>
 #if HAVE_DVB_API_VERSION < 3
 #define VIDEO_DEV "/dev/dvb/card0/video0"
 #define AUDIO_DEV "/dev/dvb/card0/audio0"
 #if HAVE_DVB_API_VERSION < 3
 #define VIDEO_DEV "/dev/dvb/card0/video0"
 #define AUDIO_DEV "/dev/dvb/card0/audio0"
@@ -65,48 +64,60 @@ int eDVBVolumecontrol::checkVolume(int vol)
 
 void eDVBVolumecontrol::setVolume(int left, int right)
 {
 
 void eDVBVolumecontrol::setVolume(int left, int right)
 {
+               /* left, right is 0..100 */
        leftVol = checkVolume(left);
        rightVol = checkVolume(right);
        
        leftVol = checkVolume(left);
        rightVol = checkVolume(right);
        
+               /* convert to -1dB steps */
        left = 63 - leftVol * 63 / 100;
        right = 63 - rightVol * 63 / 100;
        left = 63 - leftVol * 63 / 100;
        right = 63 - rightVol * 63 / 100;
-       
-#if HAVE_DVB_API_VERSION < 3   
-               audioMixer_t mixer;
+               /* now range is 63..0, where 0 is loudest */
+
+#if HAVE_DVB_API_VERSION < 3
+       audioMixer_t mixer;
 #else
 #else
-               audio_mixer_t mixer;
+       audio_mixer_t mixer;
 #endif
 
 #endif
 
-#ifdef HAVE_DVB_API_VERSION
-               mixer.volume_left = (left * left) / 64;
-               mixer.volume_right = (right * right) / 64;
+#if HAVE_DVB_API_VERSION < 3
+               /* convert to linear scale. 0 = loudest, ..63 */
+       mixer.volume_left = 63.0-pow(1.068241, 63-left);
+       mixer.volume_right = 63.0-pow(1.068241, 63-right);
+#else
+       mixer.volume_left = left;
+       mixer.volume_right = right;
+#endif
+
+       printf("Setvolume: %d %d (raw)\n", leftVol, rightVol);
+       printf("Setvolume: %d %d (-1db)\n", left, right);
+#if HAVE_DVB_API_VERSION < 3
+       printf("Setvolume: %d %d (lin)\n", mixer.volume_left, mixer.volume_right);
 #endif
 
 #endif
 
-               int fd = openMixer();
+       int fd = openMixer();
+       if (fd >= 0)
+       {
 #ifdef HAVE_DVB_API_VERSION
                ioctl(fd, AUDIO_SET_MIXER, &mixer);
 #endif
                closeMixer(fd);
 #ifdef HAVE_DVB_API_VERSION
                ioctl(fd, AUDIO_SET_MIXER, &mixer);
 #endif
                closeMixer(fd);
-               
-               printf("Setvolume: %d %d\n", leftVol, rightVol);
-               printf("Setvolume: %d %d\n", left, right);              
-               
+               return;
+       }
+
        //HACK?
        FILE *f;
        if((f = fopen("/proc/stb/avs/0/volume", "wb")) == NULL) {
                printf("cannot open /proc/stb/avs/0/volume\n");
                return;
        }
        //HACK?
        FILE *f;
        if((f = fopen("/proc/stb/avs/0/volume", "wb")) == NULL) {
                printf("cannot open /proc/stb/avs/0/volume\n");
                return;
        }
-       
-       fprintf(f, "%d", left);
+
+       fprintf(f, "%d", left); /* in -1dB */
 
        fclose(f);
 }
 
 int eDVBVolumecontrol::getVolume()
 {
 
        fclose(f);
 }
 
 int eDVBVolumecontrol::getVolume()
 {
-       if (isMuted())
-               return 0;
        return leftVol;
 }
 
        return leftVol;
 }
 
@@ -127,8 +138,8 @@ void eDVBVolumecontrol::volumeMute()
 
        //HACK?
        FILE *f;
 
        //HACK?
        FILE *f;
-       if((f = fopen("/proc/stb/adc/j1_mute", "wb")) == NULL) {
-               printf("cannot open /proc/stb/adc/j1_mute\n");
+       if((f = fopen("/proc/stb/audio/j1_mute", "wb")) == NULL) {
+               printf("cannot open /proc/stb/audio/j1_mute\n");
                return;
        }
        
                return;
        }
        
@@ -148,8 +159,8 @@ void eDVBVolumecontrol::volumeUnMute()
 
        //HACK?
        FILE *f;
 
        //HACK?
        FILE *f;
-       if((f = fopen("/proc/stb/adc/j1_mute", "wb")) == NULL) {
-               printf("cannot open /proc/stb/adc/j1_mute\n");
+       if((f = fopen("/proc/stb/audio/j1_mute", "wb")) == NULL) {
+               printf("cannot open /proc/stb/audio/j1_mute\n");
                return;
        }
        
                return;
        }