From 1a6d941d1dea2ab1d924983cb1b09b0360c5e8bf Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Tue, 25 Jun 2013 23:05:56 +0200 Subject: [PATCH] USB audio: Use system-wide USB_audio.h instead local one * switching driver code to use system usb/USB_audio.h header; * refactor USB_audio.h specification header for both USB audio specifications. --- headers/os/drivers/usb/USB_audio.h | 494 +++++++++++++++-- .../audio/usb_audio/AudioControlInterface.cpp | 364 ++++++++----- .../audio/usb_audio/AudioControlInterface.h | 7 +- .../usb_audio/AudioStreamingInterface.cpp | 89 ++-- .../audio/usb_audio/AudioStreamingInterface.h | 22 +- .../kernel/drivers/audio/usb_audio/Device.cpp | 8 +- .../kernel/drivers/audio/usb_audio/Driver.cpp | 3 +- .../kernel/drivers/audio/usb_audio/Stream.cpp | 29 +- .../drivers/audio/usb_audio/USB_audio_spec.h | 498 ------------------ .../kernel/drivers/audio/usb_audio/audio.h | 165 ------ 10 files changed, 754 insertions(+), 925 deletions(-) delete mode 100644 src/add-ons/kernel/drivers/audio/usb_audio/USB_audio_spec.h delete mode 100644 src/add-ons/kernel/drivers/audio/usb_audio/audio.h diff --git a/headers/os/drivers/usb/USB_audio.h b/headers/os/drivers/usb/USB_audio.h index 23aa841ea8..e28a37f9e6 100644 --- a/headers/os/drivers/usb/USB_audio.h +++ b/headers/os/drivers/usb/USB_audio.h @@ -1,10 +1,11 @@ #ifndef USB_AUDIO_H #define USB_AUDIO_H -// (Partial) USB Class Definitions for Audio Devices, version 1.0 -// Reference: http://www.usb.org/developers/devclass_docs/audio10.pdf +// (Partial) USB Device Class Definition for Audio Devices +// R1: Release 1.0 March 18, 1998 +// R2: Release 2.0 May 31, 2006 -#include // for _PACKED definition +#include #define USB_AUDIO_DEVICE_CLASS 0x01 #define USB_AUDIO_CLASS_VERSION 0x0100 @@ -14,29 +15,299 @@ enum { }; enum { // Audio Interface Subclasses - USB_AUDIO_INTERFACE_AUDIOCONTROL_SUBCLASS = 0x01, // + USB_AUDIO_INTERFACE_UNDEFINED_SUBCLASS = 0x00, + USB_AUDIO_INTERFACE_AUDIOCONTROL_SUBCLASS = 0x01, USB_AUDIO_INTERFACE_AUDIOSTREAMING_SUBCLASS, // USB_AUDIO_INTERFACE_MIDISTREAMING_SUBCLASS // }; -enum { // Audio Class-Specific AudioControl Interface descriptor subtypes - USB_AUDIO_AC_DESCRIPTOR_UNDEFINED = 0x00, - USB_AUDIO_AC_HEADER = 0x01, - USB_AUDIO_AC_INPUT_TERMINAL, - USB_AUDIO_AC_OUTPUT_TERMINAL, - USB_AUDIO_AC_MIXER_UNIT, - USB_AUDIO_AC_SELECTOR_UNIT, - USB_AUDIO_AC_FEATURE_UNIT, - USB_AUDIO_AC_PROCESSING_UNIT, - USB_AUDIO_AC_EXTENSION_UNIT +enum { // Audio Interface Protocol Codes + USB_AUDIO_PROTOCOL_UNDEFINED = 0x00 }; -enum { // Audio Class-Specific AudioStreaming Interface descriptor subtypes - USB_AUDIO_AS_GENERAL = 0x01, - USB_AUDIO_AS_FORMAT_TYPE, - USB_AUDIO_AS_FORMAT_SPECIFIC +enum { // Audio Interface Protocol Codes + USB_AUDIO_CS_UNDEFINED = 0x20, + USB_AUDIO_CS_DEVICE = 0x21, + USB_AUDIO_CS_CONFIGURATION = 0x22, + USB_AUDIO_CS_STRING = 0x23, + USB_AUDIO_CS_INTERFACE = 0x24, + USB_AUDIO_CS_ENDPOINT = 0x25 }; + +enum { // Audio Class-Specific AudioControl Interface descriptor subtypes + USB_AUDIO_AC_DESCRIPTOR_UNDEFINED = 0x00, + USB_AUDIO_AC_HEADER = 0x01, + USB_AUDIO_AC_INPUT_TERMINAL = 0x02, + USB_AUDIO_AC_OUTPUT_TERMINAL = 0x03, + USB_AUDIO_AC_MIXER_UNIT = 0x04, + USB_AUDIO_AC_SELECTOR_UNIT = 0x05, + USB_AUDIO_AC_FEATURE_UNIT = 0x06, + USB_AUDIO_AC_PROCESSING_UNIT = 0x07, + USB_AUDIO_AC_EXTENSION_UNIT = 0x08, + USB_AUDIO_AC_EFFECT_UNIT_R2 = 0x07, + USB_AUDIO_AC_PROCESSING_UNIT_R2 = 0x08, + USB_AUDIO_AC_EXTENSION_UNIT_R2 = 0x09, + USB_AUDIO_AC_CLOCK_SOURCE_R2 = 0x0A, + USB_AUDIO_AC_CLOCK_SELECTOR_R2 = 0x0B, + USB_AUDIO_AC_CLOCK_MULTIPLIER_R2 = 0x0C, + USB_AUDIO_AC_SAMPLE_RATE_CONVERTER_R2 = 0x0D +}; + + +// Class Specific Audio Control Interface Header +// R1: Table 4-2 p.37 / R2: Table 4-5 p.48 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_HEADER + uint16 bcd_release_no; + union { + struct { + uint16 total_length; + uint8 in_collection; + uint8 interface_numbers[1]; + } _PACKED r1; + + struct { + uint8 function_category; + uint16 total_length; + uint8 bm_controls; + } _PACKED r2; + }; +} _PACKED usb_audiocontrol_header_descriptor; + + +// Input Terminal Descriptor +// R1: Table 4-3 p.39 / R2: Table 4-9, page 53 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_INPUT_TERMINAL + uint8 terminal_id; + uint16 terminal_type; + uint8 assoc_terminal; + union { + struct { + uint8 num_channels; + uint8 channel_config; + uint8 channel_names; + uint8 terminal; + } _PACKED r1; + + struct { + uint8 clock_source_id; + uint8 num_channels; + uint32 channel_config; + uint8 channel_names; + uint16 bm_controls; + uint8 terminal; + } _PACKED r2; + }; +} _PACKED usb_audio_input_terminal_descriptor; + + +// Output Terminal Descriptor +// R1: Table 4-4 p.40 / R2: Table 4-10, page 54 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_OUTPUT_TERMINAL + uint8 terminal_id; + uint16 terminal_type; + uint8 assoc_terminal; + uint8 source_id; + union { + struct { + uint8 terminal; + } _PACKED r1; + + struct { + uint8 clock_source_id; + uint16 bm_controls; + uint8 terminal; + } _PACKED r2; + }; +} _PACKED usb_audio_output_terminal_descriptor; + + +// pseudo-descriptor for a section corresponding to logical output channels +// used in mixer, processing and extension descriptions. +typedef struct { + uint8 num_output_pins; // number of mixer output pins + uint16 channel_config; // location of logical channels + uint8 channel_names; // id of name string of first logical channel +} _PACKED usb_audio_output_channels_descriptor_r1; + +typedef struct { + uint8 num_output_pins; // number of mixer output pins + uint32 channel_config; // location of logical channels + uint8 channel_names; // id of name string of first logical channel +} _PACKED usb_audio_output_channels_descriptor; + + +// Mixer Unit Descriptor +// R1: Table 4-5 p.41 / R2: Table 4-11, page 57 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_MIXER_UNIT + uint8 unit_id; + uint8 num_input_pins; + uint8 input_pins[1]; + // use usb_audio_output_channels_descriptor to parse the rest +} _PACKED usb_audio_mixer_unit_descriptor; + + +// Selector Unit Descriptor +// R1: Table 4-6 p.43 / R2: Table 4-12, page 58 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_SELECTOR_UNIT + uint8 unit_id; + uint8 num_input_pins; + uint8 input_pins[1]; + // uint8 selector_string; +} _PACKED usb_audio_selector_unit_descriptor; + + +// Feature Unit Descriptor +// R1: Table 4-7 p.43 / R2: Table 4-13, page 59 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_FEATURE_UNIT + uint8 unit_id; + uint8 source_id; + union { + struct { + uint8 control_size; + uint8 bma_controls[1]; + // uint8 feature_string; + } _PACKED r1; + + struct { + uint32 bma_controls[1]; + // uint8 feature_string; + } _PACKED r2; + }; +} _PACKED usb_audio_feature_unit_descriptor; + + +// Processing Unit Descriptor +// R1: Table 4-8 p.45 / R2: Table 4-20, page 66 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_PROCESSING_UNIT + uint8 unit_id; + uint16 process_type; + uint8 num_input_pins; + uint8 input_pins[1]; + // use usb_audio_output_channels_descriptor to parse the rest +// TODO - the bmControl!!!! +} _PACKED usb_audio_processing_unit_descriptor; + +// Extension Unit Descriptor +// R1: Table 4-15, p. 56 / R2: Table 4-24, p.73 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AC_EXTENSION_UNIT + uint8 unit_id; + uint16 extension_code; + uint8 num_input_pins; + uint8 input_pins[1]; + // use usb_audio_output_channels_descriptor to parse the rest +} _PACKED usb_audio_extension_unit_descriptor; + + +enum { // Audio Class-Specific AudioStreaming Interface descriptor subtypes + USB_AUDIO_AS_DESCRIPTOR_UNDEFINED = 0x00, + USB_AUDIO_AS_GENERAL = 0x01, + USB_AUDIO_AS_FORMAT_TYPE = 0x02, + USB_AUDIO_AS_FORMAT_SPECIFIC = 0x03 +}; + +// Class Specific Audio Streaming Interface Descriptor +// R1: Table 4-19 p.60 / R2: Table 4-27 p.76 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AS_GENERAL + uint8 terminal_link; + union { + struct { + uint8 delay; + uint16 format_tag; + } _PACKED r1; + + struct { + uint8 bm_controls; + uint8 format_type; + uint32 bm_formats; + uint8 num_output_pins; + uint32 channel_config; + uint8 channel_names; + } _PACKED r2; + }; +} _PACKED usb_audio_streaming_interface_descriptor; + + +// Class-specific As Isochronous Audio Data Endpoint descriptor +// R1: Table 4-21, p. 62 / R2: Table 4-34, page 87 +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_ENDPOINT + uint8 descriptor_subtype; // USB_AUDIO_EP_GENERAL + uint8 attributes; + uint8 lock_delay_units; + uint16 lock_delay; +} _PACKED usb_audio_streaming_endpoint_descriptor; + + +// Sampling Rate are represented as 3-byte integer +typedef struct { + uint8 bytes[3]; +} _PACKED usb_audio_sampling_freq; + + +// Format Type I/II/III Descriptors +// T1: Table 2-1, p.10 etc. +// T2: Table 2-2, p.15 etc. +typedef struct { + uint8 length; + uint8 descriptor_type; // USB_AUDIO_CS_INTERFACE + uint8 descriptor_subtype; // USB_AUDIO_AS_FORMAT_TYPE + uint8 format_type; // USB_AUDIO_FORMAT_TYPE_I/II/III + union { + struct { + uint8 nr_channels; + uint8 subframe_size; + uint8 bit_resolution; + uint8 sam_freq_type; + usb_audio_sampling_freq sam_freqs[1]; + } _PACKED typeI; + + struct { + uint16 max_bit_rate; + uint16 samples_per_frame; + uint8 sam_freq_type; + usb_audio_sampling_freq sam_freqs[1]; + } _PACKED typeII; + + struct { + uint8 nr_channels; + uint8 subframe_size; + uint8 bit_resolution; + uint8 sam_freq_type; + usb_audio_sampling_freq sam_freqs[1]; + } _PACKED typeIII; + }; +} _PACKED usb_audio_format_descriptor; + + enum { // Processing Unit Process Types (for USB_AUDIO_AC_PROCESSING_UNIT) USB_AUDIO_UPDOWNMIX_PROCESS = 0x01, USB_AUDIO_DOLBY_PROLOGIC_PROCESS, @@ -46,35 +317,38 @@ enum { // Processing Unit Process Types (for USB_AUDIO_AC_PROCESSING_UNIT) USB_AUDIO_DYN_RANGE_COMP_PROCESS }; -// AudioControl request codes -#define USB_AUDIO_SET_CURRENT 0x01 -#define USB_AUDIO_GET_CURRENT 0x81 -#define USB_AUDIO_SET_MIN 0x02 -#define USB_AUDIO_GET_MIN 0x82 -#define USB_AUDIO_SET_MAX 0x03 -#define USB_AUDIO_GET_MAX 0x83 -#define USB_AUDIO_SET_RES 0x04 -#define USB_AUDIO_GET_RES 0x84 -#define USB_AUDIO_SET_MEM 0x05 -#define USB_AUDIO_GET_MEM 0x85 -#define USB_AUDIO_GET_STATUS 0xFF +enum { // Audio Class-Specific Request Codes + USB_AUDIO_SET_CUR = 0x01, + USB_AUDIO_GET_CUR = 0x81, + USB_AUDIO_SET_MIN = 0x02, + USB_AUDIO_GET_MIN = 0x82, + USB_AUDIO_SET_MAX = 0x03, + USB_AUDIO_GET_MAX = 0x83, + USB_AUDIO_SET_RES = 0x04, + USB_AUDIO_GET_RES = 0x84, + USB_AUDIO_SET_MEM = 0x05, + USB_AUDIO_GET_MEM = 0x85, + USB_AUDIO_GET_STATUS = 0xFF +}; enum { // Terminal Control Selectors USB_AUDIO_COPY_PROTECT_CONTROL = 0x01 }; /* A.10.2 Feature Unit Control Selectors */ -#define AC_FU_CONTROL_UNDEFINED 0x00 -#define USB_AUDIO_MUTE_CONTROL 0x01 -#define USB_AUDIO_VOLUME_CONTROL 0x02 -#define USB_AUDIO_BASS_CONTROL 0x03 -#define USB_AUDIO_MID_CONTROL 0x04 -#define USB_AUDIO_TREBLE_CONTROL 0x05 -#define USB_AUDIO_GRAPHIC_EQUALIZER_CONTROL 0x06 -#define USB_AUDIO_AUTOMATIC_GAIN_CONTROL 0x07 -#define USB_AUDIO_DELAY_CONTROL 0x08 -#define USB_AUDIO_BASS_BOOST_CONTROL 0x09 -#define USB_AUDIO_LOUDNESS_CONTROL 0x0A +enum { + USB_AUDIO_AC_FU_CONTROL_UNDEFINED = 0x00, + USB_AUDIO_MUTE_CONTROL = 0x01, + USB_AUDIO_VOLUME_CONTROL = 0x02, + USB_AUDIO_BASS_CONTROL = 0x03, + USB_AUDIO_MID_CONTROL = 0x04, + USB_AUDIO_TREBLE_CONTROL = 0x05, + USB_AUDIO_GRAPHIC_EQUALIZER_CONTROL = 0x06, + USB_AUDIO_AUTOMATIC_GAIN_CONTROL = 0x07, + USB_AUDIO_DELAY_CONTROL = 0x08, + USB_AUDIO_BASS_BOOST_CONTROL = 0x09, + USB_AUDIO_LOUDNESS_CONTROL = 0x0A +}; /* A.10.3.1 Up/Down-mix Processing Unit Control Selectors */ #define USB_AUDIO_UD_CONTROL_UNDEFINED 0x00 @@ -119,10 +393,13 @@ enum { // Terminal Control Selectors #define USB_AUDIO_XU_ENABLE_CONTROL 0x01 /* A.10.5 Endpoint Control Selectors */ -#define USB_AUDIO_EP_CONTROL_UNDEFINED 0x00 -#define USB_AUDIO_SAMPLING_FREQ_CONTROL 0x01 -#define USB_AUDIO_PITCH_CONTROL 0x02 +enum { + USB_AUDIO_EP_CONTROL_UNDEFINED = 0x00, + USB_AUDIO_SAMPLING_FREQ_CONTROL = 0x01, + USB_AUDIO_PITCH_CONTROL = 0x02 +}; +/* typedef struct { uint8 length; @@ -147,10 +424,131 @@ typedef struct { // if sample_freq_type != 1, // (sample_freq_type - 1) x uint8 sample_freq[3] follows... } _PACKED usb_audio_format_type_descriptor; +*/ +// bitset for feature control bitmap +// Table 4-7, page 44, bmaControls field +enum { + BMA_CTL_MUTE_R1 = 0X0001, + BMA_CTL_VOLUME_R1 = 0X0002, + BMA_CTL_BASS_R1 = 0X0004, + BMA_CTL_MID_R1 = 0X0008, + BMA_CTL_TREBLE_R1 = 0X0010, + BMA_CTL_GRAPHEQ_R1 = 0X0020, + BMA_CTL_AUTOGAIN_R1 = 0X0040, + BMA_CTL_DELAY_R1 = 0X0080, + BMA_CTL_BASSBOOST_R1 = 0X0100, + BMA_CTL_LOUDNESS_R1 = 0X0200, + // Release 2.0 + BMA_CTL_MUTE = 0X00000003, + BMA_CTL_VOLUME = 0X0000000C, + BMA_CTL_BASS = 0X00000030, + BMA_CTL_MID = 0X000000C0, + BMA_CTL_TREBLE = 0X00000300, + BMA_CTL_GRAPHEQ = 0X00000C00, + BMA_CTL_AUTOGAIN = 0X00003000, + BMA_CTL_DELAY = 0X0000C000, + BMA_CTL_BASSBOOST = 0X00030000, + BMA_CTL_LOUDNESS = 0X000C0000, + BMA_CTL_INPUTGAIN = 0X00300000, + BMA_CTL_INPUTGAINPAD = 0X00C00000, + BMA_CTL_PHASEINVERTER = 0X03000000, + BMA_CTL_UNDERFLOW = 0X0C000000, + BMA_CTL_OVERFLOW = 0X30000000 +}; + +// Table A-4, page 30 +// Format Type Codes +enum { + USB_AUDIO_FORMAT_TYPE_UNDEFINED = 0x00, + USB_AUDIO_FORMAT_TYPE_I = 0x01, + USB_AUDIO_FORMAT_TYPE_II = 0x02, + USB_AUDIO_FORMAT_TYPE_III = 0x03 +}; + +// Table A-1, page 29, wFormatTag +// Audio Data Format Type I codes +enum { + USB_AUDIO_FORMAT_TYPE_I_UNDEFINED = 0x0000, + USB_AUDIO_FORMAT_PCM = 0x0001, + USB_AUDIO_FORMAT_PCM8 = 0x0002, + USB_AUDIO_FORMAT_IEEE_FLOAT = 0x0003, + USB_AUDIO_FORMAT_ALAW = 0x0004, + USB_AUDIO_FORMAT_MULAW = 0x0005 +}; + + +enum { + // USB Terminal Types + USB_AUDIO_UNDEFINED_USB_IO = 0x100, + USB_AUDIO_STREAMING_USB_IO = 0x101, + USB_AUDIO_VENDOR_USB_IO = 0x1ff, + // Input Terminal Types + USB_AUDIO_UNDEFINED_IN = 0x200, + USB_AUDIO_MICROPHONE_IN = 0x201, + USB_AUDIO_DESKTOPMIC_IN = 0x202, + USB_AUDIO_PERSONALMIC_IN = 0x203, + USB_AUDIO_OMNI_MIC_IN = 0x204, + USB_AUDIO_MICS_ARRAY_IN = 0x205, + USB_AUDIO_PROC_MICS_ARRAY_IN = 0x206, + // Output Terminal Types + USB_AUDIO_UNDEFINED_OUT = 0x300, + USB_AUDIO_SPEAKER_OUT = 0x301, + USB_AUDIO_HEAD_PHONES_OUT = 0x302, + USB_AUDIO_HMD_AUDIO_OUT = 0x303, + USB_AUDIO_DESKTOP_SPEAKER = 0x304, + USB_AUDIO_ROOM_SPEAKER = 0x305, + USB_AUDIO_COMM_SPEAKER = 0x306, + USB_AUDIO_LFE_SPEAKER = 0x307, + // Bi-directional Terminal Types + USB_AUDIO_UNDEFINED_IO = 0x400, + USB_AUDIO_HANDSET_IO = 0x401, + USB_AUDIO_HEADSET_IO = 0x402, + USB_AUDIO_SPEAKER_PHONE_IO = 0x403, + USB_AUDIO_SPEAKER_PHONEES_IO = 0x404, + USB_AUDIO_SPEAKER_PHONEEC_IO = 0x405, + // Telephony Terminal Types + USB_AUDIO_UNDEF_TELEPHONY_IO = 0x500, + USB_AUDIO_PHONE_LINE_IO = 0x501, + USB_AUDIO_TELEPHONE_IO = 0x502, + USB_AUDIO_DOWNLINE_PHONE_IO = 0x503, + // External Terminal Types + USB_AUDIO_UNDEFINEDEXT_IO = 0x600, + USB_AUDIO_ANALOG_CONNECTOR_IO = 0x601, + USB_AUDIO_DAINTERFACE_IO = 0x602, + USB_AUDIO_LINE_CONNECTOR_IO = 0x603, + USB_AUDIO_LEGACY_CONNECTOR_IO = 0x604, + USB_AUDIO_SPDIF_INTERFACE_IO = 0x605, + USB_AUDIO_DA1394_STREAM_IO = 0x606, + USB_AUDIO_DV1394_STREAMSOUND_IO = 0x607, + USB_AUDIO_ADAT_LIGHTPIPE_IO = 0x608, + USB_AUDIO_TDIF_IO = 0x609, + USB_AUDIO_MADI_IO = 0x60a, + // Embedded Terminal Types + USB_AUDIO_UNDEF_EMBEDDED_IO = 0x700, + USB_AUDIO_LC_NOISE_SOURCE_OUT = 0x701, + USB_AUDIO_EQUALIZATION_NOISE_OUT = 0x702, + USB_AUDIO_CDPLAYER_IN = 0x703, + USB_AUDIO_DAT_IO = 0x704, + USB_AUDIO_DCC_IO = 0x705, + USB_AUDIO_MINI_DISK_IO = 0x706, + USB_AUDIO_ANALOG_TAPE_IO = 0x707, + USB_AUDIO_PHONOGRAPH_IN = 0x708, + USB_AUDIO_VCR_AUDIO_IN = 0x709, + USB_AUDIO_VIDEO_DISC_AUDIO_IN = 0x70a, + USB_AUDIO_DVD_AUDIO_IN = 0x70b, + USB_AUDIO_TV_TUNER_AUDIO_IN = 0x70c, + USB_AUDIO_SAT_RECEIVER_AUDIO_IN = 0x70d, + USB_AUDIO_CABLE_TUNER_AUDIO_IN = 0x70e, + USB_AUDIO_DSS_AUDIO_IN = 0x70f, + USB_AUDIO_RADIO_RECEIVER_IN = 0x710, + USB_AUDIO_RADIO_TRANSMITTER_IN = 0x711, + USB_AUDIO_MULTI_TRACK_RECORDER_IO = 0x712, + USB_AUDIO_SYNTHESIZER_IO = 0x713, + USB_AUDIO_PIANO_IO = 0x714, + USB_AUDIO_GUITAR_IO = 0x715, + USB_AUDIO_DRUMS_IO = 0x716, + USB_AUDIO_INSTRUMENT_IO = 0x717 +}; -#define USB_AUDIO_FORMAT_TYPE_UNDEFINED 0x00 -#define USB_AUDIO_FORMAT_TYPE_I 0x01 -#define USB_AUDIO_FORMAT_TYPE_II 0x02 -#define USB_AUDIO_FORMAT_TYPE_III 0x03 #endif // USB_AUDIO_H diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.cpp b/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.cpp index 3bf0b52f1d..c448c5a52e 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.cpp +++ b/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.cpp @@ -7,12 +7,13 @@ #include "AudioControlInterface.h" -#include "audio.h" +#include + #include "Device.h" #include "Driver.h" #include "Settings.h" - +/* enum TerminalTypes { // USB Terminal Types UndefinedUSB_IO = 0x100, @@ -84,12 +85,92 @@ enum TerminalTypes { Guitar_IO = 0x715, Drums_IO = 0x716, Instrument_IO = 0x717 -}; +}; */ const char* GetTerminalDescription(uint16 TerminalType) { + static struct _pair { + uint16 type; + const char* description; + } termInfoPairs[] = { + // USB Terminal Types + { USB_AUDIO_UNDEFINED_USB_IO, "USB I/O" }, + { USB_AUDIO_STREAMING_USB_IO, "USB Streaming I/O" }, + { USB_AUDIO_VENDOR_USB_IO, "Vendor USB I/O" }, + // Input Terminal Types + { USB_AUDIO_UNDEFINED_IN, "Undefined Input" }, + { USB_AUDIO_MICROPHONE_IN, "Microphone" }, + { USB_AUDIO_DESKTOPMIC_IN, "Desktop Microphone" }, + { USB_AUDIO_PERSONALMIC_IN, "Personal Microphone" }, + { USB_AUDIO_OMNI_MIC_IN, "Omni-directional Mic" }, + { USB_AUDIO_MICS_ARRAY_IN, "Microphone Array" }, + { USB_AUDIO_PROC_MICS_ARRAY_IN, "Processing Mic Array" }, + // Output Terminal Types + { USB_AUDIO_UNDEFINED_OUT, "Undefined Output" }, + { USB_AUDIO_SPEAKER_OUT, "Speaker" }, + { USB_AUDIO_HEAD_PHONES_OUT, "Headphones" }, + { USB_AUDIO_HMD_AUDIO_OUT, "Head Mounted Disp.Audio" }, + { USB_AUDIO_DESKTOP_SPEAKER, "Desktop Speaker" }, + { USB_AUDIO_ROOM_SPEAKER, "Room Speaker" }, + { USB_AUDIO_COMM_SPEAKER, "Communication Speaker" }, + { USB_AUDIO_LFE_SPEAKER, "LFE Speaker" }, + // Bi-directional Terminal Types + { USB_AUDIO_UNDEFINED_IO, "Undefined I/O" }, + { USB_AUDIO_HANDSET_IO, "Handset" }, + { USB_AUDIO_HEADSET_IO, "Headset" }, + { USB_AUDIO_SPEAKER_PHONE_IO, "Speakerphone" }, + { USB_AUDIO_SPEAKER_PHONEES_IO, "Echo-supp Speakerphone" }, + { USB_AUDIO_SPEAKER_PHONEEC_IO, "Echo-cancel Speakerphone" }, + // Telephony Terminal Types + { USB_AUDIO_UNDEF_TELEPHONY_IO, "Undefined Telephony" }, + { USB_AUDIO_PHONE_LINE_IO, "Phone Line" }, + { USB_AUDIO_TELEPHONE_IO, "Telephone" }, + { USB_AUDIO_DOWNLINE_PHONE_IO, "Down Line Phone" }, + // External Terminal Types + { USB_AUDIO_UNDEFINEDEXT_IO, "Undefined External I/O" }, + { USB_AUDIO_ANALOG_CONNECTOR_IO, "Analog Connector" }, + { USB_AUDIO_DAINTERFACE_IO, "Digital Audio Interface" }, + { USB_AUDIO_LINE_CONNECTOR_IO, "Line Connector" }, + { USB_AUDIO_LEGACY_CONNECTOR_IO, "LegacyAudioConnector" }, + { USB_AUDIO_SPDIF_INTERFACE_IO, "S/PDIF Interface" }, + { USB_AUDIO_DA1394_STREAM_IO, "1394 DA Stream" }, + { USB_AUDIO_DV1394_STREAMSOUND_IO, "1394 DV Stream Soundtrack" }, + { USB_AUDIO_ADAT_LIGHTPIPE_IO, "Alesis DAT Stream" }, + { USB_AUDIO_TDIF_IO, "Tascam Digital Interface" }, + { USB_AUDIO_MADI_IO, "AES Multi-channel interface" }, + // Embedded Terminal Types + { USB_AUDIO_UNDEF_EMBEDDED_IO, "Undefined Embedded I/O" }, + { USB_AUDIO_LC_NOISE_SOURCE_OUT, "Level Calibration Noise Source" }, + { USB_AUDIO_EQUALIZATION_NOISE_OUT, "Equalization Noise" }, + { USB_AUDIO_CDPLAYER_IN, "CD Player" }, + { USB_AUDIO_DAT_IO, "DAT" }, + { USB_AUDIO_DCC_IO, "DCC" }, + { USB_AUDIO_MINI_DISK_IO, "Mini Disk" }, + { USB_AUDIO_ANALOG_TAPE_IO, "Analog Tape" }, + { USB_AUDIO_PHONOGRAPH_IN, "Phonograph" }, + { USB_AUDIO_VCR_AUDIO_IN, "VCR Audio" }, + { USB_AUDIO_VIDEO_DISC_AUDIO_IN, "Video Disc Audio" }, + { USB_AUDIO_DVD_AUDIO_IN, "DVD Audio" }, + { USB_AUDIO_TV_TUNER_AUDIO_IN, "TV Tuner Audio" }, + { USB_AUDIO_SAT_RECEIVER_AUDIO_IN, "Satellite Receiver Audio" }, + { USB_AUDIO_CABLE_TUNER_AUDIO_IN, "Cable Tuner Audio" }, + { USB_AUDIO_DSS_AUDIO_IN, "DSS Audio" }, + { USB_AUDIO_RADIO_RECEIVER_IN, "Radio Receiver" }, + { USB_AUDIO_RADIO_TRANSMITTER_IN, "Radio Transmitter" }, + { USB_AUDIO_MULTI_TRACK_RECORDER_IO,"Multi-track Recorder" }, + { USB_AUDIO_SYNTHESIZER_IO, "Synthesizer" }, + { USB_AUDIO_PIANO_IO, "Piano" }, + { USB_AUDIO_GUITAR_IO, "Guitar" }, + { USB_AUDIO_DRUMS_IO, "Percussion Instrument" }, + { USB_AUDIO_INSTRUMENT_IO, "Musical Instrument" } + }; + + for (size_t i = 0; _countof(termInfoPairs); i++) + if (termInfoPairs[i].type == TerminalType) + return termInfoPairs[i].description; +/* switch(TerminalType) { // USB Terminal Types case UndefinedUSB_IO: return "USB I/O"; @@ -161,7 +242,7 @@ GetTerminalDescription(uint16 TerminalType) case Guitar_IO: return "Guitar"; case Drums_IO: return "Percussion Instrument"; case Instrument_IO: return "Musical Instrument"; - } + } */ TRACE_ALWAYS("Unknown Terminal Type: %#06x", TerminalType); return "Unknown"; @@ -259,7 +340,7 @@ _Terminal::Name() bool _Terminal::IsUSBIO() { - return (fTerminalType & 0xff00) == UndefinedUSB_IO; + return (fTerminalType & 0xff00) == USB_AUDIO_UNDEFINED_USB_IO; } @@ -268,8 +349,8 @@ InputTerminal::InputTerminal(AudioControlInterface* interface, : _AudioChannelCluster<_Terminal>(interface, Header) { - usb_input_terminal_descriptor_r1* Terminal - = (usb_input_terminal_descriptor_r1*) Header; + usb_audio_input_terminal_descriptor* Terminal + = (usb_audio_input_terminal_descriptor*) Header; fID = Terminal->terminal_id; fTerminalType = Terminal->terminal_type; fAssociatedTerminal = Terminal->assoc_terminal; @@ -280,19 +361,17 @@ InputTerminal::InputTerminal(AudioControlInterface* interface, TRACE("Assoc.terminal:%d\n", fAssociatedTerminal); if (fInterface->SpecReleaseNumber() < 0x200) { - fOutChannelsNumber = Terminal->num_channels; - fChannelsConfig = Terminal->channel_config; - fChannelNames = Terminal->channel_names; - fStringIndex = Terminal->terminal; + fOutChannelsNumber = Terminal->r1.num_channels; + fChannelsConfig = Terminal->r1.channel_config; + fChannelNames = Terminal->r1.channel_names; + fStringIndex = Terminal->r1.terminal; } else { - usb_input_terminal_descriptor* Terminal - = (usb_input_terminal_descriptor*) Header; - fClockSourceId = Terminal->clock_source_id; - fOutChannelsNumber = Terminal->num_channels; - fChannelsConfig = Terminal->channel_config; - fChannelNames = Terminal->channel_names; - fControlsBitmap = Terminal->bm_controls; - fStringIndex = Terminal->terminal; + fClockSourceId = Terminal->r2.clock_source_id; + fOutChannelsNumber = Terminal->r2.num_channels; + fChannelsConfig = Terminal->r2.channel_config; + fChannelNames = Terminal->r2.channel_names; + fControlsBitmap = Terminal->r2.bm_controls; + fStringIndex = Terminal->r2.terminal; TRACE("Clock Source ID:%d\n", fClockSourceId); TRACE("Controls Bitmap:%#04x\n", fControlsBitmap); @@ -317,8 +396,8 @@ OutputTerminal::OutputTerminal(AudioControlInterface* interface, : _Terminal(interface, Header) { - usb_output_terminal_descriptor_r1* Terminal - = (usb_output_terminal_descriptor_r1*) Header; + usb_audio_output_terminal_descriptor* Terminal + = (usb_audio_output_terminal_descriptor*) Header; fID = Terminal->terminal_id; fTerminalType = Terminal->terminal_type; @@ -332,14 +411,11 @@ OutputTerminal::OutputTerminal(AudioControlInterface* interface, TRACE("Source ID:%d\n", fSourceID); if (fInterface->SpecReleaseNumber() < 0x200) { - fStringIndex = Terminal->terminal; + fStringIndex = Terminal->r1.terminal; } else { - usb_output_terminal_descriptor* Terminal - = (usb_output_terminal_descriptor*) Header; - - fClockSourceId = Terminal->clock_source_id; - fControlsBitmap = Terminal->bm_controls; - fStringIndex = Terminal->terminal; + fClockSourceId = Terminal->r2.clock_source_id; + fControlsBitmap = Terminal->r2.bm_controls; + fStringIndex = Terminal->r2.terminal; TRACE("Clock Source ID:%d\n", fClockSourceId); TRACE("Controls Bitmap:%#04x\n", fControlsBitmap); @@ -362,8 +438,8 @@ MixerUnit::MixerUnit(AudioControlInterface* interface, _AudioChannelCluster<_AudioControl>(interface, Header), fControlsBitmap(0) { - usb_mixer_unit_descriptor* Mixer - = (usb_mixer_unit_descriptor*) Header; + usb_audio_mixer_unit_descriptor* Mixer + = (usb_audio_mixer_unit_descriptor*) Header; fID = Mixer->unit_id; TRACE("Mixer ID:%d >>>\n", fID); @@ -378,8 +454,8 @@ MixerUnit::MixerUnit(AudioControlInterface* interface, uint8 mixerControlsSize = 0; if (fInterface->SpecReleaseNumber() < 0x200) { - usb_output_channels_descriptor_r1* OutChannels - = (usb_output_channels_descriptor_r1*) + usb_audio_output_channels_descriptor_r1* OutChannels + = (usb_audio_output_channels_descriptor_r1*) &Mixer->input_pins[Mixer->num_input_pins]; fOutChannelsNumber = OutChannels->num_output_pins; @@ -390,8 +466,8 @@ MixerUnit::MixerUnit(AudioControlInterface* interface, mixerControlsSize = Mixer->length - 10 - Mixer->num_input_pins; fStringIndex = *(mixerControlsData + mixerControlsSize); } else { - usb_output_channels_descriptor* OutChannels - = (usb_output_channels_descriptor*) + usb_audio_output_channels_descriptor* OutChannels + = (usb_audio_output_channels_descriptor*) &Mixer->input_pins[Mixer->num_input_pins]; fOutChannelsNumber = OutChannels->num_output_pins; @@ -433,8 +509,8 @@ SelectorUnit::SelectorUnit(AudioControlInterface* interface, _AudioControl(interface, Header), fControlsBitmap(0) { - usb_selector_unit_descriptor* Selector - = (usb_selector_unit_descriptor*) Header; + usb_audio_selector_unit_descriptor* Selector + = (usb_audio_selector_unit_descriptor*) Header; fID = Selector->unit_id; TRACE("Selector ID:%d >>>\n", fID); @@ -489,8 +565,8 @@ FeatureUnit::FeatureUnit(AudioControlInterface* interface, : _AudioControl(interface, Header) { - usb_feature_unit_descriptor* Feature - = (usb_feature_unit_descriptor*) Header; + usb_audio_feature_unit_descriptor* Feature + = (usb_audio_feature_unit_descriptor*) Header; fID = Feature->unit_id; TRACE("Feature ID:%d >>>\n", fID); @@ -500,21 +576,19 @@ FeatureUnit::FeatureUnit(AudioControlInterface* interface, uint8 controlSize = 4; uint8 channelsCount = (Feature->length - 6) / controlSize; - uint8* ControlsBitmapPointer = (uint8*)&Feature->bma_controls[0]; + uint8* ControlsBitmapPointer = (uint8*)&Feature->r2.bma_controls[0]; if (fInterface->SpecReleaseNumber() < 0x200) { - usb_feature_unit_descriptor_r1* Feature - = (usb_feature_unit_descriptor_r1*)Header; - controlSize = Feature->control_size; - channelsCount = (Feature->length - 7) / Feature->control_size; - ControlsBitmapPointer = &Feature->bma_controls[0]; + controlSize = Feature->r1.control_size; + channelsCount = (Feature->length - 7) / Feature->r1.control_size; + ControlsBitmapPointer = &Feature->r1.bma_controls[0]; } TRACE("Channel bitmap size:%d\n", controlSize); TRACE("Channels number:%d\n", channelsCount - 1); // not add master! for (size_t i = 0; i < channelsCount; i++) { - uint8* controlPointer = &ControlsBitmapPointer[i* controlSize]; + uint8* controlPointer = &ControlsBitmapPointer[i* controlSize]; switch(controlSize) { case 1: fControlBitmaps.PushBack(*controlPointer); break; case 2: fControlBitmaps.PushBack(*(uint16*)controlPointer); break; @@ -546,7 +620,7 @@ FeatureUnit::Name() // first check if source of this FU is an input terminal _AudioControl* control = fInterface->Find(fSourceID); while (control != 0) { - if (control->SubType() != IDSInputTerminal) + if (control->SubType() != USB_AUDIO_AC_INPUT_TERMINAL) break; // USB I/O terminal is a not good candidate to use it's name @@ -560,7 +634,7 @@ FeatureUnit::Name() // check if output of this FU is connected to output terminal control = fInterface->FindOutputTerminal(fID); while (control != 0) { - if (control->SubType() != IDSOutputTerminal) + if (control->SubType() != USB_AUDIO_AC_OUTPUT_TERMINAL) break; // USB I/O terminal is a not good candidate to use it's name @@ -601,21 +675,21 @@ FeatureUnit::NormalizeAndTraceChannel(int32 Channel) uint32 rev2Bits; const char* name; } remapInfos[] = { - { MuteControl1, MuteControl, "Mute" }, - { VolumeControl1, VolumeControl, "Volume" }, - { BassControl1, BassControl, "Bass" }, - { MidControl1, MidControl, "Mid" }, - { TrebleControl1, TrebleControl, "Treble" }, - { GraphEqControl1, GraphEqControl, "Graphic Equalizer" }, - { AutoGainControl1, AutoGainControl, "Automatic Gain" }, - { DelayControl1, DelayControl, "Delay" }, - { BassBoostControl1, BassBoostControl, "Bass Boost" }, - { LoudnessControl1, LoudnessControl, "Loudness" }, - { 0, InputGainControl, "InputGain" }, - { 0, InputGainPadControl, "InputGainPad" }, - { 0, PhaseInverterControl, "PhaseInverter" }, - { 0, UnderflowControl, "Underflow" }, - { 0, OverflowControl, "Overflow" } + { BMA_CTL_MUTE_R1, BMA_CTL_MUTE, "Mute" }, + { BMA_CTL_VOLUME_R1, BMA_CTL_VOLUME, "Volume" }, + { BMA_CTL_BASS_R1, BMA_CTL_BASS, "Bass" }, + { BMA_CTL_MID_R1, BMA_CTL_MID, "Mid" }, + { BMA_CTL_TREBLE_R1, BMA_CTL_TREBLE, "Treble" }, + { BMA_CTL_GRAPHEQ_R1, BMA_CTL_GRAPHEQ, "Graphic Equalizer" }, + { BMA_CTL_AUTOGAIN_R1, BMA_CTL_AUTOGAIN, "Automatic Gain"}, + { BMA_CTL_DELAY_R1, BMA_CTL_DELAY, "Delay" }, + { BMA_CTL_BASSBOOST_R1, BMA_CTL_BASSBOOST, "Bass Boost" }, + { BMA_CTL_LOUDNESS_R1, BMA_CTL_LOUDNESS, "Loudness" }, + { 0, BMA_CTL_INPUTGAIN, "InputGain" }, + { 0, BMA_CTL_INPUTGAINPAD, "InputGainPad" }, + { 0, BMA_CTL_PHASEINVERTER, "PhaseInverter" }, + { 0, BMA_CTL_UNDERFLOW, "Underflow" }, + { 0, BMA_CTL_OVERFLOW, "Overflow" } }; if (Channel == 0) @@ -647,8 +721,8 @@ EffectUnit::EffectUnit(AudioControlInterface* interface, : _AudioControl(interface, Header) { - usb_input_terminal_descriptor* D - = (usb_input_terminal_descriptor*) Header; + usb_audio_input_terminal_descriptor* D + = (usb_audio_input_terminal_descriptor*) Header; TRACE("Effect Unit:%d >>>\n", D->terminal_id); } @@ -665,8 +739,8 @@ ProcessingUnit::ProcessingUnit(AudioControlInterface* interface, fProcessType(0), fControlsBitmap(0) { - usb_processing_unit_descriptor* Processing - = (usb_processing_unit_descriptor*) Header; + usb_audio_processing_unit_descriptor* Processing + = (usb_audio_processing_unit_descriptor*) Header; fID = Processing->unit_id; TRACE("Processing ID:%d >>>\n", fID); @@ -681,16 +755,16 @@ ProcessingUnit::ProcessingUnit(AudioControlInterface* interface, } if (fInterface->SpecReleaseNumber() < 0x200) { - usb_output_channels_descriptor_r1* OutChannels - = (usb_output_channels_descriptor_r1*) + usb_audio_output_channels_descriptor_r1* OutChannels + = (usb_audio_output_channels_descriptor_r1*) &Processing->input_pins[Processing->num_input_pins]; fOutChannelsNumber = OutChannels->num_output_pins; fChannelsConfig = OutChannels->channel_config; fChannelNames = OutChannels->channel_names; } else { - usb_output_channels_descriptor* OutChannels - = (usb_output_channels_descriptor*) + usb_audio_output_channels_descriptor* OutChannels + = (usb_audio_output_channels_descriptor*) &Processing->input_pins[Processing->num_input_pins]; fOutChannelsNumber = OutChannels->num_output_pins; @@ -732,8 +806,8 @@ ExtensionUnit::ExtensionUnit(AudioControlInterface* interface, fExtensionCode(0), fControlsBitmap(0) { - usb_extension_unit_descriptor* Extension - = (usb_extension_unit_descriptor*) Header; + usb_audio_extension_unit_descriptor* Extension + = (usb_audio_extension_unit_descriptor*) Header; fID = Extension->unit_id; TRACE("Extension ID:%d >>>\n", fID); @@ -748,16 +822,16 @@ ExtensionUnit::ExtensionUnit(AudioControlInterface* interface, } if (fInterface->SpecReleaseNumber() < 0x200) { - usb_output_channels_descriptor_r1* OutChannels - = (usb_output_channels_descriptor_r1*) + usb_audio_output_channels_descriptor_r1* OutChannels + = (usb_audio_output_channels_descriptor_r1*) &Extension->input_pins[Extension->num_input_pins]; fOutChannelsNumber = OutChannels->num_output_pins; fChannelsConfig = OutChannels->channel_config; fChannelNames = OutChannels->channel_names; } else { - usb_output_channels_descriptor* OutChannels - = (usb_output_channels_descriptor*) + usb_audio_output_channels_descriptor* OutChannels + = (usb_audio_output_channels_descriptor*) &Extension->input_pins[Extension->num_input_pins]; fOutChannelsNumber = OutChannels->num_output_pins; @@ -797,8 +871,8 @@ ClockSource::ClockSource(AudioControlInterface* interface, : _AudioControl(interface, Header) { - usb_input_terminal_descriptor* D - = (usb_input_terminal_descriptor*) Header; + usb_audio_input_terminal_descriptor* D + = (usb_audio_input_terminal_descriptor*) Header; TRACE("Clock Source:%d >>>\n", D->terminal_id); } @@ -813,8 +887,8 @@ ClockSelector::ClockSelector(AudioControlInterface* interface, : _AudioControl(interface, Header) { - usb_input_terminal_descriptor* D - = (usb_input_terminal_descriptor*) Header; + usb_audio_input_terminal_descriptor* D + = (usb_audio_input_terminal_descriptor*) Header; TRACE("Clock Selector:%d >>>\n", D->terminal_id); } @@ -829,8 +903,8 @@ ClockMultiplier::ClockMultiplier(AudioControlInterface* interface, : _AudioControl(interface, Header) { - usb_input_terminal_descriptor* D - = (usb_input_terminal_descriptor*) Header; + usb_audio_input_terminal_descriptor* D + = (usb_audio_input_terminal_descriptor*) Header; TRACE("Clock Multiplier:%d >>>\n", D->terminal_id); } @@ -845,8 +919,8 @@ SampleRateConverter::SampleRateConverter(AudioControlInterface* interface, : _AudioControl(interface, Header) { - usb_input_terminal_descriptor* D - = (usb_input_terminal_descriptor*) Header; + usb_audio_input_terminal_descriptor* D + = (usb_audio_input_terminal_descriptor*) Header; TRACE("Sample Rate Converter:%d >>>\n", D->terminal_id); } @@ -891,7 +965,7 @@ AudioControlInterface::Init(size_t interface, usb_interface_info* Interface) usb_audiocontrol_header_descriptor* Header = (usb_audiocontrol_header_descriptor* )Interface->generic[i]; - if (Header->descriptor_type != AC_CS_INTERFACE) { + if (Header->descriptor_type != USB_AUDIO_CS_INTERFACE) { TRACE_ALWAYS("Ignore Audio Control of " "unknown descriptor type %#04x.\n", Header->descriptor_type); continue; @@ -904,62 +978,62 @@ AudioControlInterface::Init(size_t interface, usb_interface_info* Interface) TRACE_ALWAYS("Ignore Audio Control of unknown " "descriptor sub-type %#04x\n", Header->descriptor_subtype); break; - case IDSUndefined: + case USB_AUDIO_AC_DESCRIPTOR_UNDEFINED: TRACE_ALWAYS("Ignore Audio Control of undefined sub-type\n"); break; - case IDSHeader: + case USB_AUDIO_AC_HEADER: InitACHeader(interface, Header); break; - case IDSInputTerminal: + case USB_AUDIO_AC_INPUT_TERMINAL: control = new InputTerminal(this, Header); break; - case IDSOutputTerminal: + case USB_AUDIO_AC_OUTPUT_TERMINAL: control = new OutputTerminal(this, Header); break; - case IDSMixerUnit: + case USB_AUDIO_AC_MIXER_UNIT: control = new MixerUnit(this, Header); break; - case IDSSelectorUnit: + case USB_AUDIO_AC_SELECTOR_UNIT: control = new SelectorUnit(this, Header); break; - case IDSFeatureUnit: + case USB_AUDIO_AC_FEATURE_UNIT: control = new FeatureUnit(this, Header); break; - case IDSEffectUnit: + case USB_AUDIO_AC_PROCESSING_UNIT: if (SpecReleaseNumber() < 200) control = new ProcessingUnit(this, Header); else control = new EffectUnit(this, Header); break; - case IDSProcessingUnit: + case USB_AUDIO_AC_EXTENSION_UNIT: if (SpecReleaseNumber() < 200) control = new ExtensionUnit(this, Header); else control = new ProcessingUnit(this, Header); break; - case IDSExtensionUnit: + case USB_AUDIO_AC_EXTENSION_UNIT_R2: control = new ExtensionUnit(this, Header); break; - case IDSClockSource: + case USB_AUDIO_AC_CLOCK_SOURCE_R2: control = new ClockSource(this, Header); break; - case IDSClockSelector: + case USB_AUDIO_AC_CLOCK_SELECTOR_R2: control = new ClockSelector(this, Header); break; - case IDSClockMultiplier: + case USB_AUDIO_AC_CLOCK_MULTIPLIER_R2: control = new ClockMultiplier(this, Header); break; - case IDSSampleRateConverter: + case USB_AUDIO_AC_SAMPLE_RATE_CONVERTER_R2: control = new SampleRateConverter(this, Header); break; } if (control != 0 && control->InitCheck() == B_OK) { switch(control->SubType()) { - case IDSOutputTerminal: + case USB_AUDIO_AC_OUTPUT_TERMINAL: fOutputTerminals.Put(control->SourceID(), control); break; - case IDSInputTerminal: + case USB_AUDIO_AC_INPUT_TERMINAL: fInputTerminals.Put(control->ID(), control); break; } @@ -1000,17 +1074,14 @@ AudioControlInterface::InitACHeader(size_t interface, TRACE("ADCSpecification:%#06x\n", fADCSpecification); if (fADCSpecification < 0x200) { - usb_audiocontrol_header_descriptor_r1* Header1 - = (usb_audiocontrol_header_descriptor_r1*) Header; - - TRACE("InterfacesCount:%d\n", Header1->in_collection); - for (size_t i = 0; i < Header1->in_collection; i++) { - fStreams.PushBack(Header1->interface_numbers[i]); + TRACE("InterfacesCount:%d\n", Header->r1.in_collection); + for (size_t i = 0; i < Header->r1.in_collection; i++) { + fStreams.PushBack(Header->r1.interface_numbers[i]); TRACE("Interface[%d] number is %d\n", i, fStreams[i]); } } else { - fFunctionCategory = Header->function_category; - fControlsBitmap = Header->bm_controls; + fFunctionCategory = Header->r2.function_category; + fControlsBitmap = Header->r2.bm_controls; TRACE("Function Category:%#04x\n", fFunctionCategory); TRACE("Controls Bitmap:%#04x\n", fControlsBitmap); } @@ -1028,12 +1099,13 @@ AudioControlInterface::GetChannelsDescription( // multi_channel_info* Channels = Description->channels; for (int32 i = 0; i < Terminals.Count(); i++) { - bool bIsInputTerminal = Terminals[i]->SubType() == IDSInputTerminal; + bool bIsInputTerminal + = Terminals[i]->SubType() == USB_AUDIO_AC_INPUT_TERMINAL; AudioChannelCluster* cluster = Terminals[i]->OutCluster(); if (cluster == 0 || cluster->ChannelsCount() <= 0) { TRACE_ALWAYS("Terminal #%d ignored due null " - "channels cluster (%08x)\n", Terminals[i]->ID(), cluster); + "channels cluster (%08x)\n", Terminals[i]->ID(), cluster); continue; } @@ -1130,12 +1202,12 @@ AudioControlInterface::GetBusChannelsDescription( AudioChannelCluster* cluster = control->OutCluster(); if (cluster == 0 || cluster->ChannelsCount() <= 0) { TRACE_ALWAYS("Terminal #%d ignored due null " - "channels cluster (%08x)\n", control->ID(), cluster); + "channels cluster (%08x)\n", control->ID(), cluster); continue; } uint32 channels = GetTerminalChannels(Channels, - cluster, B_MULTI_OUTPUT_BUS); + cluster, B_MULTI_OUTPUT_BUS); Description->output_bus_channel_count += channels; addedChannels += channels; @@ -1151,7 +1223,7 @@ AudioControlInterface::GetBusChannelsDescription( AudioChannelCluster* cluster = control->OutCluster(); if (cluster == 0 || cluster->ChannelsCount() <= 0) { TRACE_ALWAYS("Terminal #%d ignored due null " - "channels cluster (%08x)\n", control->ID(), cluster); + "channels cluster (%08x)\n", control->ID(), cluster); continue; } @@ -1176,21 +1248,20 @@ AudioControlInterface::_HarvestRecordFeatureUnits(_AudioControl* rootControl, } switch(rootControl->SubType()) { - case IDSOutputTerminal: + case USB_AUDIO_AC_OUTPUT_TERMINAL: // _HarvestRecordFeatureUnits(Find(rootControl->SourceID()), Map); break; - case IDSSelectorUnit: + case USB_AUDIO_AC_SELECTOR_UNIT: { SelectorUnit* unit = static_cast(rootControl); for (int i = 0; i < unit->fInputPins.Count(); i++) _HarvestRecordFeatureUnits(Find(unit->fInputPins[i]), Map); - Map.Put(rootControl->ID(), rootControl); } break; - case IDSFeatureUnit: + case USB_AUDIO_AC_FEATURE_UNIT: Map.Put(rootControl->ID(), rootControl); break; } @@ -1205,9 +1276,9 @@ AudioControlInterface::_InitGainLimits(multi_mix_control& Control) int16 data; float& value; } gainInfos[] = { - { UAS_GET_MIN, 0, Control.gain.min_gain }, - { UAS_GET_MAX, 0, Control.gain.max_gain }, - { UAS_GET_RES, 0, Control.gain.granularity } + { USB_AUDIO_GET_MIN, 0, Control.gain.min_gain }, + { USB_AUDIO_GET_MAX, 0, Control.gain.max_gain }, + { USB_AUDIO_GET_RES, 0, Control.gain.granularity } }; Control.gain.min_gain = 0.; @@ -1249,19 +1320,19 @@ AudioControlInterface::_ListFeatureUnitOption(uint32 controlType, bool initGainLimits = false; switch(controlType) { - case MuteControl: - id = UAS_MUTE_CONTROL; + case BMA_CTL_MUTE: + id = USB_AUDIO_MUTE_CONTROL; flags = B_MULTI_MIX_ENABLE; string = S_MUTE; break; - case VolumeControl: - id = UAS_VOLUME_CONTROL; + case BMA_CTL_VOLUME: + id = USB_AUDIO_VOLUME_CONTROL; flags = B_MULTI_MIX_GAIN; string = S_GAIN; initGainLimits = true; break; - case AutoGainControl: - id = UAS_AUTOMATIC_GAIN_CONTROL; + case BMA_CTL_AUTOGAIN: + id = USB_AUDIO_AUTOMATIC_GAIN_CONTROL; flags = B_MULTI_MIX_ENABLE; name = "Auto Gain"; break; @@ -1379,18 +1450,18 @@ AudioControlInterface::_ListFeatureUnitControl(int32& index, int32 parentIndex, } // First list possible Mute controls - _ListFeatureUnitOption(MuteControl, index, groupIndex, Info, + _ListFeatureUnitOption(BMA_CTL_MUTE, index, groupIndex, Info, unit, channel, channelInfos[i].channels); // Gain controls may be usefull too - if (_ListFeatureUnitOption(VolumeControl, index, groupIndex, Info, + if (_ListFeatureUnitOption(BMA_CTL_VOLUME, index, groupIndex, Info, unit, channel, channelInfos[i].channels) == 0) { masterIndex = (i == 0) ? groupIndex : 0 ; TRACE("channel:%d set master index to %d\n", channel, masterIndex); } // Auto Gain checkbox will be listed too - _ListFeatureUnitOption(AutoGainControl, index, groupIndex, Info, + _ListFeatureUnitOption(BMA_CTL_AUTOGAIN, index, groupIndex, Info, unit, channel, channelInfos[i].channels); // Now check if the group filled with something usefull. @@ -1427,7 +1498,7 @@ AudioControlInterface::_ListSelectorUnitControl(int32& index, int32 parentGroup, multi_mix_control_info* Info, _AudioControl* control) { SelectorUnit* selector = static_cast(control); - if (selector == 0 || selector->SubType() != IDSSelectorUnit) + if (selector == 0 || selector->SubType() != USB_AUDIO_AC_SELECTOR_UNIT) return; multi_mix_control* Controls = Info->controls; @@ -1474,11 +1545,11 @@ AudioControlInterface::_ListMixControlsPage(int32& index, for (AudioControlsIterator I = Map.Begin(); I != Map.End(); I++) { TRACE("%s control %d listed.\n", Name, I->Value()->ID()); switch(I->Value()->SubType()) { - case IDSFeatureUnit: + case USB_AUDIO_AC_FEATURE_UNIT: group = _ListFeatureUnitControl(index, groupIndex, Info, I->Value()); break; - case IDSSelectorUnit: + case USB_AUDIO_AC_SELECTOR_UNIT: _ListSelectorUnitControl(index, group, Info, I->Value()); break; } @@ -1506,7 +1577,7 @@ AudioControlInterface::ListMixControls(multi_mix_control_info* Info) I != fAudioControls.End(); I++) { _AudioControl* control = I->Value(); // filter out feature units - if (control->SubType() != IDSFeatureUnit) + if (control->SubType() != USB_AUDIO_AC_FEATURE_UNIT) continue; // ignore controls that are already in the record controls map @@ -1514,7 +1585,8 @@ AudioControlInterface::ListMixControls(multi_mix_control_info* Info) continue; _AudioControl* sourceControl = Find(control->SourceID()); - if (sourceControl != 0 && sourceControl->SubType() == IDSInputTerminal) + if (sourceControl != 0 + && sourceControl->SubType() == USB_AUDIO_AC_INPUT_TERMINAL) InputControlsMap.Put(control->ID(), control); else OutputControlsMap.Put(control->ID(), control); @@ -1541,12 +1613,12 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info) uint16 length = 0; int16 data = 0; switch(CS_FROM_CTLID(Info->values[i].id)) { - case UAS_VOLUME_CONTROL: + case USB_AUDIO_VOLUME_CONTROL: length = 2; break; case 0: // Selector Unit - case UAS_MUTE_CONTROL: - case UAS_AUTOMATIC_GAIN_CONTROL: + case USB_AUDIO_MUTE_CONTROL: + case USB_AUDIO_AUTOMATIC_GAIN_CONTROL: length = 1; break; default: @@ -1557,7 +1629,7 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info) size_t actualLength = 0; status_t status = gUSBModule->send_request(fDevice->USBDevice(), - USB_REQTYPE_INTERFACE_IN | USB_REQTYPE_CLASS, UAS_GET_CUR, + USB_REQTYPE_INTERFACE_IN | USB_REQTYPE_CLASS, USB_AUDIO_GET_CUR, REQ_VALUE(Info->values[i].id), REQ_INDEX(Info->values[i].id), length, &data, &actualLength); @@ -1568,21 +1640,21 @@ AudioControlInterface::GetMix(multi_mix_value_info* Info) } switch(CS_FROM_CTLID(Info->values[i].id)) { - case UAS_VOLUME_CONTROL: + case USB_AUDIO_VOLUME_CONTROL: Info->values[i].gain = static_cast(data) / 256.; TRACE("Gain control %d; channel: %d; is %f dB.\n", ID_FROM_CTLID(Info->values[i].id), CN_FROM_CTLID(Info->values[i].id), Info->values[i].gain); break; - case UAS_MUTE_CONTROL: + case USB_AUDIO_MUTE_CONTROL: Info->values[i].enable = data > 0; TRACE("Mute control %d; channel: %d; is %d.\n", ID_FROM_CTLID(Info->values[i].id), CN_FROM_CTLID(Info->values[i].id), Info->values[i].enable); break; - case UAS_AUTOMATIC_GAIN_CONTROL: + case USB_AUDIO_AUTOMATIC_GAIN_CONTROL: Info->values[i].enable = data > 0; TRACE("AGain control %d; channel: %d; is %d.\n", ID_FROM_CTLID(Info->values[i].id), @@ -1612,7 +1684,7 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info) int16 data = 0; switch(CS_FROM_CTLID(Info->values[i].id)) { - case UAS_VOLUME_CONTROL: + case USB_AUDIO_VOLUME_CONTROL: data = static_cast(Info->values[i].gain * 256.); length = 2; TRACE("Gain control %d; channel: %d; about to set to %f dB.\n", @@ -1620,7 +1692,7 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info) CN_FROM_CTLID(Info->values[i].id), Info->values[i].gain); break; - case UAS_MUTE_CONTROL: + case USB_AUDIO_MUTE_CONTROL: data = (Info->values[i].enable ? 1 : 0); length = 1; TRACE("Mute control %d; channel: %d; about to set to %d.\n", @@ -1628,7 +1700,7 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info) CN_FROM_CTLID(Info->values[i].id), Info->values[i].enable); break; - case UAS_AUTOMATIC_GAIN_CONTROL: + case USB_AUDIO_AUTOMATIC_GAIN_CONTROL: data = (Info->values[i].enable ? 1 : 0); length = 1; TRACE("AGain control %d; channel: %d; about to set to %d.\n", @@ -1651,7 +1723,7 @@ AudioControlInterface::SetMix(multi_mix_value_info* Info) size_t actualLength = 0; status_t status = gUSBModule->send_request(fDevice->USBDevice(), - USB_REQTYPE_INTERFACE_OUT | USB_REQTYPE_CLASS, UAS_SET_CUR, + USB_REQTYPE_INTERFACE_OUT | USB_REQTYPE_CLASS, USB_AUDIO_SET_CUR, REQ_VALUE(Info->values[i].id), REQ_INDEX(Info->values[i].id), length, &data, &actualLength); diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.h b/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.h index 016f864f05..5df574bd6b 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.h +++ b/src/add-ons/kernel/drivers/audio/usb_audio/AudioControlInterface.h @@ -8,11 +8,10 @@ #define _AUDIO_CONTROL_INTERFACE_H_ -#include "USB_audio_spec.h" -#include - -#include #include +#include +#include +#include class Device; diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.cpp b/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.cpp index 250f193461..01911d04a2 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.cpp +++ b/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.cpp @@ -1,6 +1,6 @@ /* * Driver for USB Audio Device Class devices. - * Copyright (c) 2009,10,12 S.Zharski + * Copyright (c) 2009-13 S.Zharski * Distributed under the tems of the MIT license. * */ @@ -8,8 +8,8 @@ #include "AudioStreamingInterface.h" +#include -#include "audio.h" #include "Driver.h" #include "Settings.h" @@ -42,15 +42,16 @@ static struct RatePair { // // ASInterfaceDescriptor::ASInterfaceDescriptor( - usb_as_interface_descriptor_r1* Descriptor) + usb_audio_streaming_interface_descriptor* Descriptor) : fTerminalLink(0), fDelay(0), fFormatTag(0) { +// TODO: what aboput rev 2??????? fTerminalLink = Descriptor->terminal_link; - fDelay = Descriptor->delay; - fFormatTag = Descriptor->format_tag; + fDelay = Descriptor->r1.delay; + fFormatTag = Descriptor->r1.format_tag; TRACE("fTerminalLink:%d\n", fTerminalLink); TRACE("fDelay:%d\n", fDelay); @@ -66,7 +67,7 @@ ASInterfaceDescriptor::~ASInterfaceDescriptor() ASEndpointDescriptor::ASEndpointDescriptor(usb_endpoint_descriptor* Endpoint, - usb_as_cs_endpoint_descriptor* Descriptor) + usb_audio_streaming_endpoint_descriptor* Descriptor) : fCSAttributes(0), fLockDelayUnits(0), @@ -75,9 +76,6 @@ ASEndpointDescriptor::ASEndpointDescriptor(usb_endpoint_descriptor* Endpoint, fEndpointAddress(0), fEndpointAttributes(0) { -// usb_audiocontrol_header_descriptor* Header -// = (usb_audiocontrol_header_descriptor*)Interface->generic[i]; - fCSAttributes = Descriptor->attributes; fLockDelayUnits = Descriptor->lock_delay_units; fLockDelay = Descriptor->lock_delay; @@ -102,9 +100,9 @@ ASEndpointDescriptor::~ASEndpointDescriptor() _ASFormatDescriptor::_ASFormatDescriptor( - usb_type_I_format_descriptor* Descriptor) + usb_audio_format_descriptor* Descriptor) : - fFormatType(UAF_FORMAT_TYPE_UNDEFINED) + fFormatType(USB_AUDIO_FORMAT_TYPE_UNDEFINED) { fFormatType = Descriptor->format_type; } @@ -116,14 +114,29 @@ _ASFormatDescriptor::~_ASFormatDescriptor() uint32 -_ASFormatDescriptor::GetSamFreq(uint8* freq) +_ASFormatDescriptor::GetSamFreq(const usb_audio_sampling_freq& freq) { - return freq[0] | freq[1] << 8 | freq[2] << 16; + return freq.bytes[0] | freq.bytes[1] << 8 | freq.bytes[2] << 16; +} + +// TODO: beautify!!! +usb_audio_sampling_freq +_ASFormatDescriptor::GetSamFreq(uint32 samplingRate) +{ + usb_audio_sampling_freq freq; + for (size_t i = 0; i < 3; i++) + freq.bytes[i] = 0xFF & samplingRate >> 8 * i; + +// return freq.bytes[0] | freq.bytes[1] << 8 | freq.bytes[2] << 16; +/* data[0] = 0xFF & samplingRate; + data[1] = 0xFF & samplingRate >> 8; + data[2] = 0xFF & samplingRate >> 16; */ + return freq; } TypeIFormatDescriptor::TypeIFormatDescriptor( - usb_type_I_format_descriptor* Descriptor) + usb_audio_format_descriptor* Descriptor) : _ASFormatDescriptor(Descriptor), fNumChannels(0), @@ -141,22 +154,22 @@ TypeIFormatDescriptor::~TypeIFormatDescriptor() status_t -TypeIFormatDescriptor::Init(usb_type_I_format_descriptor* Descriptor) +TypeIFormatDescriptor::Init(usb_audio_format_descriptor* Descriptor) { - fNumChannels = Descriptor->nr_channels; - fSubframeSize = Descriptor->subframe_size; - fBitResolution = Descriptor->bit_resolution; - fSampleFrequencyType = Descriptor->sam_freq_type; + fNumChannels = Descriptor->typeI.nr_channels; + fSubframeSize = Descriptor->typeI.subframe_size; + fBitResolution = Descriptor->typeI.bit_resolution; + fSampleFrequencyType = Descriptor->typeI.sam_freq_type; if (fSampleFrequencyType == 0) { fSampleFrequencies.PushBack( - GetSamFreq(Descriptor->sf.cont.lower_sam_freq)); + GetSamFreq(Descriptor->typeI.sam_freqs[0])); fSampleFrequencies.PushBack( - GetSamFreq(Descriptor->sf.cont.upper_sam_freq)); + GetSamFreq(Descriptor->typeI.sam_freqs[1])); } else for (size_t i = 0; i < fSampleFrequencyType; i++) fSampleFrequencies.PushBack( - GetSamFreq(Descriptor->sf.discr.sam_freq[i])); + GetSamFreq(Descriptor->typeI.sam_freqs[i])); TRACE("fNumChannels:%d\n", fNumChannels); TRACE("fSubframeSize:%d\n", fSubframeSize); @@ -171,9 +184,9 @@ TypeIFormatDescriptor::Init(usb_type_I_format_descriptor* Descriptor) TypeIIFormatDescriptor::TypeIIFormatDescriptor( - usb_type_II_format_descriptor* Descriptor) + usb_audio_format_descriptor* Descriptor) : - _ASFormatDescriptor((usb_type_I_format_descriptor*)Descriptor), + _ASFormatDescriptor(Descriptor), fMaxBitRate(0), fSamplesPerFrame(0), fSampleFrequencyType(0), @@ -188,9 +201,9 @@ TypeIIFormatDescriptor::~TypeIIFormatDescriptor() TypeIIIFormatDescriptor::TypeIIIFormatDescriptor( - usb_type_III_format_descriptor* Descriptor) + usb_audio_format_descriptor* Descriptor) : - TypeIFormatDescriptor((usb_type_I_format_descriptor*)Descriptor) + TypeIFormatDescriptor(Descriptor) { } @@ -326,9 +339,13 @@ AudioStreamAlternate::GetFormatId() uint32 formats = 0; switch (Interface()->fFormatTag) { - case UAF_PCM8: formats = B_FMT_8BIT_U; break; - case UAF_IEEE_FLOAT: formats = B_FMT_FLOAT; break; - case UAF_PCM: + case USB_AUDIO_FORMAT_PCM8: + formats = B_FMT_8BIT_U; + break; + case USB_AUDIO_FORMAT_IEEE_FLOAT: + formats = B_FMT_FLOAT; + break; + case USB_AUDIO_FORMAT_PCM: switch(format->fBitResolution) { case 8: formats = B_FMT_8BIT_S; break; case 16: formats = B_FMT_16BIT; break; @@ -404,19 +421,19 @@ AudioStreamingInterface::AudioStreamingInterface( usb_audiocontrol_header_descriptor* Header = (usb_audiocontrol_header_descriptor*)Interface->generic[i]; - if (Header->descriptor_type == AC_CS_INTERFACE) { + if (Header->descriptor_type == USB_AUDIO_CS_INTERFACE) { switch(Header->descriptor_subtype) { - case UAS_AS_GENERAL: + case USB_AUDIO_AS_GENERAL: if (ASInterface == 0) ASInterface = new ASInterfaceDescriptor( - (usb_as_interface_descriptor_r1*) Header); + (usb_audio_streaming_interface_descriptor*)Header); else TRACE_ALWAYS("Duplicate AStream interface ignored.\n"); break; - case UAS_FORMAT_TYPE: + case USB_AUDIO_AS_FORMAT_TYPE: if (ASFormat == 0) ASFormat = new TypeIFormatDescriptor( - (usb_type_I_format_descriptor*) Header); + (usb_audio_format_descriptor*) Header); else TRACE_ALWAYS("Duplicate AStream format ignored.\n"); break; @@ -428,12 +445,12 @@ AudioStreamingInterface::AudioStreamingInterface( continue; } - if (Header->descriptor_type == AC_CS_ENDPOINT) { + if (Header->descriptor_type == USB_AUDIO_CS_ENDPOINT) { if (ASEndpoint == 0) { usb_endpoint_descriptor* Endpoint = Interface->endpoint[0].descr; ASEndpoint = new ASEndpointDescriptor(Endpoint, - (usb_as_cs_endpoint_descriptor*)Header); + (usb_audio_streaming_endpoint_descriptor*)Header); } else TRACE_ALWAYS("Duplicate AStream endpoint ignored.\n"); continue; diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.h b/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.h index d747b58c8b..9d6c3b40e9 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.h +++ b/src/add-ons/kernel/drivers/audio/usb_audio/AudioStreamingInterface.h @@ -8,17 +8,17 @@ #define _AUDIO_STREAMING_INTERFACE_H_ -#include #include +#include #include "AudioControlInterface.h" -#include "USB_audio_spec.h" class ASInterfaceDescriptor { public: ASInterfaceDescriptor( - usb_as_interface_descriptor_r1* Descriptor); + usb_audio_streaming_interface_descriptor* + Descriptor); ~ASInterfaceDescriptor(); // protected: @@ -32,7 +32,8 @@ class ASEndpointDescriptor { public: ASEndpointDescriptor( usb_endpoint_descriptor* Endpoint, - usb_as_cs_endpoint_descriptor* Descriptor); + usb_audio_streaming_endpoint_descriptor* + Descriptor); ~ASEndpointDescriptor(); // protected: @@ -48,22 +49,23 @@ public: class _ASFormatDescriptor { public: _ASFormatDescriptor( - usb_type_I_format_descriptor* Descriptor); + usb_audio_format_descriptor* Descriptor); virtual ~_ASFormatDescriptor(); // protected: uint8 fFormatType; - uint32 GetSamFreq(uint8* freq); + static uint32 GetSamFreq(const usb_audio_sampling_freq& freq); + static usb_audio_sampling_freq GetSamFreq(uint32 rate); }; class TypeIFormatDescriptor : public _ASFormatDescriptor { public: TypeIFormatDescriptor( - usb_type_I_format_descriptor* Descriptor); + usb_audio_format_descriptor* Descriptor); virtual ~TypeIFormatDescriptor(); - status_t Init(usb_type_I_format_descriptor* Descriptor); + status_t Init(usb_audio_format_descriptor* Descriptor); // protected: uint8 fNumChannels; @@ -77,7 +79,7 @@ public: class TypeIIFormatDescriptor : public _ASFormatDescriptor { public: TypeIIFormatDescriptor( - usb_type_II_format_descriptor* Descriptor); + usb_audio_format_descriptor* Descriptor); virtual ~TypeIIFormatDescriptor(); // protected: @@ -91,7 +93,7 @@ public: class TypeIIIFormatDescriptor : public TypeIFormatDescriptor { public: TypeIIIFormatDescriptor( - usb_type_III_format_descriptor* Descriptor); + usb_audio_format_descriptor* Descriptor); virtual ~TypeIIIFormatDescriptor(); // protected: diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/Device.cpp b/src/add-ons/kernel/drivers/audio/usb_audio/Device.cpp index 46e8a56da5..98d231f705 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/Device.cpp +++ b/src/add-ons/kernel/drivers/audio/usb_audio/Device.cpp @@ -8,6 +8,8 @@ #include "Device.h" +#include + #include "Driver.h" #include "Settings.h" @@ -572,14 +574,14 @@ Device::_SetupEndpoints() for (size_t i = 0; i < config->interface_count; i++) { usb_interface_info* Interface = config->interface[i].active; - if (Interface->descr->interface_class != UAS_AUDIO) + if (Interface->descr->interface_class != USB_AUDIO_INTERFACE_AUDIO_CLASS) continue; switch (Interface->descr->interface_subclass) { - case UAS_AUDIOCONTROL: + case USB_AUDIO_INTERFACE_AUDIOCONTROL_SUBCLASS: fAudioControl.Init(i, Interface); break; - case UAS_AUDIOSTREAMING: + case USB_AUDIO_INTERFACE_AUDIOSTREAMING_SUBCLASS: { Stream* stream = new Stream(this, i, &config->interface[i]); if (B_OK == stream->Init()) { diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/Driver.cpp b/src/add-ons/kernel/drivers/audio/usb_audio/Driver.cpp index 95067f6b6a..f8acd6ee5a 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/Driver.cpp +++ b/src/add-ons/kernel/drivers/audio/usb_audio/Driver.cpp @@ -8,6 +8,7 @@ #include "Driver.h" #include +#include #include "Device.h" #include "Settings.h" @@ -135,7 +136,7 @@ init_driver() }; static usb_support_descriptor supportedDevices[] = { - { UAS_AUDIO, 0, 0, 0, 0 } + { USB_AUDIO_INTERFACE_AUDIO_CLASS, 0, 0, 0, 0 } }; gUSBModule->register_driver(DRIVER_NAME, supportedDevices, 0, NULL); diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/Stream.cpp b/src/add-ons/kernel/drivers/audio/usb_audio/Stream.cpp index ad9578374c..232b666d4c 100644 --- a/src/add-ons/kernel/drivers/audio/usb_audio/Stream.cpp +++ b/src/add-ons/kernel/drivers/audio/usb_audio/Stream.cpp @@ -8,6 +8,7 @@ #include "Stream.h" +#include #include "Device.h" #include "Driver.h" @@ -57,18 +58,19 @@ Stream::_ChooseAlternate() continue; } - if (fAlternates[i]->Format()->fFormatType != UAF_FORMAT_TYPE_I) { + if (fAlternates[i]->Format()->fFormatType + != USB_AUDIO_FORMAT_TYPE_I) { TRACE("Ignore alternate %d - format type %#02x is not supported.\n", i, fAlternates[i]->Format()->fFormatType); continue; } switch (fAlternates[i]->Interface()->fFormatTag) { - case UAF_PCM: - case UAF_PCM8: - case UAF_IEEE_FLOAT: - // case UAF_ALAW: - // case UAF_MULAW: + case USB_AUDIO_FORMAT_PCM: + case USB_AUDIO_FORMAT_PCM8: + case USB_AUDIO_FORMAT_IEEE_FLOAT: + // case USB_AUDIO_FORMAT_ALAW: + // case USB_AUDIO_FORMAT_MULAW: break; default: TRACE("Ignore alternate %d - format %#04x is not supported.\n", @@ -85,7 +87,7 @@ Stream::_ChooseAlternate() continue; } - if (fAlternates[i]->Interface()->fFormatTag == UAF_PCM) { + if (fAlternates[i]->Interface()->fFormatTag == USB_AUDIO_FORMAT_PCM) { switch(format->fBitResolution) { default: TRACE("Ignore alternate %d - bit resolution %d " @@ -330,7 +332,6 @@ Stream::_TransferCallback(void* cookie, int32 status, void* data, release_sem_etc(stream->fDevice->fBuffersReadySem, 1, B_DO_NOT_RESCHEDULE); - // TRACE_ALWAYS("st:%#010x, len:%d -> %#010x\n", status, actualLength, result); TRACE("st:%#010x, data:%#010x, len:%d\n", status, data, actualLength); atomic_add(&stream->fInsideNotify, -1); @@ -426,19 +427,19 @@ Stream::SetGlobalFormat(multi_format_info* Format) // set endpoint speed uint32 samplingRate = fAlternates[fActiveAlternate]->GetSamplingRate(); size_t actualLength = 0; - uint8 data[3]; - data[0] = 0xFF & samplingRate; + usb_audio_sampling_freq freq = _ASFormatDescriptor::GetSamFreq(samplingRate); +/* data[0] = 0xFF & samplingRate; data[1] = 0xFF & samplingRate >> 8; - data[2] = 0xFF & samplingRate >> 16; + data[2] = 0xFF & samplingRate >> 16; */ uint8 address = fAlternates[fActiveAlternate]->Endpoint()->fEndpointAddress; status = gUSBModule->send_request(fDevice->fDevice, USB_REQTYPE_CLASS | USB_REQTYPE_ENDPOINT_OUT, - UAS_SET_CUR, UAS_SAMPLING_FREQ_CONTROL << 8, - address, 3, data, &actualLength); + USB_AUDIO_SET_CUR, USB_AUDIO_SAMPLING_FREQ_CONTROL << 8, + address, sizeof(freq), &freq, &actualLength); TRACE_ALWAYS("set_speed %02x%02x%02x for ep %#x %d: %x\n", - data[0], data[1], data[2], + freq.bytes[0], freq.bytes[1], freq.bytes[2], address, actualLength, status); return status; } diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/USB_audio_spec.h b/src/add-ons/kernel/drivers/audio/usb_audio/USB_audio_spec.h deleted file mode 100644 index 6a328c8433..0000000000 --- a/src/add-ons/kernel/drivers/audio/usb_audio/USB_audio_spec.h +++ /dev/null @@ -1,498 +0,0 @@ -/* - * USB audio spec stuctures - * - * Based on the USB Device Class Definition for Audio Devices Release 1.0 - * (March 18, 1998) - * - * And the USB Device Class Definition for Audio Formats Release 1.0 - * (March 18, 1998) - */ -#ifndef __USB_AUDIO_SPEC_H__ -#define __USB_AUDIO_SPEC_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Audio Device Class Codes - */ - -// Audio Control descriptors - -// Audio Control Interface descriptors -#define UAS_AUDIO 0x01 - -#define UAS_SUBCLASS_UNDEFINED 0x00 -#define UAS_AUDIOCONTROL 0x01 -#define UAS_AUDIOSTREAMING 0x02 -#define UAS_MIDISTREAMING 0x03 - -#define UAS_PR_PROTOCOL_UNDEFINED 0x00 - -// Table A-4, page 99 -#define UAS_CS_UNDEFINED 0x20 -#define UAS_CS_DEVICE 0x21 -#define UAS_CS_CONFIGURATION 0x22 -#define UAS_CS_STRING 0x23 -#define UAS_CS_INTERFACE 0x24 -#define UAS_CS_ENDPOINT 0x25 - - -// Audio Function Categories -// Table A-7 page 132 - -enum AudioFunctionCategory { - AFCUndefined = 0x00, - AFCDesktopSpeaker = 0x01, - AFCHomeTheater = 0x02, - AFCMicrophone = 0x03, - AFCHeadset = 0x04, - AFCTelephone = 0x05, - AFCConverter = 0x06, - AFCVoiceRecorder = 0x07, - AFCIOBox = 0x08, - AFCInstrument = 0x09, - AFCProAudio = 0x0a, - AFCAudioVideo = 0x0b, - AFCControlPanel = 0x0c, - AFCOther = 0xff -}; - -/* -// Table A-5, page 100 -#define UAS_AC_DESCRIPTOR_UNDEFINED 0x00 -#define UAS_HEADER 0x01 -#define UAS_INPUT_TERMINAL 0x02 -#define UAS_OUTPUT_TERMINAL 0x03 -#define UAS_MIXER_UNIT 0x04 -#define UAS_SELECTOR_UNIT 0x05 -#define UAS_FEATURE_UNIT 0x06 -#define UAS_PROCESSING_UNIT 0x07 -#define UAS_EXTENSION_UNIT 0x08 -*/ -// Specification Release 2.0 -// Table A-9 page 131 -enum ACInterfaceDescriptorSubtype { - IDSUndefined = 0x00, - IDSHeader = 0x01, - IDSInputTerminal = 0x02, - IDSOutputTerminal = 0x03, - IDSMixerUnit = 0x04, - IDSSelectorUnit = 0x05, - IDSFeatureUnit = 0x06, - IDSEffectUnit = 0x07, - IDSProcessingUnit = 0x08, - IDSExtensionUnit = 0x09, - IDSClockSource = 0x0a, - IDSClockSelector = 0x0b, - IDSClockMultiplier = 0x0c, - IDSSampleRateConverter = 0x0d -}; - -// Table A-6, page 100 -#define UAS_AS_DESCRIPTOR_UNDEFINED 0x00 -#define UAS_AS_GENERAL 0x01 -#define UAS_FORMAT_TYPE 0x02 -#define UAS_FORMAT_SPECIFIC 0x03 - -// Audio Class-Specific Endpoint Descriptor Subtypes -// Table A-8, page 101 -#define UAS_DESCRIPTOR_UNDEFINED 0x00 -#define UAS_EP_GENERAL 0x01 - -// Audio Class-Specific Request Codes -#define UAS_REQUEST_CODE_UNDEFINED 0x00 -#define UAS_SET_CUR 0x01 -#define UAS_GET_CUR 0x81 -#define UAS_SET_MIN 0x02 -#define UAS_GET_MIN 0x82 -#define UAS_SET_MAX 0x0x -#define UAS_GET_MAX 0x83 -#define UAS_SET_RES 0x04 -#define UAS_GET_RES 0x84 -#define UAS_SET_MEM 0x05 -#define UAS_GET_MEM 0x85 -#define UAS_GET_STAT 0xff - -#define UAS_bmReqType_00100001B 0x21 -#define UAS_bmReqType_00100010B 0x22 -#define UAS_bmReqType_10100001B 0xa1 -#define UAS_bmReqType_10100010B 0xa2 - -// Table A-10.2, page 102 -#define UAS_FU_CONTROL_UNDEFINED 0x00 -#define UAS_MUTE_CONTROL 0x01 -#define UAS_VOLUME_CONTROL 0x02 -#define UAS_BASS_CONTROL 0x03 -#define UAS_MID_CONTROL 0x04 -#define UAS_TREBLE_CONTROL 0x05 -#define UAS_GRAPHIC_EQUALIZER_CONTROL 0x06 -#define UAS_AUTOMATIC_GAIN_CONTROL 0x07 -#define UAS_DELAY_CONTROL 0x08 -#define UAS_BASS_BOOST_CONTROL 0x09 -#define UAS_LOUDNESS_CONTROL 0x0a - -// Endpoint control selectors -// Table A-10.5, page 104 -#define UAS_EP_CONTROL_UNDEFINED 0x00 -#define UAS_SAMPLING_FREQ_CONTROL 0x01 -#define UAS_PITCH_CONTROL 0x02 - - -// header descriptor -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // HEADER - uint16 bcd_release_no; // Audio Device Class Specification relno - uint16 total_length; // - uint8 in_collection; // # of audiostreaming units - uint8 interface_numbers[1]; // or more -} _PACKED usb_audiocontrol_header_descriptor_r1; - -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // HEADER - uint16 bcd_release_no; // Audio Device Class Specification relno - uint8 function_category; // this Audio function Category - uint16 total_length; // - uint8 bm_controls; // bitmap of controls -} _PACKED usb_audiocontrol_header_descriptor; - -// input terminal descriptor -// Table 4-3, page 39 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // INPUT_TERMINAL - uint8 terminal_id; // - uint16 terminal_type; // 0x0101 ? - uint8 assoc_terminal; // OT terminal ID of corresponding outp - uint8 num_channels; // stereo = 2 - uint8 channel_config; // spatial location of two channels - // (bitmap 0x03 is plain stereo) - uint8 channel_names; // index of string descr, - // name of first logical channel - uint8 terminal; // index of string descr, - // name of Input Terminal -} _PACKED usb_input_terminal_descriptor_r1; - -// Table 4-9, page 53 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // INPUT_TERMINAL - uint8 terminal_id; // - uint16 terminal_type; // 0x0101 ? - uint8 assoc_terminal; // OT terminal ID of corresponding outp - uint8 clock_source_id; // - uint8 num_channels; // stereo = 2 - uint32 channel_config; // spatial location of two channels - // (bitmap 0x03 is plain stereo) - uint8 channel_names; // index of string descr, - // name of first logical channel - uint16 bm_controls; // - uint8 terminal; // index of string descr, - // name of Input Terminal -} _PACKED usb_input_terminal_descriptor; - -// output terminal descriptor -// Table 4-4, page 40 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // OUTPUT_TERMINAL - uint8 terminal_id; // - uint16 terminal_type; // 0x0101 ? - uint8 assoc_terminal; // OT terminal ID of corresponding outp - uint8 source_id; // ID of the unit or terminal to which - // this terminal is connected - uint8 terminal; // index of string descr, - // name of Input Terminal -} _PACKED usb_output_terminal_descriptor_r1; - -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // OUTPUT_TERMINAL - uint8 terminal_id; // - uint16 terminal_type; // 0x0101 ? - uint8 assoc_terminal; // OT terminal ID of corresponding outp - uint8 source_id; // ID of the unit or terminal to which - // this terminal is connected - uint8 clock_source_id; // - uint16 bm_controls; // - uint8 terminal; // index of string descr, - // name of Input Terminal -} _PACKED usb_output_terminal_descriptor; - - -// mixer unit descriptor -// Table 4-5, page 41 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // MIXER_UNIT - uint8 unit_id; // unique within audio function - uint8 num_input_pins; // - uint8 input_pins[1]; // array of source ids for the mixer - // use usb_output_channels_descriptor - // to parse the rest -} _PACKED usb_mixer_unit_descriptor; - -// pseudo-descriptor for a section corresponding to logical output channels -// used in mixer, processing and extension descriptions. -typedef struct { - uint8 num_output_pins; // number of mixer output pins - uint16 channel_config; // location of logical channels - uint8 channel_names; // id of name string of first logical channel -} _PACKED usb_output_channels_descriptor_r1; - -typedef struct { - uint8 num_output_pins; // number of mixer output pins - uint32 channel_config; // location of logical channels - uint8 channel_names; // id of name string of first logical channel -} _PACKED usb_output_channels_descriptor; - -// selector unit descriptor -// Table 4-6, page 43 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // SELECTOR_UNIT - uint8 unit_id; // unique within audio function - uint8 num_input_pins; // - uint8 input_pins[1]; // id of the unit or terminal - // this pin is connected to -/* uint8 selector_string; */ // be afraid of the variable - // size of input_pins array! -} _PACKED usb_selector_unit_descriptor; - -// feature unit descriptor -// Table 4-7, page 43 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // FEATURE_UNIT - uint8 unit_id; // unique within audio function - uint8 source_id; // id of the unit or terminal to - // which this unit is connected - uint8 control_size; // size of element in bma_controls array - uint8 bma_controls[1]; // the size of element must be equal - // to control_size!! - // the channel 0 is master one! -/* uint8 feature_string; */ // be afraid of the variable size - // of bma_controls array! -} _PACKED usb_feature_unit_descriptor_r1; - -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // FEATURE_UNIT - uint8 unit_id; // unique within audio function - uint8 source_id; // id of the unit or terminal to - // which this unit is connected - uint32 bma_controls[1]; // the channel 0 is master one! -/* uint8 feature_string; */ // be afraid of the variable size of - // bma_controls array! -} _PACKED usb_feature_unit_descriptor; - -// bitset for feature control bitmap -// Table 4-7, page 44, bmaControls field -enum FeatureControls { - MuteControl1 = 0x0001, - VolumeControl1 = 0x0002, - BassControl1 = 0x0004, - MidControl1 = 0x0008, - TrebleControl1 = 0x0010, - GraphEqControl1 = 0x0020, - AutoGainControl1 = 0x0040, - DelayControl1 = 0x0080, - BassBoostControl1 = 0x0100, - LoudnessControl1 = 0x0200, - // Release 2.0 - MuteControl = 0x00000003, - VolumeControl = 0x0000000c, - BassControl = 0x00000030, - MidControl = 0x000000c0, - TrebleControl = 0x00000300, - GraphEqControl = 0x00000c00, - AutoGainControl = 0x00003000, - DelayControl = 0x0000c000, - BassBoostControl = 0x00030000, - LoudnessControl = 0x000c0000, - InputGainControl = 0x00300000, - InputGainPadControl = 0x00c00000, - PhaseInverterControl= 0x03000000, - UnderflowControl = 0x0c000000, - OverflowControl = 0x30000000 -}; - -// processing unit descriptor -// Table 4-8, page 45 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // PROCESSING_UNIT - uint8 unit_id; // unique within audio function - uint16 process_type; // type of processing this unit is performing - uint8 num_input_pins; // number of input pins of this unit - uint8 input_pins[1]; // array of source ids for the processing unit - // use usb_output_channels_descriptor - // to parse the rest -// TODO - the bmControl!!!! -} _PACKED usb_processing_unit_descriptor; - -// extension unit descriptor -// Table 4-15, page 56 -typedef struct { - uint8 length; - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // EXTENSION_UNIT - uint8 unit_id; // unique within audio function - uint16 extension_code; // vendor-specific code identifying this unit - uint8 num_input_pins; // number of input pins - uint8 input_pins[1]; // array of source ids for the processing unit - // use usb_output_channels_descriptor - // to parse the rest -} _PACKED usb_extension_unit_descriptor; - - -// Audio Streaming (as) descriptors - - -// Class-specific AS interface descriptor -// Table 4-19, page 60 -typedef struct { - uint8 length; // 7 - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // UAS_AS_GENERAL - uint8 terminal_link; // terminal ID to which this endp is connected - uint8 delay; // delay in # of frames - uint16 format_tag; // wFormatTag, 0x0001 = PCM -} _PACKED usb_as_interface_descriptor_r1; - -typedef struct { - uint8 length; // 7 - uint8 descriptor_type; // CS_INTERFACE descriptor type (0x24) - uint8 descriptor_subtype; // UAS_AS_GENERAL - uint8 terminal_link; // terminal ID to which this endp is connected - uint8 bm_controls; // controls bitmap - uint8 format_type; // type of audio streaming use - uint32 bm_formats; // audio data formats to be used with - // this interface - uint8 num_output_pins; // number of physical channels in the claster - uint32 channel_config; // spatial location of channels - uint8 channel_names; // id of name string of first physical channel -} _PACKED usb_as_interface_descriptor; - -// Class-specific As Isochronous Audio Data Endpoint descriptor -// Table 4-21, page 62 -typedef struct { - uint8 length; // 7 - uint8 descriptor_type; // UAS_CS_ENDPOINT descriptor type (0x25) - uint8 descriptor_subtype; // UAS_EP_GENERAL - uint8 attributes; // d0 = samfq d1 = pitch d7 = maxpacketsonly - uint8 lock_delay_units; // 1 = ms 2 = decpcmsampl - uint16 lock_delay; // time for endp to lock internal - // clock recovery circuitry -} _PACKED usb_as_cs_endpoint_descriptor; - - - -/* 3-byte integer */ -typedef struct { - uint8 data[3]; -} _PACKED usb_triplet; - -// and - -/* - * Audio data formats spec - */ - -// constants -// Table A-1, page 29, wFormatTag -// Audio Data Format Type I codes -#define UAF_TYPE_I_UNDEFINED 0x0000 -#define UAF_PCM 0x0001 -#define UAF_PCM8 0x0002 -#define UAF_IEEE_FLOAT 0x0003 -#define UAF_ALAW 0x0004 -#define UAF_MULAW 0x0005 - -// Table A-4, page 30 -// Format Type Codes -#define UAF_FORMAT_TYPE_UNDEFINED 0x00 -#define UAF_FORMAT_TYPE_I 0x01 -#define UAF_FORMAT_TYPE_II 0x02 -#define UAF_FORMAT_TYPE_III 0x03 // Not _II again I guess.. - -// Table 2-2 and 2-3, page 10 -typedef struct { - uint8 lower_sam_freq[3]; - uint8 upper_sam_freq[3]; -} _PACKED usb_audio_continuous_freq_descr; - -typedef struct { - uint8 sam_freq[1][3]; -} _PACKED usb_audio_discrete_freq_descr; - -typedef union { - usb_audio_continuous_freq_descr cont; - usb_audio_discrete_freq_descr discr; -} _PACKED usb_audio_sam_freq_descr; - -// Table 2-1, page 10 -typedef struct { - uint8 length; // 0e for - uint8 descriptor_type; // UAS_CS_INTERFACE (0x24) - uint8 descriptor_subtype; // UAS_FORMAT_TYPE (0x02) - uint8 format_type; // UAF_FORMAT_TYPE_I (0x01) - uint8 nr_channels; // hopefully 2 - uint8 subframe_size; // 1, 2, or 4 bytes - uint8 bit_resolution; // 8, 16 or 20 bits - uint8 sam_freq_type; // 0 == continuous, 1 == a fixed - // number of discrete sam freqs - usb_audio_sam_freq_descr sf; // union -// uint8 sam_freq[12 * 3]; -} _PACKED usb_type_I_format_descriptor; - -// Table 2-4, page 13 -typedef struct { - uint8 length; // 0e for - uint8 descriptor_type; // UAS_CS_INTERFACE (0x24) - uint8 descriptor_subtype; // UAS_FORMAT_TYPE (0x02) - uint8 format_type; // UAF_FORMAT_TYPE_II (0x02) - uint16 max_bit_rate; // max bit rate in kbits/sec - uint16 samples_per_frame; // samples per frame - uint8 sam_freq_type; // 0 == continuous, 1 == a fixed - // number of discrete sam freqs - usb_audio_sam_freq_descr sf; // union -// uint8 sam_freq[12 * 3]; -} _PACKED usb_type_II_format_descriptor; - -// Table 2-23, page 26 (the same as Type I) -typedef struct { - uint8 length; // 0e for - uint8 descriptor_type; // UAS_CS_INTERFACE (0x24) - uint8 descriptor_subtype; // UAS_FORMAT_TYPE (0x02) - uint8 format_type; // UAF_FORMAT_TYPE_III (0x03) - uint8 nr_channels; // hopefully 2 - uint8 subframe_size; // 1, 2, or 4 bytes - uint8 bit_resolution; // 8, 16 or 20 bits - uint8 sam_freq_type; // 0 == continuous, 1 == a fixed - // number of discrete sam freqs - usb_audio_sam_freq_descr sf; // union -// uint8 sam_freq[12 * 3]; -} _PACKED usb_type_III_format_descriptor; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/add-ons/kernel/drivers/audio/usb_audio/audio.h b/src/add-ons/kernel/drivers/audio/usb_audio/audio.h deleted file mode 100644 index 36415fb7af..0000000000 --- a/src/add-ons/kernel/drivers/audio/usb_audio/audio.h +++ /dev/null @@ -1,165 +0,0 @@ -/* Copyright 2000 Be Incorporated. All Rights Reserved. -** This file may be used under the terms of the Be Sample Code -** License. -*/ - -#ifndef _USB_AUDIO_H_ -#define _USB_AUDIO_H_ - -/* See: Universal Serial Bus Device Class Definition for Audio Devices, Release 1.0 */ - - -/* A.1 Audio Interface Class Code */ -#define AC_AUDIO 0x01 - -/* A.2 Audio Interface Subclass Codes */ -#define AC_SUBCLASS_UNDEFINED 0x00 -#define AC_AUDIOCONTROL 0x01 -#define AC_AUDIOSTREAMING 0x02 -#define AC_MIDISTREAMING 0x03 - -/* A.3 Audio Interface Protocol Codes */ -#define AC_PR_PROTOCOL_UNDEFINED 0x00 - -/* A.4 Audio Class-Specific Descriptor Types */ -#define AC_CS_UNDEFINED 0x20 -#define AC_CS_DEVICE 0x21 -#define AC_CS_CONFIGURATION 0x22 -#define AC_CS_STRING 0x23 -#define AC_CS_INTERFACE 0x24 -#define AC_CS_ENDPOINT 0x25 - -/* A.5 Audio Class-Specific AC Interface Descriptor Subtypes */ -#define AC_AC_DESCRIPTOR_UNDEFINED 0x00 -#define AC_HEADER 0x01 -#define AC_INPUT_TERMINAL 0x02 -#define AC_OUTPUT_TERMINAL 0x03 -#define AC_MIXER_UNIT 0x04 -#define AC_SELECTOR_UNIT 0x05 -#define AC_FEATURE_UNIT 0x06 -#define AC_PROCESSING_UNIT 0x07 -#define AC_EXTENSION_UNIT 0x08 - -/* A.6 Audio Class-Specific AS Interface Descriptor Subtypes */ -#define AC_AS_DESCRIPTOR_UNDEFINED 0x00 -#define AC_AS_GENERAL 0x01 -#define AC_FORMAT_TYPE 0x02 -#define AC_FORMAT_SPECIFIC 0x03 - -/* A.7 Processing Unit Process Types */ -#define AC_PROCESS_UNDEFINED 0x00 -#define AC_UPDOWNMIX_PROCESS 0x01 -#define AC_DOLBY_PROLOGIC_PROCESS 0x02 -#define AC_3D_STEREO_EXTENDER_PROCESS 0x03 -#define AC_REVERBERATION_PROCESS 0x04 -#define AC_CHORUS_PROCESS 0x05 -#define AC_DYN_RANGE_COMP_PROCESS 0x07 - -/* A.8 Audio Class-Specific Endpoint Descriptor Subtypes */ -#define AC_DESCRIPTOR_UNDEFINED 0x00 -#define AC_EP_GENERAL 0x01 - -/* A.9 Audio Class-Specific Request Codes */ -#define AC_REQUEST_CODE_UNDEFINED 0x00 -#define AC_SET_CUR 0x01 -#define AC_GET_CUR 0x81 -#define AC_SET_MIN 0x02 -#define AC_GET_MIN 0x82 -#define AC_SET_MAX 0x03 -#define AC_GET_MAX 0x83 -#define AC_SET_RES 0x04 -#define AC_GET_RES 0x84 -#define AC_SET_MEM 0x05 -#define AC_GET_MEM 0x85 -#define AC_GET_STAT 0xFF - -/* A.10.1 Terminal Control Selectors */ -#define AC_TE_CONTROL_UNDEFINED 0x00 -#define AC_COPY_PROTECT_CONTROL 0x01 - -/* A.10.2 Feature Unit Control Selectors */ -#define AC_FU_CONTROL_UNDEFINED 0x00 -#define AC_MUTE_CONTROL 0x01 -#define AC_VOLUME_CONTROL 0x02 -#define AC_BASS_CONTROL 0x03 -#define AC_MID_CONTROL 0x04 -#define AC_TREBLE_CONTROL 0x05 -#define AC_GRAPHIC_EQUALIZER_CONTROL 0x06 -#define AC_AUTOMATIC_GAIN_CONTROL 0x07 -#define AC_DELAY_CONTROL 0x08 -#define AC_BASS_BOOST_CONTROL 0x09 -#define AC_LOUDNESS_CONTROL 0x0A - -/* A.10.3.1 Up/Down-mix Processing Unit Control Selectors */ -#define AC_UD_CONTROL_UNDEFINED 0x00 -#define AC_UD_ENABLED_CONTROL 0x01 -#define AC_UD_MODE_SELECT_CONTROL 0x02 - -/* A.10.3.2 Dolby Prologic(tm) Processing Unit Control Selectors */ -#define AC_DP_CONTROL_UNDEFINED 0x00 -#define AC_DP_ENABLE_CONTROL 0x01 -#define AC_DP_MODE_SELECT_CONTROL 0x02 - -/* A.10.3.3 3D Stereo Extender Processing Unit Control Selectors */ -#define AC_3D_CONTROL_UNDEFINED 0x00 -#define AC_3D_ENABLED_CONTROL 0x01 -#define AC_3D_SPACIOUSNESS_CONTROL 0x03 - -/* A.10.3.4 Reverberation Processing Unit Control Selectors */ -#define AC_RV_CONTROL_UNDEFINED 0x00 -#define AC_RV_ENABLE_CONTROL 0x01 -#define AC_RV_REVERB_LEVEL_CONTROL 0x02 -#define AC_RV_REVERB_TIME_CONTROL 0x03 -#define AC_RV_REVERB_FEEDBACK_CONTROL 0x04 - -/* A.10.3.5 Chorus Processing Unit Control Selectors */ -#define AC_CH_CONTROL_UNDEFINED 0x00 -#define AC_CH_ENABLE_CONTROL 0x01 -#define AC_CHORUS_LEVEL_CONTROL 0x02 -#define AC_CHORUS_RATE_CONTROL 0x03 -#define AC_CHORUS_DETH_CONTROL 0x04 - -/* A.10.3.6 Dynamic Range Compressor Processing Unit Control Selectors */ -#define AC_DR_CONTROL_UNDEFINED 0x00 -#define AC_DR_ENABLE_CONTROL 0x01 -#define AC_COMPRESSION_RATE_CONTROL 0x02 -#define AC_MAXAMPL_CONTROL 0x03 -#define AC_THRESHOLD_CONTROL 0x04 -#define AC_ATTACK_TIME 0x05 -#define AC_RELEASE_TIME 0x06 - -/* A.10.4 Extension Unit Control Selectors */ -#define AC_XU_CONTROL_UNDEFINED 0x00 -#define AC_XU_ENABLE_CONTROL 0x01 - -/* A.10.5 Endpoint Control Selectors */ -#define AC_EP_CONTROL_UNDEFINED 0x00 -#define AC_SAMPLING_FREQ_CONTROL 0x01 -#define AC_PITCH_CONTROL 0x02 - -typedef struct -{ - uint8 length; - uint8 type; - uint8 subtype; - uint8 unit_id; - uint8 source_id; - uint8 control_size; - uint16 controls[0]; -} _PACKED usb_feature_unit_descr; - -typedef struct -{ - uint8 length; - uint8 type; - uint8 subtype; - uint8 format_type; - uint8 num_channels; - uint8 subframe_size; - uint8 bit_resolution; - uint8 sample_freq_type; - uint8 lower_sample_freq[3]; - uint8 upper_sample_freq[3]; -} _PACKED usb_format_type_descr; - -#endif