Звук в Андройде

Материал из Toshiba AC100 wiki
Версия от 18:25, 15 ноября 2014; Zombah (обсуждение | вклад) (add break lines)
(разн.) ← Предыдущая версия | Текущая версия (разн.) | Следующая версия → (разн.)
Перейти к навигации Перейти к поиску

Звук

На текущий момент используется Generic Audio завязанный на tinyalsa. Есть два пути развития:

  • Допиливать audio_hw.c до нормального состояния
  • Перейти на использование чистой alsa из android-x86
    • Попробовать android-x86 и посмотреть все ли так ок со звуком или спросить на #android-x86 канале

Нужно разгрести инфу
http://www.alsa-project.org/main/index.php/Detailed_SoC_changes_v1.0.24_v1.0.25 ключевое слово - HeadsetObserver
http://www.mail-archive.com/[email protected]/msg00233.html
http://pastebin.com/xveMmB8H
http://forum.xda-developers.com/archive/index.php/t-941027.html
http://code.google.com/p/toggleheadset2/
http://lxr.free-electrons.com/source/drivers/staging/android/switch/switch_gpio.c?a=blackfin
http://source-android.frandroid.com/system/core/include/system/audio.h

Попробовать

% git diff
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 50ff369..4c26ae7 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -71,6 +71,9 @@
 #define MIXER_I2S_OUT_CAPTURE_MUX                      "I2SOut Mux"
 
 
+/* Audio device masks */
+#define AUDIO_DEVICE_OUT_HEADPHONE_MASK (AUDIO_DEVICE_OUT_WIRED_HEADPHONE | AUDIO_DEVICE_OUT_WIRED_HEADSET)
+
 /* ALSA card */
 #define CARD_SND 0
 
