LIFsCode / ELOC-3.0

Firmware for ELOC 3.0 Hardware
MIT License
2 stars 3 forks source link

Add central Factory class to set up WAV Writer, edgeImpulse and I2S sampler in correct order #85

Open LIFsCode opened 4 months ago

LIFsCode commented 4 months ago
LIFsCode commented 3 months ago

@OOHehir I would add a standardized interface class for exchanging data with the I2S Sampler and WavWriter & EdgeImpulse to get rid of the dependencies between them.

My idea was to use something similar to inferenct_t with additional notify method, e.g.

class I2S_DataBuffer {
    signed short *buffers[2];
    unsigned char buf_select;
    unsigned char buf_ready;
    unsigned int buf_count;
    unsigned int n_samples;
    unsigned int subsampling_rate;
    /**
     * @brief Ideally this bool would be encapsulated in the EdgeImpulse class
     *        but issues with conflicting paths
     */
    bool status_running;

    void notifyConsumerTask() {
      if (status_running && mTaskHandle != NULL) {
        buf_ready = 1;
        xTaskNotify(mTaskHandle, (0), eNoAction);
      }
    }

    I2S_DataBuffer(TaskHandle_t& taskHandle) : mTaskHandle(taskHandle) 
    {}
private:
  TaskHandle_t& mTaskHandle;
};

With that the I2S Sampler only gets a I2S_DataBuffer registered and there would be no separate handling for edgeImpulse buffer and wav buffer.

@OOHehir any thoughts/comments about that?

OOHehir commented 3 months ago

@LIFsCode Sounds like a good idea. Certainly there's unnecessary differences of the interfaces to the EdgeImpulse & WAVWriter.

Some points that come to mind that may be of importance:

  1. The sample rates may be different for the EdgeImpulse & WAVWriter
  2. There's an outstanding requirement to make the WAV file an exact size, #71. It probably won't impact on this issue but would mean that a file would need to be closed & another opened while a buffer is being processed by the WAVWriter.
LIFsCode commented 3 months ago

@OOHehir thanks for the hint, I totally forgot about #71 but that should not be too difficult to add this.

The other topic with the different sample rates is more complicated. I added a new issue #91 to keep this discussion isolated