summaryrefslogtreecommitdiffstats
path: root/spec/sound-theme-spec.xml
blob: d7efc5b6920b8e8b9ca2ca463f59ef1bcafb05fa (plain)
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
<?xml version="1.0"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
]>
<article id="index">
  <articleinfo>
    <title>Sound Theme Specification</title>
    <releaseinfo>Version 0.1</releaseinfo>
    <date>February 11 2008</date>
    <authorgroup>
      <author>
	<firstname>Marc-Andre</firstname>
	<surname>Lureau</surname>
	<affiliation>
	  <address>
	    <email>marc-andre.lureau@nokia.com</email>
	  </address>
	</affiliation>
      </author>
    </authorgroup>
  </articleinfo>

  <sect1 id="overview">
    <title>Overview</title>
    <para>
    A sound theme is a set of sounds that share a common feel, or
    instrument set.  The user can then select the sound theme that
    they want to use, and all apps use sounds from the theme. The
    initial user of sounds themes is the desktop notification
    service. But it can have other uses.
    </para>
    <para>
    From a programmer perspective a sound theme is just a
    mapping. Given a set of directories to look for sounds in and a
    theme name it maps from sound name to an sound filename.
    </para>
  </sect1>

  <sect1 id="definitions">
    <title>Definitions</title>
    <variablelist>
      <varlistentry>
	<term>Sound Theme</term>
	<listitem>
	  <para>
          A sound theme is a named set of sounds. It is used to map
          from a sound name. Themes may inherit
          from other themes as a way to extend them.
	  </para>
	</listitem>
      </varlistentry>
      <varlistentry>
	<term>Sound file</term>
	<listitem>
	  <para>
          The supported sound file formats are WAV/PCM 48kHz, 16bits,
          and OGG/Vorbis.  WAV is the recommended uncompressed format,
          and OGG/Vorbis is for compressed. Support for OGGs is
          optional.
	  </para>
	</listitem>
      </varlistentry>
      <varlistentry>
	<term>Base Directory</term>
	<listitem>
	  <para>
          Sounds and themes are searched for in a set of directories,
          called base directories. The themes are stored in
          subdirectories of the base directories.
	  </para>
	</listitem>
      </varlistentry>
    </variablelist>
  </sect1>

  <sect1 id="directory_layout">
    <title>Directory Layout</title>
    <para>
    Sounds and themes are looked for in a set of directories. By
    default, apps should look in $XDG_DATA_DIRS/sounds.  Applications
    may further add their own sound directories to this list, and
    users may extend or change the list (in application/desktop
    specific ways).In each of these directories themes are stored as
    subdirectories. A theme can be spread across several base
    directories by having subdirectories of the same name. This way
    users can extend and override system themes.
    </para>
    <para>
    In order to have a place for third party applications to install
    their sounds there should always exist a theme called
    "freedesktop". The data for the freedesktop theme is available for
    download at: http://www.freedesktop.org/software/sound-theme/.
    Implementations are required to look in the "freedesktop" theme if
    a sound was not found in the current theme.
    </para>
    <para>
    Each theme is stored as subdirectories of the base
    directories. The internal name of the theme is the name of the
    subdirectory, although the user-visible name as specified by the
    theme may be different. Hence, theme names are case sensitive, and
    are limited to ASCII characters. Theme names may also not contain
    comma or space.
    </para>
    <para>
    In at least one of the theme directories there must be a file
    called index.theme that describes the theme. The first index.theme
    found while searching the base directories in order is used. This
    file describes the general attributes of the theme.
    </para>
    <para>
    In the theme directory are also a set of subdirectories containing
    sound files. The subdirectories are allowed to be several levels
    deep, e.g. the subdirectory "stereo/alerts" in the theme "freedesktop"
    would end up at $basedir/freedesktop/stereo/alerts. (FIXME)
    </para>
    <para>
    The sounds files must be one of the types: WAV/PCM 48kHz, 16 bits
    or OGG/Vorbis.  The extension must be ".wav", or ".ogg"
    respectively (lower case). The support for OGG files is
    optional. Implementations that do not support OGGs should just
    ignore any ".ogg" files. In addition to this there may be an
    additional file with extra sound-data for each file. It should
    have the same basename as the sound file, with the extension
    ".sound". e.g. if the sound file is called "system-log-out.wav"
    the corresponding file would be named "system-log-out.sound".
    </para>
  </sect1>

  <sect1 id="file_formats">
    <title>File Formats</title>
    <para>
    Both the sound theme description file and the sound data files are
    ini-style text files, as described in the desktop file
    specification. They don't have any encoding field. Instead, they
    must always be stored in UTF-8 encoding.
    </para>
    <para>
    The index.theme file must start with a section called
    <citetitle>Sound Theme</citetitle>, with contents according to
    table 1 below. All lists are comma-separated.
    <table>
      <title>Standard Keys</title>
      <tgroup cols="4">
	<thead>
	  <row>
	    <entry>Key</entry>
	    <entry>Description</entry>
	    <entry>Value Type</entry>
	    <entry>Required</entry>
	  </row>
	</thead>
	<tbody>
	  <row>
	    <entry>Name</entry>
	    <entry>
              short name of the sound theme, used in e.g. lists when
              selecting themes.
	    </entry>
	    <entry>localestring</entry>
	    <entry>YES</entry>
	  </row>
	  <row>
	    <entry>Comment</entry>
	    <entry>
              longer string describing the theme
	    </entry>
	    <entry>localestring</entry>
	    <entry>YES</entry>
	  </row>
	  <row>
	    <entry>Inherits</entry>
	    <entry>
              <para>
              The name of the theme that this theme inherits from. If a sound
              name is not found in the current theme, it is searched for in the
              inherited theme (and recursively in all the inherited themes).
              </para>
              <para>
              If no theme is specified implementations are required to add
              the "freedesktop" theme to the inheritance tree. An implementation
              may optionally add other default themes in between the last
              specified theme and the freedesktop theme.
              </para>
	    </entry>
	    <entry>strings</entry>
	    <entry>NO</entry>
	  </row>
	  <row>
	    <entry>Directories</entry>
	    <entry>
             list of subdirectories for this theme. For every
             subdirectory there must be a section in the index.theme
             file describing that directory.
	    </entry>
	    <entry>strings</entry>
	    <entry>YES</entry>
	  </row>
	  <row>
	    <entry>Hidden</entry>
	    <entry>
            Whether to hide the theme in a theme selection user interface.
            This is used for things such as fallback-themes that are not supposed
            to be visible to the user.
	    </entry>
	    <entry>boolean</entry>
	    <entry>NO</entry>
	  </row>
	  <row>
	    <entry>Example</entry>
	    <entry>
              The name of a sound that should be used as an example of
              how this theme sounds like.
	    </entry>
	    <entry>string</entry>
	    <entry>NO</entry>
	  </row>
	</tbody>
      </tgroup>
    </table>
    </para>
    <para>
    Each directory specified in the Directory key has a corresponding section
    with the same name as the directory. The contents of this section is
    listed in table 2 below.
    <table>
      <title>Per-Directory Keys</title>
      <tgroup cols="4">
	<thead>
	  <row>
	    <entry>Key</entry>
	    <entry>Description</entry>
	    <entry>Value Type</entry>
	    <entry>Required</entry>
	    <entry>Type</entry>
	  </row>
	</thead>
	<tbody>
	  <row>
	    <entry>Context</entry>
	    <entry>
              The context the sound is normally used in. This
              is in detail discussed in <xref linkend="context"/>.
	    </entry>
	    <entry>string</entry>
	    <entry>NO</entry>
	  </row>
	  <row>
	    <entry>SoundSystem</entry>
	    <entry>
	      Define the sound system for which the sounds are made
	      for. It can be "stereo" or "5.1", or whatever system
	      suits the configuration in which they are recorded.
	    </entry>
	    <entry>string</entry>
	    <entry>NO</entry>
	  </row>
	  <row>
	    <entry>Length</entry>
	    <entry>
              Nominal length in seconds of the sounds in this directory. (FIXME)
	    </entry>
	    <entry>integer</entry>
	    <entry>NO</entry>
	  </row>
	  <row>
	    <entry>Locale</entry>
	    <entry>
              Locale name, if applicable. (FIXME: not usable since
              transaltions would have to update the index.. instead
              subdirectoy locale seems more efficient...)
	    </entry>
	    <entry>string</entry>
	    <entry>NO</entry>
	  </row>
	</tbody>
      </tgroup>
    </table>
    </para>
    <para>
    In addition to these groups you may add extra groups to the
    index.theme file in order to extend it. These extensions must
    begin with "X-", and can be used to add desktop specific
    information to the theme file. Example group names would be "X-KDE
    Sound Theme" or "X-Gnome Sound Theme".
    </para>
    <para>
    The optional filename.sound file contains a group called "Sound
    Data", with the content listed in table 3.
    <table>
      <title>Sound Data Keys</title>
      <tgroup cols="4">
	<thead>
	  <row>
	    <entry>Key</entry>
	    <entry>Description</entry>
	    <entry>Value Type</entry>
	    <entry>Required</entry>
	  </row>
	</thead>
	<tbody>
	  <row>
	    <entry>DisplayName</entry>
	    <entry>
              A translated UTF8 string that can be displayed instead
              of the sound by a user interface.
	    </entry>
	    <entry>localestring</entry>
	    <entry>NO</entry>
	  </row>
	  <row>
	    <entry>Loop</entry>
	    <entry>
	      Indicates if the sound is appropriate in loop-mode
	      playing. This can be useful for ringing tones,
	      environment, instruments...
	    </entry>
	    <entry>boolean</entry>
	    <entry>NO</entry>
	  </row>
	</tbody>
      </tgroup>
    </table>
    </para>
    <para>
    Extensions to the filename.sound file are allowed, but the
    keys must be begin with "X-" to avoid collisions with future
    standardized extensions to this format.
    </para>

    <sect2 id="context">
	<title>Context</title>

	<para>The <systemitem>Context</systemitem> allows
    	  the designer to group sounds on a conceptual level.
	  It doesn't act as a namespace in the file system, such
	  that sounds can have identical names, but allows
	  implementations to categorize and sort by it, for example.
 	</para>

	<para>These are the available contexts:</para>
	<itemizedlist>

	  <listitem>
	    <formalpara>
	    <title>Alert</title>
	    <para>Sounds to alert the user of an action or event
	    which may have a major imact on the system or their
	    current use case, such as
	    <action>dialog-error</action>.</para>
	    </formalpara>
	  </listitem>

	  <listitem>
	    <formalpara>
	    <title>Notification</title>
	    <para>Sounds to notify the user that the system, or their
	    current use case has changed state in some way, e.g. new email
	    arriving, new non-critical update available...</para>
	    </formalpara>
	  </listitem>

	  <listitem>
	    <formalpara>
	      <title>Support</title>
	      <para>Sounds that give the user feedback on their
	      actions. Sounds on window opening / closing for
	      example.</para>
	    </formalpara>
	  </listitem>

	  <listitem>
	    <formalpara>
	      <title>Game</title>
	      <para>Sounds used for games.</para>
	    </formalpara>
	  </listitem>

	</itemizedlist>

    </sect2>
  </sect1>

  <sect1 id="sound_lookup">
    <title>Sound Lookup</title>
    <para>
    The sound lookup mechanism has two global settings, the list of
    base directories and the internal name of the current theme. Given
    these we need to specify how to look up  sound file from the sound
    name.
    </para>
    <para>
    The lookup is done first in the current theme, and then
    recursively in each of the current theme's parents, and finally in
    the default theme called "freedesktop" (implementations may add
    more default themes before "freedesktop", but "freedesktop" must
    be last). As soon as there is a sound that matches in a theme, the
    search is stopped.
    </para>
    <para>
    The lookup inside a theme is done in three phases. First all the
    directories are scanned for an exact match, e.g. one where the
    locale of the sound match what was looked up. Then all
    the directories are scanned for any sound that matches the name. If
    that fails we finally fall back on unthemed sound. If we fail to
    find any sound at all it is up to the application to pick a good
    fallback, as the correct choice depends on the context.
    </para>
    <para>
    The exact algorithm (in pseudocode) for looking up a sound in a theme
    (if the implementation supports OGG) is:

    <programlisting>
