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

Public Member Functions | List of all members
SampleHuffman Class Reference

A sample player for samples encoded with Huffman compression. More...

`#include <SampleHuffman.h>`

## Public Member Functions
| SampleHuffman (uint8_t const *SOUNDDATA, int16_t const *HUFFMAN_DATA, uint32_t const SOUNDDATA_BITS)
| Constructor. More...
int16_t | next ()
| Update and return the next audio sample. More...
void | setLoopingOn ()
| Turns looping on, with the whole sample length as the loop range.
void | setLoopingOff ()
| Turns looping off.
void | start ()
| Sets the playhead to the beginning of the sample.

## Detailed Description

A sample player for samples encoded with Huffman compression.

This class and the audio2huff.py script are adapted from "audioout", an Arduino sketch by Thomas Grill, 2011 http//grrrr.org

Huffman decoding is used on sample differentials, saving 50-70% of space for 8 bit data, depending on the sample rate.

This implementation just plays back one sample each time next() is called, with no speed or other adjustments. It's slow, so it's likely you will only be able to play one sound at a time.

Audio data, Huffman decoder table, sample rate and bit depth are defined in a sounddata.h header file. This file can be generated for a sound file with the accompanying Python script audio2huff.py, in Mozzi/extras/python/

Invoke with: python audio2huff.py –sndfile=arduinosnd.wav –hdrfile=sounddata.h –bits=8 –name=soundtablename

You can resample and dither your audio file with SOX, e.g. to 8 bits depth @ Mozzi's 16384 Hz sample rate: sox fullglory.wav -b 8 -r 16384 arduinosnd.wav

Alternatively you can export a sound from Audacity, which seems to have less noticeable or no dithering, using Project Rate 16384 Hz and these output options: Other uncompressed files, Header: WAV(Microsoft), Encoding: Unsigned 8 bit PCM

The header file contains two lengthy arrays: One is "SOUNDDATA" which must fit into Flash RAM (available in total: 32k for ATMega328) The other is "HUFFMAN" which must also fit into Flash RAM

Definition at line 49 of file SampleHuffman.h.

## Constructor & Destructor Documentation

## ◆ SampleHuffman()

SampleHuffman::SampleHuffman | ( | uint8_t const * | SOUNDDATA,
|  | int16_t const * | HUFFMAN_DATA,
|  | uint32_t const | SOUNDDATA_BITS
| ) |  |
| inline

Constructor.

Parameters

  SOUNDDATA | the name of the SOUNDDATA table in the huffman sample .h file
  HUFFMAN_DATA | the name of the HUFFMAN table in the huffman sample .h file
  SOUNDDATA_BITS | from the huffman sample .h file

Definition at line 59 of file SampleHuffman.h.

## Member Function Documentation

## ◆ next()

int16_t SampleHuffman::next | ( |  | ) |
| inline

Update and return the next audio sample.

So far it just plays back one sample at a time without any variable tuning or speed.

Returns
  the next audio sample

Note
  timing: about 5 to 40 us, varies continuously depending on data

Definition at line 70 of file SampleHuffman.h.