-
Notifications
You must be signed in to change notification settings - Fork 2
/
rda_snd_cfg.c
190 lines (143 loc) · 6.96 KB
/
rda_snd_cfg.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#include <stdio.h>
#include <string.h>
#include <tinyalsa/asoundlib.h>
/* Mixer control names */
#define MIXER_PLAYBACK_VOLUME "Playback Volume"
#define MIXER_CAPTURE_VOLUME "Capture Volume"
#define MIXER_ITF "ITF"
#define MIXER_SPK_SEL "SpkSel"
#define MIXER_FORCE_MAINMIC "ForceMainMic"
#define MIXER_CODEC_APP_MODE "CodecAppMode"
#define MIXER_START_PLAY "StartPlay"
#define MIXER_START_RECORD "StartRecord"
#define MIXER_STOP "Stop"
#define MIXER_OUT_SAMPLE_RATE "OutSampleRate"
#define MIXER_IN_SAMPLE_RATE "InSampleRate"
#define MIXER_OUT_CHANNEL_NB "OutChannelNumber"
#define MIXER_IN_CHANNEL_NB "InChannelNumber"
#define MIXER_COMMIT_SETUP "Commit Setup"
#define MIXER_LOOP_MODE "Loop Mode"
typedef struct {
struct mixer_ctl *playback_volume;
struct mixer_ctl *capture_volume;
struct mixer_ctl *itf;
struct mixer_ctl *codec_app_mode;
struct mixer_ctl *start_play;
struct mixer_ctl *start_record;
struct mixer_ctl *stop;
struct mixer_ctl *out_sample_rate;
struct mixer_ctl *out_channel_nb;
struct mixer_ctl *in_sample_rate;
struct mixer_ctl *in_channel_nb;
struct mixer_ctl *spkSel;
struct mixer_ctl *force_mainmic;
struct mixer_ctl *commit_setup;
struct mixer_ctl *loop_mode;
} mixer_ctls;
struct mixer *g_mixer = NULL;
mixer_ctls g_mixer_ctls;
int open_mixer(void)
{
g_mixer = mixer_open(0);
if (!g_mixer) {
printf( "audio-hal : Unable to open the mixer, aborting.\n");
return -1;
}
memset(&g_mixer_ctls, 0, sizeof(g_mixer_ctls));
g_mixer_ctls.playback_volume = mixer_get_ctl_by_name(g_mixer, MIXER_PLAYBACK_VOLUME);
g_mixer_ctls.capture_volume = mixer_get_ctl_by_name(g_mixer, MIXER_CAPTURE_VOLUME);
g_mixer_ctls.itf = mixer_get_ctl_by_name(g_mixer, MIXER_ITF);
g_mixer_ctls.spkSel = mixer_get_ctl_by_name(g_mixer, MIXER_SPK_SEL);
g_mixer_ctls.force_mainmic = mixer_get_ctl_by_name(g_mixer, MIXER_FORCE_MAINMIC);
g_mixer_ctls.codec_app_mode = mixer_get_ctl_by_name(g_mixer, MIXER_CODEC_APP_MODE);
g_mixer_ctls.start_play = mixer_get_ctl_by_name(g_mixer, MIXER_START_PLAY);
g_mixer_ctls.start_record = mixer_get_ctl_by_name(g_mixer, MIXER_START_RECORD);
g_mixer_ctls.stop = mixer_get_ctl_by_name(g_mixer, MIXER_STOP);
g_mixer_ctls.out_sample_rate = mixer_get_ctl_by_name(g_mixer, MIXER_OUT_SAMPLE_RATE);
g_mixer_ctls.out_channel_nb = mixer_get_ctl_by_name(g_mixer, MIXER_OUT_CHANNEL_NB);
g_mixer_ctls.in_sample_rate = mixer_get_ctl_by_name(g_mixer, MIXER_IN_SAMPLE_RATE);
g_mixer_ctls.in_channel_nb = mixer_get_ctl_by_name(g_mixer, MIXER_IN_CHANNEL_NB);
g_mixer_ctls.commit_setup = mixer_get_ctl_by_name(g_mixer, MIXER_COMMIT_SETUP);
g_mixer_ctls.loop_mode = mixer_get_ctl_by_name(g_mixer, MIXER_LOOP_MODE);
if( !g_mixer_ctls.playback_volume ||
!g_mixer_ctls.capture_volume ||
!g_mixer_ctls.itf ||
!g_mixer_ctls.spkSel ||
!g_mixer_ctls.force_mainmic ||
!g_mixer_ctls.codec_app_mode||
!g_mixer_ctls.start_play||
!g_mixer_ctls.start_record||
!g_mixer_ctls.stop||
!g_mixer_ctls.out_sample_rate ||
!g_mixer_ctls.out_channel_nb||
!g_mixer_ctls.in_sample_rate ||
!g_mixer_ctls.in_channel_nb||
!g_mixer_ctls.commit_setup) {
printf("audio-hal : Get mixers error, aborting.\n");
printf("audio-hal : mixer_ctls.playback_volume [%x] \n", (unsigned int)g_mixer_ctls.playback_volume);
printf("audio-hal : mixer_ctls.capture_volume [%x] \n", (unsigned int)g_mixer_ctls.capture_volume);
printf("audio-hal : mixer_ctls.itf [%x] \n", (unsigned int)g_mixer_ctls.itf);
printf("audio-hal : mixer_ctls.spkSel [%x] \n", (unsigned int)g_mixer_ctls.spkSel);
printf("audio-hal : mixer_ctls.force_mainmic [%x] \n", (unsigned int)g_mixer_ctls.force_mainmic);
printf("audio-hal : mixer_ctls.codec_app_mode [%x] \n", (unsigned int)g_mixer_ctls.codec_app_mode);
printf("audio-hal : mixer_ctls.start_play [%x] \n", (unsigned int)g_mixer_ctls.start_play);
printf("audio-hal : mixer_ctls.start_record [%x] \n", (unsigned int)g_mixer_ctls.start_record);
printf("audio-hal : mixer_ctls.stop [%x] \n", (unsigned int)g_mixer_ctls.stop);
printf("audio-hal : mixer_ctls.out_sample_rate [%x] \n", (unsigned int)g_mixer_ctls.out_sample_rate);
printf("audio-hal : mixer_ctls.in_sample_rate [%x] \n", (unsigned int)g_mixer_ctls.in_sample_rate);
printf("audio-hal : mixer_ctls.out_channel_nb [%x] \n", (unsigned int)g_mixer_ctls.out_channel_nb);
printf("audio-hal : mixer_ctls.in_channel_nb [%x] \n", (unsigned int)g_mixer_ctls.in_channel_nb);
printf("audio-hal : mixer_ctls.commit_setup [%x] \n", (unsigned int)g_mixer_ctls.commit_setup);
return -1;
}
return 0;
}
void close_mixer(void)
{
if(g_mixer)
mixer_close(g_mixer);
g_mixer = NULL;
}
void main(int argc, char *argv[])
{
// see all defines in kernel - rda_codec_adp.h
int ret;
if (open_mixer()) {
printf("open mixer err, exit. \n");
return;
}
//*************
ret = mixer_ctl_set_value(g_mixer_ctls.itf, 0, 1); //headset
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.spkSel, 0, 1); //headset
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.capture_volume, 0, 2);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.force_mainmic, 0, 0);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.playback_volume, 0, 7);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.commit_setup , 0, 0);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
//************
//************
ret = mixer_ctl_set_value(g_mixer_ctls.out_sample_rate , 0, 44100);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.out_channel_nb, 0, 2);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.in_channel_nb, 0, 1);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.in_sample_rate, 0, 8000);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.codec_app_mode, 0, 0);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
ret = mixer_ctl_set_value(g_mixer_ctls.commit_setup , 0, 0);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
//********
if (argc == 2 && strcmp(argv[1], "s") == 0)
ret = mixer_ctl_set_value(g_mixer_ctls.stop, 0, 0);
else
ret = mixer_ctl_set_value(g_mixer_ctls.start_play, 0, 0);
printf("%s:%s[%d] ret = %d\n", __FILE__, __func__, __LINE__, ret);
close_mixer();
}