zte's code,first commit
Change-Id: I9a04da59e459a9bc0d67f101f700d9d7dc8d681b
diff --git a/ap/lib/libtinyalsa/MODULE_LICENSE_BSD b/ap/lib/libtinyalsa/MODULE_LICENSE_BSD
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ap/lib/libtinyalsa/MODULE_LICENSE_BSD
diff --git a/ap/lib/libtinyalsa/Makefile b/ap/lib/libtinyalsa/Makefile
new file mode 100755
index 0000000..78ead51
--- /dev/null
+++ b/ap/lib/libtinyalsa/Makefile
@@ -0,0 +1,133 @@
+# /*****************************************************************************
+#* °æÈ¨ËùÓÐ (C)2015, ÖÐÐËͨѶ¹É·ÝÓÐÏÞ¹«Ë¾¡£
+#*
+#* ÎļþÃû³Æ: Makefile
+#* Îļþ±êʶ: Makefile
+#* ÄÚÈÝÕªÒª: Makefile of ZTE librarys
+#* ʹÓ÷½·¨: void
+#*
+#* ÐÞ¸ÄÈÕÆÚ °æ±¾ºÅ Ð޸ıê¼Ç ÐÞ¸ÄÈË ÐÞ¸ÄÄÚÈÝ
+#* -----------------------------------------------------------------------------
+#* 2018/01/15 V1.0 Create chentianming ´´½¨
+#*
+# ******************************************************************************/
+
+#*******************************************************************************
+# include ZTE library makefile
+#*******************************************************************************
+include $(COMMON_MK)
+
+
+#*******************************************************************************
+# library
+#*******************************************************************************
+LIB_SHARED = libtinyalsa.so
+LIB_STATIC = libtinyalsa.a
+
+ifeq ($(_APP_AUDIO_TYPE_),watch_cap)
+OBJS = mixer.o pcm.o mixer_ctrl_watch_cap.o
+else
+OBJS = mixer.o pcm.o audio_mixer_ctrl.o
+endif
+CFLAGS += -g
+LDFLAGS += -lpthread
+
+##############USER COMIZE END##################
+
+CFLAGS += -I$(zte_lib_path)/libtinyalsa/include
+CFLAGS += -I$(STAGEDIR)/include
+CFLAGS += -I$(APP_DIR)/include
+CFLAGS += -fPIC
+
+LDFLAGS_SHARED += -shared
+
+
+#*******************************************************************************
+# comp test app and
+#*******************************************************************************
+EXEC_tinyplay = tinyplay
+EXEC_tinycap = tinycap
+EXEC_tinymix = tinymix
+EXEC_tinypcminfo = tinyinfo
+EXEC_alsatest = alsatest
+EXEC_voltest = voltest
+
+#*******************************************************************************
+# objects
+#*******************************************************************************
+tinyplay_OBJECTS += mixer.o pcm.o tinyplay.o
+tinycap_OBJECTS += mixer.o pcm.o tinycap.o
+tinymix_OBJECTS += mixer.o pcm.o tinymix.o
+tinypcminfo_OBJECTS += mixer.o pcm.o tinypcminfo.o
+alsatest_OBJECTS += mixer.o pcm.o alsatest.o
+voltest_OBJECTS += vol_test.o
+#########################for linux######################################
+
+ifeq ($(V3PHONE_TYPE), K318)
+ CFLAGS += -D_USE_7520V3_PHONE_TYPE_K318
+endif
+ifeq ($(V3PHONE_TYPE), C31F)
+ CFLAGS += -D_USE_7520V3_PHONE_TYPE_C31F
+endif
+ifeq ($(V3PHONE_TYPE), XRSD)
+ CFLAGS += -D_USE_7520V3_PHONE_TYPE_XRSD
+endif
+ifeq ($(V3PHONE_TYPE), FWP)
+ CFLAGS += -D_USE_7520V3_PHONE_TYPE_FWP
+endif
+ifeq ($(V3PHONE_TYPE), WTWD)
+ CFLAGS += -D_USE_7520V3_PHONE_TYPE_WTWD
+endif
+
+
+CFLAGS += -I./include/
+CFLAGS += -g -Werror=implicit-function-declaration
+SHAREDFLAG := -shared -lc
+LDLIBS += -L$(LIB_DIR)/libtinyalsa
+LDLIBS += -ltinyalsa
+
+all: $(LIB_STATIC) $(LIB_SHARED) $(EXEC_tinyplay) $(EXEC_tinycap) $(EXEC_tinymix) $(EXEC_tinypcminfo)
+
+$(LIB_STATIC) : $(OBJS)
+ $(AR) rcs $(LIB_STATIC) $(OBJS)
+
+$(LIB_SHARED): $(OBJS)
+ $(CC) $(LDFLAGS) $(LDFLAGS_SHARED) -o $@ $^
+
+
+$(EXEC_tinyplay): $(tinyplay_OBJECTS)
+ $(CC) $(LDFLAGS) -o $@ $(tinyplay_OBJECTS) -Wl,--start-group $(LDLIBS) -Wl,--end-group
+$(EXEC_tinycap): $(tinycap_OBJECTS)
+ $(CC) $(LDFLAGS) -o $@ $(tinycap_OBJECTS) -Wl,--start-group $(LDLIBS) -Wl,--end-group
+$(EXEC_tinymix): $(tinymix_OBJECTS)
+ $(CC) $(LDFLAGS) -o $@ $(tinymix_OBJECTS) -Wl,--start-group $(LDLIBS) -Wl,--end-group
+$(EXEC_tinypcminfo): $(tinypcminfo_OBJECTS)
+ $(CC) $(LDFLAGS) -o $@ $(tinypcminfo_OBJECTS) -Wl,--start-group $(LDLIBS) -Wl,--end-group
+#$(EXEC_alsatest): $(alsatest_OBJECTS)
+# $(CC) $(LDFLAGS) -o $@ $(alsatest_OBJECTS) -Wl,--start-group $(LDLIBS) -Wl,--end-group
+#$(EXEC_voltest): $(voltest_OBJECTS)
+# $(CC) $(LDFLAGS) -o $@ $(voltest_OBJECTS) -Wl,--start-group $(LDLIBS) -lm -Wl,--end-group
+
+clean:
+ rm -f $(tinyplay_OBJECTS) $(tinycap_OBJECTS) $(tinymix_OBJECTS) $(tinypcminfo_OBJECTS) $(lib_OBJECTS) $(LIB_SHARED) $(LIB_STATIC) $(EXEC_tinyplay) $(EXEC_tinycap) $(EXEC_tinymix) $(EXEC_tinypcminfo) $(EXEC_alsatest) *.elf *.gdb *.o core
+
+romfs:
+ $(ROMFSINST) $(LIB_SHARED) /lib/$(LIB_SHARED)
+ #$(ROMFSINST) $(EXEC_tinyplay) /bin/$(EXEC_tinyplay)
+ #$(ROMFSINST) $(EXEC_tinycap) /bin/$(EXEC_tinycap)
+ #$(ROMFSINST) $(EXEC_tinymix) /bin/$(EXEC_tinymix)
+ #$(ROMFSINST) $(EXEC_tinypcminfo) /bin/$(EXEC_tinypcminfo)
+ #$(ROMFSINST) $(EXEC_voltest) /bin/$(EXEC_voltest)
+ cp -v $(EXEC_tinyplay) $(APP_DIR)/test_tools/
+ cp -v $(EXEC_tinycap) $(APP_DIR)/test_tools/
+ cp -v $(EXEC_tinymix) $(APP_DIR)/test_tools/
+ cp -v $(EXEC_tinypcminfo) $(APP_DIR)/test_tools/
+# $(ROMFSINST) $(EXEC_alsatest) /bin/$(EXEC_alsatest)
+
+
+# cp $(EXEC_tinyplay) $(EXEC_tinyplay).elf
+# cp $(EXEC_tinycap) $(EXEC_tinycap).elf
+
+# cp $(EXEC_tinymix) $(EXEC_tinymix).elf
+# cp $(EXEC_tinypcminfo) $(EXEC_tinypcminfo).elf
+# cp $(EXEC_alsatest) $(EXEC_alsatest).elf
diff --git a/ap/lib/libtinyalsa/NOTICE b/ap/lib/libtinyalsa/NOTICE
new file mode 100644
index 0000000..5debd99
--- /dev/null
+++ b/ap/lib/libtinyalsa/NOTICE
@@ -0,0 +1,25 @@
+Copyright 2011, The Android Open Source Project
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of The Android Open Source Project nor the names of
+ its contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGE.
+
diff --git a/ap/lib/libtinyalsa/README b/ap/lib/libtinyalsa/README
new file mode 100644
index 0000000..85b1e5e
--- /dev/null
+++ b/ap/lib/libtinyalsa/README
@@ -0,0 +1,9 @@
+tinyalsa: a small library to interface with ALSA in the Linux kernel
+
+The aims are:
+
+- Provide a basic pcm and mixer API
+- If it's not absolutely needed, don't add it to the API
+- Avoid supporting complex and unnecessary operations that could be
+ dealt with at a higher level
+
diff --git a/ap/lib/libtinyalsa/alsatest.c b/ap/lib/libtinyalsa/alsatest.c
new file mode 100644
index 0000000..e599fff
--- /dev/null
+++ b/ap/lib/libtinyalsa/alsatest.c
@@ -0,0 +1,764 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+//#include <stdlib.h>
+//#include "pthread.h"
+//#include "alsatest.h"
+//#include <stdbool.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <tinyalsa/asoundlib.h>
+#include <sound/asound.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <ctype.h>
+
+#define ID_RIFF 0x46464952
+#define ID_WAVE 0x45564157
+#define ID_FMT 0x20746d66
+#define ID_DATA 0x61746164
+
+#define FORMAT_PCM 1
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
+
+struct riff_wave_header {
+ uint32_t riff_id;
+ uint32_t riff_sz;
+ uint32_t wave_id;
+};
+
+struct chunk_header {
+ uint32_t id;
+ uint32_t sz;
+};
+
+struct chunk_fmt {
+ uint16_t audio_format;
+ uint16_t num_channels;
+ uint32_t sample_rate;
+ uint32_t byte_rate;
+ uint16_t block_align;
+ uint16_t bits_per_sample;
+};
+struct wav_header {
+ uint32_t riff_id;
+ uint32_t riff_sz;
+ uint32_t riff_fmt;
+ uint32_t fmt_id;
+ uint32_t fmt_sz;
+ uint16_t audio_format;
+ uint16_t num_channels;
+ uint32_t sample_rate;
+ uint32_t byte_rate;
+ uint16_t block_align;
+ uint16_t bits_per_sample;
+ uint32_t data_id;
+ uint32_t data_sz;
+};
+
+enum t_output_path{
+ T_OUTPUT_RECEIVER,
+ T_OUTPUT_SPEAKER,
+ T_OUTPUT_HEADSET,
+};
+
+enum t_input_path{
+ T_INPUT_MICLP,
+ T_INPUT_MICRP,
+};
+
+enum t_output_vol{
+ T_OUTPUT_VOL_MINUS_63_5DB = 0,
+ T_OUTPUT_VOL_MINUS_63DB = 1,
+ T_OUTPUT_VOL_MINUS_6DB = 115,
+ T_OUTPUT_VOL_MINUS_3DB = 121,
+ T_OUTPUT_VOL_MINUS_2DB = 123,
+ T_OUTPUT_VOL_MINUS_1DB = 125,
+ T_OUTPUT_VOL_0DB = 127,
+ T_OUTPUT_VOL_1DB = 129,
+ T_OUTPUT_VOL_2DB = 131,
+ T_OUTPUT_VOL_3DB = 133,
+ T_OUTPUT_VOL_6DB = 139,
+ T_OUTPUT_VOL_9DB = 145,
+ T_OUTPUT_VOL_12DB = 151,
+ T_OUTPUT_VOL_24DB = 175,
+};
+
+enum t_input_vol{
+ T_INPUT_VOL_MINUS_12DB = 0,
+ T_INPUT_VOL_MINUS_3DB = 18,
+ T_INPUT_VOL_MINUS_2DB = 20,
+ T_INPUT_VOL_MINUS_1DB = 22,
+ T_INPUT_VOL_0DB = 24,
+ T_INPUT_VOL_1DB = 26,
+ T_INPUT_VOL_2DB = 28,
+ T_INPUT_VOL_3DB = 30,
+ T_INPUT_VOL_20DB = 64,
+};
+
+struct audio_para_conf {
+ const char *control;
+ char *values[2];
+};
+
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"Speaker Analog Playback Volume",{"127"}},
+ {"Speaker Driver Playback Switch",{"1"}},
+ {"DAC Left Input",{"Mono"}},
+ {"DAC Right Input",{"Mono"}},
+ {"Output Right From Right DAC",{"1"}},
+ {"Output Left From Left DAC",{"1"}},
+ {"HP Analog Playback Volume",{"127","127"}},
+ {"HP Driver Playback Switch",{"1","1"}}, //7dB
+
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"Mic PGA Capture Volume",{"40"}},
+ {"ADC Capture Switch",{"1"}},
+ {"ADC Fine Capture Volume",{"0"}},
+
+};
+
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"Speaker Switch",{"0"}},
+ {"HP Left Switch",{"1"}},
+ {"HP Right Switch",{"1"}},
+ {"HP Driver Playback Volume",{"0","0"}},
+};
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"Speaker Switch",{"1"}},
+ {"Speaker Driver Playback Volume",{"2"}}, //18dB
+ {"HP Left Switch",{"0"}},
+ {"HP Right Switch",{"0"}},
+};
+
+static struct audio_para_conf mic1lp_mc1lm_inpath_para_audio[] = { //¶ÔÓ¦ÓÚMic1lp_Mic1lmÊäÈëͨµÀ
+ {"MIC1LM P-Terminal",{"Off"}},
+ {"MIC1RP P-Terminal",{"Off"}},
+ {"MIC1LP P-Terminal",{"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal",{"FFR 10 Ohm"}},
+
+};
+
+static struct audio_para_conf mic1rp_inpath_para_audio[] = {//¶ÔÓ¦ÓÚMic1rpÊäÈëͨµÀ
+ {"MIC1LM P-Terminal",{"Off"}},
+ {"MIC1RP P-Terminal",{"FFR 10 Ohm"}},
+ {"MIC1LP P-Terminal",{"Off"}},
+ {"MIC1LM M-Terminal",{"Off"}},
+};
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"Speaker Switch",{"0"}},
+ {"DAC Playback Volume",{"129","129"}},
+ {"HP Left Switch",{"1"}},
+ {"HP Right Switch",{"1"}},
+ {"HP Driver Playback Volume",{"7","7"}},
+ {"MIC1LM P-Terminal",{"Off"}},
+ {"MIC1RP P-Terminal",{"Off"}},
+ {"MIC1LP P-Terminal",{"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal",{"FFR 10 Ohm"}},
+ {"ADC Capture Volume",{"24"}},
+ {"voice processing path select",{"handset"}},
+
+};
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"Speaker Switch",{"0"}},
+ {"DAC Playback Volume ",{"129","129"}},
+ {"HP Left Switch",{"1"}},
+ {"HP Right Switch",{"1"}},
+ {"HP Driver Playback Switch",{"7","7"}}, //7dB
+ {"MIC1LM P-Terminal",{"Off"}},
+ {"MIC1RP P-Terminal",{"FFR 10 Ohm"}},
+ {"MIC1LP P-Terminal",{"Off"}},
+ {"MIC1LM M-Terminal",{"Off"}},
+ {"ADC Capture Volume",{"24"}},
+ {"voice processing select",{"headset"}},
+};
+
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+
+ {"DAC Playback Volume",{"124","124"}}, //-1.5dB
+ {"Speaker Switch",{"1"}},
+ {"Speaker Driver Playback Volume",{"2"}}, //18dB
+ {"HP Left Switch",{"0"}},
+ {"HP Right Switch",{"0"}},
+ {"MIC1LM P-Terminal",{"Off"}},
+ {"MIC1RP P-Terminal",{"Off"}},
+ {"MIC1LP P-Terminal",{"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal",{"FFR 10 Ohm"}},
+ {"ADC Capture Volume",{"24"}},
+ {"voice processing path select",{"speak"}},
+};
+
+static struct audio_para_conf output_dac_vol = {"DAC Playback Volume",{"24"}};
+
+static struct audio_para_conf input_adc_vol = {"ADC Capture Volume",{"129","129"}};
+
+static int sig_close = 1;
+
+static int s_outpath = T_OUTPUT_SPEAKER;
+static int s_inpath = T_INPUT_MICLP;
+static int s_invol = T_INPUT_VOL_0DB;
+static int s_outvol = T_OUTPUT_VOL_0DB;
+
+void stream_close(int sig)
+{
+ /* allow the stream to be closed gracefully */
+ signal(sig, SIG_IGN);
+ sig_close = 0;
+}
+
+static void tinymix_set_value_test(struct mixer *mixer, const char *control,
+ char **values)
+{
+ struct mixer_ctl *ctl;
+ enum mixer_ctl_type type;
+ unsigned int num_ctl_values;
+ unsigned int i;
+
+ if (isdigit(control[0]))
+ ctl = mixer_get_ctl(mixer, atoi(control));
+ else
+ ctl = mixer_get_ctl_by_name(mixer, control);
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ type = mixer_ctl_get_type(ctl);
+ num_ctl_values = mixer_ctl_get_num_values(ctl);
+
+ if (isdigit(values[0][0])) {
+
+ for (i = 0; i < num_ctl_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, atoi(values[i]))) {
+ fprintf(stderr, "Error: invalid value for index %d\n", i);
+ return;
+ }
+ }
+
+ } else {
+ if (type == MIXER_CTL_TYPE_ENUM) {
+ /*if (num_values != 1) {
+ fprintf(stderr, "Enclose strings in quotes and try again\n");
+ return;
+ }*/
+ if (mixer_ctl_set_enum_by_string(ctl, values[0]))
+ fprintf(stderr, "Error: invalid enum value\n");
+ } else {
+ fprintf(stderr, "Error: only enum types can be set with strings\n");
+ }
+ }
+}
+
+int mix_set_outputpath(struct mixer *mixer, int path)
+{
+ int i;
+ for(i = 0;i<ARRAY_SIZE(common_out_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,common_out_para_audio[i].control,common_out_para_audio[i].values);
+ }
+ switch(path)
+ {
+ case T_OUTPUT_RECEIVER:
+ for(i = 0;i<ARRAY_SIZE(hp_outpath_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,hp_outpath_para_audio[i].control,hp_outpath_para_audio[i].values);
+ }
+ break;
+ case T_OUTPUT_SPEAKER:
+ for(i = 0;i<ARRAY_SIZE(spk_outpath_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,spk_outpath_para_audio[i].control,spk_outpath_para_audio[i].values);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mix_set_inputpath(struct mixer *mixer, int path)
+{
+ int i;
+ for(i = 0;i<ARRAY_SIZE(common_in_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,common_in_para_audio[i].control,common_in_para_audio[i].values);
+ }
+ switch(path)
+ {
+ case T_INPUT_MICLP:
+ for(i = 0;i<ARRAY_SIZE(mic1lp_mc1lm_inpath_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,mic1lp_mc1lm_inpath_para_audio[i].control,mic1lp_mc1lm_inpath_para_audio[i].values);
+ }
+ break;
+ case T_INPUT_MICRP:
+ for(i = 0;i<ARRAY_SIZE(mic1rp_inpath_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,mic1rp_inpath_para_audio[i].control,mic1rp_inpath_para_audio[i].values);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mix_set_inputvol(struct mixer *mixer, int volume)
+{
+
+ struct mixer_ctl *ctl = input_adc_vol.control;
+ enum mixer_ctl_type type;
+ unsigned int num_ctl_values;
+ unsigned int i;
+
+ ctl = mixer_get_ctl_by_name(mixer, ctl);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+// int value = atoi(input_adc_vol.values[0]);
+// mixer_ctl_set_value(ctl, 0, value);
+ mixer_ctl_set_value(ctl, 0, volume);
+
+ return 0;
+}
+
+int mix_set_outputvol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl = output_dac_vol.control;
+ enum mixer_ctl_type type;
+ unsigned int i;
+
+ ctl = mixer_get_ctl_by_name(mixer, ctl);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ mixer_ctl_set_value(ctl, 0, volume);
+ mixer_ctl_set_value(ctl, 1, volume);
+// int value = atoi(output_dac_vol.values[0]);
+// mixer_ctl_set_value(ctl, 0, value);
+// value = atoi(output_dac_vol.values[1]);
+// mixer_ctl_set_value(ctl, 1, value);
+
+ return 0;
+}
+
+int mix_set_output_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl = "DAC Mute";
+ enum mixer_ctl_type type;
+ unsigned int i;
+ printf("mix_set_output_mute %d\n",enable);
+
+ ctl = mixer_get_ctl_by_name(mixer, ctl);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+ mixer_ctl_set_value(ctl, 0, enable);
+ mixer_ctl_set_value(ctl, 1, enable);
+}
+
+int mix_set_input_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl = "ADC Capture Switch";
+ enum mixer_ctl_type type;
+ unsigned int i;
+
+ ctl = mixer_get_ctl_by_name(mixer, ctl);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ mixer_ctl_set_value(ctl, 0, !enable);
+}
+
+int check_param(struct pcm_params *params, unsigned int param, unsigned int value,
+ char *param_name, char *param_unit)
+{
+ unsigned int min;
+ unsigned int max;
+ int is_within_bounds = 1;
+
+ min = pcm_params_get_min(params, param);
+ if (value < min) {
+ fprintf(stderr, "%s is %u%s, device only supports >= %u%s\n", param_name, value,
+ param_unit, min, param_unit);
+ is_within_bounds = 0;
+ }
+
+ max = pcm_params_get_max(params, param);
+ if (value > max) {
+ fprintf(stderr, "%s is %u%s, device only supports <= %u%s\n", param_name, value,
+ param_unit, max, param_unit);
+ is_within_bounds = 0;
+ }
+
+ return is_within_bounds;
+}
+
+int sample_is_playable(unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count)
+{
+ struct pcm_params *params;
+ int can_play;
+
+ params = pcm_params_get(card, device, PCM_OUT);
+ if (params == NULL) {
+ fprintf(stderr, "Unable to open PCM device %u.\n", device);
+ return 0;
+ }
+
+ can_play = check_param(params, PCM_PARAM_RATE, rate, "Sample rate", "Hz");
+ can_play &= check_param(params, PCM_PARAM_CHANNELS, channels, "Sample", " channels");
+ can_play &= check_param(params, PCM_PARAM_SAMPLE_BITS, bits, "Bitrate", " bits");
+ can_play &= check_param(params, PCM_PARAM_PERIOD_SIZE, period_size, "Period size", "Hz");
+ can_play &= check_param(params, PCM_PARAM_PERIODS, period_count, "Period count", "Hz");
+
+ pcm_params_free(params);
+
+ return can_play;
+}
+
+void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count)
+{
+ struct pcm_config config;
+ struct pcm *pcm;
+ char *buffer;
+ int size;
+ int num_read;
+
+ memset(&config, 0, sizeof(config));
+ config.channels = channels;
+ config.rate = rate;
+ config.period_size = period_size;
+ config.period_count = period_count;
+ if (bits == 32)
+ config.format = PCM_FORMAT_S32_LE;
+ else if (bits == 16)
+ config.format = PCM_FORMAT_S16_LE;
+ config.start_threshold = 0;
+ config.stop_threshold = 0;
+ config.silence_threshold = 0;
+
+ if (!sample_is_playable(card, device, channels, rate, bits, period_size, period_count)) {
+ return;
+ }
+
+ pcm = pcm_open(card, device, PCM_OUT, &config);
+ if (!pcm || !pcm_is_ready(pcm)) {
+ fprintf(stderr, "Unable to open PCM device %u (%s)\n",
+ device, pcm_get_error(pcm));
+ return;
+ }
+
+ size = pcm_frames_to_bytes(pcm, pcm_get_buffer_size(pcm));
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %d bytes\n", size);
+ free(buffer);
+ pcm_close(pcm);
+ return;
+ }
+
+ printf("Playing sample: %u ch, %u hz, %u bit\n", channels, rate, bits);
+
+ /* catch ctrl-c to shutdown cleanly */
+ signal(SIGINT, stream_close);
+
+ do {
+ num_read = fread(buffer, 1, size, file);
+ if (num_read > 0) {
+ if (pcm_write(pcm, buffer, num_read)) {
+ fprintf(stderr, "Error playing sample\n");
+ break;
+ }
+ }
+ } while (sig_close && num_read > 0);
+
+ free(buffer);
+ pcm_close(pcm);
+}
+
+unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device,
+ unsigned int channels, unsigned int rate,
+ enum pcm_format format, unsigned int period_size,
+ unsigned int period_count)
+{
+ struct pcm_config config;
+ struct pcm *pcm;
+ char *buffer;
+ unsigned int size;
+ unsigned int bytes_read = 0;
+
+ memset(&config, 0, sizeof(config));
+ config.channels = channels;
+ config.rate = rate;
+ config.period_size = period_size;
+ config.period_count = period_count;
+ config.format = format;
+ config.start_threshold = 0;
+ config.stop_threshold = 0;
+ config.silence_threshold = 0;
+
+ pcm = pcm_open(card, device, PCM_IN, &config);
+ if (!pcm || !pcm_is_ready(pcm)) {
+ fprintf(stderr, "Unable to open PCM device (%s)\n",
+ pcm_get_error(pcm));
+ return 0;
+ }
+
+ size = pcm_frames_to_bytes(pcm, pcm_get_buffer_size(pcm));
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %d bytes\n", size);
+ free(buffer);
+ pcm_close(pcm);
+ return 0;
+ }
+
+ printf("Capturing sample: %u ch, %u hz, %u bit\n", channels, rate,
+ pcm_format_to_bits(format));
+
+ while (sig_close && !pcm_read(pcm, buffer, size)) {
+ if (fwrite(buffer, 1, size, file) != size) {
+ fprintf(stderr,"Error capturing sample\n");
+ break;
+ }
+ bytes_read += size;
+ if (bytes_read>=300000)
+ break;
+ }
+
+ free(buffer);
+ pcm_close(pcm);
+ return pcm_bytes_to_frames(pcm, bytes_read);
+}
+
+int main(int argc, char **argv)
+{
+ FILE *file;
+ struct wav_header header;
+ unsigned int card = 0;
+ unsigned int device = 0;
+ unsigned int channels = 2;
+ unsigned int rate = 44100;
+ unsigned int bits = 16;
+ unsigned int frames;
+ unsigned int period_size = 1024;
+ unsigned int period_count = 4;
+ enum pcm_format format;
+
+ struct riff_wave_header riff_wave_header;
+ struct chunk_header chunk_header;
+ struct chunk_fmt chunk_fmt;
+ char *filename;
+ int more_chunks = 1;
+ struct mixer *mixer;
+
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s cap file.wav [-D card] [-d device] [-c channels] "
+ "[-r rate] [-b bits] [-p period_size] [-n n_periods]\n", argv[0]);
+ fprintf(stderr, "Usage: %s play file.wav [-D card] [-d device] [-p period_size]"
+ " [-n n_periods] \n", argv[0]);
+ return 1;
+ }
+
+ if (strcmp(argv[1], "play") == 0) {
+ mixer = mixer_open(card);
+ if (!mixer) {
+ fprintf(stderr, "Failed to open mixer\n");
+ return -1;
+ }
+ mix_set_outputpath(mixer, T_OUTPUT_SPEAKER);
+ mix_set_outputvol(mixer, T_OUTPUT_VOL_0DB);
+ // mix_set_output_mute(mixer,false);
+ mixer_close(mixer);
+
+ filename = argv[2];
+ file = fopen(filename, "rb");
+ if (!file) {
+ fprintf(stderr, "Unable to open file '%s'\n", filename);
+ return 1;
+ }
+
+ fread(&riff_wave_header, sizeof(riff_wave_header), 1, file);
+ if ((riff_wave_header.riff_id != ID_RIFF) ||
+ (riff_wave_header.wave_id != ID_WAVE)) {
+ fprintf(stderr, "Error: '%s' is not a riff/wave file\n", filename);
+ fclose(file);
+ return 1;
+ }
+
+ do {
+ fread(&chunk_header, sizeof(chunk_header), 1, file);
+
+ switch (chunk_header.id) {
+ case ID_FMT:
+ fread(&chunk_fmt, sizeof(chunk_fmt), 1, file);
+ /* If the format header is larger, skip the rest */
+ if (chunk_header.sz > sizeof(chunk_fmt))
+ fseek(file, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
+ break;
+ case ID_DATA:
+ /* Stop looking for chunks */
+ more_chunks = 0;
+ break;
+ default:
+ /* Unknown chunk, skip bytes */
+ fseek(file, chunk_header.sz, SEEK_CUR);
+ }
+ } while (more_chunks);
+
+ /* parse command line arguments */
+ argv += 3;
+ while (*argv) {
+ if (strcmp(*argv, "-d") == 0) {
+ argv++;
+ if (*argv)
+ device = atoi(*argv);
+ }
+ if (strcmp(*argv, "-p") == 0) {
+ argv++;
+ if (*argv)
+ period_size = atoi(*argv);
+ }
+ if (strcmp(*argv, "-n") == 0) {
+ argv++;
+ if (*argv)
+ period_count = atoi(*argv);
+ }
+ if (strcmp(*argv, "-D") == 0) {
+ argv++;
+ if (*argv)
+ card = atoi(*argv);
+ }
+ if (*argv)
+ argv++;
+ }
+
+ play_sample(file, card, device, chunk_fmt.num_channels, chunk_fmt.sample_rate,
+ chunk_fmt.bits_per_sample, period_size, period_count);
+
+ fclose(file);
+
+ }else if(strcmp(argv[1], "cap") == 0) {
+ mixer = mixer_open(card);
+ if (!mixer) {
+ fprintf(stderr, "Failed to open mixer\n");
+ return -1;
+ }
+ mix_set_inputpath(mixer, T_INPUT_MICLP);
+ mix_set_inputvol(mixer, T_INPUT_VOL_0DB);
+ mixer_close(mixer);
+
+ file = fopen(argv[2], "wb");
+ if (!file) {
+ fprintf(stderr, "Unable to create file '%s'\n", argv[1]);
+ return 1;
+ }
+
+ /* parse command line arguments */
+ argv += 3;
+ while (*argv) {
+ if (strcmp(*argv, "-d") == 0) {
+ argv++;
+ if (*argv)
+ device = atoi(*argv);
+ } else if (strcmp(*argv, "-c") == 0) {
+ argv++;
+ if (*argv)
+ channels = atoi(*argv);
+ } else if (strcmp(*argv, "-r") == 0) {
+ argv++;
+ if (*argv)
+ rate = atoi(*argv);
+ } else if (strcmp(*argv, "-b") == 0) {
+ argv++;
+ if (*argv)
+ bits = atoi(*argv);
+ } else if (strcmp(*argv, "-D") == 0) {
+ argv++;
+ if (*argv)
+ card = atoi(*argv);
+ } else if (strcmp(*argv, "-p") == 0) {
+ argv++;
+ if (*argv)
+ period_size = atoi(*argv);
+ } else if (strcmp(*argv, "-n") == 0) {
+ argv++;
+ if (*argv)
+ period_count = atoi(*argv);
+ }
+ if (*argv)
+ argv++;
+ }
+
+ header.riff_id = ID_RIFF;
+ header.riff_sz = 0;
+ header.riff_fmt = ID_WAVE;
+ header.fmt_id = ID_FMT;
+ header.fmt_sz = 16;
+ header.audio_format = FORMAT_PCM;
+ header.num_channels = channels;
+ header.sample_rate = rate;
+
+ switch (bits) {
+ case 32:
+ format = PCM_FORMAT_S32_LE;
+ break;
+ case 24:
+ format = PCM_FORMAT_S24_LE;
+ break;
+ case 16:
+ format = PCM_FORMAT_S16_LE;
+ break;
+ default:
+ fprintf(stderr, "%d bits is not supported.\n", bits);
+ return 1;
+ }
+
+ header.bits_per_sample = pcm_format_to_bits(format);
+ header.byte_rate = (header.bits_per_sample / 8) * channels * rate;
+ header.block_align = channels * (header.bits_per_sample / 8);
+ header.data_id = ID_DATA;
+
+ /* leave enough room for header */
+ fseek(file, sizeof(struct wav_header), SEEK_SET);
+
+ /* install signal handler and begin capturing */
+ signal(SIGINT, stream_close);
+ frames = capture_sample(file, card, device, header.num_channels,
+ header.sample_rate, format,
+ period_size, period_count);
+ printf("Captured %d frames\n", frames);
+
+ /* write header now all information is known */
+ header.data_sz = frames * header.block_align;
+ header.riff_sz = header.data_sz + sizeof(header) - 8;
+ fseek(file, 0, SEEK_SET);
+ fwrite(&header, sizeof(struct wav_header), 1, file);
+
+ fclose(file);
+ }
+
+ return 0;
+}
diff --git a/ap/lib/libtinyalsa/audio_mixer_ctrl.c b/ap/lib/libtinyalsa/audio_mixer_ctrl.c
new file mode 100755
index 0000000..68448ab
--- /dev/null
+++ b/ap/lib/libtinyalsa/audio_mixer_ctrl.c
@@ -0,0 +1,1327 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <tinyalsa/asoundlib.h>
+#include <sound/asound.h>
+#include <tinyalsa/audio_mixer_ctrl.h>
+
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
+struct audio_para_conf {
+ const char *control;
+ char *values[2];
+};
+
+
+#if defined _USE_CODEC_TI3100
+
+
+enum t_output_vol {
+ T_OUTPUT_VOL_MINUS_63_5DB = 0,
+ T_OUTPUT_VOL_MINUS_63DB = 1,
+ T_OUTPUT_VOL_MINUS_27DB = 73,
+ T_OUTPUT_VOL_MINUS_24DB = 79,
+ T_OUTPUT_VOL_MINUS_21DB = 85,
+ T_OUTPUT_VOL_MINUS_18DB = 91,
+ T_OUTPUT_VOL_MINUS_15DB = 97,
+ T_OUTPUT_VOL_MINUS_12DB = 103,
+ T_OUTPUT_VOL_MINUS_9DB = 109,
+ T_OUTPUT_VOL_MINUS_6DB = 115,
+ T_OUTPUT_VOL_MINUS_3DB = 121,
+ T_OUTPUT_VOL_MINUS_2DB = 123,
+ T_OUTPUT_VOL_MINUS_1DB = 125,
+ T_OUTPUT_VOL_0DB = 127,
+ T_OUTPUT_VOL_1DB = 129,
+ T_OUTPUT_VOL_2DB = 131,
+ T_OUTPUT_VOL_3DB = 133,
+ T_OUTPUT_VOL_6DB = 139,
+ T_OUTPUT_VOL_9DB = 145,
+ T_OUTPUT_VOL_12DB = 151,
+ T_OUTPUT_VOL_24DB = 175,
+};
+
+enum t_input_vol {
+ T_INPUT_VOL_MINUS_12DB = 0,
+ T_INPUT_VOL_MINUS_7DB = 10,
+ T_INPUT_VOL_MINUS_6DB = 12,
+ T_INPUT_VOL_MINUS_5DB = 14,
+ T_INPUT_VOL_MINUS_4DB = 16,
+ T_INPUT_VOL_MINUS_3DB = 18,
+ T_INPUT_VOL_MINUS_2DB = 20,
+ T_INPUT_VOL_MINUS_1DB = 22,
+ T_INPUT_VOL_0DB = 24,
+ T_INPUT_VOL_1DB = 26,
+ T_INPUT_VOL_2DB = 28,
+ T_INPUT_VOL_3DB = 30,
+ T_INPUT_VOL_20DB = 64,
+};
+
+static struct audio_para_conf init_default_para[] = { //¿ª»ú³õʼ»¯µ÷ÓÃ
+ {"Mic PGA Capture Volume", {"40"}},
+ {"ADC Mute", {"0"}},
+ {"ADC Fine Capture Volume", {"0"}},
+ {"Speaker Analog Playback Volume", {"127"}},
+ {"Speaker Driver Playback Switch", {"1"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+};
+
+#ifdef _USE_7520V3_PHONE_TYPE_FWP
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"Speaker Analog Playback Volume", {"127"}},
+ {"Speaker Driver Playback Switch", {"1"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"Mic PGA Capture Volume", {"12"}},
+ {"ADC Mute", {"0"}},
+ {"ADC Fine Capture Volume", {"0"}},
+
+};
+
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"Speaker Switch", {"0"}},
+ {"HP Left Switch", {"1"}},
+ {"HP Right Switch", {"1"}},
+ {"HP Driver Playback Volume", {"0", "0"}},
+};
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"Speaker Switch", {"1"}},
+ {"Speaker Driver Playback Volume", {"2"}}, //18dB
+ {"HP Left Switch", {"0"}},
+ {"HP Right Switch", {"0"}},
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚMic1lp_Mic1lmÊäÈëͨµÀ
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"Off"}},
+ {"MIC1LP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal", {"FFR 10 Ohm"}},
+
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚMic1rpÊäÈëͨµÀ
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LP P-Terminal", {"Off"}},
+ {"MIC1LM M-Terminal", {"Off"}},
+};
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"Mic PGA Capture Volume", {"12"}},
+ //{"ADC Mute", {"0"}},
+ //{"ADC Fine Capture Volume", {"0"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+ {"Speaker Switch", {"0"}},
+ {"DAC Playback Volume", {"129", "129"}},
+ {"HP Left Switch", {"1"}},
+ {"HP Right Switch", {"1"}},
+ {"HP Driver Playback Volume", {"5", "5"}},
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"Off"}},
+ {"MIC1LP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal", {"FFR 10 Ohm"}},
+ {"ADC Capture Volume", {"24"}},
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"Mic PGA Capture Volume", {"40"}},
+ //{"ADC Mute", {"0"}},
+ //{"ADC Fine Capture Volume", {"0"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+ {"Speaker Switch", {"0"}},
+ {"DAC Playback Volume ", {"129", "129"}},
+ {"HP Left Switch", {"1"}},
+ {"HP Right Switch", {"1"}},
+ {"HP Driver Playback Switch", {"7", "7"}}, //7dB
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LP P-Terminal", {"Off"}},
+ {"MIC1LM M-Terminal", {"Off"}},
+ {"ADC Capture Volume", {"24"}},
+ {"voice processing select", {"headset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"Mic PGA Capture Volume", {"12"}},
+ //{"ADC Mute", {"0"}},
+ //{"ADC Fine Capture Volume", {"0"}},
+ {"Speaker Analog Playback Volume", {"127"}},
+ {"Speaker Driver Playback Switch", {"1"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"DAC Playback Volume", {"124", "124"}}, //-1.5dB
+ {"Speaker Switch", {"1"}},
+ {"Speaker Driver Playback Volume", {"0"}}, //18dB
+ {"HP Left Switch", {"0"}},
+ {"HP Right Switch", {"0"}},
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"Off"}},
+ {"MIC1LP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal", {"FFR 10 Ohm"}},
+ {"ADC Capture Volume", {"24"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+#else
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"Speaker Analog Playback Volume", {"127"}},
+ {"Speaker Driver Playback Switch", {"1"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"Mic PGA Capture Volume", {"40"}},
+ {"ADC Mute", {"0"}},
+ {"ADC Fine Capture Volume", {"0"}},
+
+};
+
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"Speaker Switch", {"0"}},
+ {"HP Left Switch", {"1"}},
+ {"HP Right Switch", {"1"}},
+ {"HP Driver Playback Volume", {"0", "0"}},
+};
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"Speaker Switch", {"1"}},
+ {"Speaker Driver Playback Volume", {"2"}}, //18dB
+ {"HP Left Switch", {"0"}},
+ {"HP Right Switch", {"0"}},
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚMic1lp_Mic1lmÊäÈëͨµÀ
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"Off"}},
+ {"MIC1LP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal", {"FFR 10 Ohm"}},
+
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚMic1rpÊäÈëͨµÀ
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LP P-Terminal", {"Off"}},
+ {"MIC1LM M-Terminal", {"Off"}},
+};
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"Mic PGA Capture Volume", {"40"}},
+ //{"ADC Mute", {"0"}},
+ //{"ADC Fine Capture Volume", {"0"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+ {"Speaker Switch", {"0"}},
+ {"DAC Playback Volume", {"129", "129"}},
+ {"HP Left Switch", {"1"}},
+ {"HP Right Switch", {"1"}},
+ {"HP Driver Playback Volume", {"7", "7"}},
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"Off"}},
+ {"MIC1LP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal", {"FFR 10 Ohm"}},
+ {"ADC Capture Volume", {"24"}},
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"Mic PGA Capture Volume", {"40"}},
+ //{"ADC Mute", {"0"}},
+ //{"ADC Fine Capture Volume", {"0"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"HP Analog Playback Volume", {"127", "127"}},
+ {"HP Driver Playback Switch", {"1", "1"}}, //7dB
+ {"Speaker Switch", {"0"}},
+ {"DAC Playback Volume ", {"129", "129"}},
+ {"HP Left Switch", {"1"}},
+ {"HP Right Switch", {"1"}},
+ {"HP Driver Playback Switch", {"7", "7"}}, //7dB
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LP P-Terminal", {"Off"}},
+ {"MIC1LM M-Terminal", {"Off"}},
+ {"ADC Capture Volume", {"24"}},
+ {"voice processing select", {"headset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"Mic PGA Capture Volume", {"20"}},
+ //{"ADC Mute", {"0"}},
+ //{"ADC Fine Capture Volume", {"0"}},
+ {"Speaker Analog Playback Volume", {"127"}},
+ {"Speaker Driver Playback Switch", {"1"}},
+ {"DAC Left Input", {"Mono"}},
+ {"DAC Right Input", {"Mono"}},
+ {"Output Right From Right DAC", {"1"}},
+ {"Output Left From Left DAC", {"1"}},
+ {"DAC Playback Volume", {"124", "124"}}, //-1.5dB
+ {"Speaker Switch", {"1"}},
+ {"Speaker Driver Playback Volume", {"2"}}, //18dB
+ {"HP Left Switch", {"0"}},
+ {"HP Right Switch", {"0"}},
+ {"MIC1LM P-Terminal", {"Off"}},
+ {"MIC1RP P-Terminal", {"Off"}},
+ {"MIC1LP P-Terminal", {"FFR 10 Ohm"}},
+ {"MIC1LM M-Terminal", {"FFR 10 Ohm"}},
+ {"ADC Capture Volume", {"24"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+#endif
+static struct audio_para_conf output_dac_vol = {"DAC Playback Volume", {"129","129"}};
+
+static struct audio_para_conf input_adc_vol = {"ADC Capture Volume", {"24"}};
+
+static struct audio_para_conf dac_mute = {"DAC Mute", {"1", "1"}};
+static struct audio_para_conf adc_mute = {"ADC Mute", {"1"}};
+
+static struct audio_para_conf spk_path_onoff[] = {
+ {"Speaker Switch", {"0"}},
+};
+static struct audio_para_conf rcv_path_onoff[] = {
+ {"HP Left Switch", {"0"}},
+ {"HP Right Switch", {"0"}},
+};
+static struct audio_para_conf earp_path_onoff[] = {
+ {"HP Left Switch", {"0"}},
+ {"HP Right Switch", {"0"}},
+};
+static int output_vol_conversion(int vol)
+{
+ switch(vol){
+ case T_AUDIO_OUTPUT_VOL_LEVEL_0:
+ return T_OUTPUT_VOL_MINUS_63_5DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_1:
+ return T_OUTPUT_VOL_MINUS_27DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_2:
+ return T_OUTPUT_VOL_MINUS_24DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_3:
+ return T_OUTPUT_VOL_MINUS_21DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_4:
+ return T_OUTPUT_VOL_MINUS_18DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_5:
+ return T_OUTPUT_VOL_MINUS_15DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_6:
+ return T_OUTPUT_VOL_MINUS_12DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_7:
+ return T_OUTPUT_VOL_MINUS_9DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_8:
+ return T_OUTPUT_VOL_MINUS_6DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_9:
+ return T_OUTPUT_VOL_MINUS_3DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_10:
+ return T_OUTPUT_VOL_0DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_11:
+ return T_OUTPUT_VOL_3DB;
+ default:
+ return T_OUTPUT_VOL_0DB;
+ }
+}
+
+static int input_vol_conversion(int vol)
+{
+ switch(vol) {
+ case T_AUDIO_INPUT_VOL_LEVEL_0:
+ return T_INPUT_VOL_MINUS_12DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_1:
+ return T_INPUT_VOL_MINUS_7DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_2:
+ return T_INPUT_VOL_MINUS_6DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_3:
+ return T_INPUT_VOL_MINUS_5DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_4:
+ return T_INPUT_VOL_MINUS_4DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_5:
+ return T_INPUT_VOL_MINUS_3DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_6:
+ return T_INPUT_VOL_MINUS_2DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_7:
+ return T_INPUT_VOL_MINUS_1DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_8:
+ return T_INPUT_VOL_0DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_9:
+ return T_INPUT_VOL_1DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_10:
+ return T_INPUT_VOL_2DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_11:
+ return T_INPUT_VOL_3DB;
+ default:
+ return T_INPUT_VOL_0DB;
+ }
+}
+
+
+#elif defined _USE_CODEC_ES8374
+
+
+enum t_output_vol {
+ T_OUTPUT_VOL_MINUS_96DB = 0,
+ T_OUTPUT_VOL_MINUS_95DB = 2,
+ T_OUTPUT_VOL_MINUS_90DB = 12,
+ T_OUTPUT_VOL_MINUS_85DB = 22,
+ T_OUTPUT_VOL_MINUS_80DB = 32,
+ T_OUTPUT_VOL_MINUS_75DB = 42,
+ T_OUTPUT_VOL_MINUS_70DB = 52,
+ T_OUTPUT_VOL_MINUS_65DB = 62,
+ T_OUTPUT_VOL_MINUS_60DB = 72,
+ T_OUTPUT_VOL_MINUS_55DB = 82,
+ T_OUTPUT_VOL_MINUS_50DB = 92,
+ T_OUTPUT_VOL_MINUS_45DB = 102,
+ T_OUTPUT_VOL_MINUS_40DB = 112,
+ T_OUTPUT_VOL_MINUS_35DB = 122,
+ T_OUTPUT_VOL_MINUS_30DB = 132,
+ T_OUTPUT_VOL_MINUS_25DB = 142,
+ T_OUTPUT_VOL_MINUS_20DB = 152,
+ T_OUTPUT_VOL_MINUS_15DB = 162,
+ T_OUTPUT_VOL_MINUS_10DB = 172,
+ T_OUTPUT_VOL_MINUS_7DB = 178,
+ T_OUTPUT_VOL_MINUS_6DB = 180,
+ T_OUTPUT_VOL_MINUS_5DB = 182,
+ T_OUTPUT_VOL_MINUS_4DB = 184,
+ T_OUTPUT_VOL_MINUS_3DB = 186,
+ T_OUTPUT_VOL_MINUS_2DB = 188,
+ T_OUTPUT_VOL_MINUS_1DB = 190,
+ T_OUTPUT_VOL_0DB = 192
+};
+
+enum t_input_vol {
+ T_INPUT_VOL_MINUS_96DB = 0,
+ T_INPUT_VOL_MINUS_95DB = 2,
+ T_INPUT_VOL_MINUS_90DB = 12,
+ T_INPUT_VOL_MINUS_85DB = 22,
+ T_INPUT_VOL_MINUS_80DB = 32,
+ T_INPUT_VOL_MINUS_75DB = 42,
+ T_INPUT_VOL_MINUS_70DB = 52,
+ T_INPUT_VOL_MINUS_65DB = 62,
+ T_INPUT_VOL_MINUS_60DB = 72,
+ T_INPUT_VOL_MINUS_55DB = 82,
+ T_INPUT_VOL_MINUS_50DB = 92,
+ T_INPUT_VOL_MINUS_45DB = 102,
+ T_INPUT_VOL_MINUS_40DB = 112,
+ T_INPUT_VOL_MINUS_35DB = 122,
+ T_INPUT_VOL_MINUS_30DB = 132,
+ T_INPUT_VOL_MINUS_25DB = 142,
+ T_INPUT_VOL_MINUS_20DB = 152,
+ T_INPUT_VOL_MINUS_15DB = 162,
+ T_INPUT_VOL_MINUS_10DB = 172,
+ T_INPUT_VOL_MINUS_7DB = 178,
+ T_INPUT_VOL_MINUS_6DB = 180,
+ T_INPUT_VOL_MINUS_5DB = 182,
+ T_INPUT_VOL_MINUS_4DB = 184,
+ T_INPUT_VOL_MINUS_3DB = 186,
+ T_INPUT_VOL_MINUS_2DB = 188,
+ T_INPUT_VOL_MINUS_1DB = 190,
+ T_INPUT_VOL_0DB = 192
+};
+
+
+static struct audio_para_conf init_default_para[] = { //¿ª»ú³õʼ»¯µ÷ÓÃ
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ALC MUX", {"0"}},
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"ALC Capture Max PGA", {"15"}},
+ {"DAC MUTE", {"0"}},
+ {"DAC Playback Volume", {"120"}},
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SRC MUX", {"0"}}
+};
+
+//#ifdef _USE_7520V3_PHONE_TYPE_C31F
+#if ( defined _USE_7520V3_PHONE_TYPE_C31F || defined _USE_7520V3_PHONE_TYPE_WTWD )
+
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DAC MUTE", {"0"}},
+ //{"DAC Playback Volume", {"120"}},
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SRC MUX", {"0"}}
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+#if 0
+ {"ALC MUX", {"1"}},
+ {"ALC Capture Target Volume", {"5"}},
+ {"ALC Capture Max PGA", {"11"}},
+ {"ALC Capture Min PGA", {"2"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"0"}},
+ {"ALC Capture Attack Time", {"0"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+};
+
+#ifdef _USE_7520V3_PHONE_TYPE_WTWD
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}},
+ {"SPEAKER MIXER GAIN", {"41"}}, //1d
+ {"SPEAKER OUTPUT Volume", {"0"}}, //1e
+ {"DAC Playback Volume", {"192"}}, //38
+};
+#else
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"audio path select",{"handset"}},
+};
+
+#endif
+/*
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER GAIN", {"4"}},
+ {"SPEAKER OUTPUT Volume", {"4"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}}
+};
+*/
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"11"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"audio path select",{"speak"}},
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚLin1-Rin1ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚLin2-Rin2ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"2"}},
+};
+
+#ifdef _USE_7520V3_PHONE_TYPE_WTWD
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ //{"voice processing path select", {"headset"}}, // handset speak headset bluetooth
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}},
+ {"SPEAKER MIXER GAIN", {"32"}}, //old 41
+ {"SPEAKER OUTPUT Volume", {"0"}}, //1
+ {"DAC Playback Volume", {"192"}}, //38
+};
+
+#else
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"11"}},
+ {"DAC Playback Volume", {"192"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+};
+#endif
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing select", {"headset"}}, // handset speak headset bluetooth
+};
+#ifdef _USE_7520V3_PHONE_TYPE_WTWD //class-d -->receiver
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"186"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+#else//momo out -> speaker
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"0"}},
+ {"DAC Playback Volume", {"186"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+#endif
+
+
+
+#else
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DAC MUTE", {"0"}},
+ //{"DAC Playback Volume", {"120"}},
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SRC MUX", {"0"}}
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+#if 1
+ {"ALC MUX", {"1"}},
+ {"ALC Capture Target Volume", {"5"}},
+ {"ALC Capture Max PGA", {"11"}},
+ {"ALC Capture Min PGA", {"2"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"0"}},
+ {"ALC Capture Attack Time", {"0"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"3"}},
+ {"ADC Capture Volume", {"180"}},
+};
+
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}}
+};
+
+/*
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER GAIN", {"4"}},
+ {"SPEAKER OUTPUT Volume", {"4"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}}
+};
+*/
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"3"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}}
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚLin1-Rin1ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚLin2-Rin2ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"2"}},
+};
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing select", {"headset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+#endif
+
+static struct audio_para_conf output_dac_vol = {"DAC Playback Volume", {"120"}};
+
+static struct audio_para_conf input_adc_vol = {"ADC Capture Volume", {"192"}};
+
+static struct audio_para_conf dac_mute = {"DAC MUTE", {"1"}};
+static struct audio_para_conf adc_mute = {"ADC MUTE", {"1"}};
+
+static struct audio_para_conf spk_path_onoff[] = {
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+};
+
+static struct audio_para_conf rcv_path_onoff[] = {
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+};
+
+static struct audio_para_conf earp_path_onoff[] = {
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+};
+
+
+static int output_vol_conversion(int vol)
+{
+ switch(vol){
+ case T_AUDIO_OUTPUT_VOL_LEVEL_0:
+ return T_OUTPUT_VOL_MINUS_96DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_1:
+ return T_OUTPUT_VOL_MINUS_45DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_2:
+ return T_OUTPUT_VOL_MINUS_40DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_3:
+ return T_OUTPUT_VOL_MINUS_35DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_4:
+ return T_OUTPUT_VOL_MINUS_30DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_5:
+ return T_OUTPUT_VOL_MINUS_25DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_6:
+ return T_OUTPUT_VOL_MINUS_20DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_7:
+ return T_OUTPUT_VOL_MINUS_15DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_8:
+ return T_OUTPUT_VOL_MINUS_10DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_9:
+ return T_OUTPUT_VOL_MINUS_6DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_10:
+ return T_OUTPUT_VOL_MINUS_3DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_11:
+ return T_OUTPUT_VOL_0DB;
+ default:
+ return T_OUTPUT_VOL_0DB;
+ }
+}
+
+static int input_vol_conversion(int vol)
+{
+ switch(vol) {
+ case T_AUDIO_INPUT_VOL_LEVEL_0:
+ return T_INPUT_VOL_MINUS_96DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_1:
+ return T_INPUT_VOL_MINUS_30DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_2:
+ return T_INPUT_VOL_MINUS_25DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_3:
+ return T_INPUT_VOL_MINUS_20DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_4:
+ return T_INPUT_VOL_MINUS_15DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_5:
+ return T_INPUT_VOL_MINUS_10DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_6:
+ return T_INPUT_VOL_MINUS_7DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_7:
+ return T_INPUT_VOL_MINUS_4DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_8:
+ return T_INPUT_VOL_MINUS_3DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_9:
+ return T_INPUT_VOL_MINUS_2DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_10:
+ return T_INPUT_VOL_MINUS_1DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_11:
+ return T_INPUT_VOL_0DB;
+ default:
+ return T_INPUT_VOL_MINUS_30DB;
+ }
+}
+
+#endif
+
+//static struct audio_para_conf nxp_voice_vol = {"voice processing path Volume",{"3"}}; //(range 0->5)
+
+static void mix_set_value_wrap(struct mixer *mixer, const char *control, char **values)
+{
+ struct mixer_ctl *ctl;
+ enum mixer_ctl_type type;
+ unsigned int num_ctl_values;
+ unsigned int i;
+
+ if (isdigit(control[0]))
+ ctl = mixer_get_ctl(mixer, atoi(control));
+ else
+ ctl = mixer_get_ctl_by_name(mixer, control);
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ type = mixer_ctl_get_type(ctl);
+ num_ctl_values = mixer_ctl_get_num_values(ctl);
+
+ if (isdigit(values[0][0])) {
+
+ for (i = 0; i < num_ctl_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, atoi(values[i]))) {
+ fprintf(stderr, "Error: invalid value for index %d\n", i);
+ return;
+ }
+ }
+
+ } else {
+ if (type == MIXER_CTL_TYPE_ENUM) {
+ /*if (num_values != 1) {
+ fprintf(stderr, "Enclose strings in quotes and try again\n");
+ return;
+ }*/
+ if (mixer_ctl_set_enum_by_string(ctl, values[0]))
+ fprintf(stderr, "Error: invalid enum value\n");
+ } else {
+ fprintf(stderr, "Error: only enum types can be set with strings\n");
+ }
+ }
+}
+
+#ifdef _CPE_AUDIO_PRJ
+int mix_set_output_path(struct mixer *mixer, int path)
+{
+
+ return 0;
+}
+
+int mix_set_input_path(struct mixer *mixer, int path)
+{
+
+
+ return 0;
+}
+
+int mix_set_input_vol(struct mixer *mixer, int volume)
+{
+
+
+ return 0;
+}
+
+int mix_set_output_vol(struct mixer *mixer, int volume)
+{
+
+
+ return 0;
+}
+
+int mix_set_output_mute(struct mixer *mixer, bool enable)
+{
+
+
+ return 0;
+}
+
+int mix_set_input_mute(struct mixer *mixer, bool enable)
+{
+
+
+ return 0;
+}
+
+int mix_set_outputpath_onoff(struct mixer *mixer, int path ,bool onoff)
+{
+
+ return 0;
+}
+
+
+int mix_set_voice_vol(struct mixer *mixer, int volume)
+{
+
+
+ return 0;
+}
+
+int mix_set_voice_mute(struct mixer *mixer, bool enable)
+{
+
+
+ return 0;
+}
+
+int mix_set_voice_path(struct mixer *mixer, int path)
+{
+ int i;
+
+
+ return 0;
+}
+
+
+int mix_set_in_call_tone(struct mixer *mixer, int tontype)
+{
+
+
+ return 0;
+}
+
+int mix_set_default_param(struct mixer *mixer)
+{
+
+ return 0;
+}
+#else
+int mix_set_output_path(struct mixer *mixer, int path)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(common_out_para_audio); i++) {
+ mix_set_value_wrap(mixer, common_out_para_audio[i].control, common_out_para_audio[i].values);
+ }
+ switch (path) {
+ case T_OUTPUT_RECEIVER:
+ for (i = 0; i < ARRAY_SIZE(hp_outpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, hp_outpath_para_audio[i].control, hp_outpath_para_audio[i].values);
+ }
+ break;
+ case T_OUTPUT_SPEAKER:
+ for (i = 0; i < ARRAY_SIZE(spk_outpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, spk_outpath_para_audio[i].control, spk_outpath_para_audio[i].values);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mix_set_input_path(struct mixer *mixer, int path)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(common_in_para_audio); i++) {
+ mix_set_value_wrap(mixer, common_in_para_audio[i].control, common_in_para_audio[i].values);
+ }
+ switch (path) {
+ case T_INPUT_MICLP:
+ for (i = 0; i < ARRAY_SIZE(main_mic_inpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, main_mic_inpath_para_audio[i].control, main_mic_inpath_para_audio[i].values);
+ }
+ break;
+ case T_INPUT_MICRP:
+ for (i = 0; i < ARRAY_SIZE(aux_mic_inpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, aux_mic_inpath_para_audio[i].control, aux_mic_inpath_para_audio[i].values);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mix_set_input_vol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl;
+ char *name = input_adc_vol.control;
+ int num_values, i;
+ int vol = input_vol_conversion(volume);
+
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, i, vol);
+ }
+
+ return 0;
+}
+
+int mix_set_output_vol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl;
+ char *name = output_dac_vol.control;
+ int num_values, i;
+
+ int vol = output_vol_conversion(volume);
+
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, i, vol);
+ }
+
+ return 0;
+}
+
+int mix_set_output_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl;
+ char *name = dac_mute.control;
+ int num_values, i;
+
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, i, enable);
+ }
+
+ return 0;
+}
+
+int mix_set_input_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl;
+ char *name = adc_mute.control;
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ int num_values, i;
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, 0, enable);
+ }
+
+ return 0;
+}
+
+int mix_set_outputpath_onoff(struct mixer *mixer, int path ,bool onoff)
+{
+ struct mixer_ctl *ctl;
+ struct audio_para_conf *path_para;
+ int i, j, num_values, size;
+ switch(path) {
+ case T_OUTPUT_RECEIVER:
+ size = ARRAY_SIZE(rcv_path_onoff);
+ path_para = rcv_path_onoff;
+ break;
+ case T_OUTPUT_SPEAKER:
+ size = ARRAY_SIZE(spk_path_onoff);
+ path_para = spk_path_onoff;
+ break;
+ case T_OUTPUT_HEADSET:
+ size = ARRAY_SIZE(earp_path_onoff);
+ path_para = earp_path_onoff;
+ break;
+ default:
+ return -1;
+ }
+
+ for (i = 0; i < size; i++) {
+ ctl = mixer_get_ctl_by_name(mixer, path_para[i].control);
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (j = 0; j < num_values; j++) {
+ mixer_ctl_set_value(ctl, j, onoff);
+ }
+
+// mix_set_value_wrap(mixer, spk_path_onoff[i].control, spk_path_onoff[i].values);
+ }
+
+ return 0;
+}
+
+
+int mix_set_voice_vol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl;
+ char name[] = "voice processing path Volume";
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ mixer_ctl_set_value(ctl, 0, volume);
+
+ return 0;
+}
+
+int mix_set_voice_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl;
+ char name[] = "voice uplink mute";
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ mixer_ctl_set_value(ctl, 0, enable);
+
+ return 0;
+}
+
+int mix_set_voice_path(struct mixer *mixer, int path)
+{
+ int i;
+/*
+ for (i = 0; i < ARRAY_SIZE(common_in_para_audio); i++) {
+ tinymix_set_value_test(mixer, common_in_para_audio[i].control, common_in_para_audio[i].values);
+ }
+
+ for(i = 0;i<ARRAY_SIZE(common_out_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,common_out_para_audio[i].control,common_out_para_audio[i].values);
+ }
+*/
+ switch (path) {
+ case T_OUTPUT_RECEIVER:
+ for (i = 0; i < ARRAY_SIZE(handset_inoutpath_para_voice); i++) {
+ mix_set_value_wrap(mixer, handset_inoutpath_para_voice[i].control, handset_inoutpath_para_voice[i].values);
+ }
+ break;
+ case T_OUTPUT_SPEAKER:
+ for (i = 0; i < ARRAY_SIZE(spk_inoutpath_para_voice); i++) {
+ mix_set_value_wrap(mixer, spk_inoutpath_para_voice[i].control, spk_inoutpath_para_voice[i].values);
+ }
+ break;
+ case T_OUTPUT_HEADSET:
+ for (i = 0; i < ARRAY_SIZE(headset_inoutpath_para_voice); i++) {
+ mix_set_value_wrap(mixer, headset_inoutpath_para_voice[i].control, headset_inoutpath_para_voice[i].values);
+ }
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
+int mix_set_in_call_tone(struct mixer *mixer, int tontype)
+{
+ struct mixer_ctl *ctl;
+ char name[] = "voice tone sel";
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ mixer_ctl_set_value(ctl, 0, tontype);
+
+ return 0;
+}
+
+int mix_set_default_param(struct mixer *mixer)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(init_default_para); i++) {
+ mix_set_value_wrap(mixer, init_default_para[i].control, init_default_para[i].values);
+ }
+
+ return 0;
+}
+#endif
diff --git a/ap/lib/libtinyalsa/include/tinyalsa/asoundlib.h b/ap/lib/libtinyalsa/include/tinyalsa/asoundlib.h
new file mode 100644
index 0000000..97ee4f3
--- /dev/null
+++ b/ap/lib/libtinyalsa/include/tinyalsa/asoundlib.h
@@ -0,0 +1,310 @@
+/* asoundlib.h
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#ifndef ASOUNDLIB_H
+#define ASOUNDLIB_H
+
+#include <sys/time.h>
+#include <stddef.h>
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/*
+ * PCM API
+ */
+
+struct pcm;
+
+#define PCM_OUT 0x00000000
+#define PCM_IN 0x10000000
+#define PCM_MMAP 0x00000001
+#define PCM_NOIRQ 0x00000002
+#define PCM_NORESTART 0x00000004 /* PCM_NORESTART - when set, calls to
+ * pcm_write for a playback stream will not
+ * attempt to restart the stream in the case
+ * of an underflow, but will return -EPIPE
+ * instead. After the first -EPIPE error, the
+ * stream is considered to be stopped, and a
+ * second call to pcm_write will attempt to
+ * restart the stream.
+ */
+#define PCM_MONOTONIC 0x00000008 /* see pcm_get_htimestamp */
+
+/* PCM runtime states */
+#define PCM_STATE_OPEN 0
+#define PCM_STATE_SETUP 1
+#define PCM_STATE_PREPARED 2
+#define PCM_STATE_RUNNING 3
+#define PCM_STATE_XRUN 4
+#define PCM_STATE_DRAINING 5
+#define PCM_STATE_PAUSED 6
+#define PCM_STATE_SUSPENDED 7
+#define PCM_STATE_DISCONNECTED 8
+
+/* Bit formats */
+enum pcm_format {
+ PCM_FORMAT_INVALID = -1,
+ PCM_FORMAT_S16_LE = 0, /* 16-bit signed */
+ PCM_FORMAT_S32_LE, /* 32-bit signed */
+ PCM_FORMAT_S8, /* 8-bit signed */
+ PCM_FORMAT_S24_LE, /* 24-bits in 4-bytes */
+ PCM_FORMAT_S24_3LE, /* 24-bits in 3-bytes */
+
+ PCM_FORMAT_MAX,
+};
+
+/* Bitmask has 256 bits (32 bytes) in asound.h */
+struct pcm_mask {
+ unsigned int bits[32 / sizeof(unsigned int)];
+};
+
+/* Configuration for a stream */
+struct pcm_config {
+ unsigned int channels;
+ unsigned int rate;
+ unsigned int period_size;
+ unsigned int period_count;
+ enum pcm_format format;
+
+ /* Values to use for the ALSA start, stop and silence thresholds, and
+ * silence size. Setting any one of these values to 0 will cause the
+ * default tinyalsa values to be used instead.
+ * Tinyalsa defaults are as follows.
+ *
+ * start_threshold : period_count * period_size
+ * stop_threshold : period_count * period_size
+ * silence_threshold : 0
+ * silence_size : 0
+ */
+ unsigned int start_threshold;
+ unsigned int stop_threshold;
+ unsigned int silence_threshold;
+ unsigned int silence_size;
+
+ /* Minimum number of frames available before pcm_mmap_write() will actually
+ * write into the kernel buffer. Only used if the stream is opened in mmap mode
+ * (pcm_open() called with PCM_MMAP flag set). Use 0 for default.
+ */
+ int avail_min;
+};
+
+/* PCM parameters */
+enum pcm_param
+{
+ /* mask parameters */
+ PCM_PARAM_ACCESS,
+ PCM_PARAM_FORMAT,
+ PCM_PARAM_SUBFORMAT,
+ /* interval parameters */
+ PCM_PARAM_SAMPLE_BITS,
+ PCM_PARAM_FRAME_BITS,
+ PCM_PARAM_CHANNELS,
+ PCM_PARAM_RATE,
+ PCM_PARAM_PERIOD_TIME,
+ PCM_PARAM_PERIOD_SIZE,
+ PCM_PARAM_PERIOD_BYTES,
+ PCM_PARAM_PERIODS,
+ PCM_PARAM_BUFFER_TIME,
+ PCM_PARAM_BUFFER_SIZE,
+ PCM_PARAM_BUFFER_BYTES,
+ PCM_PARAM_TICK_TIME,
+};
+
+/* Mixer control types */
+enum mixer_ctl_type {
+ MIXER_CTL_TYPE_BOOL,
+ MIXER_CTL_TYPE_INT,
+ MIXER_CTL_TYPE_ENUM,
+ MIXER_CTL_TYPE_BYTE,
+ MIXER_CTL_TYPE_IEC958,
+ MIXER_CTL_TYPE_INT64,
+ MIXER_CTL_TYPE_UNKNOWN,
+
+ MIXER_CTL_TYPE_MAX,
+};
+
+/* Open and close a stream */
+struct pcm *pcm_open(unsigned int card, unsigned int device,
+ unsigned int flags, struct pcm_config *config);
+int pcm_close(struct pcm *pcm);
+int pcm_is_ready(struct pcm *pcm);
+
+/* Obtain the parameters for a PCM */
+struct pcm_params *pcm_params_get(unsigned int card, unsigned int device,
+ unsigned int flags);
+void pcm_params_free(struct pcm_params *pcm_params);
+
+struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params,
+ enum pcm_param param);
+unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
+ enum pcm_param param);
+void pcm_params_set_min(struct pcm_params *pcm_params,
+ enum pcm_param param, unsigned int val);
+unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
+ enum pcm_param param);
+void pcm_params_set_max(struct pcm_params *pcm_params,
+ enum pcm_param param, unsigned int val);
+
+/* Converts the pcm parameters to a human readable string.
+ * The string parameter is a caller allocated buffer of size bytes,
+ * which is then filled up to size - 1 and null terminated,
+ * if size is greater than zero.
+ * The return value is the number of bytes copied to string
+ * (not including null termination) if less than size; otherwise,
+ * the number of bytes required for the buffer.
+ */
+int pcm_params_to_string(struct pcm_params *params, char *string, unsigned int size);
+
+/* Returns 1 if the pcm_format is present (format bit set) in
+ * the pcm_params structure; 0 otherwise, or upon unrecognized format.
+ */
+int pcm_params_format_test(struct pcm_params *params, enum pcm_format format);
+
+/* Set and get config */
+int pcm_get_config(struct pcm *pcm, struct pcm_config *config);
+int pcm_set_config(struct pcm *pcm, struct pcm_config *config);
+
+/* Returns a human readable reason for the last error */
+const char *pcm_get_error(struct pcm *pcm);
+
+/* Returns the sample size in bits for a PCM format.
+ * As with ALSA formats, this is the storage size for the format, whereas the
+ * format represents the number of significant bits. For example,
+ * PCM_FORMAT_S24_LE uses 32 bits of storage.
+ */
+unsigned int pcm_format_to_bits(enum pcm_format format);
+
+/* Returns the buffer size (int frames) that should be used for pcm_write. */
+unsigned int pcm_get_buffer_size(struct pcm *pcm);
+unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames);
+unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes);
+
+/* Returns the pcm latency in ms */
+unsigned int pcm_get_latency(struct pcm *pcm);
+
+/* Returns available frames in pcm buffer and corresponding time stamp.
+ * The clock is CLOCK_MONOTONIC if flag PCM_MONOTONIC was specified in pcm_open,
+ * otherwise the clock is CLOCK_REALTIME.
+ * For an input stream, frames available are frames ready for the
+ * application to read.
+ * For an output stream, frames available are the number of empty frames available
+ * for the application to write.
+ */
+int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail,
+ struct timespec *tstamp);
+
+/* Write data to the fifo.
+ * Will start playback on the first write or on a write that
+ * occurs after a fifo underrun.
+ */
+int pcm_write(struct pcm *pcm, const void *data, unsigned int count);
+int pcm_read(struct pcm *pcm, void *data, unsigned int count);
+
+/*
+ * mmap() support.
+ */
+int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count);
+int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count);
+int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset,
+ unsigned int *frames);
+int pcm_mmap_commit(struct pcm *pcm, unsigned int offset, unsigned int frames);
+int pcm_mmap_avail(struct pcm *pcm);
+
+/* Prepare the PCM substream to be triggerable */
+int pcm_prepare(struct pcm *pcm);
+/* Start and stop a PCM channel that doesn't transfer data */
+int pcm_start(struct pcm *pcm);
+int pcm_stop(struct pcm *pcm);
+
+/* ioctl function for PCM driver */
+int pcm_ioctl(struct pcm *pcm, int request, ...);
+
+/* Interrupt driven API */
+int pcm_wait(struct pcm *pcm, int timeout);
+int pcm_get_poll_fd(struct pcm *pcm);
+
+/* Change avail_min after the stream has been opened with no need to stop the stream.
+ * Only accepted if opened with PCM_MMAP and PCM_NOIRQ flags
+ */
+int pcm_set_avail_min(struct pcm *pcm, int avail_min);
+
+/*
+ * MIXER API
+ */
+
+struct mixer;
+struct mixer_ctl;
+
+/* Open and close a mixer */
+struct mixer *mixer_open(unsigned int card);
+void mixer_close(struct mixer *mixer);
+
+/* Get info about a mixer */
+const char *mixer_get_name(struct mixer *mixer);
+
+/* Obtain mixer controls */
+unsigned int mixer_get_num_ctls(struct mixer *mixer);
+struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id);
+struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name);
+
+/* Get info about mixer controls */
+const char *mixer_ctl_get_name(struct mixer_ctl *ctl);
+enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl);
+const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl);
+unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl);
+unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl);
+const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
+ unsigned int enum_id);
+
+/* Some sound cards update their controls due to external events,
+ * such as HDMI EDID byte data changing when an HDMI cable is
+ * connected. This API allows the count of elements to be updated.
+ */
+void mixer_ctl_update(struct mixer_ctl *ctl);
+
+/* Set and get mixer controls */
+int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id);
+int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent);
+
+int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id);
+int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count);
+int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value);
+int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count);
+int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string);
+
+/* Determe range of integer mixer controls */
+int mixer_ctl_get_range_min(struct mixer_ctl *ctl);
+int mixer_ctl_get_range_max(struct mixer_ctl *ctl);
+
+#if defined(__cplusplus)
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/ap/lib/libtinyalsa/include/tinyalsa/audio_mixer_ctrl.h b/ap/lib/libtinyalsa/include/tinyalsa/audio_mixer_ctrl.h
new file mode 100644
index 0000000..d4e0a58
--- /dev/null
+++ b/ap/lib/libtinyalsa/include/tinyalsa/audio_mixer_ctrl.h
@@ -0,0 +1,87 @@
+#ifndef _AUDIO_MIXER_CTRL_H
+#define _AUDIO_MIXER_CTRL_H
+#include <stdint.h>
+#include <stdbool.h>
+#include <tinyalsa/asoundlib.h>
+#include <sound/asound.h>
+
+enum t_tone_class {
+ T_LOWPOWER_TONE = 0,
+ T_SMS_TONE = 1,
+ T_CALLSTD_TONE = 2,
+ T_ALARM_TONE = 3,
+ T_CALL_TIME_TONE = 4,
+};
+
+enum t_output_path {
+ T_OUTPUT_RECEIVER = 0,
+ T_OUTPUT_SPEAKER = 1,
+ T_OUTPUT_HEADSET = 2,
+};
+
+enum t_input_path {
+ T_INPUT_MICLP = 0,
+ T_INPUT_MICRP = 1,
+};
+
+enum t_audio_out_vol {
+ T_AUDIO_OUTPUT_VOL_LEVEL_0 = 0,
+ T_AUDIO_OUTPUT_VOL_LEVEL_1,
+ T_AUDIO_OUTPUT_VOL_LEVEL_2,
+ T_AUDIO_OUTPUT_VOL_LEVEL_3,
+ T_AUDIO_OUTPUT_VOL_LEVEL_4,
+ T_AUDIO_OUTPUT_VOL_LEVEL_5,
+ T_AUDIO_OUTPUT_VOL_LEVEL_6,
+ T_AUDIO_OUTPUT_VOL_LEVEL_7,
+ T_AUDIO_OUTPUT_VOL_LEVEL_8,
+ T_AUDIO_OUTPUT_VOL_LEVEL_9,
+ T_AUDIO_OUTPUT_VOL_LEVEL_10,
+ T_AUDIO_OUTPUT_VOL_LEVEL_11,
+ T_AUDIO_OUTPUT_VOL_LEVEL_12,
+ T_AUDIO_OUTPUT_VOL_LEVEL_13,
+ T_AUDIO_OUTPUT_VOL_LEVEL_14,
+ T_AUDIO_OUTPUT_VOL_LEVEL_15,
+ T_AUDIO_OUTPUT_VOL_LEVEL_16,
+ T_MAX_AUDIO_OUTPUT_VOL_LEVEL
+};
+
+enum t_audio_in_vol {
+ T_AUDIO_INPUT_VOL_LEVEL_0 = 0,
+ T_AUDIO_INPUT_VOL_LEVEL_1,
+ T_AUDIO_INPUT_VOL_LEVEL_2,
+ T_AUDIO_INPUT_VOL_LEVEL_3,
+ T_AUDIO_INPUT_VOL_LEVEL_4,
+ T_AUDIO_INPUT_VOL_LEVEL_5,
+ T_AUDIO_INPUT_VOL_LEVEL_6,
+ T_AUDIO_INPUT_VOL_LEVEL_7,
+ T_AUDIO_INPUT_VOL_LEVEL_8,
+ T_AUDIO_INPUT_VOL_LEVEL_9,
+ T_AUDIO_INPUT_VOL_LEVEL_10,
+ T_AUDIO_INPUT_VOL_LEVEL_11,
+
+ T_MAX_AUDIO_INPUT_VOL_LEVEL
+} ;
+
+enum t_voice_vol { // volume level for voice
+ T_VOICE_VOL_0_LEVEL = 0,
+ T_VOICE_VOL_1_LEVEL = 1,
+ T_VOICE_VOL_2_LEVEL = 2,
+ T_VOICE_VOL_3_LEVEL = 3,
+ T_VOICE_VOL_4_LEVEL = 4,
+ T_VOICE_VOL_5_LEVEL = 5,
+};
+
+int mix_set_output_path(struct mixer *mixer, int path);
+int mix_set_input_path(struct mixer *mixer, int path);
+int mix_set_input_vol(struct mixer *mixer, int volume);
+int mix_set_output_vol(struct mixer *mixer, int volume);
+int mix_set_output_mute(struct mixer *mixer, bool enable);
+int mix_set_input_mute(struct mixer *mixer, bool enable);
+int mix_set_outputpath_onoff(struct mixer *mixer, int path ,bool onoff);
+int mix_set_voice_vol(struct mixer *mixer, int volume);
+int mix_set_voice_mute(struct mixer *mixer, bool enable);
+int mix_set_voice_path(struct mixer *mixer, int path);
+int mix_set_in_call_tone(struct mixer *mixer, int tontype);
+int mix_set_default_param(struct mixer *mixer);
+
+#endif
diff --git a/ap/lib/libtinyalsa/mixer.c b/ap/lib/libtinyalsa/mixer.c
new file mode 100644
index 0000000..c4e6765
--- /dev/null
+++ b/ap/lib/libtinyalsa/mixer.c
@@ -0,0 +1,555 @@
+/* mixer.c
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <ctype.h>
+
+#include <sys/ioctl.h>
+
+#include <linux/ioctl.h>
+#define __force
+#define __bitwise
+#define __user
+#include <sound/asound.h>
+
+#include <tinyalsa/asoundlib.h>
+
+struct mixer_ctl {
+ struct mixer *mixer;
+ struct snd_ctl_elem_info *info;
+ char **ename;
+};
+
+struct mixer {
+ int fd;
+ struct snd_ctl_card_info card_info;
+ struct snd_ctl_elem_info *elem_info;
+ struct mixer_ctl *ctl;
+ unsigned int count;
+};
+
+void mixer_close(struct mixer *mixer)
+{
+ unsigned int n,m;
+
+ if (!mixer)
+ return;
+
+ if (mixer->fd >= 0)
+ close(mixer->fd);
+
+ if (mixer->ctl) {
+ for (n = 0; n < mixer->count; n++) {
+ if (mixer->ctl[n].ename) {
+ unsigned int max = mixer->ctl[n].info->value.enumerated.items;
+ for (m = 0; m < max; m++)
+ free(mixer->ctl[n].ename[m]);
+ free(mixer->ctl[n].ename);
+ }
+ }
+ free(mixer->ctl);
+ }
+
+ if (mixer->elem_info)
+ free(mixer->elem_info);
+
+ free(mixer);
+
+ /* TODO: verify frees */
+}
+
+struct mixer *mixer_open(unsigned int card)
+{
+ struct snd_ctl_elem_list elist;
+ struct snd_ctl_elem_info tmp;
+ struct snd_ctl_elem_id *eid = NULL;
+ struct mixer *mixer = NULL;
+ unsigned int n, m;
+ int fd;
+ char fn[256];
+
+ snprintf(fn, sizeof(fn), "/dev/snd/controlC%u", card);
+ fd = open(fn, O_RDWR);
+ if (fd < 0)
+ return 0;
+
+ memset(&elist, 0, sizeof(elist));
+ if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_LIST, &elist) < 0)
+ goto fail;
+
+ mixer = calloc(1, sizeof(*mixer));
+ if (!mixer)
+ goto fail;
+
+ mixer->ctl = calloc(elist.count, sizeof(struct mixer_ctl));
+ mixer->elem_info = calloc(elist.count, sizeof(struct snd_ctl_elem_info));
+ if (!mixer->ctl || !mixer->elem_info)
+ goto fail;
+
+ if (ioctl(fd, SNDRV_CTL_IOCTL_CARD_INFO, &mixer->card_info) < 0)
+ goto fail;
+
+ eid = calloc(elist.count, sizeof(struct snd_ctl_elem_id));
+ if (!eid)
+ goto fail;
+
+ mixer->count = elist.count;
+ mixer->fd = fd;
+ elist.space = mixer->count;
+ elist.pids = eid;
+ if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_LIST, &elist) < 0)
+ goto fail;
+
+ for (n = 0; n < mixer->count; n++) {
+ struct snd_ctl_elem_info *ei = mixer->elem_info + n;
+ ei->id.numid = eid[n].numid;
+ if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_INFO, ei) < 0)
+ goto fail;
+ mixer->ctl[n].info = ei;
+ mixer->ctl[n].mixer = mixer;
+ if (ei->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
+ char **enames = calloc(ei->value.enumerated.items, sizeof(char*));
+ if (!enames)
+ goto fail;
+ mixer->ctl[n].ename = enames;
+ for (m = 0; m < ei->value.enumerated.items; m++) {
+ memset(&tmp, 0, sizeof(tmp));
+ tmp.id.numid = ei->id.numid;
+ tmp.value.enumerated.item = m;
+ if (ioctl(fd, SNDRV_CTL_IOCTL_ELEM_INFO, &tmp) < 0)
+ goto fail;
+ enames[m] = strdup(tmp.value.enumerated.name);
+ if (!enames[m])
+ goto fail;
+ }
+ }
+ }
+
+ free(eid);
+ return mixer;
+
+fail:
+ /* TODO: verify frees in failure case */
+ if (eid)
+ free(eid);
+ if (mixer)
+ mixer_close(mixer);
+ else if (fd >= 0)
+ close(fd);
+ return 0;
+}
+
+const char *mixer_get_name(struct mixer *mixer)
+{
+ return (const char *)mixer->card_info.name;
+}
+
+unsigned int mixer_get_num_ctls(struct mixer *mixer)
+{
+ if (!mixer)
+ return 0;
+
+ return mixer->count;
+}
+
+struct mixer_ctl *mixer_get_ctl(struct mixer *mixer, unsigned int id)
+{
+ if (mixer && (id < mixer->count))
+ return mixer->ctl + id;
+
+ return NULL;
+}
+
+struct mixer_ctl *mixer_get_ctl_by_name(struct mixer *mixer, const char *name)
+{
+ unsigned int n;
+
+ if (!mixer)
+ return NULL;
+
+ for (n = 0; n < mixer->count; n++)
+ if (!strcmp(name, (char*) mixer->elem_info[n].id.name))
+ return mixer->ctl + n;
+
+ return NULL;
+}
+
+void mixer_ctl_update(struct mixer_ctl *ctl)
+{
+ ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_INFO, ctl->info);
+}
+
+const char *mixer_ctl_get_name(struct mixer_ctl *ctl)
+{
+ if (!ctl)
+ return NULL;
+
+ return (const char *)ctl->info->id.name;
+}
+
+enum mixer_ctl_type mixer_ctl_get_type(struct mixer_ctl *ctl)
+{
+ if (!ctl)
+ return MIXER_CTL_TYPE_UNKNOWN;
+
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN: return MIXER_CTL_TYPE_BOOL;
+ case SNDRV_CTL_ELEM_TYPE_INTEGER: return MIXER_CTL_TYPE_INT;
+ case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return MIXER_CTL_TYPE_ENUM;
+ case SNDRV_CTL_ELEM_TYPE_BYTES: return MIXER_CTL_TYPE_BYTE;
+ case SNDRV_CTL_ELEM_TYPE_IEC958: return MIXER_CTL_TYPE_IEC958;
+ case SNDRV_CTL_ELEM_TYPE_INTEGER64: return MIXER_CTL_TYPE_INT64;
+ default: return MIXER_CTL_TYPE_UNKNOWN;
+ };
+}
+
+const char *mixer_ctl_get_type_string(struct mixer_ctl *ctl)
+{
+ if (!ctl)
+ return "";
+
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN: return "BOOL";
+ case SNDRV_CTL_ELEM_TYPE_INTEGER: return "INT";
+ case SNDRV_CTL_ELEM_TYPE_ENUMERATED: return "ENUM";
+ case SNDRV_CTL_ELEM_TYPE_BYTES: return "BYTE";
+ case SNDRV_CTL_ELEM_TYPE_IEC958: return "IEC958";
+ case SNDRV_CTL_ELEM_TYPE_INTEGER64: return "INT64";
+ default: return "Unknown";
+ };
+}
+
+unsigned int mixer_ctl_get_num_values(struct mixer_ctl *ctl)
+{
+ if (!ctl)
+ return 0;
+
+ return ctl->info->count;
+}
+
+static int percent_to_int(struct snd_ctl_elem_info *ei, int percent)
+{
+ int range;
+
+ if (percent > 100)
+ percent = 100;
+ else if (percent < 0)
+ percent = 0;
+
+ range = (ei->value.integer.max - ei->value.integer.min);
+
+ return ei->value.integer.min + (range * percent) / 100;
+}
+
+static int int_to_percent(struct snd_ctl_elem_info *ei, int value)
+{
+ int range = (ei->value.integer.max - ei->value.integer.min);
+
+ if (range == 0)
+ return 0;
+
+ return ((value - ei->value.integer.min) / range) * 100;
+}
+
+int mixer_ctl_get_percent(struct mixer_ctl *ctl, unsigned int id)
+{
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
+ return -EINVAL;
+
+ return int_to_percent(ctl->info, mixer_ctl_get_value(ctl, id));
+}
+
+int mixer_ctl_set_percent(struct mixer_ctl *ctl, unsigned int id, int percent)
+{
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
+ return -EINVAL;
+
+ return mixer_ctl_set_value(ctl, id, percent_to_int(ctl->info, percent));
+}
+
+int mixer_ctl_get_value(struct mixer_ctl *ctl, unsigned int id)
+{
+ struct snd_ctl_elem_value ev;
+ int ret;
+
+ if (!ctl || (id >= ctl->info->count))
+ return -EINVAL;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.id.numid = ctl->info->id.numid;
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
+ if (ret < 0)
+ return ret;
+
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
+ return !!ev.value.integer.value[id];
+
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ return ev.value.integer.value[id];
+
+ case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
+ return ev.value.enumerated.item[id];
+
+ case SNDRV_CTL_ELEM_TYPE_BYTES:
+ return ev.value.bytes.data[id];
+
+ default:
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int mixer_ctl_get_array(struct mixer_ctl *ctl, void *array, size_t count)
+{
+ struct snd_ctl_elem_value ev;
+ int ret = 0;
+ size_t size;
+ void *source;
+
+ if (!ctl || (count > ctl->info->count) || !count || !array)
+ return -EINVAL;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.id.numid = ctl->info->id.numid;
+
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
+ if (ret < 0)
+ return ret;
+ size = sizeof(ev.value.integer.value[0]);
+ source = ev.value.integer.value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_BYTES:
+ /* check if this is new bytes TLV */
+ if (ctl->info->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) {
+ struct snd_ctl_tlv *tlv;
+ int ret;
+
+ if (count > SIZE_MAX - sizeof(*tlv))
+ return -EINVAL;
+ tlv = calloc(1, sizeof(*tlv) + count);
+ if (!tlv)
+ return -ENOMEM;
+ tlv->numid = ctl->info->id.numid;
+ tlv->length = count;
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_READ, tlv);
+
+ source = tlv->tlv;
+ memcpy(array, source, count);
+
+ free(tlv);
+
+ return ret;
+ } else {
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
+ if (ret < 0)
+ return ret;
+ size = sizeof(ev.value.bytes.data[0]);
+ source = ev.value.bytes.data;
+ break;
+ }
+
+ case SNDRV_CTL_ELEM_TYPE_IEC958:
+ size = sizeof(ev.value.iec958);
+ source = &ev.value.iec958;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ memcpy(array, source, size * count);
+
+ return 0;
+}
+
+int mixer_ctl_set_value(struct mixer_ctl *ctl, unsigned int id, int value)
+{
+ struct snd_ctl_elem_value ev;
+ int ret;
+
+ if (!ctl || (id >= ctl->info->count))
+ return -EINVAL;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.id.numid = ctl->info->id.numid;
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_READ, &ev);
+ if (ret < 0)
+ return ret;
+
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
+ ev.value.integer.value[id] = !!value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ ev.value.integer.value[id] = value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
+ ev.value.enumerated.item[id] = value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_BYTES:
+ ev.value.bytes.data[id] = value;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
+}
+
+int mixer_ctl_set_array(struct mixer_ctl *ctl, const void *array, size_t count)
+{
+ struct snd_ctl_elem_value ev;
+ size_t size;
+ void *dest;
+
+ if (!ctl || (count > ctl->info->count) || !count || !array)
+ return -EINVAL;
+
+ memset(&ev, 0, sizeof(ev));
+ ev.id.numid = ctl->info->id.numid;
+
+ switch (ctl->info->type) {
+ case SNDRV_CTL_ELEM_TYPE_BOOLEAN:
+ case SNDRV_CTL_ELEM_TYPE_INTEGER:
+ size = sizeof(ev.value.integer.value[0]);
+ dest = ev.value.integer.value;
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_BYTES:
+ /* check if this is new bytes TLV */
+ if (ctl->info->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE) {
+ struct snd_ctl_tlv *tlv;
+ int ret = 0;
+ if (count > SIZE_MAX - sizeof(*tlv))
+ return -EINVAL;
+ tlv = calloc(1, sizeof(*tlv) + count);
+ if (!tlv)
+ return -ENOMEM;
+ tlv->numid = ctl->info->id.numid;
+ tlv->length = count;
+ memcpy(tlv->tlv, array, count);
+
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_TLV_WRITE, tlv);
+ free(tlv);
+
+ return ret;
+ } else {
+ size = sizeof(ev.value.bytes.data[0]);
+ dest = ev.value.bytes.data;
+ }
+ break;
+
+ case SNDRV_CTL_ELEM_TYPE_IEC958:
+ size = sizeof(ev.value.iec958);
+ dest = &ev.value.iec958;
+ break;
+
+ default:
+ return -EINVAL;
+ }
+
+ memcpy(dest, array, size * count);
+
+ return ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
+}
+
+int mixer_ctl_get_range_min(struct mixer_ctl *ctl)
+{
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
+ return -EINVAL;
+
+ return ctl->info->value.integer.min;
+}
+
+int mixer_ctl_get_range_max(struct mixer_ctl *ctl)
+{
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_INTEGER))
+ return -EINVAL;
+
+ return ctl->info->value.integer.max;
+}
+
+unsigned int mixer_ctl_get_num_enums(struct mixer_ctl *ctl)
+{
+ if (!ctl)
+ return 0;
+
+ return ctl->info->value.enumerated.items;
+}
+
+const char *mixer_ctl_get_enum_string(struct mixer_ctl *ctl,
+ unsigned int enum_id)
+{
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED) ||
+ (enum_id >= ctl->info->value.enumerated.items))
+ return NULL;
+
+ return (const char *)ctl->ename[enum_id];
+}
+
+int mixer_ctl_set_enum_by_string(struct mixer_ctl *ctl, const char *string)
+{
+ unsigned int i, num_enums;
+ struct snd_ctl_elem_value ev;
+ int ret;
+
+ if (!ctl || (ctl->info->type != SNDRV_CTL_ELEM_TYPE_ENUMERATED))
+ return -EINVAL;
+
+ num_enums = ctl->info->value.enumerated.items;
+ for (i = 0; i < num_enums; i++) {
+ if (!strcmp(string, ctl->ename[i])) {
+ memset(&ev, 0, sizeof(ev));
+ ev.value.enumerated.item[0] = i;
+ ev.id.numid = ctl->info->id.numid;
+ ret = ioctl(ctl->mixer->fd, SNDRV_CTL_IOCTL_ELEM_WRITE, &ev);
+ if (ret < 0)
+ return ret;
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
diff --git a/ap/lib/libtinyalsa/mixer_ctrl_watch_cap.c b/ap/lib/libtinyalsa/mixer_ctrl_watch_cap.c
new file mode 100755
index 0000000..b20a653
--- /dev/null
+++ b/ap/lib/libtinyalsa/mixer_ctrl_watch_cap.c
@@ -0,0 +1,1201 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <tinyalsa/asoundlib.h>
+#include <sound/asound.h>
+#include <tinyalsa/audio_mixer_ctrl.h>
+
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
+struct audio_para_conf {
+ const char *control;
+ char *values[2];
+};
+
+
+
+
+#if defined _USE_CODEC_ES8374
+
+
+enum t_output_vol {
+ T_OUTPUT_VOL_MINUS_96DB = 0,
+ T_OUTPUT_VOL_MINUS_95DB = 2,
+ T_OUTPUT_VOL_MINUS_90DB = 12,
+ T_OUTPUT_VOL_MINUS_85DB = 22,
+ T_OUTPUT_VOL_MINUS_80DB = 32,
+ T_OUTPUT_VOL_MINUS_75DB = 42,
+ T_OUTPUT_VOL_MINUS_70DB = 52,
+ T_OUTPUT_VOL_MINUS_65DB = 62,
+ T_OUTPUT_VOL_MINUS_60DB = 72,
+ T_OUTPUT_VOL_MINUS_55DB = 82,
+ T_OUTPUT_VOL_MINUS_50DB = 92,
+ T_OUTPUT_VOL_MINUS_45DB = 102,
+ T_OUTPUT_VOL_MINUS_40DB = 112,
+ T_OUTPUT_VOL_MINUS_35DB = 122,
+ T_OUTPUT_VOL_MINUS_30DB = 132,
+ T_OUTPUT_VOL_MINUS_25DB = 142,
+ T_OUTPUT_VOL_MINUS_20DB = 152,
+ T_OUTPUT_VOL_MINUS_15DB = 162,
+ T_OUTPUT_VOL_MINUS_10DB = 172,
+ T_OUTPUT_VOL_MINUS_7DB = 178,
+ T_OUTPUT_VOL_MINUS_6DB = 180,
+ T_OUTPUT_VOL_MINUS_5DB = 182,
+ T_OUTPUT_VOL_MINUS_4DB = 184,
+ T_OUTPUT_VOL_MINUS_3DB = 186,
+ T_OUTPUT_VOL_MINUS_2DB = 188,
+ T_OUTPUT_VOL_MINUS_1DB = 190,
+ T_OUTPUT_VOL_0DB = 192
+};
+
+enum t_input_vol {
+ T_INPUT_VOL_MINUS_96DB = 0,
+ T_INPUT_VOL_MINUS_95DB = 2,
+ T_INPUT_VOL_MINUS_90DB = 12,
+ T_INPUT_VOL_MINUS_85DB = 22,
+ T_INPUT_VOL_MINUS_80DB = 32,
+ T_INPUT_VOL_MINUS_75DB = 42,
+ T_INPUT_VOL_MINUS_70DB = 52,
+ T_INPUT_VOL_MINUS_65DB = 62,
+ T_INPUT_VOL_MINUS_60DB = 72,
+ T_INPUT_VOL_MINUS_55DB = 82,
+ T_INPUT_VOL_MINUS_50DB = 92,
+ T_INPUT_VOL_MINUS_45DB = 102,
+ T_INPUT_VOL_MINUS_40DB = 112,
+ T_INPUT_VOL_MINUS_35DB = 122,
+ T_INPUT_VOL_MINUS_30DB = 132,
+ T_INPUT_VOL_MINUS_25DB = 142,
+ T_INPUT_VOL_MINUS_20DB = 152,
+ T_INPUT_VOL_MINUS_15DB = 162,
+ T_INPUT_VOL_MINUS_10DB = 172,
+ T_INPUT_VOL_MINUS_7DB = 178,
+ T_INPUT_VOL_MINUS_6DB = 180,
+ T_INPUT_VOL_MINUS_5DB = 182,
+ T_INPUT_VOL_MINUS_4DB = 184,
+ T_INPUT_VOL_MINUS_3DB = 186,
+ T_INPUT_VOL_MINUS_2DB = 188,
+ T_INPUT_VOL_MINUS_1DB = 190,
+ T_INPUT_VOL_0DB = 192
+};
+
+
+static struct audio_para_conf init_default_para[] = { //¿ª»ú³õʼ»¯µ÷ÓÃ
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ALC MUX", {"0"}},
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"ALC Capture Max PGA", {"15"}},
+ {"DAC MUTE", {"0"}},
+ {"DAC Playback Volume", {"120"}},
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SRC MUX", {"0"}}
+};
+
+//#ifdef _USE_7520V3_PHONE_TYPE_C31F
+#if ( defined _USE_7520V3_PHONE_TYPE_C31F || defined _USE_7520V3_PHONE_TYPE_WTWD )
+
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DAC MUTE", {"0"}},
+ //{"DAC Playback Volume", {"120"}},
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SRC MUX", {"0"}}
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+#if 0
+ {"ALC MUX", {"1"}},
+ {"ALC Capture Target Volume", {"5"}},
+ {"ALC Capture Max PGA", {"11"}},
+ {"ALC Capture Min PGA", {"2"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"0"}},
+ {"ALC Capture Attack Time", {"0"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+};
+
+#ifdef _USE_7520V3_PHONE_TYPE_WTWD
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}},
+ {"SPEAKER MIXER GAIN", {"41"}}, //1d
+ {"SPEAKER OUTPUT Volume", {"0"}}, //1e
+ {"DAC Playback Volume", {"192"}}, //38
+};
+#else
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"audio path select", {"handset"}},
+};
+
+#endif
+/*
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER GAIN", {"4"}},
+ {"SPEAKER OUTPUT Volume", {"4"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}}
+};
+*/
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"11"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"audio path select", {"speak"}},
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚLin1-Rin1ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚLin2-Rin2ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"2"}},
+};
+
+#ifdef _USE_7520V3_PHONE_TYPE_WTWD
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ //{"voice processing path select", {"headset"}}, // handset speak headset bluetooth
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}},
+ {"SPEAKER MIXER GAIN", {"32"}}, //old 41
+ {"SPEAKER OUTPUT Volume", {"0"}}, //1
+ {"DAC Playback Volume", {"192"}}, //38
+};
+
+#else
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"11"}},
+ {"DAC Playback Volume", {"192"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+};
+#endif
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing select", {"headset"}}, // handset speak headset bluetooth
+};
+#ifdef _USE_7520V3_PHONE_TYPE_WTWD //class-d -->receiver
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"186"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+#else//momo out -> speaker
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"6"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"0"}},
+ {"DAC Playback Volume", {"186"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+#endif
+
+
+
+#else
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DAC MUTE", {"0"}},
+ //{"DAC Playback Volume", {"120"}},
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SRC MUX", {"0"}}
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+#if 1
+ {"ALC MUX", {"1"}},
+ {"ALC Capture Target Volume", {"5"}},
+ {"ALC Capture Max PGA", {"11"}},
+ {"ALC Capture Min PGA", {"2"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"0"}},
+ {"ALC Capture Attack Time", {"0"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"3"}},
+ {"ADC Capture Volume", {"180"}},
+};
+
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}}
+};
+
+/*
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+ {"SPEAKER MIXER GAIN", {"4"}},
+ {"SPEAKER OUTPUT Volume", {"4"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"1"}}
+};
+*/
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"3"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}}
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚLin1-Rin1ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚLin2-Rin2ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"2"}},
+};
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing select", {"headset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"SDP OUT MUX", {"0"}},
+ {"ADC Soft Ramp", {"0"}},
+ {"ADC HPF COEFFICIENT", {"5"}},
+
+ {"ALC MUX", {"0"}},
+#if 0
+ {"ALC Capture Target Volume", {"7"}},
+ {"ALC Capture Max PGA", {"13"}},
+ {"ALC Capture Min PGA", {"8"}},
+ {"ALC Capture Hold Time", {"0"}},
+ {"ALC Capture Decay Time", {"1"}},
+ {"ALC Capture Attack Time", {"2"}},
+ {"ALC WIN SIZE", {"6"}},
+ {"ALC Capture NG Threshold", {"14"}},
+ {"ALC Capture NG Type", {"0"}},
+ {"ALC Capture NG Switch", {"0"}},
+#endif
+ {"D2SE MIC BOOST GAIN", {"1"}},
+ {"LIN PGA GAIN", {"7"}},
+ {"ADC Capture Volume", {"192"}},
+ {"SPEAKER MIXER DAC TO SPEAKER OUT Switch", {"0"}},
+ {"MONO OUT GAIN", {"4"}},
+ {"DAC Playback Volume", {"190"}},
+ {"MONO MIXER DAC TO MONO OUT Switch", {"1"}},
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+#endif
+
+static struct audio_para_conf output_dac_vol = {"DAC Playback Volume", {"120"}};
+
+static struct audio_para_conf input_adc_vol = {"ADC Capture Volume", {"192"}};
+
+static struct audio_para_conf dac_mute = {"DAC MUTE", {"1"}};
+static struct audio_para_conf adc_mute = {"ADC MUTE", {"1"}};
+
+static struct audio_para_conf spk_path_onoff[] = {
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+};
+
+static struct audio_para_conf rcv_path_onoff[] = {
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+};
+
+static struct audio_para_conf earp_path_onoff[] = {
+ {"MONO MIXER DAC TO MONO OUT Switch", {"0"}},
+};
+
+
+static int output_vol_conversion(int vol)
+{
+ switch (vol) {
+ case T_AUDIO_OUTPUT_VOL_LEVEL_0:
+ return T_OUTPUT_VOL_MINUS_96DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_1:
+ return T_OUTPUT_VOL_MINUS_45DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_2:
+ return T_OUTPUT_VOL_MINUS_40DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_3:
+ return T_OUTPUT_VOL_MINUS_35DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_4:
+ return T_OUTPUT_VOL_MINUS_30DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_5:
+ return T_OUTPUT_VOL_MINUS_25DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_6:
+ return T_OUTPUT_VOL_MINUS_20DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_7:
+ return T_OUTPUT_VOL_MINUS_15DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_8:
+ return T_OUTPUT_VOL_MINUS_10DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_9:
+ return T_OUTPUT_VOL_MINUS_6DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_10:
+ return T_OUTPUT_VOL_MINUS_3DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_11:
+ return T_OUTPUT_VOL_0DB;
+ default:
+ return T_OUTPUT_VOL_0DB;
+ }
+}
+
+static int input_vol_conversion(int vol)
+{
+ switch (vol) {
+ case T_AUDIO_INPUT_VOL_LEVEL_0:
+ return T_INPUT_VOL_MINUS_96DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_1:
+ return T_INPUT_VOL_MINUS_30DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_2:
+ return T_INPUT_VOL_MINUS_25DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_3:
+ return T_INPUT_VOL_MINUS_20DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_4:
+ return T_INPUT_VOL_MINUS_15DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_5:
+ return T_INPUT_VOL_MINUS_10DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_6:
+ return T_INPUT_VOL_MINUS_7DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_7:
+ return T_INPUT_VOL_MINUS_4DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_8:
+ return T_INPUT_VOL_MINUS_3DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_9:
+ return T_INPUT_VOL_MINUS_2DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_10:
+ return T_INPUT_VOL_MINUS_1DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_11:
+ return T_INPUT_VOL_0DB;
+ default:
+ return T_INPUT_VOL_MINUS_30DB;
+ }
+}
+
+#elif defined _USE_CODEC_ES8312
+
+enum t_output_vol {
+ T_OUTPUT_VOL_MINUS_95_5DB = 0,
+ T_OUTPUT_VOL_MINUS_90DB = 11,
+ T_OUTPUT_VOL_MINUS_85DB = 21,
+ T_OUTPUT_VOL_MINUS_80DB = 31,
+ T_OUTPUT_VOL_MINUS_75DB = 41,
+ T_OUTPUT_VOL_MINUS_70DB = 51,
+ T_OUTPUT_VOL_MINUS_65DB = 61,
+ T_OUTPUT_VOL_MINUS_60DB = 71,
+ T_OUTPUT_VOL_MINUS_55DB = 81,
+ T_OUTPUT_VOL_MINUS_50DB = 91,
+ T_OUTPUT_VOL_MINUS_45DB = 101,
+ T_OUTPUT_VOL_MINUS_40DB = 111,
+ T_OUTPUT_VOL_MINUS_35DB = 121,
+ T_OUTPUT_VOL_MINUS_30DB = 131,
+ T_OUTPUT_VOL_MINUS_25DB = 141,
+ T_OUTPUT_VOL_MINUS_20DB = 151,
+ T_OUTPUT_VOL_MINUS_15DB = 161,
+ T_OUTPUT_VOL_MINUS_10DB = 171,
+ T_OUTPUT_VOL_MINUS_7DB = 177,
+ T_OUTPUT_VOL_MINUS_6DB = 179,
+ T_OUTPUT_VOL_MINUS_5DB = 181,
+ T_OUTPUT_VOL_MINUS_4DB = 183,
+ T_OUTPUT_VOL_MINUS_3DB = 185,
+ T_OUTPUT_VOL_MINUS_2DB = 187,
+ T_OUTPUT_VOL_MINUS_1DB = 189,
+ T_OUTPUT_VOL_0DB = 191,
+ T_OUTPUT_VOL_32DB = 255
+};
+
+enum t_input_vol {
+ T_INPUT_VOL_MINUS_95_5DB = 0,
+ T_INPUT_VOL_MINUS_90DB = 11,
+ T_INPUT_VOL_MINUS_85DB = 21,
+ T_INPUT_VOL_MINUS_80DB = 31,
+ T_INPUT_VOL_MINUS_75DB = 41,
+ T_INPUT_VOL_MINUS_70DB = 51,
+ T_INPUT_VOL_MINUS_65DB = 61,
+ T_INPUT_VOL_MINUS_60DB = 71,
+ T_INPUT_VOL_MINUS_55DB = 81,
+ T_INPUT_VOL_MINUS_50DB = 91,
+ T_INPUT_VOL_MINUS_45DB = 101,
+ T_INPUT_VOL_MINUS_40DB = 111,
+ T_INPUT_VOL_MINUS_35DB = 121,
+ T_INPUT_VOL_MINUS_30DB = 131,
+ T_INPUT_VOL_MINUS_25DB = 141,
+ T_INPUT_VOL_MINUS_20DB = 151,
+ T_INPUT_VOL_MINUS_15DB = 161,
+ T_INPUT_VOL_MINUS_10DB = 171,
+ T_INPUT_VOL_MINUS_7DB = 177,
+ T_INPUT_VOL_MINUS_6DB = 179,
+ T_INPUT_VOL_MINUS_5DB = 181,
+ T_INPUT_VOL_MINUS_4DB = 183,
+ T_INPUT_VOL_MINUS_3DB = 185,
+ T_INPUT_VOL_MINUS_2DB = 187,
+ T_INPUT_VOL_MINUS_1DB = 199,
+ T_INPUT_VOL_0DB = 191,
+ T_INPUT_VOL_32DB = 255
+};
+
+
+static struct audio_para_conf init_default_para[] = { //¿ª»ú³õʼ»¯µ÷ÓÃ
+ {"DMIC MUX", {"0"}},
+ {"DAC SDP MUTE", {"0"}},
+ {"ADC SDP MUTE", {"0"}},
+};
+
+static struct audio_para_conf common_out_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DAC SDP MUTE", {"0"}},
+};
+
+static struct audio_para_conf common_in_para_audio[] = { //¶ÔÓ¦¹«¹²²¿·Ö
+ {"DMIC MUX", {"0"}},
+ {"ALC MUX", {"0"}},
+ {"SDP OUT MUX", {"1"}},
+ {"MIC PGA GAIN", {"10"}},
+};
+
+static struct audio_para_conf hp_outpath_para_audio[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ
+// {"DAC SDP SRC MUX", {"0"}},
+ {"DRC MUX", {"0"}},
+ //{"DRC EQ MUX", {"1"}},
+};
+
+static struct audio_para_conf spk_outpath_para_audio[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀ
+// {"DAC SDP SRC MUX", {"0"}},
+ {"DRC MUX", {"0"}},
+ //{"DRC EQ MUX", {"1"}},
+};
+
+static struct audio_para_conf main_mic_inpath_para_audio[] = { //¶ÔÓ¦ÓÚLin1-Rin1ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"1"}},
+};
+
+static struct audio_para_conf aux_mic_inpath_para_audio[] = {//¶ÔÓ¦ÓÚLin2-Rin2ÊäÈëͨµÀ
+ {"DIFFERENTIAL MUX", {"2"}},
+};
+
+static struct audio_para_conf handset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"voice processing path select", {"handset"}}, // handset speak headset bluetooth
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DRC MUX", {"0"}},
+ //{"DRC EQ MUX", {"1"}},
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"ALC MUX", {"0"}},
+ {"ALC MAX LEVEL", {"10"}},
+ {"ALC MIN LEVEL", {"0"}},
+ {"SDP OUT MUX", {"1"}},
+ {"MIC PGA GAIN", {"8"}},
+ {"ADC VOLUME", {"191"}},
+ {"DAC VOLUME", {"190"}},
+ {"DAC SDP MUTE", {"0"}},
+ {"ADC SDP MUTE", {"0"}},
+};
+
+static struct audio_para_conf headset_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚHpÊä³öͨµÀ Mic1rpÊäÈëͨµÀ
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DRC MUX", {"0"}},
+ //{"DRC EQ MUX", {"1"}},
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"ALC MUX", {"0"}},
+ {"ALC MAX LEVEL", {"10"}},
+ {"ALC MIN LEVEL", {"0"}},
+ {"SDP OUT MUX", {"1"}},
+ {"MIC PGA GAIN", {"8"}},
+ {"ADC VOLUME", {"191"}},
+ {"DAC VOLUME", {"190"}},
+ {"DAC SDP MUTE", {"0"}},
+ {"ADC SDP MUTE", {"0"}},
+ {"voice processing path select", {"headset"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf spk_inoutpath_para_voice[] = { //¶ÔÓ¦ÓÚSpkÊä³öͨµÀMic1lp_Mic1lmÊäÈëͨµÀ
+ {"DAC SDP SRC MUX", {"0"}},
+ {"DRC MUX", {"0"}},
+ //{"DRC EQ MUX", {"1"}},
+ {"DAC VOLUME", {"190"}},
+ {"DAC SDP MUTE", {"0"}},
+
+ {"DIFFERENTIAL MUX", {"1"}},
+ {"DMIC MUX", {"0"}},
+ {"ALC MUX", {"0"}},
+ {"ALC MAX LEVEL", {"10"}},
+ {"ALC MIN LEVEL", {"0"}},
+ {"SDP OUT MUX", {"1"}},
+ {"MIC PGA GAIN", {"8"}},
+ {"ADC VOLUME", {"191"}},
+ /*
+ {"ALC MUX", {"0"}},
+ {"SDP OUT MUX", {"1"}},
+ {"MIC PGA GAIN", {"10"}},
+ {"ADC VOLUME", {"191"}},*/
+ {"ADC SDP MUTE", {"0"}},
+
+ {"voice processing path select", {"speak"}}, // handset speak headset bluetooth
+};
+
+static struct audio_para_conf output_dac_vol = {"DAC VOLUME", {"190"}};
+
+static struct audio_para_conf input_adc_vol = {"ADC VOLUME", {"191"}};
+
+static struct audio_para_conf dac_mute = {"DAC SDP MUTE", {"0"}};
+static struct audio_para_conf adc_mute = {"ADC SDP MUTE", {"0"}};
+
+
+static struct audio_para_conf spk_path_onoff[] = {
+ {"DAC SDP MUTE", {"0"}},
+};
+
+static struct audio_para_conf rcv_path_onoff[] = {
+ {"DAC SDP MUTE", {"0"}},
+};
+
+static struct audio_para_conf earp_path_onoff[] = {
+ {"DAC SDP MUTE", {"0"}},
+};
+
+
+static int output_vol_conversion(int vol)
+{
+ switch (vol) {
+ case T_AUDIO_OUTPUT_VOL_LEVEL_0:
+ return T_INPUT_VOL_MINUS_95_5DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_1:
+ return T_OUTPUT_VOL_MINUS_60DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_2:
+ return T_OUTPUT_VOL_MINUS_55DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_3:
+ return T_OUTPUT_VOL_MINUS_50DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_4:
+ return T_OUTPUT_VOL_MINUS_45DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_5:
+ return T_OUTPUT_VOL_MINUS_40DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_6:
+ return T_OUTPUT_VOL_MINUS_35DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_7:
+ return T_OUTPUT_VOL_MINUS_30DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_8:
+ return T_OUTPUT_VOL_MINUS_25DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_9:
+ return T_OUTPUT_VOL_MINUS_20DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_10:
+ return T_OUTPUT_VOL_MINUS_15DB;
+ case T_AUDIO_OUTPUT_VOL_LEVEL_11:
+ return T_OUTPUT_VOL_MINUS_10DB;
+ default:
+ return T_OUTPUT_VOL_MINUS_10DB;
+ }
+}
+
+static int input_vol_conversion(int vol)
+{
+ switch (vol) {
+ case T_AUDIO_INPUT_VOL_LEVEL_0:
+ return T_INPUT_VOL_MINUS_95_5DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_1:
+ return T_INPUT_VOL_MINUS_50DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_2:
+ return T_INPUT_VOL_MINUS_45DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_3:
+ return T_INPUT_VOL_MINUS_40DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_4:
+ return T_INPUT_VOL_MINUS_35DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_5:
+ return T_INPUT_VOL_MINUS_30DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_6:
+ return T_INPUT_VOL_MINUS_25DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_7:
+ return T_INPUT_VOL_MINUS_20DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_8:
+ return T_INPUT_VOL_MINUS_15DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_9:
+ return T_INPUT_VOL_MINUS_10DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_10:
+ return T_INPUT_VOL_MINUS_7DB;
+ case T_AUDIO_INPUT_VOL_LEVEL_11:
+ return T_INPUT_VOL_0DB;
+ default:
+ return T_INPUT_VOL_0DB;
+ }
+}
+
+#endif
+
+//static struct audio_para_conf nxp_voice_vol = {"voice processing path Volume",{"3"}}; //(range 0->5)
+
+static void mix_set_value_wrap(struct mixer *mixer, const char *control, char **values)
+{
+ struct mixer_ctl *ctl;
+ enum mixer_ctl_type type;
+ unsigned int num_ctl_values;
+ unsigned int i;
+
+ if (isdigit(control[0]))
+ ctl = mixer_get_ctl(mixer, atoi(control));
+ else
+ ctl = mixer_get_ctl_by_name(mixer, control);
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ type = mixer_ctl_get_type(ctl);
+ num_ctl_values = mixer_ctl_get_num_values(ctl);
+
+ if (isdigit(values[0][0])) {
+
+ for (i = 0; i < num_ctl_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, atoi(values[i]))) {
+ fprintf(stderr, "Error: invalid value for index %d\n", i);
+ return;
+ }
+ }
+
+ } else {
+ if (type == MIXER_CTL_TYPE_ENUM) {
+ /*if (num_values != 1) {
+ fprintf(stderr, "Enclose strings in quotes and try again\n");
+ return;
+ }*/
+ if (mixer_ctl_set_enum_by_string(ctl, values[0]))
+ fprintf(stderr, "Error: invalid enum value\n");
+ } else {
+ fprintf(stderr, "Error: only enum types can be set with strings\n");
+ }
+ }
+}
+
+#ifdef _CPE_AUDIO_PRJ
+int mix_set_output_path(struct mixer *mixer, int path)
+{
+
+ return 0;
+}
+
+int mix_set_input_path(struct mixer *mixer, int path)
+{
+
+
+ return 0;
+}
+
+int mix_set_input_vol(struct mixer *mixer, int volume)
+{
+
+
+ return 0;
+}
+
+int mix_set_output_vol(struct mixer *mixer, int volume)
+{
+
+
+ return 0;
+}
+
+int mix_set_output_mute(struct mixer *mixer, bool enable)
+{
+
+
+ return 0;
+}
+
+int mix_set_input_mute(struct mixer *mixer, bool enable)
+{
+
+
+ return 0;
+}
+
+int mix_set_outputpath_onoff(struct mixer *mixer, int path , bool onoff)
+{
+
+ return 0;
+}
+
+
+int mix_set_voice_vol(struct mixer *mixer, int volume)
+{
+
+
+ return 0;
+}
+
+int mix_set_voice_mute(struct mixer *mixer, bool enable)
+{
+
+
+ return 0;
+}
+
+int mix_set_voice_path(struct mixer *mixer, int path)
+{
+ int i;
+
+
+ return 0;
+}
+
+
+int mix_set_in_call_tone(struct mixer *mixer, int tontype)
+{
+
+
+ return 0;
+}
+
+int mix_set_default_param(struct mixer *mixer)
+{
+
+ return 0;
+}
+#else
+int mix_set_output_path(struct mixer *mixer, int path)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(common_out_para_audio); i++) {
+ mix_set_value_wrap(mixer, common_out_para_audio[i].control, common_out_para_audio[i].values);
+ }
+ switch (path) {
+ case T_OUTPUT_RECEIVER:
+ for (i = 0; i < ARRAY_SIZE(hp_outpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, hp_outpath_para_audio[i].control, hp_outpath_para_audio[i].values);
+ }
+ break;
+ case T_OUTPUT_SPEAKER:
+ for (i = 0; i < ARRAY_SIZE(spk_outpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, spk_outpath_para_audio[i].control, spk_outpath_para_audio[i].values);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mix_set_input_path(struct mixer *mixer, int path)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(common_in_para_audio); i++) {
+ mix_set_value_wrap(mixer, common_in_para_audio[i].control, common_in_para_audio[i].values);
+ }
+ switch (path) {
+ case T_INPUT_MICLP:
+ for (i = 0; i < ARRAY_SIZE(main_mic_inpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, main_mic_inpath_para_audio[i].control, main_mic_inpath_para_audio[i].values);
+ }
+ break;
+ case T_INPUT_MICRP:
+ for (i = 0; i < ARRAY_SIZE(aux_mic_inpath_para_audio); i++) {
+ mix_set_value_wrap(mixer, aux_mic_inpath_para_audio[i].control, aux_mic_inpath_para_audio[i].values);
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+int mix_set_input_vol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl;
+ char *name = input_adc_vol.control;
+ int num_values, i;
+ int vol = input_vol_conversion(volume);
+
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, i, vol);
+ }
+
+ return 0;
+}
+
+int mix_set_output_vol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl;
+ char *name = output_dac_vol.control;
+ int num_values, i;
+
+ int vol = output_vol_conversion(volume);
+
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, i, vol);
+ }
+
+ return 0;
+}
+
+int mix_set_output_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl;
+ char *name = dac_mute.control;
+ int num_values, i;
+
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, i, enable);
+ }
+
+ return 0;
+}
+
+int mix_set_input_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl;
+ char *name = adc_mute.control;
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ int num_values, i;
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (i = 0; i < num_values; i++) {
+ mixer_ctl_set_value(ctl, 0, enable);
+ }
+
+ return 0;
+}
+
+int mix_set_outputpath_onoff(struct mixer *mixer, int path , bool onoff)
+{
+ struct mixer_ctl *ctl;
+ struct audio_para_conf *path_para;
+ int i, j, num_values, size;
+ switch (path) {
+ case T_OUTPUT_RECEIVER:
+ size = ARRAY_SIZE(rcv_path_onoff);
+ path_para = rcv_path_onoff;
+ break;
+ case T_OUTPUT_SPEAKER:
+ size = ARRAY_SIZE(spk_path_onoff);
+ path_para = spk_path_onoff;
+ break;
+ case T_OUTPUT_HEADSET:
+ size = ARRAY_SIZE(earp_path_onoff);
+ path_para = earp_path_onoff;
+ break;
+ default:
+ return -1;
+ }
+
+ for (i = 0; i < size; i++) {
+ ctl = mixer_get_ctl_by_name(mixer, path_para[i].control);
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ for (j = 0; j < num_values; j++) {
+ mixer_ctl_set_value(ctl, j, onoff);
+ }
+
+// mix_set_value_wrap(mixer, spk_path_onoff[i].control, spk_path_onoff[i].values);
+ }
+
+ return 0;
+}
+
+
+int mix_set_voice_vol(struct mixer *mixer, int volume)
+{
+ struct mixer_ctl *ctl;
+ char name[] = "voice processing path Volume";
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ mixer_ctl_set_value(ctl, 0, volume);
+
+ return 0;
+}
+
+int mix_set_voice_mute(struct mixer *mixer, bool enable)
+{
+ struct mixer_ctl *ctl;
+ char name[] = "voice uplink mute";
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ mixer_ctl_set_value(ctl, 0, enable);
+
+ return 0;
+}
+
+int mix_set_voice_path(struct mixer *mixer, int path)
+{
+ int i;
+ /*
+ for (i = 0; i < ARRAY_SIZE(common_in_para_audio); i++) {
+ tinymix_set_value_test(mixer, common_in_para_audio[i].control, common_in_para_audio[i].values);
+ }
+
+ for(i = 0;i<ARRAY_SIZE(common_out_para_audio);i++)
+ {
+ tinymix_set_value_test(mixer,common_out_para_audio[i].control,common_out_para_audio[i].values);
+ }
+ */
+ switch (path) {
+ case T_OUTPUT_RECEIVER:
+ for (i = 0; i < ARRAY_SIZE(handset_inoutpath_para_voice); i++) {
+ mix_set_value_wrap(mixer, handset_inoutpath_para_voice[i].control, handset_inoutpath_para_voice[i].values);
+ }
+ break;
+ case T_OUTPUT_SPEAKER:
+ for (i = 0; i < ARRAY_SIZE(spk_inoutpath_para_voice); i++) {
+ mix_set_value_wrap(mixer, spk_inoutpath_para_voice[i].control, spk_inoutpath_para_voice[i].values);
+ }
+ break;
+ case T_OUTPUT_HEADSET:
+ for (i = 0; i < ARRAY_SIZE(headset_inoutpath_para_voice); i++) {
+ mix_set_value_wrap(mixer, headset_inoutpath_para_voice[i].control, headset_inoutpath_para_voice[i].values);
+ }
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+
+int mix_set_in_call_tone(struct mixer *mixer, int tontype)
+{
+ struct mixer_ctl *ctl;
+ char name[] = "voice tone sel";
+ ctl = mixer_get_ctl_by_name(mixer, name);
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return -1;
+ }
+
+ mixer_ctl_set_value(ctl, 0, tontype);
+
+ return 0;
+}
+
+int mix_set_default_param(struct mixer *mixer)
+{
+ int i;
+ for (i = 0; i < ARRAY_SIZE(init_default_para); i++) {
+ mix_set_value_wrap(mixer, init_default_para[i].control, init_default_para[i].values);
+ }
+
+ return 0;
+}
+#endif
diff --git a/ap/lib/libtinyalsa/pcm.c b/ap/lib/libtinyalsa/pcm.c
new file mode 100644
index 0000000..78e1cea
--- /dev/null
+++ b/ap/lib/libtinyalsa/pcm.c
@@ -0,0 +1,1310 @@
+/* pcm.c
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <stdarg.h>
+#include <string.h>
+#include <errno.h>
+#include <unistd.h>
+#include <poll.h>
+
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <sys/time.h>
+#include <limits.h>
+
+#include <linux/ioctl.h>
+#define __force
+#define __bitwise
+#define __user
+#include <sound/asound.h>
+
+#include <tinyalsa/asoundlib.h>
+
+#define PARAM_MAX SNDRV_PCM_HW_PARAM_LAST_INTERVAL
+
+/* Logs information into a string; follows snprintf() in that
+ * offset may be greater than size, and though no characters are copied
+ * into string, characters are still counted into offset. */
+#define STRLOG(string, offset, size, ...) \
+ do { int temp, clipoffset = offset > size ? size : offset; \
+ temp = snprintf(string + clipoffset, size - clipoffset, __VA_ARGS__); \
+ if (temp > 0) offset += temp; } while (0)
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+#endif
+
+/* refer to SNDRV_PCM_ACCESS_##index in sound/asound.h. */
+static const char * const access_lookup[] = {
+ "MMAP_INTERLEAVED",
+ "MMAP_NONINTERLEAVED",
+ "MMAP_COMPLEX",
+ "RW_INTERLEAVED",
+ "RW_NONINTERLEAVED",
+};
+
+/* refer to SNDRV_PCM_FORMAT_##index in sound/asound.h. */
+static const char * const format_lookup[] = {
+ /*[0] =*/ "S8",
+ "U8",
+ "S16_LE",
+ "S16_BE",
+ "U16_LE",
+ "U16_BE",
+ "S24_LE",
+ "S24_BE",
+ "U24_LE",
+ "U24_BE",
+ "S32_LE",
+ "S32_BE",
+ "U32_LE",
+ "U32_BE",
+ "FLOAT_LE",
+ "FLOAT_BE",
+ "FLOAT64_LE",
+ "FLOAT64_BE",
+ "IEC958_SUBFRAME_LE",
+ "IEC958_SUBFRAME_BE",
+ "MU_LAW",
+ "A_LAW",
+ "IMA_ADPCM",
+ "MPEG",
+ /*[24] =*/ "GSM",
+ /* gap */
+ [31] = "SPECIAL",
+ "S24_3LE",
+ "S24_3BE",
+ "U24_3LE",
+ "U24_3BE",
+ "S20_3LE",
+ "S20_3BE",
+ "U20_3LE",
+ "U20_3BE",
+ "S18_3LE",
+ "S18_3BE",
+ "U18_3LE",
+ /*[43] =*/ "U18_3BE",
+#if 0
+ /* recent additions, may not be present on local asound.h */
+ "G723_24",
+ "G723_24_1B",
+ "G723_40",
+ "G723_40_1B",
+ "DSD_U8",
+ "DSD_U16_LE",
+#endif
+};
+
+/* refer to SNDRV_PCM_SUBFORMAT_##index in sound/asound.h. */
+static const char * const subformat_lookup[] = {
+ "STD",
+};
+
+static inline int param_is_mask(int p)
+{
+ return (p >= SNDRV_PCM_HW_PARAM_FIRST_MASK) &&
+ (p <= SNDRV_PCM_HW_PARAM_LAST_MASK);
+}
+
+static inline int param_is_interval(int p)
+{
+ return (p >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL) &&
+ (p <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL);
+}
+
+static inline struct snd_interval *param_to_interval(struct snd_pcm_hw_params *p, int n)
+{
+ return &(p->intervals[n - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]);
+}
+
+static inline struct snd_mask *param_to_mask(struct snd_pcm_hw_params *p, int n)
+{
+ return &(p->masks[n - SNDRV_PCM_HW_PARAM_FIRST_MASK]);
+}
+
+static void param_set_mask(struct snd_pcm_hw_params *p, int n, unsigned int bit)
+{
+ if (bit >= SNDRV_MASK_MAX)
+ return;
+ if (param_is_mask(n)) {
+ struct snd_mask *m = param_to_mask(p, n);
+ m->bits[0] = 0;
+ m->bits[1] = 0;
+ m->bits[bit >> 5] |= (1 << (bit & 31));
+ }
+}
+
+static void param_set_min(struct snd_pcm_hw_params *p, int n, unsigned int val)
+{
+ if (param_is_interval(n)) {
+ struct snd_interval *i = param_to_interval(p, n);
+ i->min = val;
+ }
+}
+
+static unsigned int param_get_min(struct snd_pcm_hw_params *p, int n)
+{
+ if (param_is_interval(n)) {
+ struct snd_interval *i = param_to_interval(p, n);
+ return i->min;
+ }
+ return 0;
+}
+
+static void param_set_max(struct snd_pcm_hw_params *p, int n, unsigned int val)
+{
+ if (param_is_interval(n)) {
+ struct snd_interval *i = param_to_interval(p, n);
+ i->max = val;
+ }
+}
+
+static unsigned int param_get_max(struct snd_pcm_hw_params *p, int n)
+{
+ if (param_is_interval(n)) {
+ struct snd_interval *i = param_to_interval(p, n);
+ return i->max;
+ }
+ return 0;
+}
+
+static void param_set_int(struct snd_pcm_hw_params *p, int n, unsigned int val)
+{
+ if (param_is_interval(n)) {
+ struct snd_interval *i = param_to_interval(p, n);
+ i->min = val;
+ i->max = val;
+ i->integer = 1;
+ }
+}
+
+static unsigned int param_get_int(struct snd_pcm_hw_params *p, int n)
+{
+ if (param_is_interval(n)) {
+ struct snd_interval *i = param_to_interval(p, n);
+ if (i->integer)
+ return i->max;
+ }
+ return 0;
+}
+
+static void param_init(struct snd_pcm_hw_params *p)
+{
+ int n;
+
+ memset(p, 0, sizeof(*p));
+ for (n = SNDRV_PCM_HW_PARAM_FIRST_MASK;
+ n <= SNDRV_PCM_HW_PARAM_LAST_MASK; n++) {
+ struct snd_mask *m = param_to_mask(p, n);
+ m->bits[0] = ~0;
+ m->bits[1] = ~0;
+ }
+ for (n = SNDRV_PCM_HW_PARAM_FIRST_INTERVAL;
+ n <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; n++) {
+ struct snd_interval *i = param_to_interval(p, n);
+ i->min = 0;
+ i->max = ~0;
+ }
+ p->rmask = ~0U;
+ p->cmask = 0;
+ p->info = ~0U;
+}
+
+#define PCM_ERROR_MAX 128
+
+struct pcm {
+ int fd;
+ unsigned int flags;
+ int running:1;
+ int prepared:1;
+ int underruns;
+ unsigned int buffer_size;
+ unsigned int boundary;
+ char error[PCM_ERROR_MAX];
+ struct pcm_config config;
+ struct snd_pcm_mmap_status *mmap_status;
+ struct snd_pcm_mmap_control *mmap_control;
+ struct snd_pcm_sync_ptr *sync_ptr;
+ void *mmap_buffer;
+ unsigned int noirq_frames_per_msec;
+ int wait_for_avail_min;
+};
+
+unsigned int pcm_get_buffer_size(struct pcm *pcm)
+{
+ return pcm->buffer_size;
+}
+
+const char* pcm_get_error(struct pcm *pcm)
+{
+ return pcm->error;
+}
+
+static int oops(struct pcm *pcm, int e, const char *fmt, ...)
+{
+ va_list ap;
+ int sz;
+
+ va_start(ap, fmt);
+ vsnprintf(pcm->error, PCM_ERROR_MAX, fmt, ap);
+ va_end(ap);
+ sz = strlen(pcm->error);
+
+ if (errno)
+ snprintf(pcm->error + sz, PCM_ERROR_MAX - sz,
+ ": %s", strerror(e));
+ return -1;
+}
+
+static unsigned int pcm_format_to_alsa(enum pcm_format format)
+{
+ switch (format) {
+ case PCM_FORMAT_S32_LE:
+ return SNDRV_PCM_FORMAT_S32_LE;
+ case PCM_FORMAT_S8:
+ return SNDRV_PCM_FORMAT_S8;
+ case PCM_FORMAT_S24_3LE:
+ return SNDRV_PCM_FORMAT_S24_3LE;
+ case PCM_FORMAT_S24_LE:
+ return SNDRV_PCM_FORMAT_S24_LE;
+ default:
+ case PCM_FORMAT_S16_LE:
+ return SNDRV_PCM_FORMAT_S16_LE;
+ };
+}
+
+unsigned int pcm_format_to_bits(enum pcm_format format)
+{
+ switch (format) {
+ case PCM_FORMAT_S32_LE:
+ case PCM_FORMAT_S24_LE:
+ return 32;
+ case PCM_FORMAT_S24_3LE:
+ return 24;
+ default:
+ case PCM_FORMAT_S16_LE:
+ return 16;
+ };
+}
+
+unsigned int pcm_bytes_to_frames(struct pcm *pcm, unsigned int bytes)
+{
+ return bytes / (pcm->config.channels *
+ (pcm_format_to_bits(pcm->config.format) >> 3));
+}
+
+unsigned int pcm_frames_to_bytes(struct pcm *pcm, unsigned int frames)
+{
+ return frames * pcm->config.channels *
+ (pcm_format_to_bits(pcm->config.format) >> 3);
+}
+
+static int pcm_sync_ptr(struct pcm *pcm, int flags) {
+ if (pcm->sync_ptr) {
+ pcm->sync_ptr->flags = flags;
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SYNC_PTR, pcm->sync_ptr) < 0)
+ return -1;
+ }
+ return 0;
+}
+
+static int pcm_hw_mmap_status(struct pcm *pcm) {
+
+ if (pcm->sync_ptr)
+ return 0;
+
+ int page_size = sysconf(_SC_PAGE_SIZE);
+ pcm->mmap_status = mmap(NULL, page_size, PROT_READ, MAP_FILE | MAP_SHARED,
+ pcm->fd, SNDRV_PCM_MMAP_OFFSET_STATUS);
+ if (pcm->mmap_status == MAP_FAILED)
+ pcm->mmap_status = NULL;
+ if (!pcm->mmap_status)
+ goto mmap_error;
+
+ pcm->mmap_control = mmap(NULL, page_size, PROT_READ | PROT_WRITE,
+ MAP_FILE | MAP_SHARED, pcm->fd, SNDRV_PCM_MMAP_OFFSET_CONTROL);
+ if (pcm->mmap_control == MAP_FAILED)
+ pcm->mmap_control = NULL;
+ if (!pcm->mmap_control) {
+ munmap(pcm->mmap_status, page_size);
+ pcm->mmap_status = NULL;
+ goto mmap_error;
+ }
+ if (pcm->flags & PCM_MMAP)
+ pcm->mmap_control->avail_min = pcm->config.avail_min;
+ else
+ pcm->mmap_control->avail_min = 1;
+
+ return 0;
+
+mmap_error:
+
+ pcm->sync_ptr = calloc(1, sizeof(*pcm->sync_ptr));
+ if (!pcm->sync_ptr)
+ return -ENOMEM;
+ pcm->mmap_status = &pcm->sync_ptr->s.status;
+ pcm->mmap_control = &pcm->sync_ptr->c.control;
+ if (pcm->flags & PCM_MMAP)
+ pcm->mmap_control->avail_min = pcm->config.avail_min;
+ else
+ pcm->mmap_control->avail_min = 1;
+
+ pcm_sync_ptr(pcm, 0);
+
+ return 0;
+}
+
+static void pcm_hw_munmap_status(struct pcm *pcm) {
+ if (pcm->sync_ptr) {
+ free(pcm->sync_ptr);
+ pcm->sync_ptr = NULL;
+ } else {
+ int page_size = sysconf(_SC_PAGE_SIZE);
+ if (pcm->mmap_status)
+ munmap(pcm->mmap_status, page_size);
+ if (pcm->mmap_control)
+ munmap(pcm->mmap_control, page_size);
+ }
+ pcm->mmap_status = NULL;
+ pcm->mmap_control = NULL;
+}
+
+static int pcm_areas_copy(struct pcm *pcm, unsigned int pcm_offset,
+ char *buf, unsigned int src_offset,
+ unsigned int frames)
+{
+ int size_bytes = pcm_frames_to_bytes(pcm, frames);
+ int pcm_offset_bytes = pcm_frames_to_bytes(pcm, pcm_offset);
+ int src_offset_bytes = pcm_frames_to_bytes(pcm, src_offset);
+
+ /* interleaved only atm */
+ if (pcm->flags & PCM_IN)
+ memcpy(buf + src_offset_bytes,
+ (char*)pcm->mmap_buffer + pcm_offset_bytes,
+ size_bytes);
+ else
+ memcpy((char*)pcm->mmap_buffer + pcm_offset_bytes,
+ buf + src_offset_bytes,
+ size_bytes);
+ return 0;
+}
+
+static int pcm_mmap_transfer_areas(struct pcm *pcm, char *buf,
+ unsigned int offset, unsigned int size)
+{
+ void *pcm_areas;
+ int commit;
+ unsigned int pcm_offset, frames, count = 0;
+
+ while (size > 0) {
+ frames = size;
+ pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
+ pcm_areas_copy(pcm, pcm_offset, buf, offset, frames);
+ commit = pcm_mmap_commit(pcm, pcm_offset, frames);
+ if (commit < 0) {
+ oops(pcm, commit, "failed to commit %d frames\n", frames);
+ return commit;
+ }
+
+ offset += commit;
+ count += commit;
+ size -= commit;
+ }
+ return count;
+}
+
+int pcm_get_htimestamp(struct pcm *pcm, unsigned int *avail,
+ struct timespec *tstamp)
+{
+ int frames;
+ int rc;
+ snd_pcm_uframes_t hw_ptr;
+
+ if (!pcm_is_ready(pcm))
+ return -1;
+
+ rc = pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_APPL|SNDRV_PCM_SYNC_PTR_HWSYNC);
+ if (rc < 0)
+ return -1;
+
+ if ((pcm->mmap_status->state != PCM_STATE_RUNNING) &&
+ (pcm->mmap_status->state != PCM_STATE_DRAINING))
+ return -1;
+
+ *tstamp = pcm->mmap_status->tstamp;
+ if (tstamp->tv_sec == 0 && tstamp->tv_nsec == 0)
+ return -1;
+
+ hw_ptr = pcm->mmap_status->hw_ptr;
+ if (pcm->flags & PCM_IN)
+ frames = hw_ptr - pcm->mmap_control->appl_ptr;
+ else
+ frames = hw_ptr + pcm->buffer_size - pcm->mmap_control->appl_ptr;
+
+ if (frames < 0)
+ frames += pcm->boundary;
+ else if (frames > (int)pcm->boundary)
+ frames -= pcm->boundary;
+
+ *avail = (unsigned int)frames;
+
+ return 0;
+}
+
+int pcm_write(struct pcm *pcm, const void *data, unsigned int count)
+{
+ struct snd_xferi x;
+
+ if (pcm->flags & PCM_IN)
+ return -EINVAL;
+
+ x.buf = (void*)data;
+ x.frames = count / (pcm->config.channels *
+ pcm_format_to_bits(pcm->config.format) / 8);
+
+ for (;;) {
+ if (!pcm->running) {
+ int prepare_error = pcm_prepare(pcm);
+ if (prepare_error)
+ return prepare_error;
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x))
+ return oops(pcm, errno, "cannot write initial data");
+ pcm->running = 1;
+ return 0;
+ }
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, &x)) {
+ pcm->prepared = 0;
+ pcm->running = 0;
+ if (errno == EPIPE) {
+ /* we failed to make our window -- try to restart if we are
+ * allowed to do so. Otherwise, simply allow the EPIPE error to
+ * propagate up to the app level */
+ pcm->underruns++;
+ if (pcm->flags & PCM_NORESTART)
+ return -EPIPE;
+ continue;
+ }
+ return oops(pcm, errno, "cannot write stream data");
+ }
+ return 0;
+ }
+}
+
+int pcm_read(struct pcm *pcm, void *data, unsigned int count)
+{
+ struct snd_xferi x;
+
+ if (!(pcm->flags & PCM_IN))
+ return -EINVAL;
+
+ x.buf = data;
+ x.frames = count / (pcm->config.channels *
+ pcm_format_to_bits(pcm->config.format) / 8);
+
+ for (;;) {
+ if (!pcm->running) {
+ if (pcm_start(pcm) < 0) {
+ fprintf(stderr, "start error");
+ return -errno;
+ }
+ }
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_READI_FRAMES, &x)) {
+ pcm->prepared = 0;
+ pcm->running = 0;
+ if (errno == EPIPE) {
+ /* we failed to make our window -- try to restart */
+ pcm->underruns++;
+ continue;
+ }
+ return oops(pcm, errno, "cannot read stream data");
+ }
+ return 0;
+ }
+}
+
+static struct pcm bad_pcm = {
+ .fd = -1,
+};
+
+struct pcm_params *pcm_params_get(unsigned int card, unsigned int device,
+ unsigned int flags)
+{
+ struct snd_pcm_hw_params *params;
+ char fn[256];
+ int fd;
+
+ snprintf(fn, sizeof(fn), "/dev/snd/pcmC%uD%u%c", card, device,
+ flags & PCM_IN ? 'c' : 'p');
+
+ fd = open(fn, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "cannot open device '%s'\n", fn);
+ goto err_open;
+ }
+
+ params = calloc(1, sizeof(struct snd_pcm_hw_params));
+ if (!params)
+ goto err_calloc;
+
+ param_init(params);
+ if (ioctl(fd, SNDRV_PCM_IOCTL_HW_REFINE, params)) {
+ fprintf(stderr, "SNDRV_PCM_IOCTL_HW_REFINE error (%d)\n", errno);
+ goto err_hw_refine;
+ }
+
+ close(fd);
+
+ return (struct pcm_params *)params;
+
+err_hw_refine:
+ free(params);
+err_calloc:
+ close(fd);
+err_open:
+ return NULL;
+}
+
+void pcm_params_free(struct pcm_params *pcm_params)
+{
+ struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
+
+ if (params)
+ free(params);
+}
+
+static int pcm_param_to_alsa(enum pcm_param param)
+{
+ switch (param) {
+ case PCM_PARAM_ACCESS:
+ return SNDRV_PCM_HW_PARAM_ACCESS;
+ case PCM_PARAM_FORMAT:
+ return SNDRV_PCM_HW_PARAM_FORMAT;
+ case PCM_PARAM_SUBFORMAT:
+ return SNDRV_PCM_HW_PARAM_SUBFORMAT;
+ case PCM_PARAM_SAMPLE_BITS:
+ return SNDRV_PCM_HW_PARAM_SAMPLE_BITS;
+ break;
+ case PCM_PARAM_FRAME_BITS:
+ return SNDRV_PCM_HW_PARAM_FRAME_BITS;
+ break;
+ case PCM_PARAM_CHANNELS:
+ return SNDRV_PCM_HW_PARAM_CHANNELS;
+ break;
+ case PCM_PARAM_RATE:
+ return SNDRV_PCM_HW_PARAM_RATE;
+ break;
+ case PCM_PARAM_PERIOD_TIME:
+ return SNDRV_PCM_HW_PARAM_PERIOD_TIME;
+ break;
+ case PCM_PARAM_PERIOD_SIZE:
+ return SNDRV_PCM_HW_PARAM_PERIOD_SIZE;
+ break;
+ case PCM_PARAM_PERIOD_BYTES:
+ return SNDRV_PCM_HW_PARAM_PERIOD_BYTES;
+ break;
+ case PCM_PARAM_PERIODS:
+ return SNDRV_PCM_HW_PARAM_PERIODS;
+ break;
+ case PCM_PARAM_BUFFER_TIME:
+ return SNDRV_PCM_HW_PARAM_BUFFER_TIME;
+ break;
+ case PCM_PARAM_BUFFER_SIZE:
+ return SNDRV_PCM_HW_PARAM_BUFFER_SIZE;
+ break;
+ case PCM_PARAM_BUFFER_BYTES:
+ return SNDRV_PCM_HW_PARAM_BUFFER_BYTES;
+ break;
+ case PCM_PARAM_TICK_TIME:
+ return SNDRV_PCM_HW_PARAM_TICK_TIME;
+ break;
+
+ default:
+ return -1;
+ }
+}
+
+struct pcm_mask *pcm_params_get_mask(struct pcm_params *pcm_params,
+ enum pcm_param param)
+{
+ int p;
+ struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
+ if (params == NULL) {
+ return NULL;
+ }
+
+ p = pcm_param_to_alsa(param);
+ if (p < 0 || !param_is_mask(p)) {
+ return NULL;
+ }
+
+ return (struct pcm_mask *)param_to_mask(params, p);
+}
+
+unsigned int pcm_params_get_min(struct pcm_params *pcm_params,
+ enum pcm_param param)
+{
+ struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
+ int p;
+
+ if (!params)
+ return 0;
+
+ p = pcm_param_to_alsa(param);
+ if (p < 0)
+ return 0;
+
+ return param_get_min(params, p);
+}
+
+void pcm_params_set_min(struct pcm_params *pcm_params,
+ enum pcm_param param, unsigned int val)
+{
+ struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
+ int p;
+
+ if (!params)
+ return;
+
+ p = pcm_param_to_alsa(param);
+ if (p < 0)
+ return;
+
+ param_set_min(params, p, val);
+}
+
+unsigned int pcm_params_get_max(struct pcm_params *pcm_params,
+ enum pcm_param param)
+{
+ struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
+ int p;
+
+ if (!params)
+ return 0;
+
+ p = pcm_param_to_alsa(param);
+ if (p < 0)
+ return 0;
+
+ return param_get_max(params, p);
+}
+
+void pcm_params_set_max(struct pcm_params *pcm_params,
+ enum pcm_param param, unsigned int val)
+{
+ struct snd_pcm_hw_params *params = (struct snd_pcm_hw_params *)pcm_params;
+ int p;
+
+ if (!params)
+ return;
+
+ p = pcm_param_to_alsa(param);
+ if (p < 0)
+ return;
+
+ param_set_max(params, p, val);
+}
+
+static int pcm_mask_test(struct pcm_mask *m, unsigned int index)
+{
+ const unsigned int bitshift = 5; /* for 32 bit integer */
+ const unsigned int bitmask = (1 << bitshift) - 1;
+ unsigned int element;
+
+ element = index >> bitshift;
+ if (element >= ARRAY_SIZE(m->bits))
+ return 0; /* for safety, but should never occur */
+ return (m->bits[element] >> (index & bitmask)) & 1;
+}
+
+static int pcm_mask_to_string(struct pcm_mask *m, char *string, unsigned int size,
+ char *mask_name,
+ const char * const *bit_array_name, size_t bit_array_size)
+{
+ unsigned int i;
+ unsigned int offset = 0;
+
+ if (m == NULL)
+ return 0;
+ if (bit_array_size < 32) {
+ STRLOG(string, offset, size, "%12s:\t%#08x\n", mask_name, m->bits[0]);
+ } else { /* spans two or more bitfields, print with an array index */
+ for (i = 0; i < (bit_array_size + 31) >> 5; ++i) {
+ STRLOG(string, offset, size, "%9s[%d]:\t%#08x\n",
+ mask_name, i, m->bits[i]);
+ }
+ }
+ for (i = 0; i < bit_array_size; ++i) {
+ if (pcm_mask_test(m, i)) {
+ STRLOG(string, offset, size, "%12s \t%s\n", "", bit_array_name[i]);
+ }
+ }
+ return offset;
+}
+
+int pcm_params_to_string(struct pcm_params *params, char *string, unsigned int size)
+{
+ struct pcm_mask *m;
+ unsigned int min, max;
+ unsigned int clipoffset, offset;
+
+ m = pcm_params_get_mask(params, PCM_PARAM_ACCESS);
+ offset = pcm_mask_to_string(m, string, size,
+ "Access", access_lookup, ARRAY_SIZE(access_lookup));
+ m = pcm_params_get_mask(params, PCM_PARAM_FORMAT);
+ clipoffset = offset > size ? size : offset;
+ offset += pcm_mask_to_string(m, string + clipoffset, size - clipoffset,
+ "Format", format_lookup, ARRAY_SIZE(format_lookup));
+ m = pcm_params_get_mask(params, PCM_PARAM_SUBFORMAT);
+ clipoffset = offset > size ? size : offset;
+ offset += pcm_mask_to_string(m, string + clipoffset, size - clipoffset,
+ "Subformat", subformat_lookup, ARRAY_SIZE(subformat_lookup));
+ min = pcm_params_get_min(params, PCM_PARAM_RATE);
+ max = pcm_params_get_max(params, PCM_PARAM_RATE);
+ STRLOG(string, offset, size, " Rate:\tmin=%uHz\tmax=%uHz\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_CHANNELS);
+ max = pcm_params_get_max(params, PCM_PARAM_CHANNELS);
+ STRLOG(string, offset, size, " Channels:\tmin=%u\t\tmax=%u\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_SAMPLE_BITS);
+ max = pcm_params_get_max(params, PCM_PARAM_SAMPLE_BITS);
+ STRLOG(string, offset, size, " Sample bits:\tmin=%u\t\tmax=%u\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_PERIOD_SIZE);
+ max = pcm_params_get_max(params, PCM_PARAM_PERIOD_SIZE);
+ STRLOG(string, offset, size, " Period size:\tmin=%u\t\tmax=%u\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_PERIODS);
+ max = pcm_params_get_max(params, PCM_PARAM_PERIODS);
+ STRLOG(string, offset, size, "Period count:\tmin=%u\t\tmax=%u\n", min, max);
+ return offset;
+}
+
+int pcm_params_format_test(struct pcm_params *params, enum pcm_format format)
+{
+ unsigned int alsa_format = pcm_format_to_alsa(format);
+
+ if (alsa_format == SNDRV_PCM_FORMAT_S16_LE && format != PCM_FORMAT_S16_LE)
+ return 0; /* caution: format not recognized is equivalent to S16_LE */
+ return pcm_mask_test(pcm_params_get_mask(params, PCM_PARAM_FORMAT), alsa_format);
+}
+
+int pcm_close(struct pcm *pcm)
+{
+ if (pcm == &bad_pcm)
+ return 0;
+
+ pcm_hw_munmap_status(pcm);
+
+ if (pcm->flags & PCM_MMAP) {
+ pcm_stop(pcm);
+ munmap(pcm->mmap_buffer, pcm_frames_to_bytes(pcm, pcm->buffer_size));
+ }
+
+ if (pcm->fd >= 0)
+ close(pcm->fd);
+ pcm->prepared = 0;
+ pcm->running = 0;
+ pcm->buffer_size = 0;
+ pcm->fd = -1;
+ free(pcm);
+ return 0;
+}
+
+struct pcm *pcm_open(unsigned int card, unsigned int device,
+ unsigned int flags, struct pcm_config *config)
+{
+ struct pcm *pcm;
+ struct snd_pcm_info info;
+ struct snd_pcm_hw_params params;
+ struct snd_pcm_sw_params sparams;
+ char fn[256];
+ int rc;
+
+ pcm = calloc(1, sizeof(struct pcm));
+ if (!pcm || !config)
+ return &bad_pcm; /* TODO: could support default config here */
+
+ pcm->config = *config;
+
+ snprintf(fn, sizeof(fn), "/dev/snd/pcmC%uD%u%c", card, device,
+ flags & PCM_IN ? 'c' : 'p');
+
+ pcm->flags = flags;
+ pcm->fd = open(fn, O_RDWR|O_NONBLOCK);
+ if (pcm->fd < 0) {
+ oops(pcm, errno, "cannot open device '%s'", fn);
+ return pcm;
+ }
+
+ if (fcntl(pcm->fd, F_SETFL, fcntl(pcm->fd, F_GETFL) &
+ ~O_NONBLOCK) < 0) {
+ oops(pcm, errno, "failed to reset blocking mode '%s'", fn);
+ goto fail_close;
+ }
+
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_INFO, &info)) {
+ oops(pcm, errno, "cannot get info");
+ goto fail_close;
+ }
+
+ param_init(¶ms);
+ param_set_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT,
+ pcm_format_to_alsa(config->format));
+ param_set_mask(¶ms, SNDRV_PCM_HW_PARAM_SUBFORMAT,
+ SNDRV_PCM_SUBFORMAT_STD);
+ param_set_min(¶ms, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, config->period_size);
+ param_set_int(¶ms, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
+ pcm_format_to_bits(config->format));
+ param_set_int(¶ms, SNDRV_PCM_HW_PARAM_FRAME_BITS,
+ pcm_format_to_bits(config->format) * config->channels);
+ param_set_int(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS,
+ config->channels);
+ param_set_int(¶ms, SNDRV_PCM_HW_PARAM_PERIODS, config->period_count);
+ param_set_int(¶ms, SNDRV_PCM_HW_PARAM_RATE, config->rate);
+
+ if (flags & PCM_NOIRQ) {
+ if (!(flags & PCM_MMAP)) {
+ oops(pcm, -EINVAL, "noirq only currently supported with mmap().");
+ goto fail_close;
+ }
+
+ params.flags |= SNDRV_PCM_HW_PARAMS_NO_PERIOD_WAKEUP;
+ pcm->noirq_frames_per_msec = config->rate / 1000;
+ }
+
+ if (flags & PCM_MMAP)
+ param_set_mask(¶ms, SNDRV_PCM_HW_PARAM_ACCESS,
+ SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);
+ else
+ param_set_mask(¶ms, SNDRV_PCM_HW_PARAM_ACCESS,
+ SNDRV_PCM_ACCESS_RW_INTERLEAVED);
+
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_HW_PARAMS, ¶ms)) {
+ oops(pcm, errno, "cannot set hw params");
+ goto fail_close;
+ }
+
+ /* get our refined hw_params */
+ config->period_size = param_get_int(¶ms, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
+ config->period_count = param_get_int(¶ms, SNDRV_PCM_HW_PARAM_PERIODS);
+ pcm->buffer_size = config->period_count * config->period_size;
+
+ if (flags & PCM_MMAP) {
+ pcm->mmap_buffer = mmap(NULL, pcm_frames_to_bytes(pcm, pcm->buffer_size),
+ PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, pcm->fd, 0);
+ if (pcm->mmap_buffer == MAP_FAILED) {
+ oops(pcm, -errno, "failed to mmap buffer %d bytes\n",
+ pcm_frames_to_bytes(pcm, pcm->buffer_size));
+ goto fail_close;
+ }
+ }
+
+ memset(&sparams, 0, sizeof(sparams));
+ sparams.tstamp_mode = SNDRV_PCM_TSTAMP_ENABLE;
+ sparams.period_step = 1;
+
+ if (!config->start_threshold) {
+ if (pcm->flags & PCM_IN)
+ pcm->config.start_threshold = sparams.start_threshold = 1;
+ else
+ pcm->config.start_threshold = sparams.start_threshold =
+ config->period_count * config->period_size / 2;
+ } else
+ sparams.start_threshold = config->start_threshold;
+
+ /* pick a high stop threshold - todo: does this need further tuning */
+ if (!config->stop_threshold) {
+ if (pcm->flags & PCM_IN)
+ pcm->config.stop_threshold = sparams.stop_threshold =
+ config->period_count * config->period_size * 10;
+ else
+ pcm->config.stop_threshold = sparams.stop_threshold =
+ config->period_count * config->period_size;
+ }
+ else
+ sparams.stop_threshold = config->stop_threshold;
+
+ if (!pcm->config.avail_min) {
+ if (pcm->flags & PCM_MMAP)
+ pcm->config.avail_min = sparams.avail_min = pcm->config.period_size;
+ else
+ pcm->config.avail_min = sparams.avail_min = 1;
+ } else
+ sparams.avail_min = config->avail_min;
+
+ sparams.xfer_align = config->period_size / 2; /* needed for old kernels */
+ sparams.silence_threshold = config->silence_threshold;
+ sparams.silence_size = config->silence_size;
+ pcm->boundary = sparams.boundary = pcm->buffer_size;
+
+ while (pcm->boundary * 2 <= INT_MAX - pcm->buffer_size)
+ pcm->boundary *= 2;
+
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sparams)) {
+ oops(pcm, errno, "cannot set sw params");
+ goto fail;
+ }
+
+ rc = pcm_hw_mmap_status(pcm);
+ if (rc < 0) {
+ oops(pcm, rc, "mmap status failed");
+ goto fail;
+ }
+
+#ifdef SNDRV_PCM_IOCTL_TTSTAMP
+ if (pcm->flags & PCM_MONOTONIC) {
+ int arg = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC;
+ rc = ioctl(pcm->fd, SNDRV_PCM_IOCTL_TTSTAMP, &arg);
+ if (rc < 0) {
+ oops(pcm, rc, "cannot set timestamp type");
+ goto fail;
+ }
+ }
+#endif
+
+ pcm->underruns = 0;
+ return pcm;
+
+fail:
+ if (flags & PCM_MMAP)
+ munmap(pcm->mmap_buffer, pcm_frames_to_bytes(pcm, pcm->buffer_size));
+fail_close:
+ close(pcm->fd);
+ pcm->fd = -1;
+ return pcm;
+}
+
+int pcm_is_ready(struct pcm *pcm)
+{
+ return pcm->fd >= 0;
+}
+
+int pcm_prepare(struct pcm *pcm)
+{
+ if (pcm->prepared)
+ return 0;
+
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_PREPARE) < 0)
+ return oops(pcm, errno, "cannot prepare channel");
+
+ pcm->prepared = 1;
+ return 0;
+}
+
+int pcm_start(struct pcm *pcm)
+{
+ int prepare_error = pcm_prepare(pcm);
+ if (prepare_error)
+ return prepare_error;
+
+ if (pcm->flags & PCM_MMAP)
+ pcm_sync_ptr(pcm, 0);
+
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_START) < 0)
+ return oops(pcm, errno, "cannot start channel");
+
+ pcm->running = 1;
+ return 0;
+}
+
+int pcm_stop(struct pcm *pcm)
+{
+ if (ioctl(pcm->fd, SNDRV_PCM_IOCTL_DROP) < 0)
+ return oops(pcm, errno, "cannot stop channel");
+
+ pcm->prepared = 0;
+ pcm->running = 0;
+ return 0;
+}
+
+static inline int pcm_mmap_playback_avail(struct pcm *pcm)
+{
+ int avail;
+
+ avail = pcm->mmap_status->hw_ptr + pcm->buffer_size - pcm->mmap_control->appl_ptr;
+
+ if (avail < 0)
+ avail += pcm->boundary;
+ else if (avail > (int)pcm->boundary)
+ avail -= pcm->boundary;
+
+ return avail;
+}
+
+static inline int pcm_mmap_capture_avail(struct pcm *pcm)
+{
+ int avail = pcm->mmap_status->hw_ptr - pcm->mmap_control->appl_ptr;
+ if (avail < 0)
+ avail += pcm->boundary;
+ return avail;
+}
+
+int pcm_mmap_avail(struct pcm *pcm)
+{
+ pcm_sync_ptr(pcm, SNDRV_PCM_SYNC_PTR_HWSYNC);
+ if (pcm->flags & PCM_IN)
+ return pcm_mmap_capture_avail(pcm);
+ else
+ return pcm_mmap_playback_avail(pcm);
+}
+
+static void pcm_mmap_appl_forward(struct pcm *pcm, int frames)
+{
+ unsigned int appl_ptr = pcm->mmap_control->appl_ptr;
+ appl_ptr += frames;
+
+ /* check for boundary wrap */
+ if (appl_ptr > pcm->boundary)
+ appl_ptr -= pcm->boundary;
+ pcm->mmap_control->appl_ptr = appl_ptr;
+}
+
+int pcm_mmap_begin(struct pcm *pcm, void **areas, unsigned int *offset,
+ unsigned int *frames)
+{
+ unsigned int continuous, copy_frames, avail;
+
+ /* return the mmap buffer */
+ *areas = pcm->mmap_buffer;
+
+ /* and the application offset in frames */
+ *offset = pcm->mmap_control->appl_ptr % pcm->buffer_size;
+
+ avail = pcm_mmap_avail(pcm);
+ if (avail > pcm->buffer_size)
+ avail = pcm->buffer_size;
+ continuous = pcm->buffer_size - *offset;
+
+ /* we can only copy frames if the are availabale and continuos */
+ copy_frames = *frames;
+ if (copy_frames > avail)
+ copy_frames = avail;
+ if (copy_frames > continuous)
+ copy_frames = continuous;
+ *frames = copy_frames;
+
+ return 0;
+}
+
+int pcm_mmap_commit(struct pcm *pcm, unsigned int offset __attribute__((unused)), unsigned int frames)
+{
+ /* update the application pointer in userspace and kernel */
+ pcm_mmap_appl_forward(pcm, frames);
+ pcm_sync_ptr(pcm, 0);
+
+ return frames;
+}
+
+int pcm_avail_update(struct pcm *pcm)
+{
+ pcm_sync_ptr(pcm, 0);
+ return pcm_mmap_avail(pcm);
+}
+
+int pcm_state(struct pcm *pcm)
+{
+ int err = pcm_sync_ptr(pcm, 0);
+ if (err < 0)
+ return err;
+
+ return pcm->mmap_status->state;
+}
+
+int pcm_set_avail_min(struct pcm *pcm, int avail_min)
+{
+ if ((~pcm->flags) & (PCM_MMAP | PCM_NOIRQ))
+ return -ENOSYS;
+
+ pcm->config.avail_min = avail_min;
+ return 0;
+}
+
+int pcm_wait(struct pcm *pcm, int timeout)
+{
+ struct pollfd pfd;
+ int err;
+
+ pfd.fd = pcm->fd;
+ pfd.events = POLLOUT | POLLERR | POLLNVAL;
+
+ do {
+ /* let's wait for avail or timeout */
+ err = poll(&pfd, 1, timeout);
+ if (err < 0)
+ return -errno;
+
+ /* timeout ? */
+ if (err == 0)
+ return 0;
+
+ /* have we been interrupted ? */
+ if (errno == -EINTR)
+ continue;
+
+ /* check for any errors */
+ if (pfd.revents & (POLLERR | POLLNVAL)) {
+ switch (pcm_state(pcm)) {
+ case PCM_STATE_XRUN:
+ return -EPIPE;
+ case PCM_STATE_SUSPENDED:
+ return -ESTRPIPE;
+ case PCM_STATE_DISCONNECTED:
+ return -ENODEV;
+ default:
+ return -EIO;
+ }
+ }
+ /* poll again if fd not ready for IO */
+ } while (!(pfd.revents & (POLLIN | POLLOUT)));
+
+ return 1;
+}
+
+int pcm_get_poll_fd(struct pcm *pcm)
+{
+ return pcm->fd;
+}
+
+int pcm_mmap_transfer(struct pcm *pcm, const void *buffer, unsigned int bytes)
+{
+ int err = 0, frames, avail;
+ unsigned int offset = 0, count;
+
+ if (bytes == 0)
+ return 0;
+
+ count = pcm_bytes_to_frames(pcm, bytes);
+
+ while (count > 0) {
+
+ /* get the available space for writing new frames */
+ avail = pcm_avail_update(pcm);
+ if (avail < 0) {
+ fprintf(stderr, "cannot determine available mmap frames");
+ return err;
+ }
+
+ /* start the audio if we reach the threshold */
+ if (!pcm->running &&
+ (pcm->buffer_size - avail) >= pcm->config.start_threshold) {
+ if (pcm_start(pcm) < 0) {
+ fprintf(stderr, "start error: hw 0x%x app 0x%x avail 0x%x\n",
+ (unsigned int)pcm->mmap_status->hw_ptr,
+ (unsigned int)pcm->mmap_control->appl_ptr,
+ avail);
+ return -errno;
+ }
+ pcm->wait_for_avail_min = 0;
+ }
+
+ /* sleep until we have space to write new frames */
+ if (pcm->running) {
+ /* enable waiting for avail_min threshold when less frames than we have to write
+ * are available. */
+ if (!pcm->wait_for_avail_min && (count > (unsigned int)avail))
+ pcm->wait_for_avail_min = 1;
+
+ if (pcm->wait_for_avail_min && (avail < pcm->config.avail_min)) {
+ int time = -1;
+
+ /* disable waiting for avail_min threshold to allow small amounts of data to be
+ * written without waiting as long as there is enough room in buffer. */
+ pcm->wait_for_avail_min = 0;
+
+ if (pcm->flags & PCM_NOIRQ)
+ time = (pcm->config.avail_min - avail) / pcm->noirq_frames_per_msec;
+
+ err = pcm_wait(pcm, time);
+ if (err < 0) {
+ pcm->prepared = 0;
+ pcm->running = 0;
+ oops(pcm, err, "wait error: hw 0x%x app 0x%x avail 0x%x\n",
+ (unsigned int)pcm->mmap_status->hw_ptr,
+ (unsigned int)pcm->mmap_control->appl_ptr,
+ avail);
+ pcm->mmap_control->appl_ptr = 0;
+ return err;
+ }
+ continue;
+ }
+ }
+
+ frames = count;
+ if (frames > avail)
+ frames = avail;
+
+ if (!frames)
+ break;
+
+ /* copy frames from buffer */
+ frames = pcm_mmap_transfer_areas(pcm, (void *)buffer, offset, frames);
+ if (frames < 0) {
+ fprintf(stderr, "write error: hw 0x%x app 0x%x avail 0x%x\n",
+ (unsigned int)pcm->mmap_status->hw_ptr,
+ (unsigned int)pcm->mmap_control->appl_ptr,
+ avail);
+ return frames;
+ }
+
+ offset += frames;
+ count -= frames;
+ }
+
+ return 0;
+}
+
+int pcm_mmap_write(struct pcm *pcm, const void *data, unsigned int count)
+{
+ if ((~pcm->flags) & (PCM_OUT | PCM_MMAP))
+ return -ENOSYS;
+
+ return pcm_mmap_transfer(pcm, (void *)data, count);
+}
+
+int pcm_mmap_read(struct pcm *pcm, void *data, unsigned int count)
+{
+ if ((~pcm->flags) & (PCM_IN | PCM_MMAP))
+ return -ENOSYS;
+
+ return pcm_mmap_transfer(pcm, data, count);
+}
+
+int pcm_ioctl(struct pcm *pcm, int request, ...)
+{
+ va_list ap;
+ void * arg;
+
+ if (!pcm_is_ready(pcm))
+ return -1;
+
+ va_start(ap, request);
+ arg = va_arg(ap, void *);
+ va_end(ap);
+
+ return ioctl(pcm->fd, request, arg);
+}
diff --git a/ap/lib/libtinyalsa/tinyalsa_voice_ref.c b/ap/lib/libtinyalsa/tinyalsa_voice_ref.c
new file mode 100644
index 0000000..3e4923b
--- /dev/null
+++ b/ap/lib/libtinyalsa/tinyalsa_voice_ref.c
@@ -0,0 +1,122 @@
+/*
+ *
+ * Based on 7510_dev.c
+ *
+ */
+
+#include <tinyalsa/audio_mixer_ctrl.h>
+
+
+struct pcm *voicePcmOut = NULL;
+struct pcm *voicePcmIn = NULL;
+
+typedef struct
+{
+ // uint32_t voice_mode;//0, 2/3g;1, volte nb;2 ,volte wb;
+ uint32_t clock_rate; //8000, 2/3g;8000, volte nb;16000 ,volte wb;
+ uint32_t channel_count;
+ uint32_t samples_per_frame;//160, 2/3g;160, volte nb;320 ,volte wb;
+ uint32_t bits_per_sample;
+} T_voiceCfg;
+
+T_voiceCfg cfgParam = {0,8000,1,160,16};
+
+
+
+
+ int voice_PreOpen(T_voiceCfg *cfgParam)
+{
+ struct mixer *voice_mixer = NULL;
+ struct pcm_config config_voice = {0};
+
+ /* open mixer dev for codec control */
+ voice_mixer = mixer_open(0);
+ if(!voice_mixer)
+ {
+ printf("zte voice_mixer open failed!");
+ goto err_ret;
+ }
+
+ /* config mixer dev */
+ mix_set_voice_path(voice_mixer, T_OUTPUT_SPEAKER);
+ mix_set_voice_vol(voice_mixer, T_VOICE_VOL_3_LEVEL);
+
+ /*close mixer */
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+
+ /* open pcm dev for data tranf*/
+ config_voice.channels = cfgParam->channel_count;
+ config_voice.rate = cfgParam->clock_rate;
+ /* buffer num */
+ config_voice.period_count = 3;
+ /* buffer size */
+ config_voice.period_size = cfgParam->samples_per_frame * cfgParam->bits_per_sample / 8;
+ /* 16-bit signed */
+ config_voice.format = PCM_FORMAT_S16_LE;
+
+ //card 0 dev 1
+ //23G card 0 dev 2
+ voicePcmOut = pcm_open(0, 1, PCM_OUT, &config_voice);
+ if(!voicePcmOut || !pcm_is_ready(voicePcmOut))
+ {
+ printf( "zte voicePcmOut open failed!");
+ goto err_ret;
+ }
+
+ voicePcmIn = pcm_open(0, 1, PCM_IN, &config_voice);
+ if(!voicePcmIn || !pcm_is_ready(voicePcmIn))
+ {
+ printf( "zte voicePcmIn open failed!");
+ goto err_ret;
+ }
+
+ if(0 != pcm_prepare(voicePcmOut))
+ {
+ printf("zte voicePcmOut pcm_prepare failed!");
+ goto err_ret;
+ }
+
+ if(0 != pcm_prepare(voicePcmIn))
+ {
+ printf("zte voicePcmIn pcm_prepare failed!");
+ goto err_ret;
+ }
+ return 0;
+err_ret:
+ if(voice_mixer)
+ {
+ mixer_close(voice_mixer);
+ voice_mixer = NULL;
+ }
+
+ if(voicePcmOut)
+ {
+ pcm_close(voicePcmOut);
+ voicePcmOut = NULL;
+ }
+ if(voicePcmIn)
+ {
+ pcm_close(voicePcmIn);
+ voicePcmIn = NULL;
+ }
+ return -1;
+
+}
+
+
+ void voice_PreClose(void)
+{
+ if(voicePcmOut)
+ {
+ pcm_close(voicePcmOut);
+ voicePcmOut = NULL;
+ }
+ if(voicePcmIn)
+ {
+ pcm_close(voicePcmIn);
+ voicePcmIn = NULL;
+ }
+}
+
+
diff --git a/ap/lib/libtinyalsa/tinycap.c b/ap/lib/libtinyalsa/tinycap.c
new file mode 100644
index 0000000..901c540
--- /dev/null
+++ b/ap/lib/libtinyalsa/tinycap.c
@@ -0,0 +1,235 @@
+/* tinycap.c
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#include <tinyalsa/asoundlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <signal.h>
+#include <string.h>
+
+#define ID_RIFF 0x46464952
+#define ID_WAVE 0x45564157
+#define ID_FMT 0x20746d66
+#define ID_DATA 0x61746164
+
+#define FORMAT_PCM 1
+
+struct wav_header {
+ uint32_t riff_id;
+ uint32_t riff_sz;
+ uint32_t riff_fmt;
+ uint32_t fmt_id;
+ uint32_t fmt_sz;
+ uint16_t audio_format;
+ uint16_t num_channels;
+ uint32_t sample_rate;
+ uint32_t byte_rate;
+ uint16_t block_align;
+ uint16_t bits_per_sample;
+ uint32_t data_id;
+ uint32_t data_sz;
+};
+
+int capturing = 1;
+
+unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device,
+ unsigned int channels, unsigned int rate,
+ enum pcm_format format, unsigned int period_size,
+ unsigned int period_count);
+
+void sigint_handler(int sig) // __unused)
+{
+ capturing = 0;
+}
+
+int main(int argc, char **argv)
+{
+ FILE *file;
+ struct wav_header header;
+ unsigned int card = 0;
+ unsigned int device = 0;
+ unsigned int channels = 2;
+ unsigned int rate = 44100;
+ unsigned int bits = 16;
+ unsigned int frames;
+ unsigned int period_size = 1024;
+ unsigned int period_count = 4;
+ enum pcm_format format;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-c channels] "
+ "[-r rate] [-b bits] [-p period_size] [-n n_periods]\n", argv[0]);
+ return 1;
+ }
+
+ file = fopen(argv[1], "wb");
+ if (!file) {
+ fprintf(stderr, "Unable to create file '%s'\n", argv[1]);
+ return 1;
+ }
+
+ /* parse command line arguments */
+ argv += 2;
+ while (*argv) {
+ if (strcmp(*argv, "-d") == 0) {
+ argv++;
+ if (*argv)
+ device = atoi(*argv);
+ } else if (strcmp(*argv, "-c") == 0) {
+ argv++;
+ if (*argv)
+ channels = atoi(*argv);
+ } else if (strcmp(*argv, "-r") == 0) {
+ argv++;
+ if (*argv)
+ rate = atoi(*argv);
+ } else if (strcmp(*argv, "-b") == 0) {
+ argv++;
+ if (*argv)
+ bits = atoi(*argv);
+ } else if (strcmp(*argv, "-D") == 0) {
+ argv++;
+ if (*argv)
+ card = atoi(*argv);
+ } else if (strcmp(*argv, "-p") == 0) {
+ argv++;
+ if (*argv)
+ period_size = atoi(*argv);
+ } else if (strcmp(*argv, "-n") == 0) {
+ argv++;
+ if (*argv)
+ period_count = atoi(*argv);
+ }
+ if (*argv)
+ argv++;
+ }
+
+ header.riff_id = ID_RIFF;
+ header.riff_sz = 0;
+ header.riff_fmt = ID_WAVE;
+ header.fmt_id = ID_FMT;
+ header.fmt_sz = 16;
+ header.audio_format = FORMAT_PCM;
+ header.num_channels = channels;
+ header.sample_rate = rate;
+
+ switch (bits) {
+ case 32:
+ format = PCM_FORMAT_S32_LE;
+ break;
+ case 24:
+ format = PCM_FORMAT_S24_LE;
+ break;
+ case 16:
+ format = PCM_FORMAT_S16_LE;
+ break;
+ default:
+ fprintf(stderr, "%d bits is not supported.\n", bits);
+ return 1;
+ }
+
+ header.bits_per_sample = pcm_format_to_bits(format);
+ header.byte_rate = (header.bits_per_sample / 8) * channels * rate;
+ header.block_align = channels * (header.bits_per_sample / 8);
+ header.data_id = ID_DATA;
+
+ /* leave enough room for header */
+ fseek(file, sizeof(struct wav_header), SEEK_SET);
+
+ /* install signal handler and begin capturing */
+ signal(SIGINT, sigint_handler);
+ frames = capture_sample(file, card, device, header.num_channels,
+ header.sample_rate, format,
+ period_size, period_count);
+ printf("Captured %d frames\n", frames);
+
+ /* write header now all information is known */
+ header.data_sz = frames * header.block_align;
+ header.riff_sz = header.data_sz + sizeof(header) - 8;
+ fseek(file, 0, SEEK_SET);
+ fwrite(&header, sizeof(struct wav_header), 1, file);
+
+ fclose(file);
+
+ return 0;
+}
+
+unsigned int capture_sample(FILE *file, unsigned int card, unsigned int device,
+ unsigned int channels, unsigned int rate,
+ enum pcm_format format, unsigned int period_size,
+ unsigned int period_count)
+{
+ struct pcm_config config;
+ struct pcm *pcm;
+ char *buffer;
+ unsigned int size;
+ unsigned int bytes_read = 0;
+
+ memset(&config, 0, sizeof(config));
+ config.channels = channels;
+ config.rate = rate;
+ config.period_size = period_size;
+ config.period_count = period_count;
+ config.format = format;
+ config.start_threshold = 0;
+ config.stop_threshold = 0;
+ config.silence_threshold = 0;
+
+ pcm = pcm_open(card, device, PCM_IN, &config);
+ if (!pcm || !pcm_is_ready(pcm)) {
+ fprintf(stderr, "Unable to open PCM device (%s)\n",
+ pcm_get_error(pcm));
+ return 0;
+ }
+
+ size = pcm_frames_to_bytes(pcm, pcm_get_buffer_size(pcm));
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %d bytes\n", size);
+ free(buffer);
+ pcm_close(pcm);
+ return 0;
+ }
+
+ printf("Capturing sample: %u ch, %u hz, %u bit\n", channels, rate,
+ pcm_format_to_bits(format));
+
+ while (capturing && !pcm_read(pcm, buffer, size)) {
+ if (fwrite(buffer, 1, size, file) != size) {
+ fprintf(stderr,"Error capturing sample\n");
+ break;
+ }
+ bytes_read += size;
+ }
+
+ free(buffer);
+ pcm_close(pcm);
+ return pcm_bytes_to_frames(pcm, bytes_read);
+}
+
diff --git a/ap/lib/libtinyalsa/tinymix.c b/ap/lib/libtinyalsa/tinymix.c
new file mode 100644
index 0000000..a3c41a2
--- /dev/null
+++ b/ap/lib/libtinyalsa/tinymix.c
@@ -0,0 +1,316 @@
+/* tinymix.c
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#include <tinyalsa/asoundlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <string.h>
+
+static void tinymix_list_controls(struct mixer *mixer);
+static void tinymix_detail_control(struct mixer *mixer, const char *control,
+ int print_all);
+static void tinymix_set_value(struct mixer *mixer, const char *control,
+ char **values, unsigned int num_values);
+static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all);
+
+int main(int argc, char **argv)
+{
+ struct mixer *mixer;
+ int card = 0;
+
+ if ((argc > 2) && (strcmp(argv[1], "-D") == 0)) {
+ argv++;
+ if (argv[1]) {
+ card = atoi(argv[1]);
+ argv++;
+ argc -= 2;
+ } else {
+ argc -= 1;
+ }
+ }
+
+ mixer = mixer_open(card);
+ if (!mixer) {
+ fprintf(stderr, "Failed to open mixer\n");
+ return EXIT_FAILURE;
+ }
+
+
+ if (argc == 1) {
+ printf("Mixer name: '%s'\n", mixer_get_name(mixer));
+ tinymix_list_controls(mixer);
+ } else if (argc == 2) {
+ tinymix_detail_control(mixer, argv[1], 1);
+ } else if (argc >= 3) {
+ tinymix_set_value(mixer, argv[1], &argv[2], argc - 2);
+ } else {
+ printf("Usage: tinymix [-D card] [control id] [value to set]\n");
+ }
+
+ mixer_close(mixer);
+
+ return 0;
+}
+
+static void tinymix_list_controls(struct mixer *mixer)
+{
+ struct mixer_ctl *ctl;
+ const char *name, *type;
+ unsigned int num_ctls, num_values;
+ unsigned int i;
+
+ num_ctls = mixer_get_num_ctls(mixer);
+
+ printf("Number of controls: %d\n", num_ctls);
+
+ printf("ctl\ttype\tnum\t%-40s value\n", "name");
+ for (i = 0; i < num_ctls; i++) {
+ ctl = mixer_get_ctl(mixer, i);
+
+ name = mixer_ctl_get_name(ctl);
+ type = mixer_ctl_get_type_string(ctl);
+ num_values = mixer_ctl_get_num_values(ctl);
+ printf("%d\t%s\t%d\t%-40s", i, type, num_values, name);
+ tinymix_detail_control(mixer, name, 0);
+ }
+}
+
+static void tinymix_print_enum(struct mixer_ctl *ctl, int print_all)
+{
+ unsigned int num_enums;
+ unsigned int i;
+ const char *string;
+
+ num_enums = mixer_ctl_get_num_enums(ctl);
+
+ for (i = 0; i < num_enums; i++) {
+ string = mixer_ctl_get_enum_string(ctl, i);
+ if (print_all)
+ printf("\t%s%s", mixer_ctl_get_value(ctl, 0) == (int)i ? ">" : "",
+ string);
+ else if (mixer_ctl_get_value(ctl, 0) == (int)i)
+ printf(" %-s", string);
+ }
+}
+
+static void tinymix_detail_control(struct mixer *mixer, const char *control,
+ int print_all)
+{
+ struct mixer_ctl *ctl;
+ enum mixer_ctl_type type;
+ unsigned int num_values;
+ unsigned int i;
+ int min, max;
+ int ret;
+ char *buf = NULL;
+ size_t len;
+
+ if (isdigit(control[0]))
+ ctl = mixer_get_ctl(mixer, atoi(control));
+ else
+ ctl = mixer_get_ctl_by_name(mixer, control);
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ type = mixer_ctl_get_type(ctl);
+ num_values = mixer_ctl_get_num_values(ctl);
+
+ if (type == MIXER_CTL_TYPE_BYTE) {
+
+ buf = calloc(1, num_values);
+ if (buf == NULL) {
+ fprintf(stderr, "Failed to alloc mem for bytes %d\n", num_values);
+ return;
+ }
+
+ len = num_values;
+ ret = mixer_ctl_get_array(ctl, buf, len);
+ if (ret < 0) {
+ fprintf(stderr, "Failed to mixer_ctl_get_array\n");
+ free(buf);
+ return;
+ }
+ }
+
+ if (print_all)
+ printf("%s:", mixer_ctl_get_name(ctl));
+
+ for (i = 0; i < num_values; i++) {
+ switch (type)
+ {
+ case MIXER_CTL_TYPE_INT:
+ printf(" %d", mixer_ctl_get_value(ctl, i));
+ break;
+ case MIXER_CTL_TYPE_BOOL:
+ printf(" %s", mixer_ctl_get_value(ctl, i) ? "On" : "Off");
+ break;
+ case MIXER_CTL_TYPE_ENUM:
+ tinymix_print_enum(ctl, print_all);
+ break;
+ case MIXER_CTL_TYPE_BYTE:
+ printf("%02x", buf[i]);
+ break;
+ default:
+ printf(" unknown");
+ break;
+ };
+ }
+
+ if (print_all) {
+ if (type == MIXER_CTL_TYPE_INT) {
+ min = mixer_ctl_get_range_min(ctl);
+ max = mixer_ctl_get_range_max(ctl);
+ printf(" (range %d->%d)", min, max);
+ }
+ }
+
+ free(buf);
+
+ printf("\n");
+}
+
+static void tinymix_set_byte_ctl(struct mixer_ctl *ctl,
+ char **values, unsigned int num_values)
+{
+ int ret;
+ char *buf;
+ char *end;
+ unsigned int i;
+ long n;
+
+ buf = calloc(1, num_values);
+ if (buf == NULL) {
+ fprintf(stderr, "set_byte_ctl: Failed to alloc mem for bytes %d\n", num_values);
+ exit(EXIT_FAILURE);
+ }
+
+ for (i = 0; i < num_values; i++) {
+ errno = 0;
+ n = strtol(values[i], &end, 0);
+ if (*end) {
+ fprintf(stderr, "%s not an integer\n", values[i]);
+ goto fail;
+ }
+ if (errno) {
+ fprintf(stderr, "strtol: %s: %s\n", values[i],
+ strerror(errno));
+ goto fail;
+ }
+ if (n < 0 || n > 0xff) {
+ fprintf(stderr, "%s should be between [0, 0xff]\n",
+ values[i]);
+ goto fail;
+ }
+ buf[i] = n;
+ }
+
+ ret = mixer_ctl_set_array(ctl, buf, num_values);
+ if (ret < 0) {
+ fprintf(stderr, "Failed to set binary control\n");
+ goto fail;
+ }
+
+ free(buf);
+ return;
+
+fail:
+ free(buf);
+ exit(EXIT_FAILURE);
+}
+
+static void tinymix_set_value(struct mixer *mixer, const char *control,
+ char **values, unsigned int num_values)
+{
+ struct mixer_ctl *ctl;
+ enum mixer_ctl_type type;
+ unsigned int num_ctl_values;
+ unsigned int i;
+
+ if (isdigit(control[0]))
+ ctl = mixer_get_ctl(mixer, atoi(control));
+ else
+ ctl = mixer_get_ctl_by_name(mixer, control);
+
+ if (!ctl) {
+ fprintf(stderr, "Invalid mixer control\n");
+ return;
+ }
+
+ type = mixer_ctl_get_type(ctl);
+ num_ctl_values = mixer_ctl_get_num_values(ctl);
+
+ if (type == MIXER_CTL_TYPE_BYTE) {
+ tinymix_set_byte_ctl(ctl, values, num_values);
+ return;
+ }
+
+ if (isdigit(values[0][0])) {
+ if (num_values == 1) {
+ /* Set all values the same */
+ int value = atoi(values[0]);
+
+ for (i = 0; i < num_ctl_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, value)) {
+ fprintf(stderr, "Error: invalid value\n");
+ return;
+ }
+ }
+ } else {
+ /* Set multiple values */
+ if (num_values > num_ctl_values) {
+ fprintf(stderr,
+ "Error: %d values given, but control only takes %d\n",
+ num_values, num_ctl_values);
+ return;
+ }
+ for (i = 0; i < num_values; i++) {
+ if (mixer_ctl_set_value(ctl, i, atoi(values[i]))) {
+ fprintf(stderr, "Error: invalid value for index %d\n", i);
+ return;
+ }
+ }
+ }
+ } else {
+ if (type == MIXER_CTL_TYPE_ENUM) {
+ if (num_values != 1) {
+ fprintf(stderr, "Enclose strings in quotes and try again\n");
+ return;
+ }
+ if (mixer_ctl_set_enum_by_string(ctl, values[0]))
+ fprintf(stderr, "Error: invalid enum value\n");
+ } else {
+ fprintf(stderr, "Error: only enum types can be set with strings\n");
+ }
+ }
+}
+
diff --git a/ap/lib/libtinyalsa/tinypcminfo.c b/ap/lib/libtinyalsa/tinypcminfo.c
new file mode 100644
index 0000000..b2d11bc
--- /dev/null
+++ b/ap/lib/libtinyalsa/tinypcminfo.c
@@ -0,0 +1,203 @@
+/* tinypcminfo.c
+**
+** Copyright 2012, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#include <tinyalsa/asoundlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+#endif
+
+/* The format_lookup is in order of SNDRV_PCM_FORMAT_##index and
+ * matches the grouping in sound/asound.h. Note this is not
+ * continuous and has an empty gap from (25 - 30).
+ */
+static const char *format_lookup[] = {
+ /*[0] =*/ "S8",
+ "U8",
+ "S16_LE",
+ "S16_BE",
+ "U16_LE",
+ "U16_BE",
+ "S24_LE",
+ "S24_BE",
+ "U24_LE",
+ "U24_BE",
+ "S32_LE",
+ "S32_BE",
+ "U32_LE",
+ "U32_BE",
+ "FLOAT_LE",
+ "FLOAT_BE",
+ "FLOAT64_LE",
+ "FLOAT64_BE",
+ "IEC958_SUBFRAME_LE",
+ "IEC958_SUBFRAME_BE",
+ "MU_LAW",
+ "A_LAW",
+ "IMA_ADPCM",
+ "MPEG",
+ /*[24] =*/ "GSM",
+ [31] = "SPECIAL",
+ "S24_3LE",
+ "S24_3BE",
+ "U24_3LE",
+ "U24_3BE",
+ "S20_3LE",
+ "S20_3BE",
+ "U20_3LE",
+ "U20_3BE",
+ "S18_3LE",
+ "S18_3BE",
+ "U18_3LE",
+ /*[43] =*/ "U18_3BE",
+#if 0
+ /* recent additions, may not be present on local asound.h */
+ "G723_24",
+ "G723_24_1B",
+ "G723_40",
+ "G723_40_1B",
+ "DSD_U8",
+ "DSD_U16_LE",
+#endif
+};
+
+/* Returns a human readable name for the format associated with bit_index,
+ * NULL if bit_index is not known.
+ */
+inline const char *pcm_get_format_name(unsigned bit_index)
+{
+ return bit_index < ARRAY_SIZE(format_lookup) ? format_lookup[bit_index] : NULL;
+}
+
+int main(int argc, char **argv)
+{
+ unsigned int device = 0;
+ unsigned int card = 0;
+ int i;
+
+ if (argc < 3) {
+ fprintf(stderr, "Usage: %s -D card -d device\n", argv[0]);
+ return 1;
+ }
+
+ /* parse command line arguments */
+ argv += 1;
+ while (*argv) {
+ if (strcmp(*argv, "-D") == 0) {
+ argv++;
+ if (*argv)
+ card = atoi(*argv);
+ }
+ if (strcmp(*argv, "-d") == 0) {
+ argv++;
+ if (*argv)
+ device = atoi(*argv);
+ }
+ if (*argv)
+ argv++;
+ }
+
+ printf("Info for card %d, device %d:\n", card, device);
+
+ for (i = 0; i < 2; i++) {
+ struct pcm_params *params;
+ struct pcm_mask *m;
+ unsigned int min;
+ unsigned int max;
+
+ printf("\nPCM %s:\n", i == 0 ? "out" : "in");
+
+ params = pcm_params_get(card, device, i == 0 ? PCM_OUT : PCM_IN);
+ if (params == NULL) {
+ printf("Device does not exist.\n");
+ continue;
+ }
+
+ m = pcm_params_get_mask(params, PCM_PARAM_ACCESS);
+ if (m) { /* bitmask, refer to SNDRV_PCM_ACCESS_*, generally interleaved */
+ printf(" Access:\t%#08x\n", m->bits[0]);
+ }
+ m = pcm_params_get_mask(params, PCM_PARAM_FORMAT);
+ if (m) { /* bitmask, refer to: SNDRV_PCM_FORMAT_* */
+ unsigned j, k, count = 0;
+ const unsigned bitcount = sizeof(m->bits[0]) * 8;
+
+ /* we only check first two format masks (out of 8) - others are zero. */
+ printf(" Format[0]:\t%#08x\n", m->bits[0]);
+ printf(" Format[1]:\t%#08x\n", m->bits[1]);
+
+ /* print friendly format names, if they exist */
+ for (k = 0; k < 2; ++k) {
+ for (j = 0; j < bitcount; ++j) {
+ const char *name;
+
+ if (m->bits[k] & (1 << j)) {
+ name = pcm_get_format_name(j + k*bitcount);
+ if (name) {
+ if (count++ == 0) {
+ printf(" Format Name:\t");
+ } else {
+ printf (", ");
+ }
+ printf("%s", name);
+ }
+ }
+ }
+ }
+ if (count) {
+ printf("\n");
+ }
+ }
+ m = pcm_params_get_mask(params, PCM_PARAM_SUBFORMAT);
+ if (m) { /* bitmask, should be 1: SNDRV_PCM_SUBFORMAT_STD */
+ printf(" Subformat:\t%#08x\n", m->bits[0]);
+ }
+ min = pcm_params_get_min(params, PCM_PARAM_RATE);
+ max = pcm_params_get_max(params, PCM_PARAM_RATE);
+ printf(" Rate:\tmin=%uHz\tmax=%uHz\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_CHANNELS);
+ max = pcm_params_get_max(params, PCM_PARAM_CHANNELS);
+ printf(" Channels:\tmin=%u\t\tmax=%u\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_SAMPLE_BITS);
+ max = pcm_params_get_max(params, PCM_PARAM_SAMPLE_BITS);
+ printf(" Sample bits:\tmin=%u\t\tmax=%u\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_PERIOD_SIZE);
+ max = pcm_params_get_max(params, PCM_PARAM_PERIOD_SIZE);
+ printf(" Period size:\tmin=%u\t\tmax=%u\n", min, max);
+ min = pcm_params_get_min(params, PCM_PARAM_PERIODS);
+ max = pcm_params_get_max(params, PCM_PARAM_PERIODS);
+ printf("Period count:\tmin=%u\t\tmax=%u\n", min, max);
+
+ pcm_params_free(params);
+ }
+
+ return 0;
+}
diff --git a/ap/lib/libtinyalsa/tinyplay.c b/ap/lib/libtinyalsa/tinyplay.c
new file mode 100644
index 0000000..88c54ae
--- /dev/null
+++ b/ap/lib/libtinyalsa/tinyplay.c
@@ -0,0 +1,272 @@
+/* tinyplay.c
+**
+** Copyright 2011, The Android Open Source Project
+**
+** Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in the
+** documentation and/or other materials provided with the distribution.
+** * Neither the name of The Android Open Source Project nor the names of
+** its contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+** THIS SOFTWARE IS PROVIDED BY The Android Open Source Project ``AS IS'' AND
+** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+** ARE DISCLAIMED. IN NO EVENT SHALL The Android Open Source Project BE LIABLE
+** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+** CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+** DAMAGE.
+*/
+
+#include <tinyalsa/asoundlib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <signal.h>
+
+#define ID_RIFF 0x46464952
+#define ID_WAVE 0x45564157
+#define ID_FMT 0x20746d66
+#define ID_DATA 0x61746164
+
+struct riff_wave_header {
+ uint32_t riff_id;
+ uint32_t riff_sz;
+ uint32_t wave_id;
+};
+
+struct chunk_header {
+ uint32_t id;
+ uint32_t sz;
+};
+
+struct chunk_fmt {
+ uint16_t audio_format;
+ uint16_t num_channels;
+ uint32_t sample_rate;
+ uint32_t byte_rate;
+ uint16_t block_align;
+ uint16_t bits_per_sample;
+};
+
+static int close = 0;
+
+void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count);
+
+void stream_close(int sig)
+{
+ /* allow the stream to be closed gracefully */
+ signal(sig, SIG_IGN);
+ close = 1;
+}
+
+int main(int argc, char **argv)
+{
+ FILE *file;
+ struct riff_wave_header riff_wave_header;
+ struct chunk_header chunk_header;
+ struct chunk_fmt chunk_fmt;
+ unsigned int device = 0;
+ unsigned int card = 0;
+ unsigned int period_size = 1024;
+ unsigned int period_count = 4;
+ char *filename;
+ int more_chunks = 1;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage: %s file.wav [-D card] [-d device] [-p period_size]"
+ " [-n n_periods] \n", argv[0]);
+ return 1;
+ }
+
+ filename = argv[1];
+ file = fopen(filename, "rb");
+ if (!file) {
+ fprintf(stderr, "Unable to open file '%s'\n", filename);
+ return 1;
+ }
+
+ fread(&riff_wave_header, sizeof(riff_wave_header), 1, file);
+ if ((riff_wave_header.riff_id != ID_RIFF) ||
+ (riff_wave_header.wave_id != ID_WAVE)) {
+ fprintf(stderr, "Error: '%s' is not a riff/wave file\n", filename);
+ fclose(file);
+ return 1;
+ }
+
+ do {
+ fread(&chunk_header, sizeof(chunk_header), 1, file);
+
+ switch (chunk_header.id) {
+ case ID_FMT:
+ fread(&chunk_fmt, sizeof(chunk_fmt), 1, file);
+ /* If the format header is larger, skip the rest */
+ if (chunk_header.sz > sizeof(chunk_fmt))
+ fseek(file, chunk_header.sz - sizeof(chunk_fmt), SEEK_CUR);
+ break;
+ case ID_DATA:
+ /* Stop looking for chunks */
+ more_chunks = 0;
+ break;
+ default:
+ /* Unknown chunk, skip bytes */
+ fseek(file, chunk_header.sz, SEEK_CUR);
+ }
+ } while (more_chunks);
+
+ /* parse command line arguments */
+ argv += 2;
+ while (*argv) {
+ if (strcmp(*argv, "-d") == 0) {
+ argv++;
+ if (*argv)
+ device = atoi(*argv);
+ }
+ if (strcmp(*argv, "-p") == 0) {
+ argv++;
+ if (*argv)
+ period_size = atoi(*argv);
+ }
+ if (strcmp(*argv, "-n") == 0) {
+ argv++;
+ if (*argv)
+ period_count = atoi(*argv);
+ }
+ if (strcmp(*argv, "-D") == 0) {
+ argv++;
+ if (*argv)
+ card = atoi(*argv);
+ }
+ if (*argv)
+ argv++;
+ }
+
+ play_sample(file, card, device, chunk_fmt.num_channels, chunk_fmt.sample_rate,
+ chunk_fmt.bits_per_sample, period_size, period_count);
+
+ fclose(file);
+
+ return 0;
+}
+
+int check_param(struct pcm_params *params, unsigned int param, unsigned int value,
+ char *param_name, char *param_unit)
+{
+ unsigned int min;
+ unsigned int max;
+ int is_within_bounds = 1;
+
+ min = pcm_params_get_min(params, param);
+ if (value < min) {
+ fprintf(stderr, "%s is %u%s, device only supports >= %u%s\n", param_name, value,
+ param_unit, min, param_unit);
+ is_within_bounds = 0;
+ }
+
+ max = pcm_params_get_max(params, param);
+ if (value > max) {
+ fprintf(stderr, "%s is %u%s, device only supports <= %u%s\n", param_name, value,
+ param_unit, max, param_unit);
+ is_within_bounds = 0;
+ }
+
+ return is_within_bounds;
+}
+
+int sample_is_playable(unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count)
+{
+ struct pcm_params *params;
+ int can_play;
+
+ params = pcm_params_get(card, device, PCM_OUT);
+ if (params == NULL) {
+ fprintf(stderr, "Unable to open PCM device %u.\n", device);
+ return 0;
+ }
+
+ can_play = check_param(params, PCM_PARAM_RATE, rate, "Sample rate", "Hz");
+ can_play &= check_param(params, PCM_PARAM_CHANNELS, channels, "Sample", " channels");
+ can_play &= check_param(params, PCM_PARAM_SAMPLE_BITS, bits, "Bitrate", " bits");
+ can_play &= check_param(params, PCM_PARAM_PERIOD_SIZE, period_size, "Period size", "Hz");
+ can_play &= check_param(params, PCM_PARAM_PERIODS, period_count, "Period count", "Hz");
+
+ pcm_params_free(params);
+
+ return can_play;
+}
+
+void play_sample(FILE *file, unsigned int card, unsigned int device, unsigned int channels,
+ unsigned int rate, unsigned int bits, unsigned int period_size,
+ unsigned int period_count)
+{
+ struct pcm_config config;
+ struct pcm *pcm;
+ char *buffer;
+ int size;
+ int num_read;
+
+ memset(&config, 0, sizeof(config));
+ config.channels = channels;
+ config.rate = rate;
+ config.period_size = period_size;
+ config.period_count = period_count;
+ if (bits == 32)
+ config.format = PCM_FORMAT_S32_LE;
+ else if (bits == 16)
+ config.format = PCM_FORMAT_S16_LE;
+ config.start_threshold = 0;
+ config.stop_threshold = 0;
+ config.silence_threshold = 0;
+
+ if (!sample_is_playable(card, device, channels, rate, bits, period_size, period_count)) {
+ return;
+ }
+
+ pcm = pcm_open(card, device, PCM_OUT, &config);
+ if (!pcm || !pcm_is_ready(pcm)) {
+ fprintf(stderr, "Unable to open PCM device %u (%s)\n",
+ device, pcm_get_error(pcm));
+ return;
+ }
+
+ size = pcm_frames_to_bytes(pcm, pcm_get_buffer_size(pcm));
+ buffer = malloc(size);
+ if (!buffer) {
+ fprintf(stderr, "Unable to allocate %d bytes\n", size);
+ free(buffer);
+ pcm_close(pcm);
+ return;
+ }
+
+ printf("Playing sample: %u ch, %u hz, %u bit\n", channels, rate, bits);
+
+ /* catch ctrl-c to shutdown cleanly */
+ signal(SIGINT, stream_close);
+
+ do {
+ num_read = fread(buffer, 1, size, file);
+ if (num_read > 0) {
+ if (pcm_write(pcm, buffer, num_read)) {
+ fprintf(stderr, "Error playing sample\n");
+ break;
+ }
+ }
+ } while (!close && num_read > 0);
+
+ free(buffer);
+ pcm_close(pcm);
+}
+
diff --git a/ap/lib/libtinyalsa/vol_test.c b/ap/lib/libtinyalsa/vol_test.c
new file mode 100644
index 0000000..ad0453c
--- /dev/null
+++ b/ap/lib/libtinyalsa/vol_test.c
@@ -0,0 +1,515 @@
+/*
+ * Copyright (C) 2017 Sanechips Technology Co., Ltd.
+*
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+
+
+/****************************************************************************
+* Include files
+****************************************************************************/
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <math.h>
+/****************************************************************************
+* Local Macros
+****************************************************************************/
+#define DB_COFF_ARRAY_SIZE 15
+#define DRV_SUCCESS 0
+#define DRV_ERROR -1
+
+typedef signed char SINT8;
+typedef unsigned char UINT8;
+typedef short SINT16;
+typedef unsigned short UINT16;
+typedef long SINT32;
+typedef void VOID;
+/****************************************************************************
+* Global Constants
+****************************************************************************/
+
+
+/****************************************************************************
+* Global Variables
+****************************************************************************/
+
+
+typedef enum {
+ VOL_PATH_RX = 0,
+ VOL_PATH_TX = 1,
+ MAX_VOL_PATH = VOL_PATH_TX
+} T_Vol_Path;
+
+typedef struct {
+
+ float gain;
+ float coff;
+
+} T_Db_Coff;
+
+typedef struct {
+
+ int rx_vol; //0~5
+ float rx_coff;
+ int rx_upflag; //rx vol update flag , 1 update, else not
+
+ int tx_vol; //0~5
+ float tx_coff;
+ int tx_upflag; //tx vol update flag , 1 update, else not
+
+} T_Vol_Inst;
+
+typedef struct {
+ int vol_on;// 0 off, 1 on
+ float vol[6];
+} T_Wrtc_Vol_Para;
+
+T_Wrtc_Vol_Para vol_para = {
+ 1,
+ // tx_vol vol[6];
+ {
+ -6,//vol0
+ -3,//vol1
+ 0,//vol2
+ 3,//vol3
+ 6,//vol4
+ 9,//vol5
+ },
+};
+
+#if 1
+T_Db_Coff coff_table[] = {
+{-96.000000,0.000016},
+{-15.000000,0.177828},
+{-14.000000,0.199526},
+{-13.000000,0.223872},
+{-12.000000,0.251189},
+{-11.000000,0.281838},
+{-10.000000,0.316228},
+{-9.000000,0.354813},
+{-8.000000,0.398107},
+{-7.000000,0.446684},
+{-6.000000,0.501187},
+{-5.000000,0.562341},
+{-4.000000,0.630957},
+{-3.000000,0.707946},
+{-2.000000,0.794328},
+{-1.000000,0.891251},
+{0.000000,1.000000},
+{1.000000,1.122018},
+{2.000000,1.258925},
+{3.000000,1.412538},
+{4.000000,1.584893},
+{5.000000,1.778279},
+{6.000000,1.995262},
+{7.000000,2.238721},
+{8.000000,2.511886},
+{9.000000,2.818383},
+{10.000000,3.162278},
+{11.000000,3.548134},
+{12.000000,3.981072},
+{13.000000,4.466835},
+{14.000000,5.011872},
+{15.000000,5.623413},
+{16.000000,6.309574},
+{17.000000,7.079458},
+{18.000000,7.943282},
+{19.000000,8.912509},
+{20.000000,10.000000},
+{21.000000,11.220183},
+{22.000000,12.589254},
+{23.000000,14.125375},
+{24.000000,15.848933},
+
+};
+#else
+T_Db_Coff coff_table[] = {
+ { -96, 0.000016},
+ { -15, 0.177828},
+ { -14, 0.199526},
+ { -13, 0.223872},
+ { -12, 0.251189},
+ { -11, 0.281838},
+ { -10, 0.316228},
+ { -9, 0.354813},
+ { -8, 0.398107},
+ { -7, 0.446684},
+ { -6, 0.501187},
+ { -5, 0.562341},
+ { -4, 0.630957},
+ { -3, 0.707946},
+ { -2, 0.794328},
+ { -1, 0.891251},
+ {0, 1.000000},
+ {1, 1.122018},
+ {2, 1.258925},
+ {3, 1.412538},
+ {4, 1.584893},
+ {5, 1.778279},
+ {6, 1.995262},
+ {7, 2.238721},
+ {8, 2.511886},
+ {9, 2.818383},
+ {10, 0},
+ {11, 0},
+ {12, 3.981072},
+ {13, 0},
+ {14, 0},
+ {15, 5.623413},
+ {16, 0},
+ {17, 0},
+ {18, 7.943282},
+ {19, 0},
+ {20, 0},
+ {21, 0},
+ {22, 0},
+ {23, 0},
+ {24, 0},
+};
+#endif
+
+T_Vol_Inst vol_inst = {
+
+
+ 3,//int rx_vol;
+ 0,//int rx_coff;
+ 1,//int rx_upflag; //rx vol update flag
+
+ 3,//int tx_vol;
+ 0,//int tx_coff;
+ 1,//int tx_upflag; //tx vol update flag
+};
+
+int mute_flag = 0;
+
+/****************************************************************************
+* Global Function Prototypes
+****************************************************************************/
+
+
+
+
+/****************************************************************************
+* Function Definitions
+****************************************************************************/
+
+float Cal_DbCoff(float db)
+{
+
+ float coff = 0.0f;
+
+ float tmp = (float)(db / 20);
+ coff = (float) pow(10, tmp);
+ printf("Cal_DbCoff db=%f,tmp=%f,coff=%f!\r\n", db , tmp , coff );
+
+ return coff;
+
+}
+
+
+
+
+VOID Cal_ArrayDbCoff(VOID)
+{
+ int i = 0;
+ int size = sizeof(coff_table) / sizeof(coff_table[0]);
+ printf("update array, Db covert into Coff size=%d!\r\n", size);
+
+ for (i = 0; i < size; i++) {
+ coff_table[i].coff = Cal_DbCoff(coff_table[i].gain);
+ printf("update array, Db covert into Coff, db=%f,coff=%f!\r\n", coff_table[i].gain , coff_table[i].coff);
+
+ }
+
+}
+
+float Get_ArrayDbCoff(float db)
+{
+ int i = 0;
+ float coff = 0;
+ int size = sizeof(coff_table) / sizeof(coff_table[0]);
+ for (i = 0; i < size; i++) {
+ if (coff_table[i].gain == db) {
+ coff = coff_table[i].coff;
+ printf("Get_ArrayDbCoff, find db=%d,coff=%d!\r\n", db * 1000, coff * 1000);
+
+ return coff;
+ }
+ }
+ if (i >= DB_COFF_ARRAY_SIZE) {
+ coff = Cal_DbCoff(db);
+
+ }
+
+ printf("Get_ArrayDbCoff, db=%d,size=%d,i=%d,coff=%d!\r\n", db * 1000, DB_COFF_ARRAY_SIZE, i, coff * 1000);
+
+ return coff;
+
+}
+
+
+float Get_VolCoff(T_Vol_Path volpath)
+{
+ float coff = 0.0f;
+ float gain = 0.0f;
+
+
+ T_Wrtc_Vol_Para *volpara;
+
+ if (volpath == VOL_PATH_TX) {
+
+ if (vol_inst.tx_upflag == 0) {
+ return vol_inst.tx_coff;
+ }
+ volpara = & vol_para;
+ gain = volpara->vol[vol_inst.tx_vol];
+ coff = Get_ArrayDbCoff(gain);
+ vol_inst.tx_coff = coff;
+ vol_inst.tx_upflag = 0;
+ } else {
+
+ if (vol_inst.rx_upflag == 0) {
+ return vol_inst.rx_coff;
+ }
+
+ volpara = & vol_para;
+ gain = volpara->vol[vol_inst.rx_vol];
+ coff = Get_ArrayDbCoff(gain);
+ vol_inst.rx_coff = coff;
+ vol_inst.rx_upflag = 0;
+
+ }
+
+
+
+ return coff;
+
+}
+
+
+
+SINT32 Adjust_DataGain(UINT8 *pinBuffer, UINT8 *poutBuffer, UINT16 sampleNums, int mute, float gain)
+{
+
+ SINT32 ret = DRV_SUCCESS;
+
+ //float coff_f = 0;
+ float coff = 0;
+ int i = 0;
+ short tmp = 0;
+
+ short *sinBuffer;
+ short *soutBuffer;
+
+ coff = Get_ArrayDbCoff(gain);
+ //coff = (int)coff_f;
+
+
+ sinBuffer = (short *)(pinBuffer);
+ soutBuffer = (short *)(poutBuffer);
+
+ if (mute_flag == 0) {
+ for (i = 0; i < sampleNums; i++) {
+ tmp = (short)coff * sinBuffer[i];
+ if ((tmp > -32768) && (tmp < 32768)) {
+ soutBuffer[i] = tmp;
+ } else if (tmp > 32767) {
+ soutBuffer[i] = 32767;
+ } else if (tmp < -32768) {
+ soutBuffer[i] = -32767;
+ }
+ }
+ } else if (mute_flag == 1) {
+ for (i = 0; i < sampleNums; i++) {
+
+ soutBuffer[i] = 0;
+ }
+ } else {
+ printf("Adjust_DataGain mute val=%d invalid!\r\n", mute);
+
+ }
+
+ return ret;
+}
+
+
+SINT32 Adjust_TxDataVol(UINT8 *pinBuffer, UINT8 *poutBuffer, UINT16 sampleNums)
+{
+
+ SINT32 ret = DRV_SUCCESS;
+
+ //float coff_f = 0;
+ float coff = 0.0f;
+ int i = 0;
+ short tmp = 0;
+
+ short *sinBuffer;
+ short *soutBuffer;
+#if 0
+ float gain;
+ T_Webrtc_Para *para = &webrtcPara;
+ //T_Webrtc_TxProcPara *procpara =&tx_procpara;
+ T_Wrtc_Vol_Para *volpara = & tx_procpara.tx_vol;
+ gain = volpara->vol[para->txvol];
+
+ coff = Get_ArrayDbCoff(gain);
+ //coff = (int)coff_f;
+#else
+ coff = Get_VolCoff(VOL_PATH_TX);
+
+#endif
+
+ sinBuffer = (short *)(pinBuffer);
+ soutBuffer = (short *)(poutBuffer);
+
+ if (mute_flag == 0) {
+ for (i = 0; i < sampleNums; i++) {
+ tmp = (short)coff * sinBuffer[i];
+ if ((tmp > -32768) && (tmp < 32768)) {
+ soutBuffer[i] = tmp;
+ } else if (tmp > 32767) {
+ soutBuffer[i] = 32767;
+ } else if (tmp < -32768) {
+ soutBuffer[i] = -32767;
+ }
+ }
+ } else if (mute_flag == 1) {
+ for (i = 0; i < sampleNums; i++) {
+
+ soutBuffer[i] = 0;
+ }
+ } else {
+ printf("Adjust_DataGain mute val=%d invalid!\r\n", mute_flag);
+
+ }
+
+ return ret;
+}
+
+SINT32 Adjust_RxDataVol(UINT8 *pinBuffer, UINT8 *poutBuffer, UINT16 sampleNums)
+{
+
+ SINT32 ret = DRV_SUCCESS;
+
+ float coff = 0.0;
+ int i = 0;
+ short tmp = 0;
+
+ short *sinBuffer;
+ short *soutBuffer;
+#if 0
+ float gain;
+
+ T_Webrtc_Para *para = &webrtcPara;
+ //T_Webrtc_RxProcPara *procpara = &rx_procpara;
+ T_Wrtc_Vol_Para *volpara = & rx_procpara.rx_vol;
+ gain = volpara->vol[para->rxvol];
+
+
+ coff = Get_ArrayDbCoff(gain);
+#else
+ coff = Get_VolCoff(VOL_PATH_RX);
+#endif
+ sinBuffer = (short *)(pinBuffer);
+ soutBuffer = (short *)(poutBuffer);
+
+
+ for (i = 0; i < sampleNums; i++) {
+ tmp = (short)coff * sinBuffer[i];
+ if ((tmp > -32768) && (tmp < 32768)) {
+ soutBuffer[i] = tmp;
+ } else if (tmp > 32767) {
+ soutBuffer[i] = 32767;
+ } else if (tmp < -32768) {
+ soutBuffer[i] = -32767;
+ }
+ }
+
+ return ret;
+}
+
+
+SINT32 Vol_SetPara(int volpath, int vol, int upflag)
+{
+ SINT32 ret = DRV_SUCCESS;
+ if (volpath == VOL_PATH_TX) {
+ vol_inst.tx_vol = vol;
+ vol_inst.tx_upflag = upflag;
+ printf(" Vol_SetPara tx volpath=%d,upflag=%d.\n", volpath, upflag);
+
+ } else if (volpath == VOL_PATH_RX) {
+ vol_inst.rx_vol = vol;
+ vol_inst.rx_upflag = upflag;
+ printf(" Vol_SetPara rx volpath=%d,upflag=%d.\n", volpath, upflag);
+
+ } else {
+ printf(" Vol_SetPara err volpath=%d.\n", volpath);
+ return DRV_ERROR;
+ }
+
+
+
+ return ret;
+}
+
+SINT32 vol_SetRxVol(int vol)
+{
+ SINT32 ret = DRV_SUCCESS;
+ float coff = 0.0f;
+ vol_inst.rx_vol = vol;
+ ret = Vol_SetPara(0, vol, 1);
+ printf(" vol_SetRxVol vol=%d,ret=%d.\n", vol, ret);
+ coff = Get_VolCoff(0);
+ printf(" vol_SetRxVol Get_VolCoff coff=%f.\n", coff);
+
+
+ return ret;
+}
+
+int main(int argc, char **argv)
+{
+
+ printf("voltest start!\n");
+
+ int vol = 0;
+ int ret = 0;
+
+
+ if (strcmp(argv[1], "caldb") == 0) {
+
+ Cal_ArrayDbCoff();
+
+ } else if (strcmp(argv[1], "setvol") == 0) {
+
+
+
+ vol = atoi(argv[2]);
+ ret = vol_SetRxVol(vol);
+
+ } else {
+ return 0;
+ }
+
+
+
+
+
+
+
+
+ return 0;
+}
+