summaryrefslogtreecommitdiffstats
path: root/abs/core/LinHES-config/soundconfig.sh
blob: 38687a4c8c424f2c4e38ce66830d196b1671a47e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#!/bin/bash
. /etc/systemconfig
. /etc/profile
echo $@ >/tmp/audio.call

BASE=""
MYTH_RUN_STATUS="1"
. /etc/profile
TESTFILE="/usr/share/sounds/alsa/Front_Center.wav"
OSSinstalled="false"

BLACKLIST=/etc/modprobe.d/soundconfig_blacklist.conf
. /usr/MythVantage/bin/install_functions.sh
home_check

echo "---------------------------------------"


function testaudio () {
    ossplay  -d$AUDIODEVICE $TESTFILE
}

function load_alsa() {
    echo "Loading ALSA ..."
    remove_service.sh alsa-utils 1> /dev/null 2> /dev/null
    KER=`uname -r`
    cd /lib/modules/$KER/
    echo "   uncompressing ALSA modules"
    tar -xf sound-preoss.tar.bz2
    #echo "   installing alsa-lib"
    #pacman -S --force --noconfirm  alsa-lib

    echo "   uninstalling oss"
    pacman -R --noconfirm oss

    echo    "triggering udev module load"
    depmod -a
    cd - > /dev/null
    #udevadm trigger
    udevadm settle
    udevadm trigger


    add_service.sh alsa-utils

}


