- Rationalised MIXER defines and usage

- Further removal of xc_ptr type usage in mixer in favour of native xc pointers
This commit is contained in:
Ross Owen
2023-02-06 20:28:29 +00:00
parent 035c20e01c
commit 317e27e421
9 changed files with 244 additions and 240 deletions

View File

@@ -997,17 +997,12 @@
#define MIXER (0) #define MIXER (0)
#endif #endif
/* Tidy up old ifndef usage */
#if defined(MIXER) && (MIXER == 0)
#undef MIXER
#endif
/** /**
* @brief Number of seperate mixes to perform * @brief Number of seperate mixes to perform
* *
* Default: 8 if MIXER enabled, else 0 * Default: 8 if MIXER enabled, else 0
*/ */
#ifdef MIXER #if (MIXER)
#ifndef MAX_MIX_COUNT #ifndef MAX_MIX_COUNT
#define MAX_MIX_COUNT (8) #define MAX_MIX_COUNT (8)
#endif #endif
@@ -1087,44 +1082,24 @@
#define VOLUME_RES_MIXER (0x100) #define VOLUME_RES_MIXER (0x100)
#endif #endif
/* Handle out volume control in the mixer */ /* Handle out volume control in the mixer - disabled by default */
#if defined(OUT_VOLUME_IN_MIXER) && (OUT_VOLUME_IN_MIXER==0) #ifndef OUT_VOLUME_IN_MIXER
#undef OUT_VOLUME_IN_MIXER #define OUT_VOLUME_IN_MIXER (0)
#else
#if defined(MIXER)
// Disabled by default
//#define OUT_VOLUME_IN_MIXER
#endif
#endif #endif
/* Apply out volume controls after the mix */ /* Apply out volume controls after the mix. Only relevant when OUT_VOLUME_IN_MIXER enabled. Enabled by default */
#if defined(OUT_VOLUME_AFTER_MIX) && (OUT_VOLUME_AFTER_MIX==0) #ifndef OUT_VOLUME_AFTER_MIX
#undef OUT_VOLUME_AFTER_MIX #define OUT_VOLUME_AFTER_MIX (1)
#else
#if defined(MIXER) && defined(OUT_VOLUME_IN_MIXER)
// Enabled by default
#define OUT_VOLUME_AFTER_MIX
#endif
#endif #endif
/* Handle in volume control in the mixer */ /* Handle in volume control in the mixer - disabled by default */
#if defined(IN_VOLUME_IN_MIXER) && (IN_VOLUME_IN_MIXER==0) #ifdef IN_VOLUNE_IN_MIXER
#undef IN_VOLUME_IN_MIXER #define IN_VOLUME_IN_MIXER (0)
#else
#if defined(MIXER)
/* Disabled by default */
//#define IN_VOLUME_IN_MIXER
#endif
#endif #endif
/* Apply in volume controls after the mix */ /* Apply in volume controls after the mix. Only relebant when IN_VOLUMNE_IN MIXER enabled. Enabled by default */
#if defined(IN_VOLUME_AFTER_MIX) && (IN_VOLUME_AFTER_MIX==0) #ifndef IN_VOLUME_AFTER_MIX
#undef IN_VOLUME_AFTER_MIX #define IN_VOLUME_AFTER_MIX (1)
#else
#if defined(MIXER) && defined(IN_VOLUME_IN_MIXER)
// Enabled by default
#define IN_VOLUME_AFTER_MIX
#endif
#endif #endif
/* Always enable explicit feedback EP, even when input stream is present */ /* Always enable explicit feedback EP, even when input stream is present */

View File

@@ -1,4 +1,4 @@
// Copyright 2011-2022 XMOS LIMITED. // Copyright 2011-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1. // This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef _XUA_MIXER_H_ #ifndef _XUA_MIXER_H_
#define _XUA_MIXER_H_ #define _XUA_MIXER_H_

View File

