-
-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unsigned support for NumberFormatConverterStreamT
- Loading branch information
1 parent
2d5d09a
commit b63db61
Showing
13 changed files
with
168 additions
and
24 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
examples/tests/conversion/numberformat-converter-typed/numberformat-converter.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "AudioTools.h" | ||
|
||
using target_t = uint32_t; // uint8_t, int8_t, int16_t, uint16_t, int24_t, uint32_t, int32_t, FloatAudio | ||
SineWaveGenerator<int16_t> sineWave; // subclass of SoundGenerator with max amplitude of 32000 | ||
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave | ||
CsvOutput<target_t> out(Serial, sound.audioInfo().channels); | ||
NumberFormatConverterStreamT<int16_t, target_t> nfc(out); | ||
StreamCopy copier(nfc, sound); // copies sound into i2s | ||
|
||
// Arduino Setup | ||
void setup(void) { | ||
// Open Serial | ||
Serial.begin(115200); | ||
AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Warning); | ||
|
||
nfc.begin(); | ||
out.begin(); | ||
sineWave.begin(); | ||
|
||
// Setup sine wave | ||
sineWave.setFrequency(N_B4); | ||
Serial.println("started..."); | ||
} | ||
|
||
// Arduino loop - copy sound to out | ||
void loop() { | ||
copier.copy(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#pragma once | ||
#include "AudioConfig.h" | ||
|
||
namespace audio_tools { | ||
|
||
/*** | ||
* A simple float number (in the range of -1.0 to 1.0) the supports the conversion to | ||
* it's corresponding scaled int values. | ||
*/ | ||
|
||
class FloatAudio { | ||
public: | ||
FloatAudio() = default; | ||
FloatAudio(float in) { this->value = in; } | ||
|
||
explicit inline operator int8_t() { return value * 127; } | ||
|
||
explicit inline operator int16_t() { return value * 32767; } | ||
|
||
inline operator float() { return value; } | ||
|
||
// explicit inline operator int24_t() { | ||
// return value * 8388607; | ||
// } | ||
|
||
explicit inline operator int32_t() { return value * 2147483647; } | ||
|
||
protected: | ||
float value = 0.0f; | ||
}; | ||
|
||
} // namespace audio_tools | ||
|
||
#ifdef USE_TYPETRAITS | ||
|
||
namespace std { | ||
template <> | ||
class numeric_limits<audio_tools::FloatAudio> { | ||
public: | ||
static audio_tools::FloatAudio lowest() { | ||
return audio_tools::FloatAudio(-1.0f); | ||
}; | ||
static audio_tools::FloatAudio min() { | ||
return audio_tools::FloatAudio(-1.0f); | ||
}; | ||
static audio_tools::FloatAudio max() { | ||
return audio_tools::FloatAudio(1.0f); | ||
}; | ||
}; | ||
} // namespace std | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters