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.h
00001 #ifndef __included_audio_h 00002 #define __included_audio_h 00003 00004 #include <stdint.h> 00005 00006 #ifndef AUDIO_DAC_PIN 00007 #define AUDIO_DAC_PIN PTE30 // J10/11 on FRDM-KL25Z 00008 #endif 00009 00010 namespace NKAudio 00011 { 00012 00013 struct AudioFile 00014 { 00015 const unsigned char *data; 00016 unsigned int length; 00017 }; 00018 00019 extern const AudioFile audioFiles[]; 00020 00021 // Analog: 00022 // GND J3/14 00023 // VrefH J3/16 00024 // output J10/11, PTE30 00025 00026 const unsigned SAMPLE_RATE_HZ = 8000; 00027 const unsigned SAMPLE_PERIOD_US = (1000000U / SAMPLE_RATE_HZ); 00028 const unsigned SAMPLE_BUFFER_SIZE = 14000; 00029 const unsigned AUDIO_WAIT_DURATION_US = 10000; 00030 const uint16_t DC_BIAS = 0x8000; 00031 00032 typedef void (*AudioCallback)(); 00033 00034 class AudioPlayer 00035 { 00036 public: 00037 static unsigned numberOfFiles() 00038 { 00039 static unsigned nFiles; 00040 if (!nFiles) { // count files first time 00041 for (AudioFile const *p = audioFiles; p->data != NULL; p++) { 00042 nFiles++; 00043 } 00044 } else { 00045 return nFiles; 00046 } 00047 } 00048 00049 static bool playFileNumbered(unsigned n, AudioCallback cb = NULL) 00050 { 00051 n %= numberOfFiles(); 00052 return playAudio(reinterpret_cast<int8_t const * const>(audioFiles[n].data), audioFiles[n].length, cb); 00053 } 00054 00055 static bool playAudio(int8_t const *start, uint16_t nsamples, AudioCallback cb = 0); 00056 00057 static bool audioDone() { return !samplesRemaining; } 00058 00059 private: 00060 static void playAudioSample(); 00061 static int8_t const * volatile nextSample; 00062 static uint16_t volatile samplesRemaining; 00063 }; 00064 00065 } // namespace NKAudio 00066 00067 #endif
Generated on Tue Jul 12 2022 18:19:51 by 1.7.2