10 #include <type_traits>
13 #include "mic_array/frame_transfer.h"
15 #include <xcore/channel.h>
19 #if defined(MIC_COUNT) || defined(SAMPLE_COUNT) || defined(FRAME_COUNT)
20 # error Application must not define the following as precompiler macros: MIC_COUNT, SAMPLE_COUNT, FRAME_COUNT.
43 template <
unsigned MIC_COUNT>
55 chanend_t c_sample_out;
71 : c_sample_out(c_sample_out) { }
78 void SetChannel(chanend_t c_sample_out);
85 void ProcessSample(int32_t sample[MIC_COUNT]);
99 template <
unsigned MIC_COUNT,
100 unsigned SAMPLE_COUNT,
101 template <
unsigned,
unsigned>
class FrameTransmitter,
102 unsigned FRAME_COUNT = 1>
110 unsigned current_frame = 0;
115 unsigned current_sample = 0;
120 int32_t frames[FRAME_COUNT][MIC_COUNT][SAMPLE_COUNT];
128 FrameTransmitter<MIC_COUNT, SAMPLE_COUNT>
FrameTx;
148 : FrameTx(frame_tx) { }
155 void OutputSample(int32_t sample[MIC_COUNT]);
173 template <
unsigned MIC_COUNT,
unsigned SAMPLE_COUNT>
181 chanend_t c_frame_out;
206 void SetChannel(chanend_t c_frame_out);
213 chanend_t GetChannel();
220 void OutputFrame(int32_t frame[MIC_COUNT][SAMPLE_COUNT]);
229 template <
unsigned MIC_COUNT>
231 chanend_t c_sample_out)
233 this->c_sample_out = c_sample_out;
237 template <
unsigned MIC_COUNT>
239 int32_t sample[MIC_COUNT])
241 ma_frame_tx(this->c_sample_out, sample, MIC_COUNT, 1);
246 template <
unsigned MIC_COUNT,
247 unsigned SAMPLE_COUNT,
248 template <
unsigned,
unsigned>
class FrameTransmitter,
249 unsigned FRAME_COUNT>
251 FrameTransmitter,FRAME_COUNT>::OutputSample(
252 int32_t sample[MIC_COUNT])
254 auto* cur_frame =
reinterpret_cast<int32_t (*)[SAMPLE_COUNT]
>(
255 &this->frames[this->current_frame][0][0]);
257 for(
int k = 0; k < MIC_COUNT; k++)
258 cur_frame[k][this->current_sample] = sample[k];
260 if(++current_sample == SAMPLE_COUNT){
263 if(current_frame == FRAME_COUNT) current_frame = 0;
265 FrameTx.OutputFrame( cur_frame );
271 template <
unsigned MIC_COUNT,
unsigned SAMPLE_COUNT>
273 chanend_t c_frame_out)
275 this->c_frame_out = c_frame_out;
278 template <
unsigned MIC_COUNT,
unsigned SAMPLE_COUNT>
281 return this->c_frame_out;
285 template <
unsigned MIC_COUNT,
unsigned SAMPLE_COUNT>
287 int32_t frame[MIC_COUNT][SAMPLE_COUNT])
289 ma_frame_tx(this->c_frame_out,
290 reinterpret_cast<int32_t*
>(frame),
291 MIC_COUNT, SAMPLE_COUNT);
Frame transmitter which transmits frame over a channel.
Definition: OutputHandler.hpp:175
chanend_t GetChannel()
Get channel used for frame transfers.
Definition: OutputHandler.hpp:279
void OutputFrame(int32_t frame[MIC_COUNT][SAMPLE_COUNT])
Transmit the specified frame.
Definition: OutputHandler.hpp:286
ChannelFrameTransmitter(chanend_t c_frame_out)
Construct a ChannelFrameTransmitter.
Definition: OutputHandler.hpp:199
ChannelFrameTransmitter()
Construct a ChannelFrameTransmitter.
Definition: OutputHandler.hpp:192
void SetChannel(chanend_t c_frame_out)
Set channel used for frame transfers.
Definition: OutputHandler.hpp:272
OutputHandler which transmits samples over a channel.
Definition: OutputHandler.hpp:45
void SetChannel(chanend_t c_sample_out)
Set the channel used for sending samples.
Definition: OutputHandler.hpp:230
ChannelSampleTransmitter(chanend_t c_sample_out)
Construct a ChannelSampleTransmitter.
Definition: OutputHandler.hpp:70
void ProcessSample(int32_t sample[MIC_COUNT])
Transmit the specified sample.
Definition: OutputHandler.hpp:238
ChannelSampleTransmitter()
Construct a ChannelSampleTransmitter.
Definition: OutputHandler.hpp:62
OutputHandler for grouping samples into frames and sending frames to subsequent processing stages.
Definition: OutputHandler.hpp:104
FrameOutputHandler()
Construct new FrameOutputHandler.
Definition: OutputHandler.hpp:138
FrameOutputHandler(FrameTransmitter< MIC_COUNT, SAMPLE_COUNT > frame_tx)
Construct new FrameOutputHandler.
Definition: OutputHandler.hpp:147
FrameTransmitter< MIC_COUNT, SAMPLE_COUNT > FrameTx
FrameTransmitter used to transmit frames to the next stage for processing.
Definition: OutputHandler.hpp:128