diff -Nru vdr-1.2.1/Makefile vdr-1.2.1-alsa_spdif/Makefile --- vdr-1.2.1/Makefile 2003-01-06 13:28:09.000000000 +0100 +++ vdr-1.2.1-alsa_spdif/Makefile 2003-07-29 01:47:53.000000000 +0200 @@ -59,6 +59,11 @@ DEFINES += -DVFAT endif +ifdef SPDIF +# volume control for SPDIF output +DEFINES += -DSPDIF +endif + all: vdr font: genfontfile fontfix.c fontosd.c @echo "font files created." @@ -80,7 +85,11 @@ # The main program: vdr: $(OBJS) $(DTVLIB) +ifdef SPDIF + $(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(NCURSESLIB) -lasound -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o vdr +else $(CXX) $(CXXFLAGS) -rdynamic $(OBJS) $(NCURSESLIB) -ljpeg -lpthread -ldl $(LIBDIRS) $(DTVLIB) -o vdr +endif # The font files: diff -Nru vdr-1.2.1/alsa_spdif.c vdr-1.2.1-alsa_spdif/alsa_spdif.c --- vdr-1.2.1/alsa_spdif.c 1970-01-01 01:00:00.000000000 +0100 +++ vdr-1.2.1-alsa_spdif/alsa_spdif.c 2003-07-29 12:00:28.000000000 +0200 @@ -0,0 +1,56 @@ +#include +#include + +class alsa_volume +{ + private: + char card[64]; + int err; + bool blocked; + snd_ctl_t *handle; + snd_ctl_elem_id_t *id; + snd_ctl_elem_value_t *control; + public: + void set(int); + alsa_volume(); + ~alsa_volume(); +} alsa_vol; + +alsa_volume::alsa_volume() +{ + strcpy(card,"default"); // change it if you need + blocked=0; + snd_ctl_elem_id_alloca(&id); + snd_ctl_elem_value_alloca(&control); + snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER); + /* below i am using numid 20 for 'IEC958 Optical Playback Volume' + on my SBLive!, while numid 17 is for: + 'IEC958 TTL Playback Volume' + you can obtain it all using 'amixer controls' */ + snd_ctl_elem_id_set_numid(id, 20); + if ((err = snd_ctl_open(&handle, card, 0)) < 0) + { + esyslog("SetVolume(): ALSA %s card open error: %s\n", card, snd_strerror(err)); + blocked=1; + } + if (!blocked) + snd_ctl_elem_value_set_id(control, id); +} + +alsa_volume::~alsa_volume() +{ + if (!blocked) + snd_ctl_close(handle); +} + +void alsa_volume::set(int Volume) +{ + if (blocked) + return; + snd_ctl_elem_value_set_integer(control, 0, Volume); //left channel + snd_ctl_elem_value_set_integer(control, 1, Volume); //right channel + if ((err = snd_ctl_elem_write(handle, control)) < 0) + { + esyslog("SetVolume(): ALSA %s card element write error: %s\n", card, snd_strerror(err)); + } +} diff -Nru vdr-1.2.1/dvbdevice.c vdr-1.2.1-alsa_spdif/dvbdevice.c --- vdr-1.2.1/dvbdevice.c 2003-05-24 15:23:51.000000000 +0200 +++ vdr-1.2.1-alsa_spdif/dvbdevice.c 2003-07-29 12:00:52.000000000 +0200 @@ -33,6 +33,10 @@ #include "status.h" #include "transfer.h" +#if defined(SPDIF) +#include "alsa_spdif.c" +#endif + #define DO_REC_AND_PLAY_ON_PRIMARY_DEVICE 1 #define DO_MULTIPLE_RECORDINGS 1 @@ -708,9 +712,13 @@ void cDvbDevice::SetVolumeDevice(int Volume) { if (HasDecoder()) { +#if defined(SPDIF) + alsa_vol.set((Volume*100)/255); +#else audio_mixer_t am; am.volume_left = am.volume_right = Volume; CHECK(ioctl(fd_audio, AUDIO_SET_MIXER, &am)); +#endif } }