blob: 92458338b1306fe024fdbc2e8331eb96eb6c3605 [file] [log] [blame]
Heidi Millerf53b3f32014-10-23 14:20:41 -07001page.title=Audio Attributes
2@jd:body
3
4<!--
5 Copyright 2013 The Android Open Source Project
6
7 Licensed under the Apache License, Version 2.0 (the "License");
8 you may not use this file except in compliance with the License.
9 You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18-->
19<div id="qv-wrapper">
20 <div id="qv">
21 <h2>In this document</h2>
22 <ol id="auto-toc">
23 </ol>
24 </div>
25</div>
26
27<p>
28Audio players support attributes that define how the audio system handles routing, volume, and focus decisions for the specified source. Applications can attach attributes to an audio playback (such as music played by Pandora or a notification for a new email) then pass the audio source attributes to the framework, where the audio system uses the attributes to make mixing decisions and to notify applications about the state of the system.
29</p>
30
31<p class="note">
32<strong>Note:</strong> Applications can also attach attributes to an audio recording (such as audio captured in a video recording), but this functionality is not exposed in the public API.
33</p>
34
35<p>
36In Android 4.4 and earlier, the framework made mixing decisions using only the audio stream type. However, basing such decisions on stream type was too limiting to produce quality output across multiple applications and devices. For example, on a mobile device, some applications (i.e. Maps) play driving directions on the STREAM_MUSIC stream type; however, on mobile devices in projection mode (i.e. Android Auto), applications cannot mix driving directions with other media streams.</p>
37
38<p>
39Using the audio attribute API, applications can now provide the audio system with detailed information about a specific audio source:
40</p>
41
42<ul>
43<li><b>Usage</b>. Specifies why the source is playing and controls routing, focus, and volume decisions.</li>
44<li><b>Content type</b>. Specifies what the source is playing (music, movie, speech, sonification, unknown).</li>
45<li><b>Flags</b>. Specifies how the source should be played. Includes support for audibility enforcement (camera shutter sounds required in some countries) and hardware audio/video synchronization.</li>
46</ul>
47
48<p>
49For dynamics processing, applications must distinguish between movie, music, and speech content. Information about the data itself may also matter, such as loudness and peak sample value.
50</p>
51
52<h2 id="using">
53Using attributes
54</h2>
55
56<p>Usage specifies the context in which the stream is used, providing information about why the sound is playing and what the sound is used for. Usage information is more expressive than a stream type and allows platforms or routing policies to refine volume or routing decisions.
57</p>
58
59<p>
60Supply one of the following usage values for any instance:
61</p>
62
63<ul>
64<li><code>USAGE_UNKNOWN</code></li>
65<li><code>USAGE_MEDIA</code></li>
66<li><code>USAGE_VOICE_COMMUNICATION</code></li>
67<li><code>USAGE_VOICE_COMMUNICATION_SIGNALLING</code></li>
68<li><code>USAGE_ALARM</code></li>
69<li><code>USAGE_NOTIFICATION</code></li>
70<li><code>USAGE_NOTIFICATION_RINGTONE</code></li>
71<li><code>USAGE_NOTIFICATION_COMMUNICATION_INSTANT</code></li>
72<li><code>USAGE_NOTIFICATION_COMMUNICATION_DELAYED</code></li>
73<li><code>USAGE_NOTIFICATION_EVENT</code></li>
74<li><code>USAGE_ASSISTANCE_ACCESSIBILITY</code></li>
75<li><code>USAGE_ASSISTANCE_NAVIGATION_GUIDANCE</code></li>
76<li><code>USAGE_ASSISTANCE_SONIFICATION</code></li>
77<li><code>USAGE_GAME</code></li>
78</ul>
79
80<p>
81Values are mutually exclusive. For examples, refer to <code>USAGE_MEDIA</code>and <code>USAGE_ALARM</code> definitions; for exceptions, refer to <code>AudioAttributes.Builder</code> definition.
82</p>
83
84<h2 id="content-type">
85Content type
86</h2>
87
88<p>
89Content type defines what the sound is and expresses the general category of the content such as movie, speech, or beep/ringtone. The audio framework uses content type information to selectively configure audio post-processing blocks. While supplying the content type is optional, you should include type information whenever the content type is known, such as using <code>CONTENT_TYPE_MOVIE</code> for a movie streaming service or <code>CONTENT_TYPE_MUSIC</code> for a music playback application.
90</p>
91
92<p>
93Supply one of the following usage values for any instance:
94</p>
95
96<ul>
97<li><code>CONTENT_TYPE_UNKNOWN</code> (default)</li>
98<li><code>CONTENT_TYPE_MOVIE</code></li>
99<li><code>CONTENT_TYPE_MUSIC</code></li>
100<li><code>CONTENT_TYPE_SONIFICATION</code></li>
101<li><code>CONTENT_TYPE_SPEECH</code></li>
102</ul>
103
104<p>
105Values are mutually exclusive.
106</p>
107
108<h2 id="flags">
109Flags
110</h2>
111
112<p>
113Flags specify how the audio framework applies effects to the audio playback. Supply one or more of the following flags for an instance:
114</p>
115
116<ul>
117<li><code>FLAG_AUDIBILITY_ENFORCED</code>. Requests the system ensure the audibility of the sound. Use to address the needs of legacy <code>STREAM_SYSTEM_ENFORCED</code> (such as forcing camera shutter sounds).</li>
118<li><code>HW_AV_SYNC</code>. Requests the system select an output stream that supports hardware A/V synchronization.</li>
119</ul>
120
121<p>
122Flags are non-exclusive (can be combined).
123</p>
124
125<h2 id="example">
126Example
127</h2>
128
129<p>
130The following example shows USAGE and CONTENT_TYPE attributes.
131</p>
132
133<pre>
134AudioTrack myTrack = new AudioTrack(
135 new AudioAttributes.Builder()
136 .setUsage(AudioAttributes.USAGE_MEDIA)
137 .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
138 .build(),
139 myFormat, myBuffSize, AudioTrack.MODE_STREAM, mySession);
140</pre>
141
142<h2 id="compatibility">
143Compatibility
144</h2>
145
146<p>
147Application developers should use audio attributes when creating or updating applications for Android 5.0. However, applications are not required to take advantage of attributes; they can handle legacy stream types only or remain unaware of attributes (i.e. a generic media player that doesnt know anything about the content its playing).
148</p>
149
150<p>
151In such cases, the framework maintains backwards compatibility with older devices and Android releases by automatically translating legacy audio stream types to audio attributes. However, the framework does not enforce or guarantee this mapping across devices, manufacturers, or Android releases.
152</p>
153
154<p>
155Compatibility mappings:
156</p>
157
158<table>
159<tr>
160 <th>Android 5.0</th>
161 <th>Android 4.4 and earlier</th>
162</tr>
163<tr>
164 <td>
165 <code>CONTENT_TYPE_SPEECH</code><br>
166 <code>USAGE_VOICE_COMMUNICATION</code>
167 </td>
168 <td>
169 <code>STREAM_VOICE_CALL</code>
170 </td>
171</tr>
172<tr>
173 <td>
174 <code>CONTENT_TYPE_SONIFICATION</code><br>
175 <code>USAGE_ASSISTANCE_SONIFICATION</code>
176 </td>
177 <td>
178 <code>STREAM_SYSTEM</code>
179 </td>
180</tr>
181<tr>
182 <td>
183 <code>CONTENT_TYPE_SONIFICATION</code><br>
184 <code>USAGE_NOTIFICATION_RINGTONE</code>
185 </td>
186 <td>
187 <code>STREAM_RING</code>
188 </td>
189</tr>
190<tr>
191 <td>
192 <code>CONTENT_TYPE_MUSIC</code><br>
193 <code>USAGE_UNKNOWN</code><br>
194 <code>USAGE_MEDIA</code><br>
195 <code>USAGE_GAME</code><br>
196 <code>USAGE_ASSISTANCE_ACCESSIBILITY</code><br>
197 <code>USAGE_ASSISTANCE_NAVIGATION_GUIDANCE</code><br>
198 </td>
199 <td>
200 <code>STREAM_MUSIC</code>
201 </td>
202</tr>
203<tr>
204 <td>
205 <code>CONTENT_TYPE_SONIFICATION</code><br>
206 <code>USAGE_ALARM</code>
207 </td>
208 <td>
209 <code>STREAM_ALARM</code>
210 </td>
211</tr>
212<tr>
213 <td>
214 <code>CONTENT_TYPE_SONIFICATION</code><br>
215 <code>USAGE_NOTIFICATION</code><br>
216 <code>USAGE_NOTIFICATION_COMMUNICATION_REQUEST</code><br>
217 <code>USAGE_NOTIFICATION_COMMUNICATION_INSTANT</code><br>
218 <code>USAGE_NOTIFICATION_COMMUNICATION_DELAYED</code><br>
219 <code>USAGE_NOTIFICATION_EVENT</code><br>
220 </td>
221 <td>
222 <code>STREAM_NOTIFICATION</code>
223 </td>
224</tr>
225<tr>
226 <td>
227 <code>CONTENT_TYPE_SPEECH</code>
228 </td>
229 <td>
230 (@hide)<code> STREAM_BLUETOOTH_SCO</code>
231 </td>
232</tr>
233<tr>
234 <td>
235 <code>FLAG_AUDIBILITY_ENFORCED</code>
236 </td>
237 <td>
238 (@hide)<code> STREAM_SYSTEM_ENFORCED</code>
239 </td>
240</tr>
241<tr>
242 <td>
243 <code>CONTENT_TYPE_SONIFICATION</code><br>
244 <code>USAGE_VOICE_COMMUNICATION_SIGNALLING</code>
245 </td>
246 <td>
247 (@hide)<code> STREAM_DTMF</code>
248 </td>
249</tr>
250</table>
251
252<p class="note">
253<strong>Note:</strong> @hide streams are used internally by the framework but are not part of the public API.
254</p>