Skip to content

Commit

Permalink
Added outputs from SFix for MonoOutput and StereoOutput
Browse files Browse the repository at this point in the history
BugFix
  • Loading branch information
tomcombriat committed Feb 26, 2024
1 parent cfe7973 commit 05ef0f1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion AudioOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#ifndef AUDIOOUTPUT_H
#define AUDIOOUTPUT_H
#include <FixMath.h>

/** The type used to store a single channel of a single frame, internally. For compatibility with earlier versions of Mozzi this is defined as int.
* If you do not care about keeping old sketches working, you may be able to save some RAM by using int16_t, instead (on boards where int is larger
Expand Down Expand Up @@ -123,8 +124,11 @@ struct MonoOutput {
/** Construct an audio frame from a zero-centered value known to be in the 8 bit range. On AVR, if MOZZI_OUTPUT_PWM mode, this is effectively the same as calling the
* constructor, directly (no scaling gets applied). On platforms/configs using more bits, an appropriate left-shift will be performed. */
static inline MonoOutput from8Bit(int16_t l) { return fromNBit(8, l); }
/** Construct an audio frame a zero-centered value known to be in the 16 bit range. This is jsut a shortcut for fromNBit(16, ...) provided for convenience. */
/** Construct an audio frame from a zero-centered value known to be in the 16 bit range. This is jsut a shortcut for fromNBit(16, ...) provided for convenience. */
static inline MonoOutput from16Bit(int16_t l) { return fromNBit(16, l); }
/** Construct an audio frame from a SFix type from FixMath. Mozzi will figure out how many bits are in there and performs appropriate shifting to match the output range. */
template<int8_t NI, int8_t NF, uint64_t RANGE>
static inline MonoOutput fromSFix(SFix<NI,NF,RANGE> l) { return MonoOutput(SCALE_AUDIO(l.asRaw(), (NI+NF))) ;}
/** Construct an audio frame a zero-centered value known to be above at almost but not quite the N bit range, e.g. at N=8 bits and a litte. On most platforms, this is
* exactly the same as fromNBit(), shifting up or down to the platforms' available resolution.
*
Expand Down Expand Up @@ -168,6 +172,9 @@ template<typename T> static inline StereoOutput fromNBit(uint8_t bits, T l, T r)
static inline StereoOutput from8Bit(int16_t l, int16_t r) { return fromNBit(8, l, r); }
/** See @ref MonoOutput::from16Bit(), stereo variant */
static inline StereoOutput from16Bit(int16_t l, int16_t r) { return fromNBit(16, l, r); }
/** See @ref MonoOutput::fromSFix(), stereo variant. Note that the two channels do not need to have the same number of bits. */
template<int8_t NI, int8_t NF, uint64_t RANGE, int8_t _NI, int8_t _NF, uint64_t _RANGE>
static inline StereoOutput fromSFix(SFix<NI,NF,RANGE> l, SFix<_NI,_NF,_RANGE> r) { return MonoOutput(SCALE_AUDIO(l.asRaw(), (NI+NF)), SCALE_AUDIO(r.asRaw(), (_NI+_NF))); }
/** See @ref MonoOutput::fromAlmostNBit(), stereo variant */
template<typename A, typename B> static inline StereoOutput fromAlmostNBit(A bits, B l, B r) { return StereoOutput(SCALE_AUDIO_NEAR(l, bits), SCALE_AUDIO_NEAR(r, bits)); }
private:
Expand Down

0 comments on commit 05ef0f1

Please sign in to comment.