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