forked from PAWPAW-Mirror/lib_xua
- Added test_mixer_routing_output
- Various buffers no longer marked static to allow for easier unit testing - Added some comments and removed some dead code from the implementation - Moved mixer control comms to functions for unit test convenience
This commit is contained in:
@@ -43,12 +43,12 @@
|
||||
|
||||
#define MAX(x,y) ((x)>(y) ? (x) : (y))
|
||||
|
||||
static unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
|
||||
unsigned samplesOut[MAX(NUM_USB_CHAN_OUT, I2S_CHANS_DAC)];
|
||||
|
||||
/* Two buffers for ADC data to allow for DAC and ADC I2S ports being offset */
|
||||
#define IN_CHAN_COUNT (I2S_CHANS_ADC + XUA_NUM_PDM_MICS + (8*XUA_ADAT_RX_EN) + (2*XUA_SPDIF_RX_EN))
|
||||
|
||||
static unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
|
||||
unsigned samplesIn[2][MAX(NUM_USB_CHAN_IN, IN_CHAN_COUNT)];
|
||||
|
||||
#ifdef XTA_TIMING_AUDIO
|
||||
#pragma xta command "add exclusion received_command"
|
||||
@@ -91,7 +91,7 @@ unsigned dsdMode = DSD_MODE_OFF;
|
||||
#endif
|
||||
|
||||
#pragma unsafe arrays
|
||||
static inline unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord)
|
||||
unsigned DoSampleTransfer(chanend ?c_out, const int readBuffNo, const unsigned underflowWord)
|
||||
{
|
||||
if(XUA_USB_EN)
|
||||
{
|
||||
|
||||
@@ -109,9 +109,14 @@ unsigned int mutesIn[NUM_USB_CHAN_IN + 1];
|
||||
#ifdef MIXER
|
||||
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];
|
||||
/* Mapping of channels to output audio interfaces */
|
||||
unsigned char channelMapAud[NUM_USB_CHAN_OUT];
|
||||
|
||||
/* Mapping of channels to USB host */
|
||||
unsigned char channelMapUsb[NUM_USB_CHAN_IN];
|
||||
|
||||
/* Mapping of channels to Mixer(s) */
|
||||
unsigned char mixSel[MAX_MIX_COUNT][MIX_INPUTS];
|
||||
#endif
|
||||
|
||||
@@ -426,12 +431,13 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c
|
||||
|
||||
#ifdef MIXER
|
||||
/* Set up mixer default state */
|
||||
for (int i = 0; i < MIXER_INPUTS * MAX_MIX_COUNT; i++)
|
||||
for (int i = 0; i < MIX_INPUTS * MAX_MIX_COUNT; i++)
|
||||
{
|
||||
mixer1Weights[i] = 0x8001; //-inf
|
||||
}
|
||||
|
||||
/* Configure default connections */
|
||||
// TODO this should be a loop using defines.
|
||||
mixer1Weights[0] = 0;
|
||||
mixer1Weights[9] = 0;
|
||||
mixer1Weights[18] = 0;
|
||||
@@ -456,20 +462,6 @@ void XUA_Endpoint0_init(chanend c_ep0_out, chanend c_ep0_in, NULLABLE_RESOURCE(c
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Set up channel mapping default */
|
||||
for (int i = 0; i < NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN; i++)
|
||||
{
|
||||
channelMap[i] = i;
|
||||
}
|
||||
|
||||
#if MAX_MIX_COUNT > 0
|
||||
/* Mixer outputs mapping defaults */
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
channelMap[NUM_USB_CHAN_OUT + NUM_USB_CHAN_IN + i] = i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Init mixer inputs */
|
||||
for(int j = 0; j < MAX_MIX_COUNT; j++)
|
||||
for(int i = 0; i < MIX_INPUTS; i++)
|
||||
|
||||
@@ -265,6 +265,32 @@ static void updateVol(int unitID, int channel, chanend ?c_mix_ctl)
|
||||
}
|
||||
#endif
|
||||
|
||||
void UpdateMixerOutputRouting(chanend c_mix_ctl, unsigned map, unsigned dst, unsigned src)
|
||||
{
|
||||
outuint(c_mix_ctl, map);
|
||||
outuint(c_mix_ctl, dst);
|
||||
outuint(c_mix_ctl, src);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
void UpdateMixMap(chanend c_mix_ctl, int mix, int input, int src)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_MAP);
|
||||
outuint(c_mix_ctl, mix); /* Mix bus */
|
||||
outuint(c_mix_ctl, input); /* Mixer input (cn) */
|
||||
outuint(c_mix_ctl, src); /* Source (mixSel[cn]) */
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
void UpdateMixerWeight(chanend c_mix_ctl, int mix, int index, unsigned val)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_MULT);
|
||||
outuint(c_mix_ctl, mix);
|
||||
outuint(c_mix_ctl, index);
|
||||
outuint(c_mix_ctl, val);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
}
|
||||
|
||||
/* Handles the audio class specific requests
|
||||
* returns: XUD_RES_OKAY if request dealt with successfully without error,
|
||||
* XUD_RES_RST for device reset
|
||||
@@ -651,10 +677,12 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
{
|
||||
if (c < NUM_USB_CHAN_OUT)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP);
|
||||
outuint(c_mix_ctl, c);
|
||||
outuint(c_mix_ctl, channelMapAud[c]);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
//outuint(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP);
|
||||
//outuint(c_mix_ctl, c);
|
||||
//outuint(c_mix_ctl, channelMapAud[c]);
|
||||
//outct(c_mix_ctl, XS1_CT_END);
|
||||
UpdateMixerOutputRouting(c_mix_ctl, SET_SAMPLES_TO_DEVICE_MAP, c, channelMapAud[c]);
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
@@ -689,10 +717,12 @@ 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, SET_SAMPLES_TO_HOST_MAP);
|
||||
outuint(c_mix_ctl, c);
|
||||
outuint(c_mix_ctl, channelMapUsb[c]);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
//outuint(c_mix_ctl, SET_SAMPLES_TO_HOST_MAP);
|
||||
//outuint(c_mix_ctl, c);
|
||||
//outuint(c_mix_ctl, channelMapUsb[c]);
|
||||
//outct(c_mix_ctl, XS1_CT_END);
|
||||
UpdateMixerOutputRouting(c_mix_ctl, SET_SAMPLES_TO_HOST_MAP, c, channelMapUsb[c]);
|
||||
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
}
|
||||
}
|
||||
@@ -744,21 +774,23 @@ int AudioClassRequests_2(XUD_ep ep0_out, XUD_ep ep0_in, USB_SetupPacket_t &sp, c
|
||||
/* Update all mix maps */
|
||||
for (int i = 0; i < MAX_MIX_COUNT; i++)
|
||||
{
|
||||
outuint(c_mix_ctl, SET_MIX_MAP);
|
||||
outuint(c_mix_ctl, i); /* Mix bus */
|
||||
outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
//outuint(c_mix_ctl, SET_MIX_MAP);
|
||||
//outuint(c_mix_ctl, i); /* Mix bus */
|
||||
//outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
//outuint(c_mix_ctl, (int) mixSel[cn]); /* Source */
|
||||
//outct(c_mix_ctl, XS1_CT_END);
|
||||
UpdateMixMap(c_mix_ctl, i, cn, (int) mixSel[cn]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Update relevant mix map */
|
||||
outuint(c_mix_ctl, SET_MIX_MAP); /* Command */
|
||||
outuint(c_mix_ctl, (cs-1)); /* Mix bus */
|
||||
outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
outuint(c_mix_ctl, (int) mixSel[cs][cn]); /* Source */
|
||||
outct(c_mix_ctl, XS1_CT_END); /* Wait for handshake back */
|
||||
//outuint(c_mix_ctl, SET_MIX_MAP); /* Command */
|
||||
//outuint(c_mix_ctl, (cs-1)); /* Mix bus */
|
||||
//outuint(c_mix_ctl, cn); /* Mixer input */
|
||||
//outuint(c_mix_ctl, (int) mixSel[cs][cn]); /* Source */
|
||||
//outct(c_mix_ctl, XS1_CT_END); /* Wait for handshake back */
|
||||
UpdateMixMap(c_mix_ctl, cs-1, cn, (int) mixSel[cs][cn]);
|
||||
}
|
||||
|
||||
return XUD_DoSetRequestStatus(ep0_in);
|
||||
@@ -810,11 +842,12 @@ 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, SET_MIX_MULT);
|
||||
outuint(c_mix_ctl, (sp.wValue & 0xff) % 8);
|
||||
outuint(c_mix_ctl, (sp.wValue & 0xff) / 8);
|
||||
outuint(c_mix_ctl, volume);
|
||||
outct(c_mix_ctl, XS1_CT_END);
|
||||
//outuint(c_mix_ctl, SET_MIX_MULT);
|
||||
//outuint(c_mix_ctl, (sp.wValue & 0xff) % 8);
|
||||
//outuint(c_mix_ctl, (sp.wValue & 0xff) / 8);
|
||||
//outuint(c_mix_ctl, volume);
|
||||
//outct(c_mix_ctl, XS1_CT_END);
|
||||
UpdateMixerWeight(c_mix_ctl, (sp.wValue & 0xff) % 8, (sp.wValue & 0xff) / 8, volume);
|
||||
}
|
||||
|
||||
/* Send 0 Length as status stage */
|
||||
|
||||
Reference in New Issue
Block a user