This struct encapsulates one frame of mono audio output.
Internally, it really just boils down to a single int value, but the struct provides useful API an top of that, for the following:
a) To construct an output frame, you should use one of the from8Bit(), fromNBit(), etc. functions. Given a raw input value, at a known resolution (number of bits), this scales the output efficiently to whatever is needed on the target platform. Using this, your updateAudio() function will be portable across different CPU and different output methods, including external DACs. b) The struct provides some convenience API on top of this. Right now, this is the function clip(), replacing the more verbose, and non-portable constrain(x, -244, 243) found in some old sketches. c) The struct provides accessors l() and r() that are source-compatible with StereoOutput, making it easy to e.g. implement support for an external DAC in both mono and stereo. d) Finally, an automatic conversion operator to int aka AudioOutput_t provides backward compatibility with old Mozzi sketches. Internally, the compiler will actually do away with this whole struct, leaving just the same basic fast integer operations as in older Mozzi sketches. However, now, you don't have to rewrite those for different configurations.
Definition at line 111 of file AudioOutput.h.
template<typename A , typename B >
static MonoOutput MonoOutput::fromAlmostNBit ( A bits, B l ) inlinestaticConstruct 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.
However, on AVR, MOZZI_OUTPUT_PWM mode (where about 8.5 bits are usable), the value will be shifted to the (almost) 9 bit range, instead of to the 8 bit range. allowing to make use of that extra half bit of resolution. In many cases it is useful to follow up this call with clip(). E.g.:
MonoOutput & clip()
Clip frame to supported range.
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...
Definition at line 153 of file AudioOutput.h.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4