aboutsummaryrefslogtreecommitdiff
path: root/lib/dvb/volume.cpp
diff options
context:
space:
mode:
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>2005-08-13 19:51:17 +0000
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>2005-08-13 19:51:17 +0000
commit0877ce3b6f6cee972818a8c0a2d1bc862c8482be (patch)
tree91d23f198dc8dba893cf47ac3d2bad660da1b366 /lib/dvb/volume.cpp
parenta072a06516d83d3a11c52544bf2f7cb8ab567b4e (diff)
downloadenigma2-0877ce3b6f6cee972818a8c0a2d1bc862c8482be.tar.gz
enigma2-0877ce3b6f6cee972818a8c0a2d1bc862c8482be.zip
adding volume control
Diffstat (limited to 'lib/dvb/volume.cpp')
-rw-r--r--lib/dvb/volume.cpp136
1 files changed, 136 insertions, 0 deletions
diff --git a/lib/dvb/volume.cpp b/lib/dvb/volume.cpp
new file mode 100644
index 00000000..bc3d6574
--- /dev/null
+++ b/lib/dvb/volume.cpp
@@ -0,0 +1,136 @@
+#include <lib/dvb/volume.h>
+#include <stdio.h>
+#include <fcntl.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"
+#include <ost/audio.h>
+#include <ost/video.h>
+#else
+#define VIDEO_DEV "/dev/dvb/adapter0/video0"
+#define AUDIO_DEV "/dev/dvb/adapter0/audio0"
+#include <linux/dvb/audio.h>
+#include <linux/dvb/video.h>
+#endif
+
+eDVBVolumecontrol* eDVBVolumecontrol::instance = NULL;
+
+eDVBVolumecontrol* eDVBVolumecontrol::getInstance()
+{
+ if (instance == NULL)
+ instance = new eDVBVolumecontrol;
+ return instance;
+}
+
+eDVBVolumecontrol::eDVBVolumecontrol()
+{
+ volumeUnMute();
+ setVolume(100, 100);
+}
+
+int eDVBVolumecontrol::openMixer()
+{
+ return open( AUDIO_DEV, O_RDWR );
+}
+
+void eDVBVolumecontrol::closeMixer(int fd)
+{
+ close(fd);
+}
+
+void eDVBVolumecontrol::volumeUp(int left, int right)
+{
+ printf("[volume.cpp] Volume up\n");
+ setVolume(leftVol + left, rightVol + right);
+}
+
+void eDVBVolumecontrol::volumeDown(int left, int right)
+{
+ printf("[volume.cpp] Volume down\n");
+ setVolume(leftVol - left, rightVol - right);
+}
+
+int eDVBVolumecontrol::checkVolume(int vol)
+{
+ if (vol < 0)
+ vol = 0;
+ else if (vol > 100)
+ vol = 100;
+ return vol;
+}
+
+void eDVBVolumecontrol::setVolume(int left, int right)
+{
+ leftVol = checkVolume(left);
+ rightVol = checkVolume(right);
+
+ left = 63 - leftVol / 100.0 * 63.0;
+ right = 63 - rightVol / 100.0 * 63.0;
+
+#if HAVE_DVB_API_VERSION < 3
+ audioMixer_t mixer;
+#else
+ audio_mixer_t mixer;
+#endif
+
+#ifdef HAVE_DVB_API_VERSION
+ mixer.volume_left = (left * left) / 64;
+ mixer.volume_right = (right * right) / 64;
+#endif
+
+ int fd = openMixer();
+#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);
+}
+
+int eDVBVolumecontrol::getVolume()
+{
+ if (isMuted())
+ return 0;
+ return leftVol;
+}
+
+bool eDVBVolumecontrol::isMuted()
+{
+ return muted;
+}
+
+
+void eDVBVolumecontrol::volumeMute()
+{
+ int fd = openMixer();
+#ifdef HAVE_DVB_API_VERSION
+ ioctl(fd, AUDIO_SET_MUTE, true);
+#endif
+ closeMixer(fd);
+ muted = true;
+}
+
+void eDVBVolumecontrol::volumeUnMute()
+{
+ int fd = openMixer();
+#ifdef HAVE_DVB_API_VERSION
+ ioctl(fd, AUDIO_SET_MUTE, false);
+#endif
+ closeMixer(fd);
+ muted = false;
+}
+
+void eDVBVolumecontrol::volumeToggleMute()
+{
+ printf("Mute\n");
+ if (isMuted())
+ volumeUnMute();
+ else
+ volumeMute();
+
+} \ No newline at end of file