@@ -58,11 +58,11 @@
#define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2) #define IN_BUFFER_PREFILL (MAX(MAX_DEVICE_AUD_PACKET_SIZE_IN_HS, MAX_DEVICE_AUD_PACKET_SIZE_IN_FS)*2)
/* Volume and mute tables */ /* Volume and mute tables */
#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1) #if (OUT_VOLUME_IN_MIXER == 0) && (OUTPUT_VOLUME_CONTROL == 1)
unsigned int multOut[NUM_USB_CHAN_OUT + 1]; unsigned int multOut[NUM_USB_CHAN_OUT + 1];
static xc_ptr p_multOut; static xc_ptr p_multOut;
#endif #endif
#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1) #if (IN_VOLUME_IN_MIXER == 0) && (INPUT_VOLUME_CONTROL == 1)
unsigned int multIn[NUM_USB_CHAN_IN + 1]; unsigned int multIn[NUM_USB_CHAN_IN + 1];
static xc_ptr p_multIn; static xc_ptr p_multIn;
#endif #endif
@@ -206,7 +206,7 @@ __builtin_unreachable();
g_aud_from_host_rdptr+=2; g_aud_from_host_rdptr+=2;
sample <<= 16; sample <<= 16;
#if (OUTPUT_VOLUME_CONTROL == 1) && !defined(OUT_VOLUME_IN_MIXER) #if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER)
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
/* Note, in 2 byte subslot mode - ignore lower result of macs */ /* Note, in 2 byte subslot mode - ignore lower result of macs */
@@ -234,7 +234,7 @@ __builtin_unreachable();
read_via_xc_ptr(sample, g_aud_from_host_rdptr); read_via_xc_ptr(sample, g_aud_from_host_rdptr);
g_aud_from_host_rdptr+=4; g_aud_from_host_rdptr+=4;
#if (OUTPUT_VOLUME_CONTROL == 1) && !defined(OUT_VOLUME_IN_MIXER) #if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER)
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
h <<= 3; h <<= 3;
@@ -289,7 +289,7 @@ __builtin_unreachable();
} }
unpackState++; unpackState++;
#if (OUTPUT_VOLUME_CONTROL == 1) && !defined(OUT_VOLUME_IN_MIXER) #if (OUTPUT_VOLUME_CONTROL == 1) && (!OUT_VOLUME_IN_MIXER)
asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i)); asm volatile("ldw %0, %1[%2]":"=r"(mult):"r"(p_multOut),"r"(i));
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
h <<= 3; h <<= 3;
@@ -335,7 +335,7 @@ __builtin_unreachable();
/* Receive sample */ /* Receive sample */
int sample = inuint(c_mix_out); int sample = inuint(c_mix_out);
#if (INPUT_VOLUME_CONTROL == 1) #if (INPUT_VOLUME_CONTROL == 1)
#if !defined(IN_VOLUME_IN_MIXER) #if (!IN_VOLUME_IN_MIXER)
/* Apply volume */ /* Apply volume */
int mult; int mult;
int h; int h;
@@ -345,7 +345,7 @@ __builtin_unreachable();
sample = h << 3; sample = h << 3;
/* Note, in 2 byte sub slot - ignore lower bits of macs */ /* Note, in 2 byte sub slot - ignore lower bits of macs */
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) #elif (IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX)
sample = sample << 3; sample = sample << 3;
#endif #endif
#endif #endif
@@ -365,7 +365,7 @@ __builtin_unreachable();
/* Receive sample */ /* Receive sample */
int sample = inuint(c_mix_out); int sample = inuint(c_mix_out);
#if(INPUT_VOLUME_CONTROL == 1) #if(INPUT_VOLUME_CONTROL == 1)
#if !defined(IN_VOLUME_IN_MIXER) #if (!IN_VOLUME_IN_MIXER)
/* Apply volume */ /* Apply volume */
int mult; int mult;
int h; int h;
@@ -376,7 +376,7 @@ __builtin_unreachable();
#if (STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED == 1) #if (STREAM_FORMAT_INPUT_RESOLUTION_32BIT_USED == 1)
sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32) sample |= (l >> 29) & 0x7; // Note, this step is not required if we assume sample depth is 24 (rather than 32)
#endif #endif
#elif defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) #elif (IN_VOLUME_IN_MIXER) && (IN_VOLUME_AFTER_MIX)
sample = sample << 3; sample = sample << 3;
#endif #endif
#endif #endif
@@ -396,7 +396,7 @@ __builtin_unreachable();
{ {
/* Receive sample */ /* Receive sample */
int sample = inuint(c_mix_out); int sample = inuint(c_mix_out);
#if (INPUT_VOLUME_CONTROL) && !defined(IN_VOLUME_IN_MIXER) #if (INPUT_VOLUME_CONTROL) && (!IN_VOLUME_IN_MIXER)
/* Apply volume */ /* Apply volume */
int mult; int mult;
int h; int h;
@@ -640,10 +640,10 @@ void XUA_Buffer_Decouple(chanend c_mix_out
int t = array_to_xc_ptr(outAudioBuff); int t = array_to_xc_ptr(outAudioBuff);
#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1) #if (!OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1)
p_multOut = array_to_xc_ptr(multOut); p_multOut = array_to_xc_ptr(multOut);
#endif #endif
#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1) #if (!IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1)
p_multIn = array_to_xc_ptr(multIn); p_multIn = array_to_xc_ptr(multIn);
#endif #endif
@@ -670,14 +670,14 @@ void XUA_Buffer_Decouple(chanend c_mix_out
xc_ptr aud_to_host_zeros = t; xc_ptr aud_to_host_zeros = t;
/* Init vol mult tables */ /* Init vol mult tables */
#if !defined(OUT_VOLUME_IN_MIXER) && (OUTPUT_VOLUME_CONTROL == 1) #if (OUT_VOLUME_IN_MIXER == 0) && (OUTPUT_VOLUME_CONTROL == 1)
for (int i = 0; i < NUM_USB_CHAN_OUT + 1; i++) for (int i = 0; i < NUM_USB_CHAN_OUT + 1; i++)
{ {
asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multOut),"r"(i)); asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multOut),"r"(i));
} }
#endif #endif
#if !defined(IN_VOLUME_IN_MIXER) && (INPUT_VOLUME_CONTROL == 1) #if (IN_VOLUME_IN_MIXER == 0) && (INPUT_VOLUME_CONTROL == 1)
for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++) for (int i = 0; i < NUM_USB_CHAN_IN + 1; i++)
{ {
asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multIn),"r"(i)); asm volatile("stw %0, %1[%2]"::"r"(MAX_VOL),"r"(p_multIn),"r"(i));

View File

