65 #define AudioOutputStorage_t int
68 template<
typename T> constexpr AudioOutputStorage_t SCALE_AUDIO_NEAR(T x,
byte bits) {
return (bits > MOZZI_AUDIO_BITS_OPTIMISTIC ? (x) >> (bits - MOZZI_AUDIO_BITS_OPTIMISTIC) : (x) << (MOZZI_AUDIO_BITS_OPTIMISTIC - bits)); }
69 template<
typename T> constexpr AudioOutputStorage_t CLIP_AUDIO(T x) {
return (constrain((x), (-(AudioOutputStorage_t) MOZZI_AUDIO_BIAS), (AudioOutputStorage_t) (MOZZI_AUDIO_BIAS-1))); }
74 #if MOZZI_IS(MOZZI_AUDIO_CHANNELS, MOZZI_STEREO)
86 #if MOZZI_COMPATIBILITY_LEVEL < MOZZI_COMPATIBILITY_LATEST
87 #if (MOZZI_COMPATIBILITY_LEVEL <= MOZZI_COMPATIBILITY_1_1) && MOZZI_IS(MOZZI_AUDIO_CHANNELS, MOZZI_MONO)
88 typedef int AudioOutput_t;
93 MOZZI_DEPRECATED(
"2.0",
"Replace AudioOutput_t with simple AudioOutput") typedef
AudioOutput AudioOutput_t;
116 #if (MOZZI_AUDIO_CHANNELS > 1)
120 StereoOutput portable() const __attribute__((deprecated("Sketch generates mono output, but Mozzi is configured for stereo. Check
MOZZI_AUDIO_CHANNELS setting.")));
123 operator AudioOutputStorage_t()
const {
return _l; };
125 AudioOutputStorage_t l()
const {
return _l; };
126 AudioOutputStorage_t r()
const {
return _l; };
141 template<
int8_t NI,
int8_t NF, u
int64_t RANGE>
156 AudioOutputStorage_t _l;
163 StereoOutput(AudioOutputStorage_t l, AudioOutputStorage_t r) : _l(l), _r(r) {};
166 #if !MOZZI_IS(MOZZI_AUDIO_CHANNELS, MOZZI_STEREO)
171 # if GITHUB_RUNNER_ACCEPT_STEREO_IN_MONO
172 inline operator AudioOutput() const __attribute__((deprecated("Stereo converted to mono on github runner"))) {
return _l; };
175 AudioOutputStorage_t l()
const {
return _l; };
176 AudioOutputStorage_t r()
const {
return _r; };
187 template<
int8_t NI,
int8_t NF, u
int64_t RANGE,
int8_t _NI,
int8_t _NF, u
int64_t _RANGE>
188 static inline StereoOutput fromSFix(SFix<NI,NF,RANGE> l, SFix<_NI,_NF,_RANGE> r) {
return StereoOutput(SCALE_AUDIO(l.asRaw(), (NI+NF+1)), SCALE_AUDIO(r.asRaw(), (_NI+_NF+1))); }
192 AudioOutputStorage_t _l;
193 AudioOutputStorage_t _r;
196 #if MOZZI_AUDIO_CHANNELS > 1
200 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_TIMED, MOZZI_OUTPUT_EXTERNAL_CUSTOM)
205 #if MOZZI_IS(MOZZI_AUDIO_MODE, MOZZI_OUTPUT_EXTERNAL_CUSTOM)
207 inline bool canBufferAudioOutput();
216 inline uint32_t pdmCode8(uint16_t sample) {
218 static const byte fast_pdm_table[]{0, 0b00010000, 0b01000100,
219 0b10010010, 0b10101010, 0b10110101,
220 0b11011101, 0b11110111, 0b11111111};
222 static uint32_t lastwritten = 0;
223 static uint32_t nexttarget = 0;
231 nexttarget += sample;
232 nexttarget -= lastwritten;
233 lastwritten = nexttarget & 0b11110000000000000;
234 return fast_pdm_table[lastwritten >> 13];
238 inline uint32_t pdmCode32(uint16_t sample) {
239 uint32_t outbits = 0;
240 for (uint8_t i = 0; i < 4; ++i) {
241 outbits = outbits << 8;
242 outbits |= pdmCode8(sample);
#define MOZZI_AUDIO_BITS
Output resolution of audio samples.
#define MOZZI_AUDIO_CHANNELS
This sets allows to change from a single/mono audio output channel to stereo output.
This struct encapsulates one frame of mono audio output.
static MonoOutput fromNBit(uint8_t bits, T l)
Construct an audio frame a zero-centered value known to be in the N bit range.
MonoOutput(AudioOutputStorage_t l)
Construct an audio frame from raw values (zero-centered)
MonoOutput & clip()
Clip frame to supported range.
static MonoOutput from16Bit(int16_t l)
Construct an audio frame from a zero-centered value known to be in the 16 bit range.
static MonoOutput from8Bit(int16_t l)
Construct an audio frame from a zero-centered value known to be in the 8 bit range.
MonoOutput()
Default constructor.
static MonoOutput fromAlmostNBit(A bits, B l)
Construct an audio frame a zero-centered value known to be above at almost but not quite the N bit ra...
static MonoOutput fromSFix(SFix< NI, NF, RANGE > l)
Construct an audio frame from a SFix type from FixMath.
This struct encapsulates one frame of mono audio output.
static StereoOutput fromAlmostNBit(A bits, B l, B r)
See MonoOutput::fromAlmostNBit(), stereo variant.
StereoOutput(AudioOutputStorage_t l, AudioOutputStorage_t r)
Construct an audio frame from raw values (zero-centered)
static StereoOutput from8Bit(int16_t l, int16_t r)
See MonoOutput::from8Bit(), stereo variant.
StereoOutput()
Default constructor.
AudioOutput portable() const __attribute__((deprecated("Sketch generates stereo output
Conversion to int operator: If used in a mono config, returns only the left channel (and gives a comp...
static StereoOutput from16Bit(int16_t l, int16_t r)
See MonoOutput::from16Bit(), stereo variant.
static StereoOutput fromNBit(uint8_t bits, T l, T r)
See MonoOutput::fromNBit(), stereo variant.
StereoOutput & clip()
See MonoOutput::clip().
static StereoOutput fromSFix(SFix< NI, NF, RANGE > l, SFix< _NI, _NF, _RANGE > r)
See MonoOutput::fromSFix(), stereo variant.