FindSound(sound, locale) {
  filename = FindSoundHelper(sound, locale, soundsystem, user selected theme);
  if filename != none
    return filename

  filename = FindSoundHelper(sound, locale, soundsystem, "freedesktop");
  if filename != none
    return filename

  return LookupFallbackSound (sound)
}

FindSoundHelper(sound, locale, soundsystem, theme) {
  filename = LookupSound (sound, locale, soundsystem, theme)
  if filename != none
    return filename

  if theme has parents
    parents = theme.parents

  for parent in parents {
    filename = FindSoundHelper (sound, locale, soundsystem, parent)
    if filename != none
      return filename
  }
  return none
}
     </programlisting>

     With the following helper functions:

     <programlisting>
LookupSound (sound, locale, soundsystem, theme) {
  // lookup localized version
  for each subdir in $(theme subdir list) {
    for each directory in $(basename list) {
      for system in (soundsystem, "stereo") {
        if DirectoryMatchesSoundSystem(subdir, system) {
          for extension in ("wav", "ogg") {
	    filename = directory/$(themename)/subdir/$locale/sound.extension
            if exist filename
              return filename
          }
        }
      }
    }
  }

 // lookup unlocalized version
  for each subdir in $(theme subdir list) {
    for each directory in $(basename list) {
      for system in (soundsystem, "stereo") {
        if DirectoryMatchesSoundSystem(subdir, system) {
          for extension in ("wav", "ogg") {
	    filename = directory/$(themename)/subdir/sound.extension
            if exist filename
              return filename
          }
        }
      }
    }
  }

  return none
}