@@ -106,7 +106,7 @@ unsigned int mutesOut[NUM_USB_CHAN_OUT + 1];
int volsIn[NUM_USB_CHAN_IN + 1]; int volsIn[NUM_USB_CHAN_IN + 1];
unsigned int mutesIn[NUM_USB_CHAN_IN + 1]; unsigned int mutesIn[NUM_USB_CHAN_IN + 1];
#ifdef MIXER #if (MIXER)
short mixer1Weights[MIX_INPUTS * MAX_MIX_COUNT]; short mixer1Weights[MIX_INPUTS * MAX_MIX_COUNT];
//unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT]; //unsigned char channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT];
@@ -429,7 +429,7 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c
#endif #endif
VendorRequests_Init(VENDOR_REQUESTS_PARAMS); VendorRequests_Init(VENDOR_REQUESTS_PARAMS);
#ifdef MIXER #if (MIXER)
/* Set up mixer default state */ /* Set up mixer default state */
for (int i = 0; i < MIX_INPUTS * MAX_MIX_COUNT; i++) for (int i = 0; i < MIX_INPUTS * MAX_MIX_COUNT; i++)
{ {

View File

@@ -308,28 +308,28 @@ typedef struct
#error NUM_USB_CHAN > 32 #error NUM_USB_CHAN > 32
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
STR_TABLE_ENTRY(mixOutStr_1); STR_TABLE_ENTRY(mixOutStr_1);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 1) #if (MIXER) && (MAX_MIX_COUNT > 1)
STR_TABLE_ENTRY(mixOutStr_2); STR_TABLE_ENTRY(mixOutStr_2);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 2) #if (MIXER) && (MAX_MIX_COUNT > 2)
STR_TABLE_ENTRY(mixOutStr_3); STR_TABLE_ENTRY(mixOutStr_3);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 3) #if (MIXER) && (MAX_MIX_COUNT > 3)
STR_TABLE_ENTRY(mixOutStr_4); STR_TABLE_ENTRY(mixOutStr_4);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 4) #if (MIXER) && (MAX_MIX_COUNT > 4)
STR_TABLE_ENTRY(mixOutStr_5); STR_TABLE_ENTRY(mixOutStr_5);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 5) #if (MIXER) && (MAX_MIX_COUNT > 5)
STR_TABLE_ENTRY(mixOutStr_6); STR_TABLE_ENTRY(mixOutStr_6);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 6) #if (MIXER) && (MAX_MIX_COUNT > 6)
STR_TABLE_ENTRY(mixOutStr_7); STR_TABLE_ENTRY(mixOutStr_7);
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 7) #if (MIXER) && (MAX_MIX_COUNT > 7)
STR_TABLE_ENTRY(mixOutStr_8); STR_TABLE_ENTRY(mixOutStr_8);
#endif #endif
#ifdef IAP #ifdef IAP
@@ -391,31 +391,31 @@ StringDescTable_t g_strTable =
#error NUM_USB_CHAN_IN > 32 #error NUM_USB_CHAN_IN > 32
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
.mixOutStr_1 = "Mix 1", .mixOutStr_1 = "Mix 1",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 1) #if (MIXER) && (MAX_MIX_COUNT > 1)
.mixOutStr_2 = "Mix 2", .mixOutStr_2 = "Mix 2",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 2) #if (MIXER) && (MAX_MIX_COUNT > 2)
.mixOutStr_3 = "Mix 3", .mixOutStr_3 = "Mix 3",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 3) #if (MIXER) && (MAX_MIX_COUNT > 3)
.mixOutStr_4 = "Mix 4", .mixOutStr_4 = "Mix 4",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 4) #if (MIXER) && (MAX_MIX_COUNT > 4)
.mixOutStr_5 = "Mix 5", .mixOutStr_5 = "Mix 5",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 5) #if (MIXER) && (MAX_MIX_COUNT > 5)
.mixOutStr_6 = "Mix 6", .mixOutStr_6 = "Mix 6",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 6) #if (MIXER) && (MAX_MIX_COUNT > 6)
.mixOutStr_7 = "Mix 7", .mixOutStr_7 = "Mix 7",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 7) #if (MIXER) && (MAX_MIX_COUNT > 7)
.mixOutStr_8 = "Mix 8", .mixOutStr_8 = "Mix 8",
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 8) #if (MIXER) && (MAX_MIX_COUNT > 8)
#error #error
#endif #endif
#ifdef IAP #ifdef IAP
@@ -558,7 +558,7 @@ unsigned char devQualDesc_Null[] =
}; };
#if defined(MIXER) && !defined(AUDIO_PATH_XUS) && (MAX_MIX_COUNT > 0) #if (MIXER) && !defined(AUDIO_PATH_XUS) && (MAX_MIX_COUNT > 0)
//#warning Extension 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 #define AUDIO_PATH_XUS
#endif #endif
@@ -575,7 +575,7 @@ unsigned char devQualDesc_Null[] =
#define DFU_LENGTH (0) #define DFU_LENGTH (0)
#endif #endif
#ifdef MIXER #if (MIXER)
#define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8) #define MIX_BMCONTROLS_LEN_TMP ((MAX_MIX_COUNT * MIX_INPUTS) / 8)
#if ((MAX_MIX_COUNT * MIX_INPUTS)%8)==0 #if ((MAX_MIX_COUNT * MIX_INPUTS)%8)==0
@@ -666,7 +666,7 @@ typedef struct
#if (NUM_USB_CHAN_OUT > 0) #if (NUM_USB_CHAN_OUT > 0)
/* Output path */ /* Output path */
USB_Descriptor_Audio_InputTerminal_t Audio_Out_InputTerminal; USB_Descriptor_Audio_InputTerminal_t Audio_Out_InputTerminal;
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
USB_Descriptor_Audio_ExtensionUnit_t Audio_Out_ExtensionUnit; USB_Descriptor_Audio_ExtensionUnit_t Audio_Out_ExtensionUnit;
#endif #endif
#if(OUTPUT_VOLUME_CONTROL == 1) #if(OUTPUT_VOLUME_CONTROL == 1)
@@ -677,7 +677,7 @@ typedef struct
#if (NUM_USB_CHAN_IN > 0) #if (NUM_USB_CHAN_IN > 0)
/* Input path */ /* Input path */
USB_Descriptor_Audio_InputTerminal_t Audio_In_InputTerminal; USB_Descriptor_Audio_InputTerminal_t Audio_In_InputTerminal;
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
USB_Descriptor_Audio_ExtensionUnit_t Audio_In_ExtensionUnit; USB_Descriptor_Audio_ExtensionUnit_t Audio_In_ExtensionUnit;
#endif #endif
#if(INPUT_VOLUME_CONTROL == 1) #if(INPUT_VOLUME_CONTROL == 1)
@@ -685,7 +685,7 @@ typedef struct
#endif #endif
USB_Descriptor_Audio_OutputTerminal_t Audio_In_OutputTerminal; USB_Descriptor_Audio_OutputTerminal_t Audio_In_OutputTerminal;
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
USB_Descriptor_Audio_ExtensionUnit2_t Audio_Mix_ExtensionUnit; USB_Descriptor_Audio_ExtensionUnit2_t Audio_Mix_ExtensionUnit;
// Currently no struct for mixer unit // Currently no struct for mixer unit
// USB_Descriptor_Audio_MixerUnit_t Audio_MixerUnit; // USB_Descriptor_Audio_MixerUnit_t Audio_MixerUnit;
@@ -1168,7 +1168,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: CS_INTERFACE */ UAC_CS_DESCTYPE_INTERFACE, /* 1 bDescriptorType: CS_INTERFACE */
UAC_CS_AC_INTERFACE_SUBTYPE_FEATURE_UNIT, /* 2 bDescriptorSubType: FEATURE_UNIT */ UAC_CS_AC_INTERFACE_SUBTYPE_FEATURE_UNIT, /* 2 bDescriptorSubType: FEATURE_UNIT */
FU_USBIN, /* 3 bUnitID */ FU_USBIN, /* 3 bUnitID */
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
ID_XU_IN, /* 4 bSourceID */ ID_XU_IN, /* 4 bSourceID */
#else #else
ID_IT_AUD, /* 4 bSourceID */ ID_IT_AUD, /* 4 bSourceID */
@@ -1300,7 +1300,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
}, },
#endif /* (NUM_USB_CHAN_IN > 0) */ #endif /* (NUM_USB_CHAN_IN > 0) */
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if (MIXER) && (MAX_MIX_COUNT > 0)
/* Extension Unit Descriptor (4.7.2.12) */ /* Extension Unit Descriptor (4.7.2.12) */
.Audio_Mix_ExtensionUnit = .Audio_Mix_ExtensionUnit =
{ {
@@ -1392,7 +1392,7 @@ USB_Config_Descriptor_Audio2_t cfgDesc_Audio2=
0x00, /* bmControls */ 0x00, /* bmControls */
0 /* Mixer unit string descriptor index */ 0 /* Mixer unit string descriptor index */
}, },
#endif /* defined(MIXER) && (MAX_MIX_COUNT > 0) */ #endif /* (MIXER) && (MAX_MIX_COUNT > 0) */
#if (XUA_SPDIF_RX_EN) || (XUA_ADAT_RX_EN) #if (XUA_SPDIF_RX_EN) || (XUA_ADAT_RX_EN)
/* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */ /* Standard AS Interrupt Endpoint Descriptor (4.8.2.1): */

View File

