What

doubleTwist has the ability to customize the way in which it interacts with devices. With the exception of the Sony PSP, most of the knowledge about a device is declared in an external XML file. These external XML files contain "device declarations" and allow customization of device identification, the folder to which music is synced, folders to search for media when browsing a device, decoder capabilities, and encoder settings.

A "catch-all" device declaration exists to provide base support for any device that isn't explicitly identified and customized by other device declarations. It defines the following behavior:
  • The entire file system (of the largest storage card) is searched for media when browsing the device in doubleTwist.
  • mp3 files can by synced to the device without incurring a transcode (bitrate: 20 - 320 kb/s, 1 or 2 channels).
  • Files that require transcoding will be encoded to mp3 at 128 kb/s, 2 channels.

Note that not all interaction with a device is customizable. Most notably, playlists are implemented by writing an M3U file to the root of the file system of the device, which is something that cannot be changed.

Why

Gains in browsing / sync efficiency and in audio quality can be achieved by creating custom device declarations. For example, rather than searching a device's entire file system for media when browsing, a set of sub-folders can be specified to limit the search. When syncing music to a device, if the device is known to support formats other than mp3, alternative decoders can be specified to avoid unnecessary transcoding. Lastly, alternative encode settings can be specified to transcode media into a format better suited for a particular device.

Where

Device declaration files live in a folder called "Devices" under the install folder of the application, which is typically C:\Program Files\doubleTwist. Any file under the Devices folder that has an extension of ".xml" will be treated as a device declaration file and parsed when the application launches, which allows for device declarations to be made across multiple XML files. If there are user-generated device declarations that conflict with doubleTwist's declarations for a given device then the user-generated ones will take precedence.

How

  • Identifying a device
  • A device can be identified by its manufacturer name, model name, and/or USB identifier (VID/PID). A device declaration contains zero or more device identifiers. If any device identifier succeeds then the device declaration is considered to be a match for the device (much like an OR operation). All match conditions within a single device identifier (manufacturer, model, USB ID) must be satisfied in order to succeed (much like an AND operation). Strings representing names and identifiers are regular expressions, which allows for considerable flexibility when defining match criteria. No manipulation is done on strings that come from devices, so case-insensitive comparisons have to be accomplished via regular expressions.

  • Specifying the music sync folder
  • The "catch-all" device declaration syncs audio files to a folder called Music under the root folder of the device ("/Music"). An alternative sync folder can be specified, however. If the folder does not exist on the device, it will be created on the first sync operation. Within this sync folder, doubleTwist will still organize music into sub-folders by album and artist, if that metadata is available.

  • Specifying additional browse folders
  • When a device is selected, doubleTwist searches a set of folders for media. If a music sync folder is specified, it will include it in the search. Additional folders can be specified, however, to broaden the search, if desired. For example, many devices have dedicated folders for video, audio, and photos.

  • Specifying decoder capabilities
  • A device can be capable of decoding multiple encoding types. Specifying what decoders are available and their constraints will allow doubleTwist to sync files that are compatible with the device without transcoding them first. By avoiding the transcode step, the sync will go faster and the quality of the media will not degrade. Decoder constaints that can be specified are file format, encoding scheme, bit rate, sample rate, sample size, and number of channels.

  • Specifying encoder parameters
  • During the music sync process, if doubleTwist determines that a file is not compatible with the device then it will use the encode parameters found in the matching device declaration to determine how to transcode the file before copying it over. Only one set of encode parameters for music files is allowed within a device declaration. Configurable audio encode parameters are file format, encoding scheme, bit rate, sample rate, and number of channels.

  • Overriding doubleTwist device declarations
  • There are two parameters within a device declaration that are relevant only when overriding an existing doubleTwist device declaration. The first is the Kind parameter, which is a well-known string that identifies the kind of device to doubleTwist so that icons and text can be matched appropriately in the UI. This string must be one of a small set of values known to doubleTwist. The second parameter is the OperationSystem parameter, which is used within a device identifier. Currently, there are only two possible values generated by a device: an empty string and "Windows Mobile". Any Windows Mobile device should match the latter value. All others will return an empty string. Support for the Sony PSP does not come from device declaration files and, therefore, cannot be customized at this time.