LookupFallbackSound (sound) {
  for each directory in $(basename list) {
    for extension in ("wav", "ogg") {
      if exists directory/sound.extension
        return directory/sound.extension
    }
  }
  return none
}

DirectoryMatchesSoundSystem(subdir, system) {
  read SoundSystem from subdir
  if SoundSystem == system
    return true
  return false
}
</programlisting>

    </para>
  </sect1>

  <sect1 id="example">
    <title>Example</title>
    <para>
     Here is an example index.theme file:
     <programlisting>
[Sound Theme]
Name=Birch
Name[fr]=Bouleau
Comment=Sound theme using wooden instruments
Comment[fr]=Theme utilisant des instruments en bois
Inherits=wood,default
Directories=stereo/alert/fr notifications/long/5.1

[stereo/alert/fr]
Context=Alert
SoundSystem=stereo

[notifications/long/5.1]
Context=Notification
SoundSystem=5.1
</programlisting>

The corresponding directory tree in the /usr/share/sounds
directory could look like this:

<programlisting>
birch/index.theme
birch/stereo/alert/evolution-urgent-message.ogg
birch/stereo/alert/evolution-urgent-message.wav
birch/stereo/alert/fr/evolution-urgent-message.ogg
birch/stereo/alert/evolution-urgent-message.sound
birch/5.1/alert/evolution-urgent-message.ogg
</programlisting>

