Skip to content

Commit

Permalink
Expose StreamNormalizer sample read/write operations
Browse files Browse the repository at this point in the history
 - correctly define disconnect() with DataSource not DataStream
 - Add virtual/override checks
  • Loading branch information
finneyj committed Oct 12, 2020
1 parent 47464be commit 72d3175
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
11 changes: 6 additions & 5 deletions inc/streams/DataStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ namespace codal

virtual ManagedBuffer pull();
virtual void connect(DataSink &sink);
virtual int getFormat();
virtual int setFormat(int format);
virtual void disconnect();
virtual int getFormat();
virtual int setFormat(int format);
};

/**
Expand Down Expand Up @@ -138,19 +139,19 @@ namespace codal
*
* @sink The component that data will be delivered to, when it is availiable
*/
virtual void connect(DataSink &sink);
virtual void connect(DataSink &sink) override;

/**
* Define a downstream component for data stream.
*
* @sink The component that data will be delivered to, when it is availiable
*/
void disconnect();
virtual void disconnect() override;

/**
* Determine the data format of the buffers streamed out of this component.
*/
int getFormat();
virtual int getFormat() override;

/**
* Determine the number of bytes that are currnetly buffered before blocking subsequent push() operations.
Expand Down
9 changes: 9 additions & 0 deletions inc/streams/StreamNormalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ DEALINGS IN THE SOFTWARE.
#ifndef STREAM_NORMALIZER_H
#define STREAM_NORMALIZER_H

/**
* Sample read/write functions for 8, 16, 24, 32 bit signed/unsigned data.
*/
typedef int (*SampleReadFn)(uint8_t *);
typedef void (*SampleWriteFn)(uint8_t *, int);


/**
* Default configuration values
*/
Expand All @@ -49,6 +56,8 @@ namespace codal{
DataStream output; // The downstream output stream of this StreamNormalizer.
ManagedBuffer buffer; // The buffer being processed.

static SampleReadFn readSample[9];
static SampleWriteFn writeSample[9];

/**
* Creates a component capable of translating one data representation format into another
Expand Down
4 changes: 4 additions & 0 deletions source/streams/DataStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ void DataSource::connect(DataSink& )
{
}

void DataSource::disconnect()
{
}

int DataSource::getFormat()
{
return DATASTREAM_FORMAT_UNKNOWN;
Expand Down
8 changes: 3 additions & 5 deletions source/streams/StreamNormalizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ static void write_sample_8(uint8_t *ptr, int value)
*(int32_t *)ptr = (int32_t) value;
}

// Lookup table to optimse parsin gof input stream.
typedef int (*SampleReadFn)(uint8_t *);
typedef void (*SampleWriteFn)(uint8_t *, int);
SampleReadFn readSample[] = {read_sample_1, read_sample_1, read_sample_2, read_sample_3, read_sample_4, read_sample_5, read_sample_6, read_sample_7, read_sample_8};
SampleWriteFn writeSample[] = {write_sample_1, write_sample_1, write_sample_2, write_sample_3, write_sample_4, write_sample_5_6, write_sample_5_6, write_sample_7, write_sample_8};
// Lookup table to optimse parsing of input stream.
SampleReadFn StreamNormalizer::readSample[] = {read_sample_1, read_sample_1, read_sample_2, read_sample_3, read_sample_4, read_sample_5, read_sample_6, read_sample_7, read_sample_8};
SampleWriteFn StreamNormalizer::writeSample[] = {write_sample_1, write_sample_1, write_sample_2, write_sample_3, write_sample_4, write_sample_5_6, write_sample_5_6, write_sample_7, write_sample_8};

/**
* Creates a component capable of translating one data representation format into another
Expand Down

0 comments on commit 72d3175

Please sign in to comment.