From 5b1311079a31374c8700cdf79ec7eba283307d5a Mon Sep 17 00:00:00 2001 From: bruceperens Date: Wed, 22 Jan 2014 02:42:40 +0000 Subject: [PATCH] Get C++11 constant types from the std:: namespace rather than the C one. git-svn-id: https://svn.code.sf.net/p/freetel/code@1387 01035d8c-6547-0410-b346-abe4f91aad63 --- freedv-server/source/audio_sink.cpp | 8 +++--- freedv-server/source/blank_panel.cpp | 4 +-- freedv-server/source/codec_noop.cpp | 14 ++++----- freedv-server/source/drivers.h | 39 +++++++++++++++++--------- freedv-server/source/keying_sink.cpp | 4 +-- freedv-server/source/modem_noop.cpp | 14 ++++----- freedv-server/source/ptt_constant.cpp | 4 +-- freedv-server/source/run.cpp | 2 +- freedv-server/source/text_constant.cpp | 16 +++++------ freedv-server/source/tone.cpp | 10 +++---- freedv-server/source/utility.cpp | 2 +- 11 files changed, 65 insertions(+), 52 deletions(-) diff --git a/freedv-server/source/audio_sink.cpp b/freedv-server/source/audio_sink.cpp index 560db6b0..82c43a43 100644 --- a/freedv-server/source/audio_sink.cpp +++ b/freedv-server/source/audio_sink.cpp @@ -14,12 +14,12 @@ namespace FreeDV { /// Return the number of audio samples the device can handle in /// a write without blocking. This version always returns SIZE_MAX. - virtual size_t + virtual std::size_t ready(); /// Write audio into the "short" type. virtual std::size_t - write16(const int16_t * array, std::size_t length); + write16(const std::int16_t * array, std::size_t length); }; AudioSink::AudioSink(const char * p) @@ -33,7 +33,7 @@ namespace FreeDV { // Write audio into the "short" type. std::size_t - AudioSink::write16(const int16_t * array, std::size_t length) + AudioSink::write16(const std::int16_t * array, std::size_t length) { return length; } @@ -44,7 +44,7 @@ namespace FreeDV { return new ::FreeDV::AudioSink(parameter); } - size_t + std::size_t AudioSink::ready() { return SIZE_MAX; diff --git a/freedv-server/source/blank_panel.cpp b/freedv-server/source/blank_panel.cpp index 9127a181..01eaecd2 100644 --- a/freedv-server/source/blank_panel.cpp +++ b/freedv-server/source/blank_panel.cpp @@ -13,7 +13,7 @@ namespace FreeDV { /// Return the amount of bytes ready for read. In this case, it always /// returns 0. - size_t ready(); + std::size_t ready(); }; BlankPanel::BlankPanel(const char * parameter, Interfaces * interfaces) @@ -25,7 +25,7 @@ namespace FreeDV { { } - size_t + std::size_t BlankPanel::ready() { return 0; diff --git a/freedv-server/source/codec_noop.cpp b/freedv-server/source/codec_noop.cpp index 30a05d65..b4fa9dc7 100644 --- a/freedv-server/source/codec_noop.cpp +++ b/freedv-server/source/codec_noop.cpp @@ -23,9 +23,9 @@ namespace FreeDV { /// \param o The array of audio samples after decoding, in an array /// of signed 16-bit integers. /// \param length The number of bytes of data to be decoded. - /// \return The number of int16_t elements in the decoded array. + /// \return The number of std::int16_t elements in the decoded array. virtual std::size_t - decode16(const uint8_t * i, int16_t * o, \ + decode16(const std::uint8_t * i, std::int16_t * o, \ std::size_t length); @@ -34,9 +34,9 @@ namespace FreeDV { /// of signed 16-bit integers. /// \param o The encoded data, in an array of unsigned 8-bit integers. /// \param length The number of audio samples to be encoded. - /// \return The number of uint8_t elements in the encoded array. + /// \return The number of std::uint8_t elements in the encoded array. virtual std::size_t - encode16(const int16_t * i, uint8_t * o, \ + encode16(const std::int16_t * i, std::uint8_t * o, \ std::size_t length); /// Return the duration of a frame in milliseconds. @@ -66,17 +66,17 @@ namespace FreeDV { std::size_t const CodecNoOp::bytes_per_frame() const { - return sizeof(int16_t); + return sizeof(std::int16_t); } std::size_t - CodecNoOp::decode16(const uint8_t * i, int16_t * o, std::size_t length) + CodecNoOp::decode16(const std::uint8_t * i, std::int16_t * o, std::size_t length) { return length; } std::size_t - CodecNoOp::encode16(const int16_t * i, uint8_t * o, std::size_t length) + CodecNoOp::encode16(const std::int16_t * i, std::uint8_t * o, std::size_t length) { return length; } diff --git a/freedv-server/source/drivers.h b/freedv-server/source/drivers.h index 35d6495d..aa9cda85 100644 --- a/freedv-server/source/drivers.h +++ b/freedv-server/source/drivers.h @@ -19,6 +19,19 @@ namespace FreeDV { /// or a memory leak will occurr. char * copy_string(const char * s); + /// Simple C++ circular buffer class. + /// Written to avoid STL templates, Boost, etc. in order to keep down the + /// size of the embedded version of this program. + class CircularBuffer { + private: + char * buffer; + std::size_t length; + char * in; + char * out; + + public: + }; + /// Set the real-time parameters in the scheduler before running our main /// loop. void set_scheduler(); @@ -106,7 +119,7 @@ namespace FreeDV { /// All drivers present a unidirectional interface. /// If the underlying device is bidirectional that detail is hidden and /// we present one or more separate read and write drivers. - virtual size_t ready() = 0; + virtual std::size_t ready() = 0; virtual ~IODevice() = 0; }; @@ -153,7 +166,7 @@ namespace FreeDV { /// Read audio into an array of the signed 16-bit integer type. virtual std::size_t - read16(int16_t * array, std::size_t length) = 0; + read16(std::int16_t * array, std::size_t length) = 0; }; /// Virtual base class for audio output drivers. @@ -171,7 +184,7 @@ namespace FreeDV { /// Write audio from an array of the signed 16-bit integer type. virtual std::size_t - write16(const int16_t * array, std::size_t length) = 0; + write16(const std::int16_t * array, std::size_t length) = 0; }; /// Virtual base class for codecs. @@ -199,9 +212,9 @@ namespace FreeDV { /// \param o The array of audio samples after decoding, in an array /// of signed 16-bit integers. /// \param length The number of bytes of data to be decoded. - /// \return The number of int16_t elements in the decoded array. + /// \return The number of std::int16_t elements in the decoded array. virtual std::size_t - decode16(const uint8_t * i, int16_t * o, \ + decode16(const std::uint8_t * i, std::int16_t * o, \ std::size_t length) = 0; @@ -210,9 +223,9 @@ namespace FreeDV { /// of signed 16-bit integers. /// \param o The encoded data, in an array of unsigned 8-bit integers. /// \param length The number of audio samples to be encoded. - /// \return The number of uint8_t elements in the encoded array. + /// \return The number of std::uint8_t elements in the encoded array. virtual std::size_t - encode16(const int16_t * i, uint8_t * o, \ + encode16(const std::int16_t * i, std::uint8_t * o, \ std::size_t length) = 0; /// Return the duration of a frame in milliseconds. @@ -333,7 +346,7 @@ namespace FreeDV { virtual void key(bool value) = 0; /// Return the amount of bytes ready to write. - virtual size_t ready() = 0; + virtual std::size_t ready() = 0; }; /// Softmodem driver. @@ -360,9 +373,9 @@ namespace FreeDV { /// of signed 16-bit integers. /// \param o The demodulated data, in an array of unsigned 8-bit integers. /// \param length The number of audio samples to be demodulated. - /// \return The number of uint8_t elements in the demodulated array. + /// \return The number of std::uint8_t elements in the demodulated array. virtual std::size_t - demodulate16(const int16_t * i, uint8_t * o, \ + demodulate16(const std::int16_t * i, std::uint8_t * o, \ std::size_t length) = 0; /// Modulate from data to audio samples. @@ -370,9 +383,9 @@ namespace FreeDV { /// \param o The array of audio samples after modulation, in an array /// of signed 16-bit integers. /// \param length The number of bytes of data to be modulated. - /// \return The number of int16_t elements in the modulated array. + /// \return The number of std::int16_t elements in the modulated array. virtual std::size_t - modulate16(const uint8_t * i, int16_t * o, \ + modulate16(const std::uint8_t * i, std::int16_t * o, \ std::size_t length) = 0; /// Return the duration of a frame in milliseconds. @@ -419,7 +432,7 @@ namespace FreeDV { public: /// Read the text data. - virtual size_t read(char * buffer, size_t length) = 0; + virtual std::size_t read(char * buffer, std::size_t length) = 0; virtual ~TextInput() = 0; }; diff --git a/freedv-server/source/keying_sink.cpp b/freedv-server/source/keying_sink.cpp index f2616c0c..54007ef0 100644 --- a/freedv-server/source/keying_sink.cpp +++ b/freedv-server/source/keying_sink.cpp @@ -17,7 +17,7 @@ namespace FreeDV { /// Return the amount of bytes ready for read. In this case, it always /// returns SIZE_MAX. - size_t ready(); + std::size_t ready(); }; KeyingSink::KeyingSink(const char * parameters) @@ -38,7 +38,7 @@ namespace FreeDV { std::cerr << "keying: RECEIVE" << std::endl; } - size_t + std::size_t KeyingSink::ready() { return SIZE_MAX; diff --git a/freedv-server/source/modem_noop.cpp b/freedv-server/source/modem_noop.cpp index c90b9a55..5d1a62c1 100644 --- a/freedv-server/source/modem_noop.cpp +++ b/freedv-server/source/modem_noop.cpp @@ -25,9 +25,9 @@ namespace FreeDV { /// of signed 16-bit integers. /// \param o The demodulated data, in an array of unsigned 8-bit integers. /// \param length The number of audio samples to be demodulated. - /// \return The number of uint8_t elements in the demodulated array. + /// \return The number of std::uint8_t elements in the demodulated array. virtual std::size_t - demodulate16(const int16_t * i, uint8_t * o, \ + demodulate16(const std::int16_t * i, std::uint8_t * o, \ std::size_t length); /// Modulate from data to audio samples. @@ -35,9 +35,9 @@ namespace FreeDV { /// \param o The array of audio samples after modulation, in an array /// of signed 16-bit integers. /// \param length The number of bytes of data to be modulated. - /// \return The number of int16_t elements in the modulated array. + /// \return The number of std::int16_t elements in the modulated array. virtual std::size_t - modulate16(const uint8_t * i, int16_t * o, \ + modulate16(const std::uint8_t * i, std::int16_t * o, \ std::size_t length); /// Return the duration of a frame in milliseconds. @@ -67,17 +67,17 @@ namespace FreeDV { std::size_t const ModemNoOp::bytes_per_frame() const { - return sizeof(int16_t); + return sizeof(std::int16_t); } std::size_t - ModemNoOp::demodulate16(const int16_t * i, uint8_t * o, std::size_t length) + ModemNoOp::demodulate16(const std::int16_t * i, std::uint8_t * o, std::size_t length) { return length; } std::size_t - ModemNoOp::modulate16(const uint8_t * i, int16_t * o, std::size_t length) + ModemNoOp::modulate16(const std::uint8_t * i, std::int16_t * o, std::size_t length) { return length; } diff --git a/freedv-server/source/ptt_constant.cpp b/freedv-server/source/ptt_constant.cpp index 2a534d29..43d21f9d 100644 --- a/freedv-server/source/ptt_constant.cpp +++ b/freedv-server/source/ptt_constant.cpp @@ -17,7 +17,7 @@ namespace FreeDV { virtual ~PTTConstant(); /// Return the amount of bytes ready for read. - size_t ready(); + std::size_t ready(); /// Return true if the PTT input is pressed. bool state(); @@ -41,7 +41,7 @@ namespace FreeDV { { } - size_t + std::size_t PTTConstant::ready() { if ( ready_one_shot ) diff --git a/freedv-server/source/run.cpp b/freedv-server/source/run.cpp index 10dbfa8d..717d97e7 100644 --- a/freedv-server/source/run.cpp +++ b/freedv-server/source/run.cpp @@ -108,7 +108,7 @@ namespace FreeDV { static void receive(Interfaces * i) { - const size_t samples_to_decode = i->receiver->ready() + const std::size_t samples_to_decode = i->receiver->ready() % i->modem->samples_per_frame(); } diff --git a/freedv-server/source/text_constant.cpp b/freedv-server/source/text_constant.cpp index df88db40..4de3c8f6 100644 --- a/freedv-server/source/text_constant.cpp +++ b/freedv-server/source/text_constant.cpp @@ -8,8 +8,8 @@ namespace FreeDV { /// This driver provides constant text. class TextConstant : public TextInput { private: - const size_t length; - size_t index; + const std::size_t length; + std::size_t index; public: /// Instantiate the constant text driver. @@ -17,10 +17,10 @@ namespace FreeDV { virtual ~TextConstant(); /// Read the text data. - size_t read(char * buffer, size_t size); + std::size_t read(char * buffer, std::size_t size); /// Return the amount of bytes ready for read. - size_t ready(); + std::size_t ready(); }; TextConstant::TextConstant(const char * parameters) @@ -32,10 +32,10 @@ namespace FreeDV { { } - size_t - TextConstant::read(char * buffer, size_t size) + std::size_t + TextConstant::read(char * buffer, std::size_t size) { - const size_t available = length - index; + const std::size_t available = length - index; if ( available == 0 ) { /// A real I/O device would block if this happened, so throw an error. @@ -52,7 +52,7 @@ namespace FreeDV { return size; } - size_t + std::size_t TextConstant::ready() { return length - index; diff --git a/freedv-server/source/tone.cpp b/freedv-server/source/tone.cpp index a8bb3305..5b96b5b5 100644 --- a/freedv-server/source/tone.cpp +++ b/freedv-server/source/tone.cpp @@ -20,7 +20,7 @@ namespace FreeDV { /// Return the amount of audio samples for read. In this case, it always /// returns SIZE_MAX. - size_t ready(); + std::size_t ready(); /// Generate a sine wave. float sine_wave(float frequency, unsigned int step); @@ -31,7 +31,7 @@ namespace FreeDV { virtual ~Tone(); // Read audio into the "short" type. - virtual std::size_t read16(int16_t * array, std::size_t length); + virtual std::size_t read16(std::int16_t * array, std::size_t length); }; Tone::Tone(const char * parameters) @@ -95,7 +95,7 @@ namespace FreeDV { } std::size_t - Tone::read16(int16_t * array, std::size_t length) + Tone::read16(std::int16_t * array, std::size_t length) { const unsigned int array_length = ((sizeof(tones) / sizeof(*tones)) - 1); @@ -113,12 +113,12 @@ namespace FreeDV { // sum of amplitudes is 1.0. if ( sumOfAmplitudes > 1.0 ) value /= sumOfAmplitudes; - array[i] = (int16_t)rint(value * master_amplitude * ((1 << 15) - 1)); + array[i] = (std::int16_t)rint(value * master_amplitude * ((1 << 15) - 1)); } clock = (clock + length) % SampleRate; } - size_t + std::size_t Tone::ready() { return SIZE_MAX; diff --git a/freedv-server/source/utility.cpp b/freedv-server/source/utility.cpp index 079a85ac..60e5b0e8 100644 --- a/freedv-server/source/utility.cpp +++ b/freedv-server/source/utility.cpp @@ -5,7 +5,7 @@ namespace FreeDV { char * copy_string(const char * s) { - const size_t length(strlen(s) + 1); + const std::size_t length(strlen(s) + 1); char * copy = new char[length]; memcpy(copy, s, length); return copy; -- 2.25.1