Download libraries/Robot_Control/src/Squawk.h from Beifengdo/Arduino-Development: direct link, hf CLI and curl.
- Browser
- Download file 10.7 kB
-
https://huggingface.co/datasets/Beifengdo/Arduino-Development/resolve/main/libraries/Robot_Control/src/Squawk.h
- Command line
-
hf download hf://datasets/Beifengdo/Arduino-Development/libraries/Robot_Control/src/Squawk.h
-
curl -L -o Squawk.h https://huggingface.co/datasets/Beifengdo/Arduino-Development/resolve/main/libraries/Robot_Control/src/Squawk.h
10.7 kB
| // Squawk Soft-Synthesizer Library for Arduino | |
| // | |
| // Davey Taylor 2013 | |
| // d.taylor@arduino.cc | |
| class SquawkStream { | |
| public: | |
| virtual ~SquawkStream() = 0; | |
| virtual uint8_t read() = 0; | |
| virtual void seek(size_t offset) = 0; | |
| }; | |
| inline SquawkStream::~SquawkStream() { } | |
| class SquawkSynth { | |
| protected: | |
| // Load and play specified melody | |
| void play(SquawkStream *melody); | |
| public: | |
| SquawkSynth() {}; | |
| // Initialize Squawk to generate samples at sample_rate Hz | |
| void begin(uint16_t sample_rate); | |
| // Load and play specified melody | |
| // melody needs to point to PROGMEM data | |
| void play(const uint8_t *melody); | |
| // Resume currently loaded melody (or enable direct osc manipulation by sketch) | |
| void play(); | |
| // Pause playback | |
| void pause(); | |
| // Stop playback (unloads song) | |
| void stop(); | |
| // Tune Squawk to a different frequency - default is 1.0 | |
| void tune(float tuning); | |
| // Change the tempo - default is 50 | |
| void tempo(uint16_t tempo); | |
| }; | |
| extern SquawkSynth Squawk; | |
| // oscillator structure | |
| typedef struct { | |
| uint8_t vol; | |
| uint16_t freq; | |
| uint16_t phase; | |
| } osc_t; | |
| typedef osc_t Oscillator; | |
| // oscillator memory | |
| extern osc_t osc[4]; | |
| extern uint8_t pcm; | |
| // channel 0 is pulse wave @ 25% duty | |
| // channel 1 is square wave | |
| // channel 2 is triangle wave | |
| // channel 3 is noise | |
| // For channel 3, freq is used as part of its LFSR and should not be changed. | |
| // LFSR: Linear feedback shift register, a method of producing a | |
| // pseudo-random bit sequence, used to generate nasty noise. | |
| // Supported configurations for ATmega32U4 | |
| /* | |
| // NOT SUPPORTED YET | |
| #define SQUAWK_PWM_PIN6 OCR4D | |
| #define SQUAWK_PWM_PIN9 OCR4B | |
| #define SQUAWK_PWM_PIN10 OCR4B | |
| */ | |
| // Supported configurations for ATmega168 | |
| // Supported configurations for ATmega328P | |
| /* | |
| // NOT SUPPORTED YET | |
| #define SQUAWK_SPI SPDR | |
| #define SQUAWK_RLD_PORTB PORTB | |
| #define SQUAWK_RLD_PORTC PORTC | |
| */ | |
| extern void squawk_playroutine() asm("squawk_playroutine"); | |
| // SAMPLE GRINDER | |
| // generates samples and updates oscillators | |
| // uses 132 cycles (not counting playroutine) | |
| // ~1/3 CPU @ 44kHz on 16MHz | |