Test program for my Multi_WS2811 library that started out as a fork of heroic/WS2811. My library uses hardware DMA on the FRDM-KL25Z to drive up to 16 strings of WS2811 or WS2812 LEDs in parallel.
Dependencies: Multi_WS2811 mbed MMA8451Q
Fork of WS2811 by
audio.cpp
00001 #include "mbed.h" 00002 #include "audio.h" 00003 00004 namespace NKAudio 00005 { 00006 00007 AnalogOut speaker(AUDIO_DAC_PIN); 00008 Ticker sampleTicker; 00009 00010 // audio samples 00011 // class static 00012 int8_t const * volatile AudioPlayer::nextSample; 00013 00014 // class static 00015 uint16_t volatile AudioPlayer::samplesRemaining; 00016 00017 // interrupt handler 00018 // class static 00019 void AudioPlayer::playAudioSample() 00020 { 00021 static uint16_t dcBias = DC_BIAS; 00022 if (samplesRemaining) 00023 { 00024 int8_t val = *nextSample++; 00025 uint16_t val16 = dcBias + (val * 256); 00026 speaker.write_u16(val16); 00027 samplesRemaining--; 00028 } 00029 else 00030 { 00031 sampleTicker.detach(); 00032 speaker.write_u16(dcBias); 00033 } 00034 } 00035 00036 bool AudioPlayer::playAudio(int8_t const *start, uint16_t nsamples, AudioCallback cb) 00037 { 00038 if (!audioDone()) 00039 { 00040 return false; 00041 } 00042 nextSample = start; 00043 samplesRemaining = nsamples; 00044 sampleTicker.attach_us(&playAudioSample, SAMPLE_PERIOD_US); 00045 while (samplesRemaining) 00046 { 00047 if (cb != NULL) 00048 { 00049 cb(); 00050 } 00051 wait_us(AUDIO_WAIT_DURATION_US); 00052 } 00053 return true; 00054 } 00055 00056 } // namespace NKAudio
Generated on Tue Jul 12 2022 18:19:51 by 1.7.2