65 #define AudioOutputStorage_t int
67 template<
typename T>
constexpr AudioOutputStorage_t SCALE_AUDIO(T x, byte bits) {
return (bits > MOZZI_AUDIO_BITS ? (x) >> (bits - MOZZI_AUDIO_BITS) : (x) << (MOZZI_AUDIO_BITS - bits)); }
75 typedef StereoOutput AudioOutput;
88 typedef int AudioOutput_t;
93 MOZZI_DEPRECATED(
"2.0",
"Replace AudioOutput_t with simple AudioOutput")
typedef AudioOutput AudioOutput_t;
120 StereoOutput portable()
const __attribute__((
deprecated(
"Sketch generates mono output, but Mozzi is configured for stereo. Check MOZZI_AUDIO_CHANNELS setting.")));
134 template<
typename T>
static inline MonoOutput fromNBit(uint8_t bits, T l) {
return MonoOutput(SCALE_AUDIO(l, bits)); }
141 template<int8_t NI, int8_t NF, uint64_t RANGE>
142 static inline MonoOutput fromSFix(SFix<NI,NF,RANGE> l) {
return MonoOutput(SCALE_AUDIO(l.asRaw(), (NI+NF+1))) ;}
170 inline AudioOutput portable()
const __attribute__((deprecated(
"Sketch generates stereo output, but Mozzi is configured for mono. Check MOZZI_AUDIO_CHANNELS setting."))) {
return _l; };
171 # if GITHUB_RUNNER_ACCEPT_STEREO_IN_MONO
181 template<
typename T>
static inline StereoOutput fromNBit(uint8_t bits, T l, T r) {
return StereoOutput(SCALE_AUDIO(l, bits), SCALE_AUDIO(r, bits)); }
187 template<int8_t NI, int8_t NF, uint64_t RANGE, int8_t _NI, int8_t _NF, uint64_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))); }
197 StereoOutput MonoOutput::portable()
const {
return StereoOutput(_l, _l); };
203 void audioOutput(
const AudioOutput f);
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);