diff --git a/module_usb_audio/endpoint0/audiorequests.xc b/module_usb_audio/endpoint0/audiorequests.xc index 6accd883..f72c2737 100644 --- a/module_usb_audio/endpoint0/audiorequests.xc +++ b/module_usb_audio/endpoint0/audiorequests.xc @@ -36,12 +36,8 @@ extern unsigned char mixer1Crossbar[]; extern short mixer1Weights[]; /* Device channel mapping */ -#if NUM_USB_CHAN_OUT > 0 extern unsigned char channelMapAud[NUM_USB_CHAN_OUT]; -#endif -#if NUM_USB_CHAN_IN > 0 extern unsigned char channelMapUsb[NUM_USB_CHAN_IN]; -#endif /* Mixer input mapping */ extern unsigned char mixSel[MIX_INPUTS]; @@ -605,10 +601,11 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c unsigned volume = 0; int c = sp.wValue & 0xff; - loop = XUD_GetBuffer(ep0_out, buffer); - if(loop < 0) - return loop; + if((result = XUD_GetBuffer(ep0_out, buffer, datalength)) != XUD_RES_OKAY) + { + return result; + } channelMapAud[c] = buffer[0] | buffer[1] << 8; @@ -643,10 +640,10 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c unsigned volume = 0; int c = sp.wValue & 0xff; - loop = XUD_GetBuffer(ep0_out, buffer); - - if(loop < 0) - return loop; + if((result = XUD_GetBuffer(ep0_out, buffer, datalength)) != XUD_RES_OKAY) + { + return result; + } channelMapUsb[c] = buffer[0] | buffer[1] << 8; @@ -677,14 +674,13 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c int cn = sp.wValue & 0xff; /* Channel number */ /* Check for Get or Set */ - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) { /* Direction: Host-to-device */ /* Host-to-device */ - datalength = XUD_GetBuffer(ep0_out, buffer); - - /* Check for reset */ - if(datalength < 0) - return datalength; + if((result = XUD_GetBuffer(ep0_out, buffer, datalength)) != XUD_RES_OKAY) + { + return result; + } if(datalength > 0) { @@ -734,14 +730,15 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c case ID_MIXER_1: - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_OUT) /* Direction: Host-to-device */ + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ { unsigned volume = 0; - /* Expect OUT here with mute */ - loop = XUD_GetBuffer(ep0_out, buffer); - if(loop < 0) - return loop; + /* Expect OUT here with mute */ + if((result = XUD_GetBuffer(ep0_out, buffer, datalength)) != XUD_RES_OKAY) + { + return result; + } mixer1Weights[sp.wValue & 0xff] = buffer[0] | buffer[1] << 8; @@ -906,7 +903,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c { case ID_MIXER_1: - if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_IN) + if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_D2H) { int length = 0; @@ -924,9 +921,9 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c if (!isnull(c_mix_ctl)) { outuint(c_mix_ctl, GET_INPUT_LEVELS); - outuint(c_mix_ctl, (i - NUM_USB_CHAN_IN)); + outuint(c_mix_ctl, i); outct(c_mix_ctl, XS1_CT_END); - storeShort(buffer, i*2, (inuint(c_mix_ctl)>>15)); + storeShort(buffer, i*2, (inuint(c_mix_ctl) >> 15)); chkct(c_mix_ctl, XS1_CT_END); } else @@ -955,7 +952,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c case 1: /* Mixer Output levels */ length = MAX_MIX_COUNT * 2; /* 2 bytes per chan */ - + for(int i = 0; i < MAX_MIX_COUNT; i++) { if (!isnull(c_mix_ctl)) diff --git a/module_usb_audio/endpoint0/descriptors.h b/module_usb_audio/endpoint0/descriptors.h index bc3b508c..dfd828a6 100644 --- a/module_usb_audio/endpoint0/descriptors.h +++ b/module_usb_audio/endpoint0/descriptors.h @@ -170,6 +170,31 @@ typedef struct #endif #if (NUM_USB_CHAN_IN > 18) #error NUM_USB_CHAN > 18 +#endif + +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + STR_TABLE_ENTRY(mixOutStr_1); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 1) + STR_TABLE_ENTRY(mixOutStr_2); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 2) + STR_TABLE_ENTRY(mixOutStr_3); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 3) + STR_TABLE_ENTRY(mixOutStr_4); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 4) + STR_TABLE_ENTRY(mixOutStr_5); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 5) + STR_TABLE_ENTRY(mixOutStr_6); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 6) + STR_TABLE_ENTRY(mixOutStr_7); +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 7) + STR_TABLE_ENTRY(mixOutStr_8); #endif STR_TABLE_ENTRY(iAPInterfaceStr); } StringDescTable_t; @@ -849,6 +874,34 @@ StringDescTable_t g_strTable = #if (NUM_USB_CHAN_IN > 18) #error NUM_USB_CHAN_IN > 18 +#endif + +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_1 = "Mix 1", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_2 = "Mix 2", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_3 = "Mix 3", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_4 = "Mix 4", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_5 = "Mix 5", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_6 = "Mix 6", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_7 = "Mix 7", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + .mixOutStr_8 = "Mix 8", +#endif +#if defined(MIXER) && (MAX_MIX_COUNT > 8) +#error #endif .iAPInterfaceStr = "iAP Interface", @@ -1021,7 +1074,7 @@ unsigned char devQualDesc_Null[] = #if defined(MIXER) && !defined(AUDIO_PATH_XUS) && (MAX_MIX_COUNT > 0) -#warning Extention units on the audio path are required for mixer. Enabling them now. +//#warning Extension units on the audio path are required for mixer. Enabling them now. #define AUDIO_PATH_XUS #endif @@ -1037,6 +1090,18 @@ unsigned char devQualDesc_Null[] = #define DFU_LENGTH (0) #endif +#ifdef MIXER + #define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8) + + #if ((MAX_MIX_COUNT * MIX_INPUTS)%8)==0 + #define MIX_BMCONTROLS_LEN (MIX_BMCONTROLS_LEN_TMP) + #else + #define MIX_BMCONTROLS_LEN (MIX_BMCONTROLS_LEN_TMP+1) + #endif + #define MIXER_LENGTH (13+1+MIX_BMCONTROLS_LEN) +#else + #define MIXER_LENGTH (0) +#endif #ifdef HID_CONTROLS @@ -1106,6 +1171,9 @@ typedef struct #if (NUM_USB_CHAN_OUT > 0) /* Output path */ USB_Descriptor_Audio_InputTerminal_t Audio_Out_InputTerminal; +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + USB_Descriptor_Audio_ExtensionUnit_t Audio_Out_ExtensionUnit; +#endif #if(OUTPUT_VOLUME_CONTROL == 1) USB_Descriptor_Audio_FeatureUnit_Out_t Audio_Out_FeatureUnit; #endif @@ -1114,12 +1182,22 @@ typedef struct #if (NUM_USB_CHAN_IN > 0) /* Input path */ USB_Descriptor_Audio_InputTerminal_t Audio_In_InputTerminal; +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + USB_Descriptor_Audio_ExtensionUnit_t Audio_In_ExtensionUnit; +#endif #if(INPUT_VOLUME_CONTROL == 1) USB_Descriptor_Audio_FeatureUnit_In_t Audio_In_FeatureUnit; #endif USB_Descriptor_Audio_OutputTerminal_t Audio_In_OutputTerminal; #endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + USB_Descriptor_Audio_ExtensionUnit2_t Audio_Mix_ExtensionUnit; + // Currently no struct for mixer unit + // USB_Descriptor_Audio_MixerUnit_t Audio_MixerUnit; + unsigned char configDesc_MixerUnit[MIXER_LENGTH]; +#endif #if defined (SPDIF_RX) || defined (ADAT_RX) + /* Interrupt EP */ USB_Descriptor_Endpoint_t Audio_Int_Endpoint; #endif } __attribute__((packed)) USB_CfgDesc_Audio2_CS_Control_Int; @@ -1369,6 +1447,23 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .iTerminal = offsetof(StringDescTable_t, usbInputTermStr_Audio2)/sizeof(char *) }, +#if defined (MIXER) && (MAX_MIX_COUNT > 0) + .Audio_Out_ExtensionUnit = + { + .bLength = sizeof(USB_Descriptor_Audio_ExtensionUnit_t), + .bDescriptorType = UAC_CS_DESCTYPE_INTERFACE, + .bDescriptorSubtype = UAC_CS_AC_INTERFACE_SUBTYPE_EXTENSION_UNIT, + .bUnitID = ID_XU_OUT, + .wExtensionCode = 0x00, + .bNrInPins = 1, + .baSourceID[0] = ID_IT_USB, + .bNrChannels = NUM_USB_CHAN_OUT, + .bmChannelConfig = 0x00000000, + .bmControls = 0x03, + .iExtension = 0 + }, +#endif + #if(OUTPUT_VOLUME_CONTROL == 1) /* Feature Unit Descriptor */ .Audio_Out_FeatureUnit = @@ -1377,7 +1472,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0x24, /* 1 bDescriptorType: CS_INTERFACE */ 0x06, /* 2 bDescriptorSubType: FEATURE_UNIT */ FU_USBOUT, /* 3 bUnitID */ -#ifdef AUDIO_PATH_XUS +#if defined (MIXER) && (MAX_MIX_COUNT > 0) ID_XU_OUT, /* 4 bSourceID */ #else ID_IT_USB, /* 4 bSourceID */ @@ -1465,6 +1560,9 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= 0, /* 11 iTerminal */ }, #endif + + + #if (NUM_USB_CHAN_IN > 0) /* Input Terminal Descriptor (Analogue Input Terminal) */ .Audio_In_InputTerminal = @@ -1483,6 +1581,23 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= .iTerminal = 0, }, +#if defined (MIXER) && (MAX_MIX_COUNT > 0) + .Audio_In_ExtensionUnit = + { + .bLength = sizeof(USB_Descriptor_Audio_ExtensionUnit_t), + .bDescriptorType = UAC_CS_DESCTYPE_INTERFACE, + .bDescriptorSubtype = UAC_CS_AC_INTERFACE_SUBTYPE_EXTENSION_UNIT, + .bUnitID = ID_XU_IN, + .wExtensionCode = 0x00, + .bNrInPins = 1, + .baSourceID[0] = ID_IT_AUD, + .bNrChannels = NUM_USB_CHAN_IN, + .bmChannelConfig = 0x00000000, + .bmControls = 0x03, + .iExtension = 0 + }, +#endif + #if (INPUT_VOLUME_CONTROL == 1) .Audio_In_FeatureUnit = { @@ -1490,7 +1605,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: CS_INTERFACE */ UAC_CS_AC_INTERFACE_SUBTYPE_FEATURE_UNIT, /* 2 bDescriptorSubType: FEATURE_UNIT */ FU_USBIN, /* 3 bUnitID */ -#ifdef AUDIO_PATH_XUS +#if defined(MIXER) && (MAX_MIX_COUNT > 0) ID_XU_IN, /* 4 bSourceID */ #else ID_IT_AUD, /* 4 bSourceID */ @@ -1580,6 +1695,100 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2= }, #endif +#if defined(MIXER) && (MAX_MIX_COUNT > 0) + /* Extension Unit Descriptor (4.7.2.12) */ + .Audio_Mix_ExtensionUnit = + { + .bLength = sizeof(USB_Descriptor_Audio_ExtensionUnit2_t), + .bDescriptorType = UAC_CS_DESCTYPE_INTERFACE, + .bDescriptorSubtype = UAC_CS_AC_INTERFACE_SUBTYPE_EXTENSION_UNIT, + .bUnitID = ID_XU_MIXSEL, + .wExtensionCode = 0x00, + .bNrInPins = 2, + .baSourceID[0] = ID_IT_USB, + .baSourceID[1] = ID_IT_AUD, + .bNrChannels = MIX_INPUTS, + .bmChannelConfig = 0x00000000, + .bmControls = 0x03, + .iExtension = 0 + }, + + /* Mixer Unit Descriptors */ + /* N = 144 (18 * 8) */ + /* Mixer Unit Bitmap - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff */ + { + MIXER_LENGTH, /* 0 bLength : 13 + num inputs + bit map (inputs * outputs) */ + UAC_CS_DESCTYPE_INTERFACE, /* bDescriptorType */ + 0x04, /* bDescriptorSubtype: MIXER_UNIT */ + ID_MIXER_1, /* Mixer unit id */ + 0x01, /* Number of input pins */ + ID_XU_MIXSEL, /* Connected terminal or unit id for input pin */ + MAX_MIX_COUNT, /* Number of mixer output channels */ + 0x00, 0x00, 0x00, 0x00, /* Spacial location ???? */ + offsetof(StringDescTable_t, mixOutStr_1)/sizeof(char *), /* iChannelNames */ +#if MIX_BMCONTROLS_LEN > 0 /* Mixer programmable control bitmap */ + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 1 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 2 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 3 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 4 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 5 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 6 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 7 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 8 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 9 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 10 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 11 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 12 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 13 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 14 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 15 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 16 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 17 + 0xff, +#endif +#if MIX_BMCONTROLS_LEN > 18 +#error unxpected BMCONTROLS_LEN +#endif + 0x00, /* bmControls */ + 0 /* Mixer unit string descriptor index */ + }, +#endif + #if defined(SPDIF_RX) || defined(ADAT_RX) /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ .Audio_Int_Endpoint = diff --git a/module_usb_audio/endpoint0/endpoint0.c b/module_usb_audio/endpoint0/endpoint0.c index cbc9d77c..33bc6298 100755 --- a/module_usb_audio/endpoint0/endpoint0.c +++ b/module_usb_audio/endpoint0/endpoint0.c @@ -76,12 +76,8 @@ unsigned char mixer1Crossbar[18]; short mixer1Weights[18*8]; unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT]; -#if (NUM_USB_CHAN_OUT > 0) unsigned char channelMapAud[NUM_USB_CHAN_OUT]; -#endif -#if (NUM_USB_CHAN_IN > 0) unsigned char channelMapUsb[NUM_USB_CHAN_IN]; -#endif unsigned char mixSel[MIX_INPUTS]; #endif diff --git a/module_usb_audio/mixer/mixer.xc b/module_usb_audio/mixer/mixer.xc index f85aefe9..918022a3 100644 --- a/module_usb_audio/mixer/mixer.xc +++ b/module_usb_audio/mixer/mixer.xc @@ -60,14 +60,17 @@ xc_ptr mix_map; #endif /* Arrays for level data */ -int samples_to_host_inputs[NUM_USB_CHAN_IN]; /* Audio transmitted to host i.e. dev inputs */ +int samples_to_host_inputs[NUM_USB_CHAN_IN]; /* Audio transmitted to host i.e. device inputs */ +xc_ptr samples_to_host_inputs_ptr; + #ifdef LEVEL_METER_LEDS -int samples_to_host_inputs_buff[NUM_USB_CHAN_IN]; /* Audio transmitted to host i.e. dev inputs */ -#endif -static int samples_to_host_streams[NUM_USB_CHAN_OUT]; /* Audio stream to host from host */ -#if (MAX_MIX_COUNT > 0) -static int samples_to_host_outputs[NUM_USB_CHAN_OUT]; /* Device outputs */ +int samples_to_host_inputs_buff[NUM_USB_CHAN_IN]; /* Audio transmitted to host i.e. dev inputs */ #endif +static int samples_from_host_streams[NUM_USB_CHAN_OUT]; /* Peak samples for audio stream from host */ + +static int samples_mixer_outputs[MAX_MIX_COUNT]; /* Peak samples out of the mixer */ +xc_ptr samples_mixer_outputs_ptr; + #if 0 #pragma xta command "add exclusion mixer1_rate_change" #pragma xta command "analyse path mixer1_req mixer1_req" @@ -87,18 +90,15 @@ static inline void ComputeMixerLevel(int sample, int i) int y; xc_ptr ptr; - x = abs(sample); - /* y = samples_to_host_outputs[i] */ - asm("ldaw %0, dp[samples_to_host_outputs]":"=r"(ptr):); /* Might want to hoist this */ - asm("ldw %0, %1[%2]":"=r"(y):"r"(ptr),"r"(i)); + /* y = samples_mixer_outputs[i] */ + read_via_xc_ptr_indexed(y, samples_mixer_outputs_ptr, i); if(x > y) { /* samples_to_host_outputs[i] = x; */ - write_via_xc_ptr_indexed(ptr,i,y); - //asm("stw %0, %1[%2]"::"r"(y),"r"(ptr),"r"(i)); + write_via_xc_ptr_indexed(samples_mixer_outputs_ptr,i,x); } } #endif @@ -117,7 +117,7 @@ int doMix8(xc_ptr samples, xc_ptr mult); /* DO NOT inline, causes 10.4.2 tools to add extra loads in loop */ /* At 18 x 12dB we could get 64 x bigger */ #pragma unsafe arrays -static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) +static inline int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) { int h=0; int l=0; @@ -153,7 +153,7 @@ static int doMix(xc_ptr samples, xc_ptr ptr, xc_ptr mult) #endif #pragma unsafe arrays -static void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multIn) +static inline void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multIn) { #if defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) int mult; @@ -186,7 +186,7 @@ static void giveSamplesToHost(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr mult } #pragma unsafe arrays -static void getSamplesFromHost(chanend c, xc_ptr samples, int base, unsigned underflow) +static inline void getSamplesFromHost(chanend c, xc_ptr samples, int base, unsigned underflow) { if(!underflow) { @@ -205,8 +205,10 @@ static void getSamplesFromHost(chanend c, xc_ptr samples, int base, unsigned und #if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS) /* Compute peak level data */ x = abs(sample); - if(x > samples_to_host_streams[i]) - samples_to_host_streams[i] = x; + if(x > samples_from_host_streams[i]) + { + samples_from_host_streams[i] = x; + } #endif #if defined(OUT_VOLUME_IN_MIXER) && !defined(OUT_VOLUME_AFTER_MIX) @@ -227,7 +229,7 @@ static void getSamplesFromHost(chanend c, xc_ptr samples, int base, unsigned und } #pragma unsafe arrays -static void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut, unsigned underflow) +static inline void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr multOut, unsigned underflow) { outuint(c, underflow); @@ -265,7 +267,7 @@ static void giveSamplesToDevice(chanend c, xc_ptr samples, xc_ptr ptr, xc_ptr mu } #pragma unsafe arrays -static void getSamplesFromDevice(chanend c, xc_ptr samples, int base) +static inline void getSamplesFromDevice(chanend c, xc_ptr samples, int base) { #if defined(IN_VOLUME_IN_MIXER) && !defined(IN_VOLUME_AFTER_MIX) int mult; @@ -278,13 +280,20 @@ static void getSamplesFromDevice(chanend c, xc_ptr samples, int base) { int sample; int x; + int old_x; sample = inuint(c); #if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS) /* Compute peak level data */ x = abs(sample); - if(x > samples_to_host_inputs[i]) - samples_to_host_inputs[i] = x; + + // old_x = samples_to_host_inputs[i] + read_via_xc_ptr_indexed(old_x, samples_to_host_inputs_ptr, i); + if(x > old_x) + { + //samples_to_host_inputs[i] = x; + write_via_xc_ptr_indexed(samples_to_host_inputs_ptr, i, x); + } #endif #if defined(IN_VOLUME_IN_MIXER) && !defined(IN_VOLUME_AFTER_MIX) @@ -300,7 +309,6 @@ static void getSamplesFromDevice(chanend c, xc_ptr samples, int base) static int mixer1_mix2_flag = (DEFAULT_FREQ > 96000); - #pragma unsafe arrays static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) { @@ -387,12 +395,13 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) break; #endif + /* Peak samples of stream from host to device (via USB) */ case GET_STREAM_LEVELS: index = inuint(c_mix_ctl); chkct(c_mix_ctl, XS1_CT_END); - outuint(c_mix_ctl, samples_to_host_streams[index]); + outuint(c_mix_ctl, samples_from_host_streams[index]); outct(c_mix_ctl, XS1_CT_END); - samples_to_host_streams[index] = 0; + samples_from_host_streams[index] = 0; break; case GET_INPUT_LEVELS: @@ -401,23 +410,32 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) #ifdef LEVEL_METER_LEDS /* Level LEDS process reseting samples_to_host_inputs * Other side makes sure we don't miss a peak */ + //val = samples_to_host_inputs_buff[index]; + //samples_to_host_inputs_buff[index] = 0; + /* Access funcs used to avoid disjointness check */ read_via_xc_ptr_indexed(val, samples_to_host_inputs_buff, index); write_via_xc_ptr_indexed(samples_to_host_inputs_buff, index, 0); #else /* We dont have a level LEDs process, so reset ourselves */ - read_via_xc_ptr_indexed(val, samples_to_host_inputs, index); - write_via_xc_ptr_indexed(samples_to_host_inputs, index, 0); + //val = samples_to_host_inputs[index]; + //samples_to_host_inputs[index] = 0; + /* Access funcs used to avoid disjointness check */ + read_via_xc_ptr_indexed(val, samples_to_host_inputs_ptr, index); + write_via_xc_ptr_indexed(samples_to_host_inputs_ptr, index, 0); #endif outuint(c_mix_ctl, val); outct(c_mix_ctl, XS1_CT_END); break; -#if MAX_MIX_COUNT > 0 +#if (MAX_MIX_COUNT > 0) + /* Peak samples of the mixer outputs */ case GET_OUTPUT_LEVELS: index = inuint(c_mix_ctl); chkct(c_mix_ctl, XS1_CT_END); - read_via_xc_ptr_indexed(val, samples_to_host_outputs, index); - write_via_xc_ptr_indexed(samples_to_host_outputs, index, mix); + read_via_xc_ptr_indexed(val, samples_mixer_outputs, index); + write_via_xc_ptr_indexed(samples_mixer_outputs, index, 0); + //val = samples_mixer_outputs[index]; + //samples_mixer_outputs[index] = 0; outuint(c_mix_ctl, val); outct(c_mix_ctl, XS1_CT_END); break; @@ -475,12 +493,12 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2) { unsigned underflow = inuint(c_host); #if MAX_MIX_COUNT > 0 - outuint(c_mixer2, 0); + outuint(c_mixer2, underflow); giveSamplesToHost(c_host, samples, samples_to_host_map, multIn); outuint(c_mixer2, 0); inuint(c_mixer2); - getSamplesFromHost(c_host, samples, 0); + getSamplesFromHost(c_host, samples, 0, underflow); outuint(c_mixer2, 0); inuint(c_mixer2); #ifdef FAST_MIXER @@ -555,44 +573,65 @@ static int mixer2_mix2_flag = (DEFAULT_FREQ > 96000); #pragma unsafe arrays static void mixer2(chanend c_mixer1, chanend c_audio) { - int mixed; + int mixed; + unsigned underflow = 0; - while (1) { - outuint(c_mixer1, 0); -#pragma xta endpoint "mixer2_req" - inuint(c_audio); - if(testct(c_mixer1)) + while (1) { - int sampFreq; -#pragma xta endpoint "mixer2_rate_change" - inct(c_mixer1); - sampFreq = inuint(c_mixer1); - - - mixer2_mix2_flag = sampFreq > 96000; - - for (int i=0;i 96000; + + /* Inform mixer2 (or audio()) about freq change */ + outct(c_audio, command); + outuint(c_audio, sampFreq); + break; + + case SET_STREAM_FORMAT_OUT: + case SET_STREAM_FORMAT_IN: + /* Inform mixer2 (or audio()) about format change */ + outct(c_audio, command); + outuint(c_audio, inuint(c_mixer1)); + outuint(c_audio, inuint(c_mixer1)); + break; + + default: + break; + } + + for (int i=0;i 1 #ifdef FAST_MIXER mixed = doMix1(samples, mix_mult_slice(1)); @@ -668,9 +707,11 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl) multIn = array_to_xc_ptr((multIn_array,unsigned[])); samples = array_to_xc_ptr((samples_array,unsigned[])); samples_to_host_map = array_to_xc_ptr((samples_to_host_map_array,unsigned[])); - samples_to_device_map = array_to_xc_ptr((samples_to_device_map_array,unsigned[])); + samples_to_host_inputs_ptr = array_to_xc_ptr((samples_to_host_inputs, unsigned[])); + samples_mixer_outputs_ptr = array_to_xc_ptr((samples_mixer_outputs, unsigned[])); + #if MAX_MIX_COUNT >0 mix_mult = array_to_xc_ptr((mix_mult_array,unsigned[])); #ifndef FAST_MIXER