function unload_alsa () {
    echo "unloading ALSA ..."
    #kill $(lsof -t /dev/dsp* /dev/audio* /dev/mixer* /dev/snd/*) && modprobe -r $(lsmod |grep ^snd |awk '{print $1}')
    sv stop alsa-utils
    remove_service.sh alsa-utils
    rm -rf /dev/adsp*
    rm -rf /dev/snd/*
    rm -rf /dev/audio
    modprobe -r $(lsmod |grep ^snd |awk '{print $1}')
}

function unload_oss {
    echo "unloading OSS ..."
    sv stop oss
    soundoff
    rm -rf /dev/dsp*
    rm -rf /dev/oss*
    rm -rf /dev/sndstat
    remove_service.sh oss
    rm -f $BLACKLIST
}

function installOSS {
    echo "installing OSS ..."
    pacman -Q oss 2>/dev/null
    if [  ! $? = 0 ]
    then
        pacman --noconfirm -S --force oss
    fi
    soundon
    add_service.sh oss
    echo "blacklist soundcore" > $BLACKLIST
    echo "install soundcore /bin/false" >> $BLACKLIST
}


function SYNCXINE {
    echo "modify xine config file"
    if [ -f $MYTHHOME/.xine/config ]
    then
        cp -f $MYTHHOME/.xine/config  $TEMPLATES/xine.config
    else
        cp $TEMPLATES/xine.config.template $TEMPLATES/xine.config
    fi

    if [ x$Audiotype = xOSS ]
    then
       DEVICENUMBER=`echo $SoundDevice|awk -F/ ' { print $3  } '|tr -d dsp `
        sed -e "s/^.*audio.driver.*$/audio.driver:oss/" \
               -e "s/^.audio.device.oss_device_name.*$/audio.device.oss_device_name:\/dev\/dsp/" \
               -e "s/^.audio.devic.oss_device_number.*$/audio.device.oss_device_number:$DEVICENUMER/" \
               -e "s/^.*audio.output.speaker_arrangement:.*$/Audio.output.speaker_arrangement:PassThrough/" \
                $TEMPLATES/xine.config > $MYTHHOME/.xine/config
    else
        cp $TEMPLATES/xine.config $MYTHHOME/.xine/config
    fi
}

function SYNCMPLAYER {
    echo "modify mplayer config file"
    if [ -f /etc/mplayer/mplayer.conf ]
    then
        backdate=`date +%b-%d-%Y-%H:%M:%S`
        mv /etc/mplayer/mplayer.conf /etc/mplayer/mplayer.conf-$backdate
    fi
    if [  x$AUDIOTYPE = xALSA  -o   x$AUDIOTYPE = xalsa ]
    then
        MPLAYERDEVICE=`echo $AUDIODEVICE | tr : = | tr , .`
        echo "ao=alsa:device=$MPLAYERDEVICE" > /etc/mplayer/mplayer.conf
        echo "ac=hwac3,hwdts," >> /etc/mplayer/mplayer.conf
    else
        echo "ao=oss:$AUDIODEVICE" > /etc/mplayer/mplayer.conf
    fi
}

function checkOSSinstalled () {
    echo "Checking if OSS is installed"
    ossinfo |grep Version |grep -q OSS >/dev/null
    resultcode=$?

    if [ $resultcode = 0 ]
    then
        OSSinstalled='true'
        echo "   OSS is loaded"
    else
        OSSinstalled='false'
        echo "   OSS is NOT loaded"
    fi
}

function write_asound {
    echo "writing asound.conf file"
    if [ -f /etc/asound.conf ]
    then
        backdate=`date +%b-%d-%Y-%H:%M:%S`
        mv /etc/asound.conf /etc/asound.conf-$backdate
    fi
    echo 'pcm.!default "'"$AUDIODEVICE"'"' > /etc/asound.conf
}

function sound_config_system {
    if [  x$AUDIOTYPE = xALSA  -o   x$AUDIOTYPE = xalsa ]
        then
        write_asound
    fi
    SYNCMPLAYER
#    if [ x$syncXine = x1 ]
#    then
#          SYNCXINE
#    fi
}

function loadsound (){
    checkOSSinstalled
    if [  x$AUDIOTYPE = xOSS  -o   x$AUDIOTYPE = xoss ]
        then
        while [ $OSSinstalled = "false" ]
        do
            unload_alsa
            if [ -e /tmp/.alsatest ]
            then
                rm /tmp/.alsatest
            fi
            installOSS
            checkOSSinstalled
        done
    else
        touch /tmp/.alsatest
        unload_oss
        load_alsa
        rm /tmp/.alsatest
    fi
}




#####################MAIN PROGRAM##########################

declare -r OPTSTRING="i:t:d:"

if [ $# -eq 0 ]
then
    echo "Valid options are:"
    echo "  -i  (oss|alsa)   oss or alsa subsystem  "
    echo "  -t  (test|real|LOAD)   "
    echo "  -d device"
    exit 1
fi




while getopts "$OPTSTRING"  SWITCH
do
    case $SWITCH in
        \?)  echo "unknown option"
            exit 11
        ;;
        i) #echo "$SWITCH"  "$OPTARG"
            AUDIOTYPE="$OPTARG"
        ;;
        d) #echo "$SWITCH"  "$OPTARG"
            AUDIODEVICE=$OPTARG
        ;;
        t) #echo "$SWITCH"  "$OPTARG"
            SOUNDOPTYPE="$OPTARG"
            if  [ x"$OPTARG" = xtest ]
            then
                TEST=true
            else
                TEST=false
            fi
        ;;
    esac
done



case $SOUNDOPTYPE in
    REAL|real )
        #loadsound
        sound_config_system
    ;;
    test|TEST)
        echo $@ > /tmp/audio.test
        #loadsound
        if [  x$AUDIOTYPE = xOSS  -o   x$AUDIOTYPE = xoss ]
        then
            echo "testing OSS  $AUDIODEVICE "
            ossplay  -d$AUDIODEVICE $TESTFILE
        else
            echo "testing ALSA $AUDIODEVICE "
            echo aplay --device=$AUDIODEVICE $TESTFILE
            aplay --device=$AUDIODEVICE $TESTFILE
        fi
    ;;
    LOAD|load)
        loadsound
    ;;
esac

exit 0