#!/bin/sh

lAudioTip=$1

script_path=`echo $0 | awk -F '/' '{for(i=2;i<NF;i++) printf"/"$i}'`
echo $script_path

AudioPowerControl=`cat $script_path/audioPowerControl.ini | ./busybox grep "audioPowerControl:" | ./busybox grep -v grep | sed 's/audioPowerControl://g' | sed 's/\r//g' | sed 's/\n//g' | sed "s/$(echo -e '\015')//g"`

if [ $? != 0 ]; then
	echo "cann't found audioPowerControl ini config file"
	exit -1
fi

if [ "$AudioPowerControl" = "yes" ];then
	if [ ! -d "/mnt/mtd/Log/" ];then
		mkdir -p /mnt/mtd/Log/
	fi
	
	[ -e "/mnt/mtd/Log/PowerControl" ] && rm /mnt/mtd/Log/PowerControl
	touch /mnt/mtd/Log/PowerControl
	echo "AudioPowerCtrlLevel:2" > /mnt/mtd/Log/PowerControl 
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/audioPowerControlSucc.pcm
	fi
fi

if [ "$AudioPowerControl" = "no" ];then
	rm -rf /mnt/mtd/Log/PowerControl
	if [ "$lAudioTip" != "no" ];then
		./simple_adec_bind_ao -r 8000 -t g711a -i audio/audioPowerControlDel.pcm
	fi
fi
