audio_block_t *blockL, *blockR; | audio_block_t *blockL, *blockR; | ||||
uint32_t saddr, offsetL, offsetR; | uint32_t saddr, offsetL, offsetR; | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
saddr = (uint32_t)(dma.TCD->SADDR); | saddr = (uint32_t)(dma.TCD->SADDR); | ||||
#endif | |||||
dma.clearInterrupt(); | dma.clearInterrupt(); | ||||
if (saddr < (uint32_t)i2s_tx_buffer + sizeof(i2s_tx_buffer) / 2) { | if (saddr < (uint32_t)i2s_tx_buffer + sizeof(i2s_tx_buffer) / 2) { | ||||
// DMA is transmitting the first half of the buffer | // DMA is transmitting the first half of the buffer |
DMAMEM __attribute__((aligned(32))) | DMAMEM __attribute__((aligned(32))) | ||||
static uint32_t SPDIF_tx_buffer[AUDIO_BLOCK_SAMPLES * 4]; //2 KB | static uint32_t SPDIF_tx_buffer[AUDIO_BLOCK_SAMPLES * 4]; //2 KB | ||||
#if defined(KINETISK) || defined(__IMXRT1052__) || defined(__IMXRT1062__) | |||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
#define PREAMBLE_B (0xE8) //11101000 | #define PREAMBLE_B (0xE8) //11101000 | ||||
#define PREAMBLE_M (0xE2) //11100010 | #define PREAMBLE_M (0xE2) //11100010 | ||||
uint32_t AudioOutputSPDIF::vucp = VUCP_VALID; | uint32_t AudioOutputSPDIF::vucp = VUCP_VALID; | ||||
#endif | |||||
FLASHMEM | FLASHMEM | ||||
void AudioOutputSPDIF::begin(void) | void AudioOutputSPDIF::begin(void) | ||||
I2S0_TCSR |= I2S_TCSR_TE | I2S_TCSR_BCE | I2S_TCSR_FRDE | I2S_TCSR_FR; | I2S0_TCSR |= I2S_TCSR_TE | I2S_TCSR_BCE | I2S_TCSR_FRDE | I2S_TCSR_FR; | ||||
dma.attachInterrupt(isr); | dma.attachInterrupt(isr); | ||||
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__) | |||||
#if defined(__IMXRT1052__) | |||||
CORE_PIN6_CONFIG = 3; //1:TX_DATA0 | |||||
#elif defined(__IMXRT1062__) | #elif defined(__IMXRT1062__) | ||||
CORE_PIN7_CONFIG = 3; //1:TX_DATA0 | CORE_PIN7_CONFIG = 3; //1:TX_DATA0 | ||||
#endif | |||||
const int nbytes_mlno = 2 * 4; // 8 Bytes per minor loop | const int nbytes_mlno = 2 * 4; // 8 Bytes per minor loop | ||||
dma.TCD->SADDR = SPDIF_tx_buffer; | dma.TCD->SADDR = SPDIF_tx_buffer; | ||||
uint32_t saddr, offset; | uint32_t saddr, offset; | ||||
uint16_t sample, lo, hi, aux; | uint16_t sample, lo, hi, aux; | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
saddr = (uint32_t)(dma.TCD->SADDR); | saddr = (uint32_t)(dma.TCD->SADDR); | ||||
#endif | |||||
dma.clearInterrupt(); | dma.clearInterrupt(); | ||||
if (saddr < (uint32_t)SPDIF_tx_buffer + sizeof(SPDIF_tx_buffer) / 2) { | if (saddr < (uint32_t)SPDIF_tx_buffer + sizeof(SPDIF_tx_buffer) / 2) { | ||||
// DMA is transmitting the first half of the buffer | // DMA is transmitting the first half of the buffer | ||||
CORE_PIN11_CONFIG = PORT_PCR_MUX(6); // pin 11, PTC6, I2S0_MCLK 11.43MHz | CORE_PIN11_CONFIG = PORT_PCR_MUX(6); // pin 11, PTC6, I2S0_MCLK 11.43MHz | ||||
#endif | #endif | ||||
#elif defined(__IMXRT1052__) || defined(__IMXRT1062__) | |||||
#elif defined(__IMXRT1062__) | |||||
CCM_CCGR5 |= CCM_CCGR5_SAI1(CCM_CCGR_ON); | CCM_CCGR5 |= CCM_CCGR5_SAI1(CCM_CCGR_ON); | ||||
//PLL: | //PLL: | ||||
#endif | #endif | ||||
} | } | ||||
#endif // KINETISK || __IMXRT1062__ | |||||
#if defined(KINETISL) | #if defined(KINETISL) | ||||
const uint32_t *src1, *src2; | const uint32_t *src1, *src2; | ||||
uint32_t i, saddr; | uint32_t i, saddr; | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
saddr = (uint32_t)(dma.TCD->SADDR); | saddr = (uint32_t)(dma.TCD->SADDR); | ||||
#endif | |||||
dma.clearInterrupt(); | dma.clearInterrupt(); | ||||
if (saddr < (uint32_t)tdm_tx_buffer + sizeof(tdm_tx_buffer) / 2) { | if (saddr < (uint32_t)tdm_tx_buffer + sizeof(tdm_tx_buffer) / 2) { | ||||
// DMA is transmitting the first half of the buffer | // DMA is transmitting the first half of the buffer |
#include <Arduino.h> | #include <Arduino.h> | ||||
#include "synth_karplusstrong.h" | #include "synth_karplusstrong.h" | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
static uint32_t pseudorand(uint32_t lo) | static uint32_t pseudorand(uint32_t lo) | ||||
{ | { | ||||
uint32_t hi; | uint32_t hi; | ||||
lo = (lo & 0x7FFFFFFF) + (lo >> 31); | lo = (lo & 0x7FFFFFFF) + (lo >> 31); | ||||
return lo; | return lo; | ||||
} | } | ||||
#endif | |||||
void AudioSynthKarplusStrong::update(void) | void AudioSynthKarplusStrong::update(void) | ||||
{ | { | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
audio_block_t *block; | audio_block_t *block; | ||||
if (state == 0) return; | if (state == 0) return; | ||||
transmit(block); | transmit(block); | ||||
release(block); | release(block); | ||||
#endif | |||||
} | } | ||||
void AudioSynthSimpleDrum::update(void) | void AudioSynthSimpleDrum::update(void) | ||||
{ | { | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
audio_block_t *block_wav; | audio_block_t *block_wav; | ||||
int16_t *p_wave, *end; | int16_t *p_wave, *end; | ||||
int32_t sin_l, sin_r, interp, mod, mod2, delta; | int32_t sin_l, sin_r, interp, mod, mod2, delta; | ||||
transmit(block_wav, 0); | transmit(block_wav, 0); | ||||
release(block_wav); | release(block_wav); | ||||
#endif | |||||
} | } | ||||
* | * | ||||
*/ | */ | ||||
void AudioSynthWavetable::update(void) { | void AudioSynthWavetable::update(void) { | ||||
#if defined(KINETISK) || defined(__IMXRT1062__) | |||||
// exit if nothing to do | // exit if nothing to do | ||||
if (env_state == STATE_IDLE || (current_sample->LOOP == false && tone_phase >= current_sample->MAX_PHASE)) { | if (env_state == STATE_IDLE || (current_sample->LOOP == false && tone_phase >= current_sample->MAX_PHASE)) { | ||||
env_state = STATE_IDLE; | env_state = STATE_IDLE; | ||||
transmit(block); | transmit(block); | ||||
release(block); | release(block); | ||||
#endif | |||||
} | } |