History

Update README.md

Jeff Snyder committed 6 years ago

Commit 38a6f101 parent 657fcba1 file · +59 −0Browse files

Unified · Split

README.md+59−0
@@ -16,3 +16,62 @@ Other interesting projects to check out that similarly target embedded applicato · 15 unmodified lines
16(3) if you are looking to add LEAF to a System Workbench (SW4STM32) project (the free IDE for developing STM32 embedded firmware) then follow this guide: https://docs.google.com/document/d/1LtMFigQvnIOkRCSL-UVge4GM91woTmVkidlzzgtCjdE/edit?usp=sharing16(3) if you are looking to add LEAF to a System Workbench (SW4STM32) project (the free IDE for developing STM32 embedded firmware) then follow this guide: https://docs.google.com/document/d/1LtMFigQvnIOkRCSL-UVge4GM91woTmVkidlzzgtCjdE/edit?usp=sharing
17 17
18 18
19
20///
21LEAF conventions:
22
23Objects types start with a lowercase t: like tCycle, tSawtooth, tRamp, tEnvelopeFollower
24
25All function names start with the object type name, followed by an underscore, then the function name in camel-case: like tCycle_setFreq(), tRamp_setDest()
26
27LEAF assumes a global sample rate (passed into LEAF when the library itself is initialized).
28////
29
30
31
32Example of using LEAF:
33
34//in your user code, create an instance of a leaf object
35
36tCycle mySine;
37
38
39//also, create a mempool object where you can store the data for the LEAF objects. It should be an array of chars
40
41#define MEM_SIZE 500000
42char myMemory[MEM_SIZE];
43
44
45//we'll assume your code has some kind of audio buffer that is transmitting samples to an audio codec or an operating system's audio driver. In this example, let's define this here.
46
47#define AUDIO_BUFFER_SIZE 128
48float audioBuffer[AUDIO_BUFFER_SIZE];
49
50
51//then initialize the whole LEAF library (this only needs to be done once, it sets global parameters like the default mempool and the sample rate)
52//the parameters are: sample rate, audio buffer size in samples, name of mempool array, size of mempool array, and address of a function to generate a random number. In this case, there is a function called randomNumber that exists elsewhere in the user code that generates a random floating point number from 0.0 to 1.0. We ask the user to pass in a random number function because LEAF has no dependencies, and users developing on embedded systems may want to use a hardware RNG, for instance.
53
54LEAF_init(48000, AUDIO_BUFFER_SIZE, myMemory, MEM_SIZE, &randomNumber);
55
56
57//now initialize the object you want to use, in this case the sine wave oscillator you created above.
58
59tCycle_init(&mySine);
60
61
62//set the frequency of the oscillator (defaults to zero). In a real use case, you'd probably want to be updating this to new values in the audio frame based on knob positions or midi data or other inputs, but here we'll assume it stays fixed.
63
64tCycle_setFreq(&mySine, 440.0);
65
66
67//now, in your audio callback (a function that will be called every audio frame, to compute the samples needed to fill the audio buffer) tick the LEAF audio object to generate or process audio samples.
68
69void audioFrame()
70{
71 for (int i = 0; i < AUDIO_BUFFER_SIZE; i++)
72 {
73 audioBuffer[i] = tCycle_tick(&mySine);
74 }
75}
76
77

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t