@@ -716,10 +719,10 @@ static int out_set_parameters(struct audio_stream *stream, const char *kvpairs)
                                (val & AUDIO_DEVICE_OUT_SPEAKER) ? 1 : 0);
 
                        mixer_ctl_set_value(adev->mixer_ctls.headset_switch, 0,
-                               (val & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) ? 1 : 0);
+                               (val & AUDIO_DEVICE_OUT_HEADPHONE_MASK) ? 1 : 0);
                                
                        LOGD("Headphone out:%c, Speaker out:%c, HDMI out:%c, BT SCO: %c\n",
-                               (val & AUDIO_DEVICE_OUT_WIRED_HEADPHONE) ? 'Y' : 'N',
+                               (val & AUDIO_DEVICE_OUT_HEADPHONE_MASK) ? 'Y' : 'N',
                                (val & AUDIO_DEVICE_OUT_SPEAKER) ? 'Y' : 'N',
                                (val & AUDIO_DEVICE_OUT_AUX_DIGITAL) ? 'Y' : 'N',
                                (val & AUDIO_DEVICE_OUT_ALL_SCO) ? 'Y' : 'N'
@@ -1970,7 +1973,7 @@ static int adev_open(const hw_module_t* module, const char* name,
        pthread_mutex_lock(&adev->lock);
        set_route_by_array(adev->mixer, defaults, 1);
        adev->mode = AUDIO_MODE_NORMAL;
-       adev->devices = AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_IN_BUILTIN_MIC | AUDIO_DEVICE_OUT_WIRED_HEADSET;
+       adev->devices = AUDIO_DEVICE_OUT_SPEAKER | AUDIO_DEVICE_IN_BUILTIN_MIC | AUDIO_DEVICE_OUT_HEADPHONE_MASK;
 
        pthread_mutex_unlock(&adev->lock);

+ "Wired Headset Routing Toggle" и/или http://code.google.com/p/toggleheadset2/

  • Значения tinymix на beta1test
Number of controls: 67
ctl	type	num	name                                     value
0	INT	2	Speaker Playback Volume                  15 15
1	BOOL	2	Speaker Playback Switch                  On On
2	INT	2	Headphone Playback Volume                15 15
3	BOOL	2	Headphone Playback Switch                Off On
4	INT	2	Auxout Playback Volume                   31 31
5	BOOL	2	Auxout Playback Switch                   Off Off
6	INT	1	Voice DAC Playback Volume                16
7	BOOL	1	Voice DAC Playback Switch                On
8	INT	1	Phone Playback Volume                    23
9	INT	2	LineIn Playback Volume                   23 23
10	INT	2	Master Playback Volume                   63 63
11	BOOL	2	Master Playback Switch                   On On
12	INT	1	Mic1 Playback Volume                     23
13	INT	1	Mic2 Playback Volume                     23
14	INT	2	Rec Capture Volume                       31 31
15	INT	1	Mic 1 Boost Volume                       0
16	INT	1	Mic 2 Boost Volume                       0
17	INT	1	DMIC Boost Capture Volume                7
18	BOOL	1	DMIC En Capture Switch                   On
19	BOOL	1	DMIC PreFilter Capture Switch            On
20	ENUM	1	AB-D Amp Mux                             AB Amp
21	BOOL	1	Right Capture Mix MIC12REC_R Capture Switch Off
22	BOOL	1	Right Capture Mix MIC22REC_R Capture Switch Off
23	BOOL	1	Right Capture Mix LIR2REC Capture Switch Off
24	BOOL	1	Right Capture Mix PH2REC_R Capture Switch Off
25	BOOL	1	Right Capture Mix HPR2REC Capture Switch Off
26	BOOL	1	Right Capture Mix SPK2REC_R Capture Switch Off
27	BOOL	1	Right Capture Mix MONO2REC_R Capture Switch Off
28	BOOL	1	Left Capture Mix MIC12REC_L Capture Switch Off
29	BOOL	1	Left Capture Mix MIC22REC_L Capture Switch Off
30	BOOL	1	Left Capture Mix LIL2REC Capture Switch  Off
31	BOOL	1	Left Capture Mix PH2REC_L Capture Switch Off
32	BOOL	1	Left Capture Mix HPL2REC Capture Switch  Off
33	BOOL	1	Left Capture Mix SPK2REC_L Capture Switch Off
34	BOOL	1	Left Capture Mix MONO2REC_L Capture Switch Off
35	BOOL	1	DMICR Mix DMICR2ADC Capture Switch       Off
36	BOOL	1	DMICL Mix DMICL2ADC Capture Switch       On
37	BOOL	1	Speaker Mix LI2SPK Playback Switch       Off
38	BOOL	1	Speaker Mix PHONE2SPK Playback Switch    Off
39	BOOL	1	Speaker Mix MIC12SPK Playback Switch     Off
40	BOOL	1	Speaker Mix MIC22SPK Playback Switch     Off
41	BOOL	1	Speaker Mix DAC2SPK Playback Switch      On
42	BOOL	1	Speaker Mix VOICE2SPK Playback Switch    Off
43	BOOL	1	Mono Mix ADC2MONO_L Playback Switch      Off
44	BOOL	1	Mono Mix ADC2MONO_R Playback Switch      Off
45	BOOL	1	Mono Mix LI2MONO Playback Switch         Off
46	BOOL	1	Mono Mix MIC12MONO Playback Switch       Off
47	BOOL	1	Mono Mix MIC22MONO Playback Switch       Off
48	BOOL	1	Mono Mix DAC2MONO Playback Switch        Off
49	BOOL	1	Mono Mix VOICE2MONO Playback Switch      Off
50	BOOL	1	HPL Mix ADC2HP_L Playback Switch         Off
51	BOOL	1	HPL Mix DACL2HP Playback Switch          On
52	BOOL	1	HPR Mix ADC2HP_R Playback Switch         Off
53	BOOL	1	HPR Mix DACR2HP Playback Switch          On
54	BOOL	1	HP Mix LI2HP Playback Switch             Off
55	BOOL	1	HP Mix PHONE2HP Playback Switch          Off
56	BOOL	1	HP Mix MIC12HP Playback Switch           Off
57	BOOL	1	HP Mix MIC22HP Playback Switch           Off
58	BOOL	1	HP Mix VOICE2HP Playback Switch          Off
59	ENUM	1	I2SOut Mux                               ADC LR
60	ENUM	1	ADCR Mux                                 Stereo ADC
61	ENUM	1	SpeakerOut N Mux                         LN/-R
62	ENUM	1	Right Headphone Mux                      HP Right Mix
63	ENUM	1	Left Headphone Mux                       HP Left Mix
64	ENUM	1	SpeakerOut Mux                           HPOut Mix
65	ENUM	1	AuxOut Mux                               Vmid
66	BOOL	1	Int Spk Switch                           On

tinyhal

  • http://opensource.wolfsonmicro.com/content/tinyhal
    • Tinyhal работает нормально, настроить его xml конфиг и проверить что все пути работают
      • Вывод на колонки работает нормально, вывод на наушники пока нет


headset detect

наушников слушая /dev/input/event

Включается это в оверлеях, вот так:

--- a/overlay/frameworks/base/core/res/res/values/config.xml
+++ b/overlay/frameworks/base/core/res/res/values/config.xml
@@ -314,6 +314,9 @@
 
     <!--  Maximum number of supported users -->
     <integer name="config_multiuserMaximumUsers">4</integer>
-
+    
+    <!-- When true use the linux /dev/input/event subsystem to detect the switch changes
+         on the headphone/microphone jack. When false use the older uevent framework. -->
+    <bool name="config_useDevInputEventForAudioJack">true</bool>
 </resources>


Android audio test

Play:
tinyplay file.wav -D card -d device -p period_size defaults to 1024 -n  period_count defaults to 4
file.wav should be a WAV PCM typically 44100 Hz stereo 16-bit signed

Capture:
tinycap file.wav -D card -d device -c channels=2 -r rate=44100 -b bits=16 -period_size=104 -n number of periods e.g. 4


cm-10.1 tinymixer out

Number of controls: 67
ctl     type    num     name                                     value
0       INT     2       Speaker Playback Volume                  31 31
1       BOOL    2       Speaker Playback Switch                  On On
2       INT     2       Headphone Playback Volume                31 31
3       BOOL    2       Headphone Playback Switch                On On
4       INT     2       Auxout Playback Volume                   31 31
5       BOOL    2       Auxout Playback Switch                   Off Off
6       INT     1       Voice DAC Playback Volume                16
7       BOOL    1       Voice DAC Playback Switch                On
8       INT     1       Phone Playback Volume                    23
9       INT     2       LineIn Playback Volume                   23 23
10      INT     2       Master Playback Volume                   63 63
11      BOOL    2       Master Playback Switch                   On On
12      INT     1       Mic1 Playback Volume                     1
13      INT     1       Mic2 Playback Volume                     23
14      INT     2       Rec Capture Volume                       20 20
15      INT     1       Mic 1 Boost Volume                       1
16      INT     1       Mic 2 Boost Volume                       0
17      INT     1       DMIC Boost Capture Volume                3
18      BOOL    1       DMIC En Capture Switch                   On
19      BOOL    1       DMIC PreFilter Capture Switch            On
20      ENUM    1       AB-D Amp Mux                             AB Amp
21      BOOL    1       Right Capture Mix MIC12REC_R Capture Switch Off
22      BOOL    1       Right Capture Mix MIC22REC_R Capture Switch Off
23      BOOL    1       Right Capture Mix LIR2REC Capture Switch Off
24      BOOL    1       Right Capture Mix PH2REC_R Capture Switch Off
25      BOOL    1       Right Capture Mix HPR2REC Capture Switch Off
26      BOOL    1       Right Capture Mix SPK2REC_R Capture Switch Off
27      BOOL    1       Right Capture Mix MONO2REC_R Capture Switch Off
28      BOOL    1       Left Capture Mix MIC12REC_L Capture Switch On
29      BOOL    1       Left Capture Mix MIC22REC_L Capture Switch Off
30      BOOL    1       Left Capture Mix LIL2REC Capture Switch  Off
31      BOOL    1       Left Capture Mix PH2REC_L Capture Switch Off
32      BOOL    1       Left Capture Mix HPL2REC Capture Switch  Off
33      BOOL    1       Left Capture Mix SPK2REC_L Capture Switch Off
34      BOOL    1       Left Capture Mix MONO2REC_L Capture Switch Off
35      BOOL    1       DMICR Mix DMICR2ADC Capture Switch       Off
36      BOOL    1       DMICL Mix DMICL2ADC Capture Switch       On
37      BOOL    1       Speaker Mix LI2SPK Playback Switch       Off
38      BOOL    1       Speaker Mix PHONE2SPK Playback Switch    Off
39      BOOL    1       Speaker Mix MIC12SPK Playback Switch     Off
40      BOOL    1       Speaker Mix MIC22SPK Playback Switch     Off
41      BOOL    1       Speaker Mix DAC2SPK Playback Switch      On
42      BOOL    1       Speaker Mix VOICE2SPK Playback Switch    Off
43      BOOL    1       Mono Mix ADC2MONO_L Playback Switch      Off
44      BOOL    1       Mono Mix ADC2MONO_R Playback Switch      Off
45      BOOL    1       Mono Mix LI2MONO Playback Switch         Off
46      BOOL    1       Mono Mix MIC12MONO Playback Switch       Off
47      BOOL    1       Mono Mix MIC22MONO Playback Switch       Off
48      BOOL    1       Mono Mix DAC2MONO Playback Switch        Off
49      BOOL    1       Mono Mix VOICE2MONO Playback Switch      Off
50      BOOL    1       HPL Mix ADC2HP_L Playback Switch         Off
51      BOOL    1       HPL Mix DACL2HP Playback Switch          On
52      BOOL    1       HPR Mix ADC2HP_R Playback Switch         Off
53      BOOL    1       HPR Mix DACR2HP Playback Switch          On
54      BOOL    1       HP Mix LI2HP Playback Switch             Off
55      BOOL    1       HP Mix PHONE2HP Playback Switch          Off
56      BOOL    1       HP Mix MIC12HP Playback Switch           Off
57      BOOL    1       HP Mix MIC22HP Playback Switch           Off
58      BOOL    1       HP Mix VOICE2HP Playback Switch          Off
59      ENUM    1       I2SOut Mux                               ADC LR
60      ENUM    1       ADCR Mux                                 Stereo ADC
61      ENUM    1       SpeakerOut N Mux                         RP/+R
62      ENUM    1       Right Headphone Mux                      HP Right Mix
63      ENUM    1       Left Headphone Mux                       HP Left Mix
64      ENUM    1       SpeakerOut Mux                           HPOut Mix
65      ENUM    1       AuxOut Mux                               Vmid
66      BOOL    1       Int Spk Switch                           On