11 #ifndef SAMPLEHUFFMAN_H
12 #define SAMPLEHUFFMAN_H
47 #include <util/atomic.h>
59 SampleHuffman(uint8_t
const * SOUNDDATA, int16_t
const * HUFFMAN_DATA, uint32_t
const SOUNDDATA_BITS):sounddata(SOUNDDATA),huffman(HUFFMAN_DATA),sounddata_bits(SOUNDDATA_BITS)
72 if(datapos >= sounddata_bits){
81 int16_t dif = decode();
110 ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
119 uint8_t
const * sounddata;
120 int16_t
const * huffman;
121 uint32_t
const sounddata_bits;
131 const uint8_t b = datapos&7;
133 if(!b) bt = pgm_read_byte(sounddata+((uint32_t)datapos>>3));
135 return ((uint8_t)bt>>(7-b))&1;
143 int16_t
const * huffcode = huffman;
146 const int16_t offs = pgm_read_word(huffcode);
147 huffcode += offs?offs+1:2;
151 while(pgm_read_word(huffcode++));
152 return pgm_read_word(huffcode);
163 #endif // #ifndef SAMPLEHUFFMAN_H
void setLoopingOn()
Turns looping on, with the whole sample length as the loop range.
SampleHuffman(uint8_t const *SOUNDDATA, int16_t const *HUFFMAN_DATA, uint32_t const SOUNDDATA_BITS)
Constructor.
void start()
Sets the playhead to the beginning of the sample.
void setLoopingOff()
Turns looping off.
A sample player for samples encoded with Huffman compression.
int16_t next()
Update and return the next audio sample.