esaiListener.cpp (3481B)
1 #include "esaiListener.h" 2 3 #include "dsp56kEmu/esai.h" 4 5 using namespace dsp56k; 6 7 #ifdef _DEBUG 8 size_t g_writeBlockSize = 8192; 9 #else 10 size_t g_writeBlockSize = 65536; 11 #endif 12 13 EsaiListener::EsaiListener(dsp56k::Esai& _esai, const uint8_t _outChannels, const uint8_t _inChannels, TCallback _callback) 14 : m_outChannels(_outChannels) 15 , m_inChannels(_inChannels) 16 , m_nextWriteSize(g_writeBlockSize) 17 , m_callback(std::move(_callback)) 18 { 19 if (_outChannels & 32) ++m_outChannelCount; 20 if (_outChannels & 16) ++m_outChannelCount; 21 if (_outChannels & 8) ++m_outChannelCount; 22 if (_outChannels & 4) ++m_outChannelCount; 23 if (_outChannels & 2) ++m_outChannelCount; 24 if (_outChannels & 1) ++m_outChannelCount; 25 26 _esai.setCallback([&](Audio* _audio) 27 { 28 onAudioCallback(_audio); 29 }, 4); 30 31 _esai.writeEmptyAudioIn(4); 32 } 33 34 void EsaiListener::setMaxSamplecount(uint32_t _max) 35 { 36 m_maxSampleCount = _max; 37 } 38 39 void EsaiListener::onAudioCallback(dsp56k::Audio* _audio) 40 { 41 constexpr size_t sampleCount = 4; 42 constexpr size_t channelsIn = 8; 43 constexpr size_t channelsOut = 12; 44 45 TWord inputData[channelsIn][sampleCount] = { {0,0,0,0}, {0,0,0,0},{0,0,0,0}, {0,0,0,0},{0,0,0,0}, {0,0,0,0},{0,0,0,0}, {0,0,0,0} }; 46 const TWord* audioIn[channelsIn] = { 47 (m_inChannels & 0x01) ? inputData[0] : nullptr, 48 (m_inChannels & 0x01) ? inputData[1] : nullptr, 49 (m_inChannels & 0x02) ? inputData[2] : nullptr, 50 (m_inChannels & 0x02) ? inputData[3] : nullptr, 51 (m_inChannels & 0x04) ? inputData[4] : nullptr, 52 (m_inChannels & 0x04) ? inputData[5] : nullptr, 53 (m_inChannels & 0x08) ? inputData[6] : nullptr, 54 (m_inChannels & 0x08) ? inputData[7] : nullptr, 55 }; 56 TWord outputData[channelsOut][sampleCount] = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} }; 57 TWord* audioOut[channelsOut] = { 58 (m_outChannels & 0x01) ? outputData[0] : nullptr, 59 (m_outChannels & 0x01) ? outputData[1] : nullptr, 60 (m_outChannels & 0x02) ? outputData[2] : nullptr, 61 (m_outChannels & 0x02) ? outputData[3] : nullptr, 62 (m_outChannels & 0x04) ? outputData[4] : nullptr, 63 (m_outChannels & 0x04) ? outputData[5] : nullptr, 64 (m_outChannels & 0x08) ? outputData[6] : nullptr, 65 (m_outChannels & 0x08) ? outputData[7] : nullptr, 66 (m_outChannels & 0x10) ? outputData[8] : nullptr, 67 (m_outChannels & 0x10) ? outputData[9] : nullptr, 68 (m_outChannels & 0x20) ? outputData[10] : nullptr, 69 (m_outChannels & 0x20) ? outputData[11] : nullptr 70 }; 71 72 m_counter++; 73 if ((m_counter & 0x1fff) == 0) 74 { 75 LOG("Deliver Audio"); 76 } 77 78 _audio->processAudioInterleaved(audioIn, audioOut, sampleCount); 79 80 if (limitReached()) 81 return; 82 83 if (!m_audioData.capacity()) 84 { 85 for (int c = 0; c < channelsOut; ++c) 86 { 87 for (int i = 0; i < sampleCount; ++i) 88 { 89 if (audioOut[c] && audioOut[c][i]) 90 { 91 m_audioData.reserve(2048); 92 break; 93 } 94 } 95 } 96 97 if(m_audioData.capacity()) 98 onBeginDeliverAudioData(); 99 } 100 101 if (m_audioData.capacity()) 102 { 103 for (int i = 0; i < sampleCount; ++i) 104 { 105 for (int c = 0; c < channelsOut; ++c) 106 { 107 if(audioOut[c] && !limitReached()) 108 { 109 m_audioData.push_back(audioOut[c][i]); 110 ++m_processedSampleCount; 111 } 112 } 113 } 114 115 if (m_audioData.size() >= m_nextWriteSize || limitReached()) 116 { 117 if (onDeliverAudioData(m_audioData)) 118 { 119 m_audioData.clear(); 120 m_nextWriteSize = g_writeBlockSize; 121 } 122 else 123 m_nextWriteSize += g_writeBlockSize; 124 } 125 } 126 127 m_callback(this, m_counter); 128 }