• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2015 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""This module provides the utilities for USB audio using chameleon."""
6
7
8def set_usb_playback_configs_on_chameleon(widget_link, playback_configs):
9    """Sets the playback configurations for the USB gadget driver on Chameleon.
10
11    This method also sets the channel map of the link based on the channel
12    number specified in the configs dictionary.
13
14    @param widget_link: The USBWidgetLink object to be handled.
15    @param playback_configs: A 4-entry dictionary with following fields:
16                             'file_type', 'sample_format', 'channel' and 'rate'.
17                             For e.g.,
18                             format = {
19                                 'file_type': 'wav',
20                                 'sample_format': 'S16_LE',
21                                 'channel': 2,
22                                 'rate': 48000
23                             }
24                             However, the 'file_type' field will be ignored
25                             since file type for playback is determined by the
26                             file type of the playback file passed in by user.
27
28    """
29    channel_number = playback_configs['channel']
30    widget_link.channel_map = \
31            _convert_channel_number_to_channel_map(channel_number)
32    usb_ctrl = widget_link.usb_ctrl
33    usb_ctrl.set_playback_configs(playback_configs)
34
35
36def set_usb_capture_configs_on_chameleon(widget_link, capture_configs):
37    """Sets the capture configurations for the USB gadget driver on Chameleon.
38
39    This method also sets the channel map of the link based on the channel
40    number specified in the configs dictionary.
41
42    @param widget_link: The USBWidgetLink object to be handled.
43    @param capture_configs: A 4-entry dictionary with following fields:
44                            'file_type', 'sample_format', 'channel' and 'rate'.
45                            For e.g.,
46                            format = {
47                                'file_type': 'wav',
48                                'sample_format': 'S16_LE',
49                                'channel': 2,
50                                'rate': 48000
51                            }
52                            'file_type' field is used to specify the file type
53                            in which captured audio data should be saved.
54
55    """
56    channel_number = capture_configs['channel']
57    widget_link.channel_map = \
58            _convert_channel_number_to_channel_map(channel_number)
59    usb_ctrl = widget_link.usb_ctrl
60    usb_ctrl.set_capture_configs(capture_configs)
61
62
63def _convert_channel_number_to_channel_map(channel_number):
64    """Converts the channel number passed into a list representing channel map.
65
66    @param channel_number: A number representing the number of channels.
67
68    @return: A list representing the corresponding channel map.
69
70    """
71    return range(channel_number)
72