|
| 1 | +# Sampler |
| 2 | +This synthesizer module is made to playback samples from RAM or FLASH memory. |
| 3 | +It allows to manipulate the playback by changing the pitch, volume and tweak parameters like ADSR (attack, decay, sustain, release). |
| 4 | +In addition to that it is possible to loop samples. |
| 5 | + |
| 6 | +To use the **sampler** you need to include ml_sampler.h into your project: |
| 7 | +```cpp |
| 8 | +#include <ml_sampler.h> |
| 9 | + |
| 10 | +``` |
| 11 | + |
| 12 | +The sampler requires an initialization by calling its init routine for example from the setup(): |
| 13 | +```cpp |
| 14 | +#include <ml_sampler.h> |
| 15 | + |
| 16 | +#define SAMPLE_RATE 44100 |
| 17 | + |
| 18 | +void setup(void) |
| 19 | +{ |
| 20 | + Sampler_Init(SAMPLE_RATE); |
| 21 | + /* |
| 22 | + * some other setup routines might be called here |
| 23 | + */ |
| 24 | +} |
| 25 | +``` |
| 26 | +
|
| 27 | +
|
| 28 | +## playing samples from FLASH |
| 29 | +### preparing samples |
| 30 | +Samples can be played directly from FLASH when they are compiled into the program code. |
| 31 | +It is possible to convert wav-files into c files into a data array. |
| 32 | +For example prepare a 16bit mono wav-file and store it as test.wav. |
| 33 | +[Audacity](https://www.audacity.de/) can be used for this conversation |
| 34 | + |
| 35 | +
|
| 36 | +Then you can use [Bin2c](https://www.segger.com/free-utilities/bin2c/) to convert it to a c-file. |
| 37 | +You will find an array in the c-file: |
| 38 | +```cpp |
| 39 | +static const unsigned char _actest[55164UL + 1] = { |
| 40 | +``` |
| 41 | +which can be used as a sample in the sampler by loading it: |
| 42 | +```cpp |
| 43 | +#include <ml_sampler.h> |
| 44 | + |
| 45 | +#define SAMPLE_RATE 44100 |
| 46 | + |
| 47 | +void setup(void) |
| 48 | +{ |
| 49 | + Sampler_Init(SAMPLE_RATE); |
| 50 | + Sampler_NewSampleStatic(_actest, sizeof(_actest)); |
| 51 | + /* |
| 52 | + * some other setup routines might be called here |
| 53 | + */ |
| 54 | +} |
| 55 | +``` |
| 56 | +Now the sampler is ready to playback the loaded sample. |
0 commit comments