Reference

  • Value types

  • The device declaration XML parser expects leaf nodes to be of predetermined types. Allowable types are as follows:

    integer

    float

    string

    regular_expression: a .NET regular expression.

    folder_path: a string representing a folder on the device. The separation character is '/'. Example: "/mobile/Music".

    frame_rate: float or "ntsc" or "pal"

    file_format: enum (mp4, asf, avi, divx, flv, mpg, wav, psp, 3gp, jpg, gif, png, bmp)

    video_encoding: enum (mp4, h263, h264, wmv7, wmv8, wmv9, vc1, dv, mpg1, mpg2, h263spark, vp6, xvid)

    audio_encoding: eum (amrnb, amrwb, aac, mp3, wma1, wma2, dv, pcm)

    image encoding: enum (jpg, bmp, gif, png)

    device_kind: enum (nokia:n95, nokia:e61i, nokia:s60, sony:ericsson, windows:mobile, motorola:rizr:z3, lg:viewty, lg:mobile, apple:iphone, camera)

    list_of_ranges: specifies a list of ranges for the given type. v1[:v1End],v2[:v2End],...,vN[:vNEnd]. This type is used by decoder declarations when specifying constraints. Example integer list_of_ranges: 2,5,7:11,23,100:200

  • XML structure

  • Devices
    type: parent_node
    description: This is the root node. It contains a list of Device nodes.

    Devices/Device
    type: parent_node
    description: A device declaration

    Devices/Device/Name
    type: string
    description: The user-friendly name presented within doubleTwist for the device. If this node is not defined then the name will come from the device itself.

    Devices/Device/Kind
    type: device_kind
    description: Informs doubleTwist the kind of device this is, which is used to draw the appopriate UI for it.

    Devices/Device/Identifiers
    type: parent_node
    description: Contains a list of Identifier nodes.

    Devices/Device/Identifiers/Identifier
    type: parent_node
    description: Specifies the conditions for matching this device declaration to a device.

    Devices/Device/Identifiers/Identifier/DeviceID
    type: regular_expression
    description: The URL-encoded USB identifier for the device, as reported by Windows PnP. Example: USB%5C%5CVID_0421%26PID_0002.

    Devices/Device/Identifiers/Identifier/Manufacturer
    type: regular_expression
    description: Matched against the manufacturer name reported by the device.

    Devices/Device/Identifiers/Identifier/Model
    type: regular_expression
    description: Matched against the model name reported by the device.

    Devices/Device/Identifiers/Identifier/OperatingSystem
    type: regular_expression
    description: Empty string or Windows Mobile. Only relevant when overriding doubleTwist's Windows Mobile device declaration.

    Devices/Device/MusicFolder
    type: folder_path
    description: The folder to which audio is copied to during a sync operation.

    Devices/Device/BrowseFolders
    type: parent_node
    description: Contains a list of Folder nodes.

    Devices/Device/BrowseFolders/Folder
    type: folder_path
    description: Specifies an additional folder to search for media when browsing a device in doubleTwist.

    Devices/Device/Decoders
    type: parent_node
    description: Contains a list of Decoder nodes.

    Devices/Device/Decoders/Decoder
    type: parent_node
    description: Specifies capabilities and constraints for a given decoder on the device.

    Devices/Device/Decoders/Decoder/FileFormat
    type: file_format
    description: The file format supported by this decoder.

    Devices/Device/Decoders/Decoder/Audio
    type: parent_node
    description: Specifies audio constraints for this decoder.

    Devices/Device/Decoders/Decoder/Audio/Encoding
    type: audio_encoding
    description: Specifies the audio encoding supported by this decoder.

    Devices/Device/Decoders/Decoder/Audio/Bitrate
    type: integer list_of_ranges
    description: Specifies, in bits per second, the minimum and maximum bitrates.

    Devices/Device/Decoders/Decoder/Audio/SampleRate
    type: integer list_of_ranges
    description: Specifies, in samples per second, the minimum and maximum sample rates.

    Devices/Device/Decoders/Decoder/Audio/Channels
    type: integer list_of_ranges
    description: Specifies the number of channels supported. Valid values are 1 and 2.

    Devices/Device/AudioEncodeProfile
    type: parent_node
    description: Specifies encode settings when transcoding audio for this device.

    Devices/Device/AudioEncodeProfile/EncodeProfile
    type: parent_node
    description: Common node type among audio, video, and image encode profiles.

    Devices/Device/AudioEncodeProfile/EncodeProfile/FileFormat
    type: file_format
    description: Target file format.

    Devices/Device/AudioEncodeProfile/EncodeProfile/FileFormat/Audio
    type: parent_node
    description: Specifies audio encode settings.

    Devices/Device/AudioEncodeProfile/EncodeProfile/FileFormat/Audio/Encoding
    type: audio_encoding
    description: Targe encoding.

    Devices/Device/AudioEncodeProfile/EncodeProfile/FileFormat/Audio/Bitrate
    type: integer
    description: Specifies, in bits per second, the target bitrate.

    Devices/Device/AudioEncodeProfile/EncodeProfile/FileFormat/Audio/SampleRate
    type: integer
    description: Specifies, in samples per second, the target sample rate.

    Devices/Device/AudioEncodeProfile/EncodeProfile/FileFormat/Audio/Channels
    type: integer
    description: Specifies number of channels. Valid values are 1 nad 2.

Example

<?xml version="1.0" encoding="utf-8" ?>
<Devices>
	<Device>
		<Name>Acme</Name>
		<Identifiers>
			<Identifier>
				<Manufacturer>.*[aA][cC][mM][eE].*</Manufacturer>
				<Model>.*[pP][hH][oO][nN][eE].*</Model>
			</Identifier>
			<Identifier>
				<DeviceID>USB%5C%5CVID_0401%26PID_04AF</DeviceID>
			</Identifier>
		</Identifiers>
		<BrowseFolders>
			<Folder>/Sounds</Folder>
			<Folder>/Video</Folder>
			<Folder>/Images</Folder>
		</BrowseFolders>
		<MusicFolder>/Music</MusicFolder>
		<Decoders>
			<Decoder>
				<Audio>
					<Encoding>mp3</Encoding>
					<Bitrate>20000:320000</Bitrate>
					<Channels>1,2</Channels>
				</Audio>
			</Decoder>
			<Decoder>
				<Audio>
					<Encoding>aac</Encoding>
					<Bitrate>16000:576000</Bitrate>
					<SampleRate>8000:48000</SampleRate>
					<Channels>1,2</Channels>
				</Audio>
			</Decoder>
		</Decoders>
		<AudioEncodeProfile>
			<EncodeProfile>
				<FileFormat>mpg</FileFormat>
				<Audio>
					<Encoding>mp3</Encoding>
					<Bitrate>128000</Bitrate>
					<Channels>2</Channels>
				</Audio>
			</EncodeProfile>
		</AudioEncodeProfile>
	</Device>
</Devices>


Source Code

The source code for some of the doubleTwist components is available as Open Source. Click here to download the source code.