|
@@ -687,48 +687,6 @@ static void i2s_stats(uint32_t now) {
|
|
|
#define PREAMBLE_M (0xE2) //11100010
|
|
|
#define PREAMBLE_W (0xE4) //11100100
|
|
|
|
|
|
-#if BYTES_PER_FRAME == 4
|
|
|
-
|
|
|
-#define VUCP ((0xCC) << 24)
|
|
|
-#define VUCP_MUTE ((0xD4) << 24) // To mute PCM, set VUCP = invalid.
|
|
|
-
|
|
|
-static const u16_t spdif_bmclookup[256] = { //biphase mark encoded values (least significant bit first)
|
|
|
- 0xcccc, 0x4ccc, 0x2ccc, 0xaccc, 0x34cc, 0xb4cc, 0xd4cc, 0x54cc,
|
|
|
- 0x32cc, 0xb2cc, 0xd2cc, 0x52cc, 0xcacc, 0x4acc, 0x2acc, 0xaacc,
|
|
|
- 0x334c, 0xb34c, 0xd34c, 0x534c, 0xcb4c, 0x4b4c, 0x2b4c, 0xab4c,
|
|
|
- 0xcd4c, 0x4d4c, 0x2d4c, 0xad4c, 0x354c, 0xb54c, 0xd54c, 0x554c,
|
|
|
- 0x332c, 0xb32c, 0xd32c, 0x532c, 0xcb2c, 0x4b2c, 0x2b2c, 0xab2c,
|
|
|
- 0xcd2c, 0x4d2c, 0x2d2c, 0xad2c, 0x352c, 0xb52c, 0xd52c, 0x552c,
|
|
|
- 0xccac, 0x4cac, 0x2cac, 0xacac, 0x34ac, 0xb4ac, 0xd4ac, 0x54ac,
|
|
|
- 0x32ac, 0xb2ac, 0xd2ac, 0x52ac, 0xcaac, 0x4aac, 0x2aac, 0xaaac,
|
|
|
- 0x3334, 0xb334, 0xd334, 0x5334, 0xcb34, 0x4b34, 0x2b34, 0xab34,
|
|
|
- 0xcd34, 0x4d34, 0x2d34, 0xad34, 0x3534, 0xb534, 0xd534, 0x5534,
|
|
|
- 0xccb4, 0x4cb4, 0x2cb4, 0xacb4, 0x34b4, 0xb4b4, 0xd4b4, 0x54b4,
|
|
|
- 0x32b4, 0xb2b4, 0xd2b4, 0x52b4, 0xcab4, 0x4ab4, 0x2ab4, 0xaab4,
|
|
|
- 0xccd4, 0x4cd4, 0x2cd4, 0xacd4, 0x34d4, 0xb4d4, 0xd4d4, 0x54d4,
|
|
|
- 0x32d4, 0xb2d4, 0xd2d4, 0x52d4, 0xcad4, 0x4ad4, 0x2ad4, 0xaad4,
|
|
|
- 0x3354, 0xb354, 0xd354, 0x5354, 0xcb54, 0x4b54, 0x2b54, 0xab54,
|
|
|
- 0xcd54, 0x4d54, 0x2d54, 0xad54, 0x3554, 0xb554, 0xd554, 0x5554,
|
|
|
- 0x3332, 0xb332, 0xd332, 0x5332, 0xcb32, 0x4b32, 0x2b32, 0xab32,
|
|
|
- 0xcd32, 0x4d32, 0x2d32, 0xad32, 0x3532, 0xb532, 0xd532, 0x5532,
|
|
|
- 0xccb2, 0x4cb2, 0x2cb2, 0xacb2, 0x34b2, 0xb4b2, 0xd4b2, 0x54b2,
|
|
|
- 0x32b2, 0xb2b2, 0xd2b2, 0x52b2, 0xcab2, 0x4ab2, 0x2ab2, 0xaab2,
|
|
|
- 0xccd2, 0x4cd2, 0x2cd2, 0xacd2, 0x34d2, 0xb4d2, 0xd4d2, 0x54d2,
|
|
|
- 0x32d2, 0xb2d2, 0xd2d2, 0x52d2, 0xcad2, 0x4ad2, 0x2ad2, 0xaad2,
|
|
|
- 0x3352, 0xb352, 0xd352, 0x5352, 0xcb52, 0x4b52, 0x2b52, 0xab52,
|
|
|
- 0xcd52, 0x4d52, 0x2d52, 0xad52, 0x3552, 0xb552, 0xd552, 0x5552,
|
|
|
- 0xccca, 0x4cca, 0x2cca, 0xacca, 0x34ca, 0xb4ca, 0xd4ca, 0x54ca,
|
|
|
- 0x32ca, 0xb2ca, 0xd2ca, 0x52ca, 0xcaca, 0x4aca, 0x2aca, 0xaaca,
|
|
|
- 0x334a, 0xb34a, 0xd34a, 0x534a, 0xcb4a, 0x4b4a, 0x2b4a, 0xab4a,
|
|
|
- 0xcd4a, 0x4d4a, 0x2d4a, 0xad4a, 0x354a, 0xb54a, 0xd54a, 0x554a,
|
|
|
- 0x332a, 0xb32a, 0xd32a, 0x532a, 0xcb2a, 0x4b2a, 0x2b2a, 0xab2a,
|
|
|
- 0xcd2a, 0x4d2a, 0x2d2a, 0xad2a, 0x352a, 0xb52a, 0xd52a, 0x552a,
|
|
|
- 0xccaa, 0x4caa, 0x2caa, 0xacaa, 0x34aa, 0xb4aa, 0xd4aa, 0x54aa,
|
|
|
- 0x32aa, 0xb2aa, 0xd2aa, 0x52aa, 0xcaaa, 0x4aaa, 0x2aaa, 0xaaaa
|
|
|
-};
|
|
|
-
|
|
|
-#else
|
|
|
-
|
|
|
#define VUCP24 (0xCC)
|
|
|
#define VUCP24I (0x32)
|
|
|
|
|
@@ -769,8 +727,6 @@ static const u16_t spdif_bmclookup[256] = {
|
|
|
0xcd55, 0xb2aa, 0xd2aa, 0xad55, 0xcaaa, 0xb555, 0xd555, 0xaaaa
|
|
|
};
|
|
|
|
|
|
-#endif
|
|
|
-
|
|
|
/*
|
|
|
SPDIF is supposed to be (before BMC encoding, from LSB to MSB)
|
|
|
0.... 1... 191.. 0
|
|
@@ -786,32 +742,23 @@ static const u16_t spdif_bmclookup[256] = {
|
|
|
*/
|
|
|
static void IRAM_ATTR spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, size_t *count) {
|
|
|
register u16_t hi, lo, aux;
|
|
|
-#if (BYTES_PER_FRAME != 4)
|
|
|
register u8_t vu;
|
|
|
vu = vucp;
|
|
|
-#endif
|
|
|
size_t cnt = *count;
|
|
|
|
|
|
while (frames--) {
|
|
|
// start with left channel
|
|
|
#if BYTES_PER_FRAME == 4
|
|
|
- hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
|
|
- lo = spdif_bmclookup[(u8_t) *src++];
|
|
|
-
|
|
|
- // invert if last preceeding bit is 1
|
|
|
- lo ^= ~((s16_t)hi) >> 16;
|
|
|
- // first 16 bits
|
|
|
- aux = 0xb333 ^ (((u32_t)((s16_t)lo)) >> 17);
|
|
|
+ hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
|
|
+ lo = spdif_bmclookup[(u8_t)*src++];
|
|
|
+ if (lo & 1) hi = ~hi;
|
|
|
|
|
|
- // set special preamble every 192 iteration
|
|
|
if (++cnt > 191) {
|
|
|
- *dst++ = VUCP | (PREAMBLE_B << 16 ) | aux; //special preamble for one of 192 frames
|
|
|
+ *dst++ = (vu << 24) | (PREAMBLE_B << 16) | 0xCCCC;
|
|
|
cnt = 0;
|
|
|
} else {
|
|
|
- *dst++ = VUCP | (PREAMBLE_M << 16) | aux;
|
|
|
- }
|
|
|
- // now write sample's 16 low bits
|
|
|
- *dst++ = ((u32_t)lo << 16) | hi;
|
|
|
+ *dst++ = (vu << 24) | (PREAMBLE_M << 16) | 0xCCCC;
|
|
|
+ }
|
|
|
#else
|
|
|
hi = spdif_bmclookup[(u8_t)(*src >> 24)];
|
|
|
lo = spdif_bmclookup[(u8_t)(*src >> 16)];
|
|
@@ -819,27 +766,29 @@ static void IRAM_ATTR spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, s
|
|
|
if (aux & 1) lo = ~lo;
|
|
|
if (lo & 1) hi = ~hi;
|
|
|
|
|
|
- // i2s library seems to swap the 32bit samples (right, left), so we change the order here
|
|
|
if (++cnt > 191) {
|
|
|
*dst++ = (vu << 24) | (PREAMBLE_B << 16) | aux;
|
|
|
cnt = 0;
|
|
|
} else {
|
|
|
*dst++ = (vu << 24) | (PREAMBLE_M << 16) | aux;
|
|
|
}
|
|
|
- *dst++ = ((u32_t)lo << 16) | hi;
|
|
|
+#endif
|
|
|
|
|
|
if (hi & 1) vu = VUCP24I;
|
|
|
else vu = VUCP24;
|
|
|
-#endif
|
|
|
+ *dst++ = ((u32_t)lo << 16) | hi;
|
|
|
|
|
|
// then do right channel, no need to check PREAMBLE_B
|
|
|
#if BYTES_PER_FRAME == 4
|
|
|
- hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
|
|
- lo = spdif_bmclookup[(u8_t) *src++];
|
|
|
- lo ^= ~((s16_t)hi) >> 16;
|
|
|
- aux = 0xb333 ^ (((u32_t)((s16_t)lo)) >> 17);
|
|
|
- *dst++ = VUCP | (PREAMBLE_W << 16) | aux;
|
|
|
- *dst++ = ((u32_t)lo << 16) | hi;
|
|
|
+ hi = spdif_bmclookup[(u8_t)(*src >> 8)];
|
|
|
+ lo = spdif_bmclookup[(u8_t)*src++];
|
|
|
+
|
|
|
+ if (lo & 1) hi = ~hi;
|
|
|
+
|
|
|
+ *dst++ = (vu << 24) | (PREAMBLE_W << 16) | 0xCCCC;
|
|
|
+
|
|
|
+ if (hi & 1) vu = VUCP24I;
|
|
|
+ else vu = VUCP24;
|
|
|
#else
|
|
|
hi = spdif_bmclookup[(u8_t)(*src >> 24)];
|
|
|
lo = spdif_bmclookup[(u8_t)(*src >> 16)];
|
|
@@ -848,17 +797,15 @@ static void IRAM_ATTR spdif_convert(ISAMPLE_T *src, size_t frames, u32_t *dst, s
|
|
|
if (lo & 1) hi = ~hi;
|
|
|
|
|
|
*dst++ = (vu << 24) | (PREAMBLE_W << 16) | aux;
|
|
|
- *dst++ = ((u32_t)lo << 16) | hi;
|
|
|
+#endif
|
|
|
|
|
|
if (hi & 1) vu = VUCP24I;
|
|
|
else vu = VUCP24;
|
|
|
-#endif
|
|
|
+ *dst++ = ((u32_t)lo << 16) | hi;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
*count = cnt;
|
|
|
-#if (BYTES_PER_FRAME != 4)
|
|
|
vucp = vu;
|
|
|
-#endif
|
|
|
}
|
|
|
|
|
|
|