@@ -31,7 +31,7 @@ extern int volsIn[];
extern unsigned int mutesIn[]; extern unsigned int mutesIn[];
/* Mixer settings */ /* Mixer settings */
#ifdef MIXER #if (MIXER)
extern short mixer1Weights[]; extern short mixer1Weights[];
/* Device channel mapping */ /* Device channel mapping */
@@ -132,10 +132,10 @@ static unsigned longMul(unsigned a, unsigned b, int prec)
static void updateMasterVol( int unitID, chanend ?c_mix_ctl) static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
{ {
int x; int x;
#ifndef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER == 0)
xc_ptr p_multOut = array_to_xc_ptr(multOut); xc_ptr p_multOut = array_to_xc_ptr(multOut);
#endif #endif
#ifndef IN_VOLUME_IN_MIXER #if (IN_VOLUME_IN_MIXER == 0)
xc_ptr p_multIn = array_to_xc_ptr(multIn); xc_ptr p_multIn = array_to_xc_ptr(multIn);
#endif #endif
switch( unitID) switch( unitID)
@@ -152,7 +152,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i]; x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[i];
#ifdef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER)
if (!isnull(c_mix_ctl)) if (!isnull(c_mix_ctl))
{ {
outuint(c_mix_ctl, SET_MIX_OUT_VOL); outuint(c_mix_ctl, SET_MIX_OUT_VOL);
@@ -178,7 +178,7 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[i]; x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[i];
#ifdef IN_VOLUME_IN_MIXER #if (IN_VOLUME_IN_MIXER)
if (!isnull(c_mix_ctl)) if (!isnull(c_mix_ctl))
{ {
outuint(c_mix_ctl, SET_MIX_IN_VOL); outuint(c_mix_ctl, SET_MIX_IN_VOL);
@@ -201,10 +201,10 @@ static void updateMasterVol( int unitID, chanend ?c_mix_ctl)
static void updateVol(int unitID, int channel, chanend ?c_mix_ctl) static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
{ {
int x; int x;
#ifndef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER == 0)
xc_ptr p_multOut = array_to_xc_ptr(multOut); xc_ptr p_multOut = array_to_xc_ptr(multOut);
#endif #endif
#ifndef IN_VOLUME_IN_MIXER #if (IN_VOLUME_IN_MIXER == 0)
xc_ptr p_multIn = array_to_xc_ptr(multIn); xc_ptr p_multIn = array_to_xc_ptr(multIn);
#endif #endif
/* Check for master volume update */ /* Check for master volume update */
@@ -225,7 +225,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[channel]; x = longMul(master_vol, vol, 29) * !mutesOut[0] * !mutesOut[channel];
#ifdef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER)
if (!isnull(c_mix_ctl)) if (!isnull(c_mix_ctl))
{ {
outuint(c_mix_ctl, SET_MIX_OUT_VOL); outuint(c_mix_ctl, SET_MIX_OUT_VOL);
@@ -247,7 +247,7 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[channel]; x = longMul(master_vol, vol, 29) * !mutesIn[0] * !mutesIn[channel];
#ifdef IN_VOLUME_IN_MIXER #if (IN_VOLUME_IN_MIXER)
if (!isnull(c_mix_ctl)) if (!isnull(c_mix_ctl))
{ {
outuint(c_mix_ctl, SET_MIX_IN_VOL); outuint(c_mix_ctl, SET_MIX_IN_VOL);
@@ -657,7 +657,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
break; /* FU_USBIN */ break; /* FU_USBIN */
#endif #endif
#if defined(MIXER) && (MAX_MIX_COUNT > 0) #if ((MIXER) && (MAX_MIX_COUNT > 0))
case ID_XU_OUT: case ID_XU_OUT:
{ {
if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */ if(sp.bmRequestType.Direction == USB_BM_REQTYPE_DIRECTION_H2D) /* Direction: Host-to-device */
@@ -974,7 +974,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
} }
break; break;
#ifdef MIXER #if (MIXER)
/* Mixer Unit */ /* Mixer Unit */
case ID_MIXER_1: case ID_MIXER_1:
storeShort((buffer, unsigned char[]), 0, 1); storeShort((buffer, unsigned char[]), 0, 1);
@@ -994,7 +994,7 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
break; /* case: RANGE */ break; /* case: RANGE */
} }
#if defined (MIXER) && (MAX_MIX_COUNT > 0) #if ((MIXER) && (MAX_MIX_COUNT > 0))
case MEM: /* Memory Requests (5.2.7.1) */ case MEM: /* Memory Requests (5.2.7.1) */
unitID = sp.wIndex >> 8; unitID = sp.wIndex >> 8;

View File

@@ -273,7 +273,7 @@ void usb_audio_core(chanend c_mix_out
#ifdef MIDI #ifdef MIDI
, chanend c_midi , chanend c_midi
#endif #endif
#ifdef MIXER #if (MIXER)
, chanend c_mix_ctl , chanend c_mix_ctl
#endif #endif
, chanend ?c_clk_int , chanend ?c_clk_int
@@ -290,7 +290,7 @@ VENDOR_REQUESTS_PARAMS_DEC_
chan c_xud_in[ENDPOINT_COUNT_IN]; chan c_xud_in[ENDPOINT_COUNT_IN];
chan c_aud_ctl; chan c_aud_ctl;
#ifndef MIXER #if (MIXER)
#define c_mix_ctl null #define c_mix_ctl null
#endif #endif
@@ -401,7 +401,7 @@ void usb_audio_io(chanend ?c_aud_in,
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
chanend c_spdif_tx, chanend c_spdif_tx,
#endif #endif
#ifdef MIXER #if (MIXER)
chanend c_mix_ctl, chanend c_mix_ctl,
#endif #endif
streaming chanend ?c_spdif_rx, streaming chanend ?c_spdif_rx,
@@ -422,7 +422,7 @@ void usb_audio_io(chanend ?c_aud_in,
#endif #endif
) )
{ {
#ifdef MIXER #if (MIXER)
chan c_mix_out; chan c_mix_out;
#endif #endif
@@ -446,7 +446,7 @@ void usb_audio_io(chanend ?c_aud_in,
par par
{ {
#ifdef MIXER #if (MIXER)
/* Mixer cores(s) */ /* Mixer cores(s) */
{ {
thread_speed(); thread_speed();
@@ -464,7 +464,7 @@ void usb_audio_io(chanend ?c_aud_in,
/* Audio I/O core (pars additional S/PDIF TX Core) */ /* Audio I/O core (pars additional S/PDIF TX Core) */
{ {
thread_speed(); thread_speed();
#ifdef MIXER #if (MIXER)
#define AUDIO_CHANNEL c_mix_out #define AUDIO_CHANNEL c_mix_out
#else #else
#define AUDIO_CHANNEL c_aud_in #define AUDIO_CHANNEL c_aud_in
@@ -531,7 +531,7 @@ int main()
#endif #endif
#endif #endif
#ifdef MIXER #if (MIXER)
chan c_mix_ctl; chan c_mix_ctl;
#endif #endif
@@ -608,7 +608,7 @@ int main()
, c_ea_data , c_ea_data
#endif #endif
#endif #endif
#ifdef MIXER #if (MIXER)
, c_mix_ctl , c_mix_ctl
#endif #endif
, c_clk_int, c_clk_ctl, dfuInterface , c_clk_int, c_clk_ctl, dfuInterface
@@ -628,7 +628,7 @@ int main()
#if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE) #if (XUA_SPDIF_TX_EN) && (SPDIF_TX_TILE != AUDIO_IO_TILE)
, c_spdif_tx , c_spdif_tx
#endif #endif
#ifdef MIXER #if (MIXER)
, c_mix_ctl , c_mix_ctl
#endif #endif
, c_spdif_rx, c_adat_rx, c_clk_ctl, c_clk_int , c_spdif_rx, c_adat_rx, c_clk_ctl, c_clk_int

View File

@@ -1,4 +1,4 @@
// Copyright 2018-2021 XMOS LIMITED. // Copyright 2018-2023 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1. // This Software is subject to the terms of the XMOS Public Licence: Version 1.
#define MAX_MIX_COUNT 8 #define MAX_MIX_COUNT 8

View File

@@ -5,23 +5,36 @@
#include <xs1.h> #include <xs1.h>
#include "xua.h" #include "xua.h"
#include "xc_ptr.h"
#include "xua_commands.h" #include "xua_commands.h"
#include "dbcalc.h" #include "dbcalc.h"
#include "print.h"
#ifdef MIXER #if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS)
#include "xc_ptr.h"
#endif
#if (MIXER)
/* FAST_MIXER has a bit of a nasty implentation but is more effcient */ /* FAST_MIXER has a bit of a nasty implentation but is more effcient */
#define FAST_MIXER 1 #ifndef FAST_MIXER
#define FAST_MIXER (1)
#endif
//#ifdef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER)
static unsigned int multOut_array[NUM_USB_CHAN_OUT + 1]; static unsigned int multOut_array[NUM_USB_CHAN_OUT + 1];
static xc_ptr multOut; unsafe
//#endif {
//#ifdef IN_VOLUME_IN_MIXER int volatile * unsafe multOut = multOut_array;
}
#endif
#if (IN_VOLUME_IN_MIXER)
static unsigned int multIn_array[NUM_USB_CHAN_IN + 1]; static unsigned int multIn_array[NUM_USB_CHAN_IN + 1];
static xc_ptr multIn; unsafe
//#endif {
int volatile * unsafe multIn = multIn_array;
}
#endif
#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST) #if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST)
static unsigned abs(int x) static unsigned abs(int x)
@@ -40,8 +53,8 @@ static unsigned abs(int x)
static const int SOURCE_COUNT = NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT + 1; static const int SOURCE_COUNT = NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT + 1;
static int samples_array[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT + 1]; /* One larger for an "off" channel for mixer sources" */ static int samples_array[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT + 1]; /* One larger for an "off" channel for mixer sources" */
int samples_to_host_map_array[NUM_USB_CHAN_IN]; static int samples_to_host_map_array[NUM_USB_CHAN_IN];
int samples_to_device_map_array[NUM_USB_CHAN_OUT]; static int samples_to_device_map_array[NUM_USB_CHAN_OUT];
unsafe unsafe
{ {
@@ -50,19 +63,25 @@ unsafe
int volatile * const unsafe samples_to_device_map = samples_to_device_map_array; int volatile * const unsafe samples_to_device_map = samples_to_device_map_array;
} }
#if MAX_MIX_COUNT > 0 #if (MAX_MIX_COUNT > 0)
int mix_mult_array[MAX_MIX_COUNT][MIX_INPUTS]; int mix_mult_array[MAX_MIX_COUNT * MIX_INPUTS];
xc_ptr mix_mult; #if (FAST_MIXER == 0)
#define write_word_to_mix_mult(x,y,val) write_via_xc_ptr_indexed(mix_mult,((x)*MIX_INPUTS)+(y), val) int mix_map_array[MAX_MIX_COUNT * MIX_INPUTS];
#define mix_mult_slice(x) (mix_mult + x * MIX_INPUTS * sizeof(int))
#ifndef FAST_MIXER
int mix_map_array[MAX_MIX_COUNT][MIX_INPUTS];
xc_ptr mix_map;
#define write_word_to_mix_map(x,y,val) write_via_xc_ptr_indexed(mix_map,((x)*MIX_INPUTS)+(y), val)
#define mix_map_slice(x) (mix_map + x * MIX_INPUTS * sizeof(int))
#endif
#endif #endif
unsafe
{
int volatile * const unsafe mix_mult = mix_mult_array;
#if (FAST_MIXER == 0)
int volatile * const unsafe mix_map = mix_map_array;
#endif
}
#define slice(a, i) (a + i * MIX_INPUTS)
#endif
#if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS)
/* Arrays for level data */ /* Arrays for level data */
int samples_to_host_inputs[NUM_USB_CHAN_IN]; /* Audio transmitted to host i.e. device 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; xc_ptr samples_to_host_inputs_ptr;
@@ -76,7 +95,6 @@ static int samples_from_host_streams[NUM_USB_CHAN_OUT]; /* Peak samples for audi
static int samples_mixer_outputs[MAX_MIX_COUNT]; /* Peak samples out of the mixer */ static int samples_mixer_outputs[MAX_MIX_COUNT]; /* Peak samples out of the mixer */
xc_ptr samples_mixer_outputs_ptr; xc_ptr samples_mixer_outputs_ptr;
#if defined (LEVEL_METER_LEDS) || defined (LEVEL_METER_HOST)
static inline void ComputeMixerLevel(int sample, int i) static inline void ComputeMixerLevel(int sample, int i)
{ {
int x; int x;
@@ -95,21 +113,22 @@ static inline void ComputeMixerLevel(int sample, int i)
} }
} }
#endif #endif
#ifdef FAST_MIXER
#if (FAST_MIXER)
void setPtr(int src, int dst, int mix); void setPtr(int src, int dst, int mix);
int doMix0(volatile int * const unsafe samples, xc_ptr mult); int doMix0(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix1(volatile int * const unsafe samples, xc_ptr mult); int doMix1(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix2(volatile int * const unsafe samples, xc_ptr mult); int doMix2(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix3(volatile int * const unsafe samples, xc_ptr mult); int doMix3(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix4(volatile int * const unsafe samples, xc_ptr mult); int doMix4(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix5(volatile int * const unsafe samples, xc_ptr mult); int doMix5(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix6(volatile int * const unsafe samples, xc_ptr mult); int doMix6(volatile int * const unsafe samples, volatile int * const unsafe mult);
int doMix7(volatile int * const unsafe samples, xc_ptr mult); int doMix7(volatile int * const unsafe samples, volatile int * const unsafe mult);
#else #else
/* DO NOT inline, causes 10.4.2 tools to add extra loads in loop */ /* DO NOT inline, causes 10.4.2 tools to add extra loads in loop */
/* At 18 x 12dB we could get 64 x bigger */ /* At 18 x 12dB we could get 64 x bigger */
#pragma unsafe arrays #pragma unsafe arrays
static inline int doMix(volatile int * unsafe samples, xc_ptr ptr, xc_ptr mult) static inline int doMix(volatile int * unsafe samples, volatile int * unsafe const mixMap, volatile int * const unsafe mult)
{ {
int h=0; int h=0;
int l=0; int l=0;
@@ -121,7 +140,7 @@ static inline int doMix(volatile int * unsafe samples, xc_ptr ptr, xc_ptr mult)
int sample; int sample;
int source; int source;
int weight; int weight;
read_via_xc_ptr_indexed(source, ptr, i); read_via_xc_ptr_indexed(source, mixMap, i);
sample = samples[source]; sample = samples[source];
read_via_xc_ptr_indexed(weight, mult, i); read_via_xc_ptr_indexed(weight, mult, i);
{h,l} = macs(sample, weight, h, l); {h,l} = macs(sample, weight, h, l);
@@ -142,9 +161,9 @@ static inline int doMix(volatile int * unsafe samples, xc_ptr ptr, xc_ptr mult)
#endif #endif
#pragma unsafe arrays #pragma unsafe arrays
static inline void GiveSamplesToHost(chanend c, volatile int * unsafe hostMap, xc_ptr multIn) static inline void GiveSamplesToHost(chanend c, volatile int * unsafe hostMap)
{ {
#if defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) #if (IN_VOLUME_IN_MIXER && IN_VOLUME_AFTER_MIX)
int mult; int mult;
int h; int h;
unsigned l; unsigned l;
@@ -164,10 +183,13 @@ static inline void GiveSamplesToHost(chanend c, volatile int * unsafe hostMap, x
sample = ptr_sample[i + NUM_USB_CHAN_OUT]; sample = ptr_sample[i + NUM_USB_CHAN_OUT];
#endif #endif
#if defined(IN_VOLUME_IN_MIXER) && defined(IN_VOLUME_AFTER_MIX) #if (IN_VOLUME_IN_MIXER && IN_VOLUME_AFTER_MIX)
#warning IN Vols in mixer, AFTER mix & map #warning IN Vols in mixer, AFTER mix & map
//asm("ldw %0, %1[%2]":"=r"(mult):"r"(multIn),"r"(i));
read_via_xc_ptr_indexed(mult, multIn, i); unsafe
{
mult = multIn[i];
}
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
//h <<= 3 done on other side */ //h <<= 3 done on other side */
@@ -190,7 +212,7 @@ static inline void GetSamplesFromHost(chanend c)
for (int i=0; i<NUM_USB_CHAN_OUT; i++) for (int i=0; i<NUM_USB_CHAN_OUT; i++)
unsafe { unsafe {
int sample, x; int sample, x;
#if defined(OUT_VOLUME_IN_MIXER) && !defined(OUT_VOLUME_AFTER_MIX) #if (OUT_VOLUME_IN_MIXER && OUT_VOLUME_AFTER_MIX)
int mult; int mult;
int h; int h;
unsigned l; unsigned l;
@@ -207,16 +229,15 @@ static inline void GetSamplesFromHost(chanend c)
} }
#endif #endif
#if defined(OUT_VOLUME_IN_MIXER) && !defined(OUT_VOLUME_AFTER_MIX) #if (OUT_VOLUME_IN_MIXER && OUT_VOLUME_AFTER_MIX)
#warning OUT Vols in mixer, BEFORE mix & map #warning OUT Vols in mixer, BEFORE mix & map
read_via_xc_ptr_indexed(mult, multOut, i); mult = multOut[i];
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
h<<=3; h<<=3;
#if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1) #if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1)
h |= (l >>29)& 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit) h |= (l >>29)& 0x7; // Note: This step is not required if we assume sample depth is 24bit (rather than 32bit)
// Note: We need all 32bits for Native DSD // Note: We need all 32bits for Native DSD
#endif #endif
write_via_xc_ptr_indexed(multOut, index, val);
write_via_xc_ptr_indexed(samples_array, i, h); write_via_xc_ptr_indexed(samples_array, i, h);
#else #else
ptr_samples[i] = sample; ptr_samples[i] = sample;
@@ -227,23 +248,23 @@ static inline void GetSamplesFromHost(chanend c)
} }
#pragma unsafe arrays #pragma unsafe arrays
static inline void GiveSamplesToDevice(chanend c, volatile int * unsafe deviceMap, xc_ptr multOut) static inline void GiveSamplesToDevice(chanend c, volatile int * unsafe deviceMap)
{ {
#if(NUM_USB_CHAN_OUT == 0) #if (NUM_USB_CHAN_OUT == 0)
outuint(c, 0); outuint(c, 0);
#else #else
#pragma loop unroll #pragma loop unroll
for (int i=0; i<NUM_USB_CHAN_OUT; i++) for (int i=0; i<NUM_USB_CHAN_OUT; i++)
{ {
int sample, x; int sample, x;
#if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) #if (OUT_VOLUME_IN_MIXER && OUT_VOLUME_AFTER_MIX)
int mult; int mult;
int h; int h;
unsigned l; unsigned l;
#endif #endif
int index; int index;
#if MAX_MIX_COUNT > 0 #if (MAX_MIX_COUNT > 0)
/* If mixer turned on sort out the channel mapping */ /* If mixer turned on sort out the channel mapping */
unsafe unsafe
{ {
@@ -258,10 +279,14 @@ static inline void GiveSamplesToDevice(chanend c, volatile int * unsafe deviceMa
} }
#endif #endif
#if defined(OUT_VOLUME_IN_MIXER) && defined(OUT_VOLUME_AFTER_MIX) #if (OUT_VOLUME_IN_MIXER && OUT_VOLUME_AFTER_MIX)
/* Do volume control processing */ /* Do volume control processing */
#warning OUT Vols in mixer, AFTER mix & map #warning OUT Vols in mixer, AFTER mix & map
read_via_xc_ptr_indexed(mult, multOut, i); unsafe
{
mult = multOut[i];
}
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
h<<=3; // Shift used to be done in audio thread but now done here incase of 32bit support h<<=3; // Shift used to be done in audio thread but now done here incase of 32bit support
#if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1) #if (STREAM_FORMAT_OUTPUT_RESOLUTION_32BIT_USED == 1)
@@ -279,7 +304,7 @@ static inline void GiveSamplesToDevice(chanend c, volatile int * unsafe deviceMa
#pragma unsafe arrays #pragma unsafe arrays
static inline void GetSamplesFromDevice(chanend c) static inline void GetSamplesFromDevice(chanend c)
{ {
#if defined(IN_VOLUME_IN_MIXER) && !defined(IN_VOLUME_AFTER_MIX) #if (IN_VOLUME_IN_MIXER && IN_VOLUME_AFTER_MIX)
int mult; int mult;
int h; int h;
unsigned l; unsigned l;
@@ -306,9 +331,12 @@ static inline void GetSamplesFromDevice(chanend c)
} }
#endif #endif
#if defined(IN_VOLUME_IN_MIXER) && !defined(IN_VOLUME_AFTER_MIX) #if (IN_VOLUME_IN_MIXER && IN_VOLUME_AFTER_MIX)
/* Read relevant multiplier */ /* Read relevant multiplier */
read_via_xc_ptr_indexed(mult, multIn, i); unsafe
{
mult = multIn[i];
}
/* Do the multiply */ /* Do the multiply */
{h, l} = macs(mult, sample, 0, 0); {h, l} = macs(mult, sample, 0, 0);
@@ -357,7 +385,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
int mix, index, val; int mix, index, val;
switch (cmd) switch (cmd)
{ {
#if MAX_MIX_COUNT > 0 #if (MAX_MIX_COUNT > 0)
case SET_SAMPLES_TO_HOST_MAP: case SET_SAMPLES_TO_HOST_MAP:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
val = inuint(c_mix_ctl); val = inuint(c_mix_ctl);
@@ -388,8 +416,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
if((index < MIX_INPUTS) && (mix < MAX_MIX_COUNT)) if((index < MIX_INPUTS) && (mix < MAX_MIX_COUNT))
unsafe { unsafe {
//mix_mult[(mix * MIX_INPUTS) + index] = val; mix_mult[(mix * MIX_INPUTS) + index] = val;
write_word_to_mix_mult(mix, index, val);
} }
assert((mix < MAX_MIX_COUNT) && msg("Mix mult mix out of range")); assert((mix < MAX_MIX_COUNT) && msg("Mix mult mix out of range"));
@@ -409,34 +436,46 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
if((input < MIX_INPUTS) && (mix < MAX_MIX_COUNT) && (source < SOURCE_COUNT)) if((input < MIX_INPUTS) && (mix < MAX_MIX_COUNT) && (source < SOURCE_COUNT))
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
setPtr(input, source, mix); setPtr(input, source, mix);
#else #else
write_word_to_mix_map(mix, input, source); unsafe
{
mix_map[(mix * MIX_INPUTS) + input] = source;
}
#endif #endif
} }
} }
break; break;
#endif /* if MAX_MIX_COUNT > 0 */ #endif /* if MAX_MIX_COUNT > 0 */
#ifdef IN_VOLUME_IN_MIXER #if (IN_VOLUME_IN_MIXER)
case SET_MIX_IN_VOL: case SET_MIX_IN_VOL:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
val = inuint(c_mix_ctl); val = inuint(c_mix_ctl);
inct(c_mix_ctl); inct(c_mix_ctl);
write_via_xc_ptr_indexed(multIn, index, val); if(index < NUM_USB_CHAN_IN+1)
unsafe{
multIn[index] = val;
}
assert((index < (NUM_USB_CHAN_IN + 1)) && msg("In volume index out of range"));
break; break;
#endif #endif
#ifdef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER)
case SET_MIX_OUT_VOL: case SET_MIX_OUT_VOL:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
val = inuint(c_mix_ctl); val = inuint(c_mix_ctl);
inct(c_mix_ctl); inct(c_mix_ctl);
write_via_xc_ptr_indexed(multOut, index, val); if(index < NUM_USB_CHAN_OUT+1)
unsafe{
multOut[index] = val;
}
assert((index < (NUM_USB_CHAN_OUT + 1)) && msg("Out volume index out of range"));
break; break;
#endif #endif
#if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS)
/* Peak samples of stream from host to device (via USB) */ /* Peak samples of stream from host to device (via USB) */
case GET_STREAM_LEVELS: case GET_STREAM_LEVELS:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
@@ -445,7 +484,6 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
samples_from_host_streams[index] = 0; samples_from_host_streams[index] = 0;
break; break;
case GET_INPUT_LEVELS: case GET_INPUT_LEVELS:
index = inuint(c_mix_ctl); index = inuint(c_mix_ctl);
chkct(c_mix_ctl, XS1_CT_END); chkct(c_mix_ctl, XS1_CT_END);
@@ -481,6 +519,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
outuint(c_mix_ctl, val); outuint(c_mix_ctl, val);
outct(c_mix_ctl, XS1_CT_END); outct(c_mix_ctl, XS1_CT_END);
break; break;
#endif
#endif #endif
} }
break; break;
@@ -537,22 +576,22 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
} }
else else
{ {
#if MAX_MIX_COUNT > 0 #if (MAX_MIX_COUNT > 0)
GetSamplesFromHost(c_host); GetSamplesFromHost(c_host);
GiveSamplesToHost(c_host, samples_to_host_map, multIn); GiveSamplesToHost(c_host, samples_to_host_map);
/* Sync with mixer 2 (once it has swapped samples with audiohub) */ /* Sync with mixer 2 (once it has swapped samples with audiohub) */
outuint(c_mixer2, 0); outuint(c_mixer2, 0);
inuint(c_mixer2); inuint(c_mixer2);
/* Do the mixing */ /* Do the mixing */
#ifdef FAST_MIXER
mixed = doMix0(ptr_samples, mix_mult_slice(0));
#else
mixed = doMix(ptr_samples, mix_map_slice(0), mix_mult_slice(0));
#endif
unsafe unsafe
{ {
#if (FAST_MIXER)
mixed = doMix0(ptr_samples, slice(mix_mult, 0));
#else
mixed = doMix(ptr_samples, slice(mix_map, 0), slice(mix_mult, 0));
#endif
ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 0] = mixed; ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 0] = mixed;
} }
@@ -565,13 +604,13 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
#endif #endif
{ {
#if MAX_MIX_COUNT > 2 #if (MAX_MIX_COUNT > 2)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix2(ptr_samples, mix_mult_slice(2)); mixed = doMix2(ptr_samples, slice(mix_mult, 2));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(2), mix_mult_slice(2)); mixed = doMix(ptr_samples, slice(mix_map, 2), slice(mix_mult, 2));
#endif #endif
ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 2] = mixed; ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 2] = mixed;
} }
@@ -580,13 +619,13 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
#endif #endif
#endif #endif
#if MAX_MIX_COUNT > 4 #if (MAX_MIX_COUNT > 4)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix4(ptr_samples, mix_mult_slice(4)); mixed = doMix4(ptr_samples, slice(mix_mult, 4));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(4), mix_mult_slice(4)); mixed = doMix(ptr_samples, slice(mix_map, 4), slice(mix_mult, 4));
#endif #endif
ptr_samples[XUA_MIXER_OFFSET_MIX + 4] = mixed; ptr_samples[XUA_MIXER_OFFSET_MIX + 4] = mixed;
} }
@@ -595,13 +634,13 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
#endif #endif
#endif #endif
#if MAX_MIX_COUNT > 6 #if (MAX_MIX_COUNT > 6)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix6(ptr_samples, mix_mult_slice(6)); mixed = doMix6(ptr_samples, slice(mix_mult, 6));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(6), mix_mult_slice(6)); mixed = doMix(ptr_samples, slice(mix_map, 6), slice(mix_mult, 6));
#endif #endif
ptr_samples[XUA_MIXER_OFFSET_MIX + 6] = mixed; ptr_samples[XUA_MIXER_OFFSET_MIX + 6] = mixed;
} }
@@ -612,7 +651,7 @@ static void mixer1(chanend c_host, chanend c_mix_ctl, chanend c_mixer2)
} }
#else /* IF MAX_MIX_COUNT > 0 */ #else /* IF MAX_MIX_COUNT > 0 */
/* No mixes, this thread runs on its own doing just volume */ /* No mixes, this thread runs on its own doing just volume */
GiveSamplesToDevice(c_mixer2, samples_to_device_map, multOut); GiveSamplesToDevice(c_mixer2, samples_to_device_map);
GetSamplesFromDevice(c_mixer2); GetSamplesFromDevice(c_mixer2);
GetSamplesFromHost(c_host); GetSamplesFromHost(c_host);
GiveSamplesToHost(c_host, samples_to_host_map, multIn); GiveSamplesToHost(c_host, samples_to_host_map, multIn);
@@ -679,7 +718,7 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
} }
else else
{ {
GiveSamplesToDevice(c_audio, samples_to_device_map, multOut); GiveSamplesToDevice(c_audio, samples_to_device_map);
GetSamplesFromDevice(c_audio); GetSamplesFromDevice(c_audio);
/* Sync with mixer 1 (once it has swapped samples with the buffering sub-system) */ /* Sync with mixer 1 (once it has swapped samples with the buffering sub-system) */
@@ -687,13 +726,13 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
outuint(c_mixer1, 0); outuint(c_mixer1, 0);
/* Do the mixing */ /* Do the mixing */
#if MAX_MIX_COUNT > 1 #if (MAX_MIX_COUNT > 1)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix1(ptr_samples, mix_mult_slice(1)); mixed = doMix1(ptr_samples, slice(mix_mult, 1));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(1), mix_mult_slice(1)); mixed = doMix(ptr_samples, slice(mix_map, 1), slice(mix_mult, 1));
#endif #endif
ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 1] = mixed; ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 1] = mixed;
} }
@@ -707,13 +746,13 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
if (!mixer2_mix2_flag) if (!mixer2_mix2_flag)
#endif #endif
{ {
#if MAX_MIX_COUNT > 3 #if (MAX_MIX_COUNT > 3)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix3(ptr_samples, mix_mult_slice(3)); mixed = doMix3(ptr_samples, slice(mix_mult, 3));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(3), mix_mult_slice(3)); mixed = doMix(ptr_samples, slice(mix_map, 3), slice(mix_mult, 3));
#endif #endif
ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 3] = mixed; ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 3] = mixed;
} }
@@ -722,13 +761,13 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
#endif #endif
#endif #endif
#if MAX_MIX_COUNT > 5 #if (MAX_MIX_COUNT > 5)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix5(ptr_samples, mix_mult_slice(5)); mixed = doMix5(ptr_samples, slice(mix_mult, 5));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(5), mix_mult_slice(5)); mixed = doMix(ptr_samples, slice(mix_map, 5), slice(mix_mult, 5));
#endif #endif
ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 5] = mixed; ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 5] = mixed;
@@ -738,13 +777,13 @@ static void mixer2(chanend c_mixer1, chanend c_audio)
#endif #endif
#endif #endif
#if MAX_MIX_COUNT > 7 #if (MAX_MIX_COUNT > 7)
unsafe unsafe
{ {
#ifdef FAST_MIXER #if (FAST_MIXER)
mixed = doMix7(ptr_samples, mix_mult_slice(7)); mixed = doMix7(ptr_samples, slice(mix_mult, 7));
#else #else
mixed = doMix(ptr_samples, mix_map_slice(7), mix_mult_slice(7)); mixed = doMix(ptr_samples, slice(mix_map, 7), slice(mix_mult, 7));
#endif #endif
ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 7] = mixed; ptr_samples[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + 7] = mixed;
} }
@@ -763,20 +802,13 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl)
#if (MAX_MIX_COUNT > 0) #if (MAX_MIX_COUNT > 0)
chan c; chan c;
#endif #endif
multOut = array_to_xc_ptr((multOut_array,unsigned[]));
multIn = array_to_xc_ptr((multIn_array,unsigned[]));
#if defined (LEVEL_METER_HOST) || defined(LEVEL_METER_LEDS)
samples_to_host_inputs_ptr = array_to_xc_ptr((samples_to_host_inputs, unsigned[])); samples_to_host_inputs_ptr = array_to_xc_ptr((samples_to_host_inputs, unsigned[]));
#ifdef LEVEL_METER_LEDS #ifdef LEVEL_METER_LEDS
samples_to_host_inputs_buff_ptr = array_to_xc_ptr((samples_to_host_inputs, unsigned[])); samples_to_host_inputs_buff_ptr = array_to_xc_ptr((samples_to_host_inputs, unsigned[]));
#endif #endif
samples_mixer_outputs_ptr = array_to_xc_ptr((samples_mixer_outputs, 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
mix_map = array_to_xc_ptr((mix_map_array,unsigned[]));
#endif
#endif #endif
for (int i=0;i<NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT;i++) for (int i=0;i<NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + MAX_MIX_COUNT;i++)
@@ -784,41 +816,38 @@ void mixer(chanend c_mix_in, chanend c_mix_out, chanend c_mix_ctl)
ptr_samples[i] = 0; ptr_samples[i] = 0;
} }
{ for (int i=0; i<NUM_USB_CHAN_OUT; i++)
int num_mixes = DEFAULT_FREQ > 96000 ? 2 : MAX_MIX_COUNT;
for (int i=0;i<NUM_USB_CHAN_OUT;i++)
{ {
samples_to_device_map_array[i] = i; samples_to_device_map_array[i] = i;
} }
}
#ifdef OUT_VOLUME_IN_MIXER #if (OUT_VOLUME_IN_MIXER)
for (int i=0;i<NUM_USB_CHAN_OUT;i++) for (int i=0; i<NUM_USB_CHAN_OUT; i++)
{ unsafe{
write_via_xc_ptr_indexed(multOut, i, MAX_VOL); multOut[i] = MAX_VOL;
} }
#endif #endif
#ifdef IN_VOLUME_IN_MIXER #if (IN_VOLUME_IN_MIXER)
for (int i=0;i<NUM_USB_CHAN_IN;i++) for (int i=0; i<NUM_USB_CHAN_IN; i++)
{ unsafe{
write_via_xc_ptr_indexed(multIn, i, MAX_VOL); multIn[i] = MAX_VOL;
} }
#endif #endif
for (int i=0;i<NUM_USB_CHAN_IN;i++) for (int i=0; i<NUM_USB_CHAN_IN; i++)
{ unsafe{
write_via_xc_ptr_indexed(samples_to_host_map, i, XUA_MIXER_OFFSET_IN + i); samples_to_host_map[i] = XUA_MIXER_OFFSET_IN + i;
} }
#if MAX_MIX_COUNT> 0 #if (MAX_MIX_COUNT> 0)
for (int i=0;i<MAX_MIX_COUNT;i++) for (int i=0;i<MAX_MIX_COUNT;i++)
for (int j=0;j<MIX_INPUTS;j++) for (int j=0;j<MIX_INPUTS;j++)
{ unsafe{
#ifndef FAST_MIXER #if (FAST_MIXER == 0)
write_word_to_mix_map(i,j, j < 16 ? j : j + 2); mix_map[i * MIX_INPUTS + j] = (j < 16 ? j : j + 2);
#endif #endif
write_word_to_mix_mult(i,j, i==j ? db_to_mult(0, XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS) : 0); mix_mult[i * MIX_INPUTS + j] = (i==j ? db_to_mult(0, XUA_MIXER_DB_FRAC_BITS, XUA_MIXER_MULT_FRAC_BITS) : 0);
} }
#endif #endif