Where birch/stereo/alert/evolution-urgent-message.sound contains:

<programlisting>
[Sound Data]
DisplayName=Evolution urgent message
DisplayName[fr]=Message urgent dans Evolution
Loop=yes
</programlisting>

    </para>
    <para>
    In this example a lookup of "evolution-urgent-message", with a 5.1
    system preference and no localization, would get the
    "birch/5.1/alert/evolution-urgent-message.ogg" sound file.
    </para>

  </sect1>

  <sect1 id="install_sounds">
    <title>Installing Application Sounds</title>
    <para>
    So, you're an application author, and you want to install sounds
    so that they can be used by your application. Minimally you should
    install the sound file in the "freedesktop" theme. This means
    installing a stereo WAV file in
    $XDG_DATA_DIRS/sounds/freedesktop/stereo/$context.

    Optionally you can install sounds in different formats and
    language. For example, installing a localized OGG/Vorbis 5.1 game
    sound in $prefix/share/sounds/freedesktop/5.1/game/fr.

    You might even want to install sounds that matches other well
    known themes so your application will fit in with some specific
    desktop environment.
    </para>
    <para>
    It is recommended that the sounds installed in the freedesktop
    theme sound neutral, since it is a fallback theme that will be
    used in combination with some very different sounds from any
    origin. But if you don't have any neutral sound, please install
    whatever sound you have in the freedesktop theme so that all your
    application can at least produce some sounds in all themes.
    </para>
  </sect1>

  <sect1 id="implementation_notes">
    <title>Implementation Notes</title>
    <para>
    The algorithm as described in this document works by always
    looking up filenames in directories (a stat in unix
    terminology). A good implementation is expected to read the
    directories once, and do all lookups in memory using that
    information.
    </para>
    <para>
    This caching can make it impossible for users to add sounds without
    having to restart applications. In order to handle this, any
    implementation that does caching is required to look at the mtime
    of the toplevel sound directories when doing a cache lookup, unless
    it already did so less than 5 seconds ago. This means that any
    sound editor or theme installation program need only to change the
    mtime of the the toplevel directory where it changed the theme to
    make sure that the new sounds will eventually get used.
    </para>
  </sect1>

  <sect1 id="background">
    <title>Background</title>
    <para>
    The sound theme specification is heavily based on the "Icon Theme
    Specification" by Alexander Larsson and Frans Englich.
    </para>
  </sect1>

  <appendix id="changes">
    <title>Change history</title>
    <formalpara>
      <title>Version 0.1, 11 February 2008, Marc-Andre Lureau</title>
      <para>
	<itemizedlist>
	  <listitem>
	    <para>
	      Initial draft.
	    </para>
	  </listitem>
	</itemizedlist>
      </para>
    </formalpara>
  </appendix>
</article>