|
46 | 46 |
|
47 | 47 | #ifndef AUDIOOUTPUT_H |
48 | 48 | #define AUDIOOUTPUT_H |
| 49 | +#include <FixMath.h> |
49 | 50 |
|
50 | 51 | /** 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. |
51 | 52 | * 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 |
@@ -123,8 +124,11 @@ struct MonoOutput { |
123 | 124 | /** 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 |
124 | 125 | * constructor, directly (no scaling gets applied). On platforms/configs using more bits, an appropriate left-shift will be performed. */ |
125 | 126 | static inline MonoOutput from8Bit(int16_t l) { return fromNBit(8, l); } |
126 | | - /** 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. */ |
| 127 | + /** 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. */ |
127 | 128 | static inline MonoOutput from16Bit(int16_t l) { return fromNBit(16, l); } |
| 129 | + /** 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. */ |
| 130 | + template<int8_t NI, int8_t NF, uint64_t RANGE> |
| 131 | + static inline MonoOutput fromSFix(SFix<NI,NF,RANGE> l) { return MonoOutput(SCALE_AUDIO(l.asRaw(), (NI+NF))) ;} |
128 | 132 | /** 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 |
129 | 133 | * exactly the same as fromNBit(), shifting up or down to the platforms' available resolution. |
130 | 134 | * |
@@ -168,6 +172,9 @@ template<typename T> static inline StereoOutput fromNBit(uint8_t bits, T l, T r) |
168 | 172 | static inline StereoOutput from8Bit(int16_t l, int16_t r) { return fromNBit(8, l, r); } |
169 | 173 | /** See @ref MonoOutput::from16Bit(), stereo variant */ |
170 | 174 | static inline StereoOutput from16Bit(int16_t l, int16_t r) { return fromNBit(16, l, r); } |
| 175 | +/** See @ref MonoOutput::fromSFix(), stereo variant. Note that the two channels do not need to have the same number of bits. */ |
| 176 | + template<int8_t NI, int8_t NF, uint64_t RANGE, int8_t _NI, int8_t _NF, uint64_t _RANGE> |
| 177 | + static inline StereoOutput from SFix(SFix<NI,NF,RANGE> l, SFix<_NI,_NF,_RANGE> r) { return MonoOutput(SCALE_AUDIO(l.asRaw(), (NI+NF)), SCALE_AUDIO(r.asRaw(), (_NI+_NF))); } |
171 | 178 | /** See @ref MonoOutput::fromAlmostNBit(), stereo variant */ |
172 | 179 | 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)); } |
173 | 180 | private: |
|
0 commit comments