| Mozzi version v1.1.0 sound synthesis library for Arduino |

Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
MonoOutput Struct Reference

This struct encapsulates one frame of mono audio output. More...

`#include <AudioOutput.h>`

## Public Member Functions
| MonoOutput (AudioOutputStorage_t l=0)
| Construct an audio frame from raw values (zero-centered)
| operator StereoOutput () const __attribute__((deprecated("Sketch generates mono output
| Conversion to stereo operator: If used in a stereo config, returns identical channels (and gives a compile time warning). More...
AudioOutputStorage_t | l () const
AudioOutputStorage_t | r () const
MonoOutput & | clip ()
| Clip frame to supported range. More...

## Static Public Member Functions
static MonoOutput | fromNBit (uint8_t bits, int16_t l)
| Construct an audio frame a zero-centered value known to be in the N bit range. More...
static MonoOutput | fromNBit (uint8_t bits, int32_t l)
| 32bit overload. More...
static MonoOutput | from8Bit (int16_t l)
| Construct an audio frame from a zero-centered value known to be in the 8 bit range. More...
static MonoOutput | from16Bit (int16_t l)
| Construct an audio frame a zero-centered value known to be in the 16 bit range. More...
static MonoOutput | fromAlmostNBit (uint8_t bits, int16_t l)
static MonoOutput | fromAlmostNBit (uint8_t bits, int32_t l)
| 32bit overload. More...

## Public Attributes
but Mozzi is configured for stereo Check mozzi_config | h { return StereoOutput(_l, _l)

## Detailed Description

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 wholw 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 130 of file AudioOutput.h.

## Member Function Documentation

## ◆ clip()

MonoOutput& MonoOutput::clip | ( |  | ) |
| inline

Clip frame to supported range.

This is useful when at times, but only rarely, the signal may exceed the usual range. Using this function does not avoid artifacts, entirely, but gives much better results than an overflow.

Definition at line 144 of file AudioOutput.h.

## ◆ from16Bit()

static MonoOutput MonoOutput::from16Bit | ( | int16_t | l | ) |
| inline static

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.

Definition at line 156 of file AudioOutput.h.

## ◆ from8Bit()

static MonoOutput MonoOutput::from8Bit | ( | int16_t | l | ) |
| inline static

Construct an audio frame from a zero-centered value known to be in the 8 bit range.

On AVR, STANDADR or STANDARD_PLUS 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.

Definition at line 154 of file AudioOutput.h.

## ◆ fromAlmostNBit()

static MonoOutput MonoOutput::fromAlmostNBit | ( | uint8_t | bits,
|  | int32_t | l
| ) |  |
| inline static

32bit overload.

See above.

Definition at line 167 of file AudioOutput.h.

## ◆ fromNBit() [1/2]

static MonoOutput MonoOutput::fromNBit | ( | uint8_t | bits,
|  | int16_t | l
| ) |  |
| inline static

Construct an audio frame a zero-centered value known to be in the N bit range.

Appropriate left- or right-shifting will be performed, based on the number of output bits available. While this function takes care of the shifting, beware of potential overflow issues, if your intermediary results exceed the 16 bit range. Use proper casts to int32_t or larger in that case (and the compiler will automatically pick the 32 bit overload in this case)

Definition at line 149 of file AudioOutput.h.

## ◆ fromNBit() [2/2]

static MonoOutput MonoOutput::fromNBit | ( | uint8_t | bits,
|  | int32_t | l
| ) |  |
| inline static

32bit overload.

See above.

Definition at line 151 of file AudioOutput.h.

## ◆ operator StereoOutput()

MonoOutput::operator StereoOutput | ( |  | ) | const
| inline

Conversion to stereo operator: If used in a stereo config, returns identical channels (and gives a compile time warning).