Commit 484da636fc503f62f1cd9d19b62fe27cc73a6e2f

Thomas de Grivel 2022-08-04T13:53:39

free and doc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
diff --git a/.gitignore b/.gitignore
index c8c3296..6c2af04 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
 .libs/
 config.mk
 /cli/rtbuf
+/doc/
 /gtk3/rtbuf-gtk3
 /gtk3/rtbuf_gtk3_resources.c
 /lib/*_type
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..d8da1e4
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "doxygen-awesome-css"]
+	path = doxygen-awesome-css
+	url = https://github.com/jothepro/doxygen-awesome-css.git
diff --git a/Makefile b/Makefile
index df27d29..a5600a1 100644
--- a/Makefile
+++ b/Makefile
@@ -12,10 +12,13 @@ clean:
 	${MAKE} -C ${PWD}/cli      clean
 	${MAKE} -C ${PWD}/gtk3     clean
 
+doc:
+	doxygen doxygen.conf
+
 install:
 	${MAKE} -C ${PWD}/librtbuf install
 	${MAKE} -C ${PWD}/lib      install
 	${MAKE} -C ${PWD}/cli      install
 	${MAKE} -C ${PWD}/gtk3     install
 
-.PHONY: all build clean install
+.PHONY: all build clean doc install
diff --git a/cli/rtbuf_cli.c b/cli/rtbuf_cli.c
index f56cdd1..9efbaac 100644
--- a/cli/rtbuf_cli.c
+++ b/cli/rtbuf_cli.c
@@ -72,7 +72,6 @@ int rtbuf_cli_load (int argc, const char *argv[])
     printf("load failed\n");
     return -1;
   }
-  rtbuf_lib_print(lib);
   return 0;
 }
 
@@ -123,8 +122,6 @@ int rtbuf_cli_new (int argc, const char *argv[])
       sscanf(argv[2], "%hd", &x) == 1 &&
       sscanf(argv[3], "%hd", &y) == 1)
     g_rtbuf_position_cb(&g_rtbuf[rtb], x, y);
-  rtbuf_print(rtb);
-  printf("\n");
   return 0;
 }
 
@@ -146,14 +143,13 @@ int rtbuf_cli_let (int argc, const char *argv[])
     if ((rtb = rtbuf_new(g_rtbuf_lib[rl].proc)) < 0)
       return rtbuf_err("buffer not created");
     v = rtbuf_var_rtbuf_set(argv[1], rtb);
-    assert(v);
+    if (!v)
+      return rtbuf_err("rtbuf_var_rtbuf_set failed");
     if (argc == 6 &&
         g_rtbuf_position_cb &&
         sscanf(argv[5], "%hd", &x) == 1 &&
         sscanf(argv[6], "%hd", &y) == 1)
       g_rtbuf_position_cb(&g_rtbuf[rtb], x, y);
-    rtbuf_var_print(v);
-    printf("\n");
     return 0;
   }
   else if (strncmp("buffer", argv[3], 7) == 0) {
@@ -163,8 +159,8 @@ int rtbuf_cli_let (int argc, const char *argv[])
     if ((rtb = rtbuf_find(argv[4])) < 0)
       return rtbuf_err("buffer not found");
     v = rtbuf_var_rtbuf_set(argv[1], rtb);
-    assert(v);
-    rtbuf_var_print(v);
+    if (!v)
+      return rtbuf_err("rtbuf_var_rtbuf_set failed");
     return 0;
   }
   return rtbuf_err("unknown type for let");
@@ -179,8 +175,6 @@ int rtbuf_cli_delete (int argc, const char *argv[])
   if (i < 0)
     return rtbuf_err("buffer not found\n");
   rtbuf_delete(&g_rtbuf[i]);
-  rtbuf_print(i);
-  printf("\n");
   return 0;
 }
 
@@ -201,7 +195,6 @@ int rtbuf_cli_bind (int argc, const char *argv[])
   if ((in = rtbuf_in_find(&g_rtbuf[dest], argv[4])) < 0)
     return rtbuf_err("input not found");
   rtbuf_bind(src, out, &g_rtbuf[dest], in);
-  rtbuf_print_long(dest);
   return 0;
 }
 
@@ -220,7 +213,6 @@ int rtbuf_cli_unbind (int argc, const char *argv[])
   }
   else
     rtbuf_unbind_all(&g_rtbuf[rtb]);
-  rtbuf_print_long(rtb);
   return 0;
 }
 
diff --git a/cli/rtbuf_cli_main.c b/cli/rtbuf_cli_main.c
index 6684a15..4b52d71 100644
--- a/cli/rtbuf_cli_main.c
+++ b/cli/rtbuf_cli_main.c
@@ -20,10 +20,13 @@
 
 int main (int argc, char *argv[])
 {
+  int res = 0;
   symbols_init();
   librtbuf_init();
   assert(g_rtbuf);
   repl_init();
   rtbuf_cli_args(argc, argv);
-  return repl();
+  res = repl();
+  librtbuf_shutdown();
+  return res;
 }
diff --git a/doxygen-awesome-css b/doxygen-awesome-css
new file mode 160000
index 0000000..4cd6230
--- /dev/null
+++ b/doxygen-awesome-css
@@ -0,0 +1 @@
+Subproject commit 4cd62308d825fe0396d2f66ffbab45d0e247724c
diff --git a/doxygen.conf b/doxygen.conf
index fb8ad2c..ddc0d22 100644
--- a/doxygen.conf
+++ b/doxygen.conf
@@ -38,7 +38,7 @@ PROJECT_NAME           = "rtbuf"
 # could be handy for archiving the generated documentation or if some version
 # control system is used.
 
-PROJECT_NUMBER         =
+PROJECT_NUMBER         = 0.3
 
 # Using the PROJECT_BRIEF tag one can provide an optional one line description
 # for a project that appears at the top of each page and should give viewer a
@@ -187,7 +187,7 @@ SHORT_NAMES            = NO
 # description.)
 # The default value is: NO.
 
-JAVADOC_AUTOBRIEF      = NO
+JAVADOC_AUTOBRIEF      = YES
 
 # If the JAVADOC_BANNER tag is set to YES then doxygen will interpret a line
 # such as
@@ -477,7 +477,7 @@ NUM_PROC_THREADS       = 1
 # normally produced when WARNINGS is set to YES.
 # The default value is: NO.
 
-EXTRACT_ALL            = NO
+EXTRACT_ALL            = YES
 
 # If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will
 # be included in the documentation.
@@ -526,7 +526,7 @@ EXTRACT_LOCAL_METHODS  = NO
 # are hidden.
 # The default value is: NO.
 
-EXTRACT_ANON_NSPACES   = NO
+EXTRACT_ANON_NSPACES   = YES
 
 # If this flag is set to YES, the name of an unnamed parameter in a declaration
 # will be determined by the corresponding definition. By default unnamed
@@ -1072,7 +1072,7 @@ FILTER_SOURCE_PATTERNS =
 # (index.html). This can be useful if you have a project on for instance GitHub
 # and want to reuse the introduction page also for the doxygen output.
 
-USE_MDFILE_AS_MAINPAGE =
+USE_MDFILE_AS_MAINPAGE = README.md
 
 #---------------------------------------------------------------------------
 # Configuration options related to source browsing
@@ -1256,7 +1256,8 @@ HTML_STYLESHEET        =
 # list). For an example see the documentation.
 # This tag requires that the tag GENERATE_HTML is set to YES.
 
-HTML_EXTRA_STYLESHEET  =
+HTML_EXTRA_STYLESHEET  = doxygen-awesome-css/doxygen-awesome.css \
+                         doxygen-awesome-css/doxygen-awesome-sidebar-only.css
 
 # The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
 # other source files which should be copied to the HTML output directory. Note
@@ -1566,7 +1567,7 @@ DISABLE_INDEX          = NO
 # The default value is: NO.
 # This tag requires that the tag GENERATE_HTML is set to YES.
 
-GENERATE_TREEVIEW      = NO
+GENERATE_TREEVIEW      = YES
 
 # When both GENERATE_TREEVIEW and DISABLE_INDEX are set to YES, then the
 # FULL_SIDEBAR option determines if the side bar is limited to only the treeview
diff --git a/lib/glfw3/keyboard.c b/lib/glfw3/keyboard.c
index 324b4a5..b33bcc6 100644
--- a/lib/glfw3/keyboard.c
+++ b/lib/glfw3/keyboard.c
@@ -240,10 +240,12 @@ void rtbuf_glfw3_keyboard_close (GLFWwindow *window)
 GLFWwindow * rtbuf_glfw3_keyboard_window (s_rtbuf *rtb)
 {
   GLFWwindow *window;
-  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
-  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
-  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
-  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+  /*
+    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
+    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
+    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
+    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
+  */
   window = glfwCreateWindow(RTBUF_GLFW3_KEYBOARD_WIDTH,
                             RTBUF_GLFW3_KEYBOARD_HEIGHT,
                             "rtbuf_glfw3_keyboard",
diff --git a/lib/music.h b/lib/music.h
index 82c6b7e..7def717 100644
--- a/lib/music.h
+++ b/lib/music.h
@@ -23,7 +23,7 @@
 
 #define RTBUF_MUSIC_RELEASE_MAX 1.0
 
-#define RTBUF_MUSIC_NOTE_SIZE RTBUF_SIGNAL_SAMPLE_SIZE
+#define RTBUF_MUSIC_NOTE_SIZE (RTBUF_SIGNAL_SAMPLE_SIZE * 4)
 #define RTBUF_MUSIC_NOTE_TYPE "music_note"
 
 typedef struct rtbuf_music_note {
diff --git a/librtbuf/README.dox b/librtbuf/README.dox
new file mode 100644
index 0000000..797b439
--- /dev/null
+++ b/librtbuf/README.dox
@@ -0,0 +1,5 @@
+/**
+
+Hello, world !
+
+*/
diff --git a/librtbuf/data.c b/librtbuf/data.c
index 54d0ba2..76656c3 100644
--- a/librtbuf/data.c
+++ b/librtbuf/data.c
@@ -23,21 +23,38 @@ s_data_type g_data_alloc_type = {
   sizeof(s_data_alloc) * 8,
   DATA_TYPE_BITS
 };
-s_data_alloc g_data_alloc;
+s_data_alloc g_data_alloc_alloc;
+s_data_alloc *g_data_alloc = NULL;
 
 s_data_type g_data_type_type = {
   sizeof(u_data_type) * 8,
   DATA_TYPE_BITS
 };
-s_data_alloc *g_data_type_alloc = 0;
+s_data_alloc *g_data_type_alloc = NULL;
+u_data_type *g_data_type = NULL;
 
 int libdata_init ()
 {
-  data_alloc_init(&g_data_alloc, &g_data_alloc_type,
+  data_alloc_init(&g_data_alloc_alloc, &g_data_alloc_type,
                   DATA_ALLOC_MAX, 0, (f_data_clean*) data_alloc_clean);
+  assert(g_data_alloc_alloc);
+  g_data_alloc = g_data_alloc_alloc.mem;
+  g_data_type_alloc = data_alloc_new(&g_data_type_type, DATA_TYPE_MAX,
+                                     0, 0);
+  assert(g_data_type_alloc);
+  g_data_type = g_data_type_alloc->mem;
   return 0;
 }
 
+void libdata_shutdown ()
+{
+  if (g_data_alloc) {
+    data_alloc_delete_all();
+    g_data_alloc = 0;
+    data_alloc_clean(&g_data_alloc_alloc);
+  }
+}
+
 void data_alloc_init (s_data_alloc *da, s_data_type *t,
                       unsigned int max, f_data_init *init,
                       f_data_clean *clean)
@@ -125,7 +142,7 @@ void data_delete (s_data_alloc *da, void *data)
 s_data_alloc * data_alloc_new (s_data_type *t, unsigned int max,
                                f_data_init *init, f_data_clean *clean)
 {
-  s_data_alloc *da = data_new(&g_data_alloc);
+  s_data_alloc *da = data_new(&g_data_alloc_alloc);
   assert(da);
   data_alloc_init(da, t, max, init, clean);
   return da;
@@ -134,15 +151,25 @@ s_data_alloc * data_alloc_new (s_data_type *t, unsigned int max,
 void data_alloc_delete (s_data_alloc *da)
 {
   assert(da);
-  data_delete(&g_data_alloc, da);
+  data_delete(&g_data_alloc_alloc, da);
+}
+
+void data_alloc_delete_all ()
+{
+  unsigned i = 0;
+  int n = g_data_alloc_alloc.n;
+  while (i < g_data_alloc_alloc.max && n > 0) {
+    if (g_data_alloc[i].t) {
+      data_alloc_delete(g_data_alloc + i);
+      n--;
+    }
+    i++;
+  }
 }
 
 u_data_type * data_type_new (unsigned int bits, unsigned int type)
 {
   u_data_type *t;
-  if (!g_data_type_alloc)
-    g_data_type_alloc = data_alloc_new(&g_data_type_type, DATA_TYPE_MAX,
-                                       0, 0);
   assert(g_data_type_alloc);
   t = data_new(g_data_type_alloc);
   assert(t);
diff --git a/librtbuf/data.h b/librtbuf/data.h
index e756285..a59b6b5 100644
--- a/librtbuf/data.h
+++ b/librtbuf/data.h
@@ -94,7 +94,9 @@ s_data_alloc * data_alloc_new (s_data_type *t,
                                unsigned int max, f_data_init *init,
                                f_data_clean *clean);
 void           data_alloc_delete (s_data_alloc *da);
+void           data_alloc_delete_all ();
 
 int libdata_init ();
+void libdata_shutdown ();
 
 #endif
diff --git a/librtbuf/lib.h b/librtbuf/lib.h
index 2d32ea8..b5bc91c 100644
--- a/librtbuf/lib.h
+++ b/librtbuf/lib.h
@@ -13,35 +13,67 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+/**
+ * @file
+ * @brief Rtbuf library header.
+ *
+ * Include <rtbuf/lib.h> to manage rtbuf libraries.
+ *
+ * Use rtbuf_lib_load to load a library, and rtbuf_lib_delete to
+ * free it.
+ *
+ * @see rtbuf_lib_load
+ * @see rtbuf_lib_delete
+ */
 #ifndef RTBUF_LIB_H
 #define RTBUF_LIB_H
 
 #include "defs.h"
 
+/**
+ * @brief Maximum number of loaded libraries.
+ */
 #define RTBUF_LIB_MAX 1000
+
+/**
+ * @brief Version for library compatibility.
+ */
 #define RTBUF_LIB_VER 0x00020001
 
+/**
+ * @brief Description of a library's proc input.
+ */
 struct rtbuf_lib_proc_in {
-  const char *name;
-  const char *type;
-  double def;
-  double min;
-  double max;
-  double log_base;
+  const char *name; /**< Name of the input. */
+  const char *type; /**< Type of the input (as a string). */
+  double def;       /**< Default value for the input. */
+  double min;       /**< Minimum value for the input. */
+  double max;       /**< Maximum value for the input. */
+  double log_base;  /**< Base for ogarithmic scale or 0 for linear. */
 };
 
+/**
+ * @brief Description of a library's proc output.
+ */
 struct rtbuf_lib_proc_out {
   const char *name;
   const char *type;
 };
 
+/**
+ * @brief Description of a library's proc.
+ *
+ * A proc is like a class for real time buffers. It has a name, a
+ * description for the buffers inputs and outputs, and pointers to
+ * functions for the buffer's start, run, and stop events.
+ */
 struct rtbuf_lib_proc {
-  const char *name;
-  f_rtbuf_proc *f;
-  f_rtbuf_proc *start;
-  f_rtbuf_proc *stop;
-  s_rtbuf_lib_proc_in *in;    /* inputs, end with NULL */
-  s_rtbuf_lib_proc_out *out;  /* outputs, end with NULL */
+  const char *name;          /**< Name of the proc. E.g. "sinus" */
+  f_rtbuf_proc *f;           /**< The real time buffer's run function. */
+  f_rtbuf_proc *start;       /**< The real time buffer's start function. */
+  f_rtbuf_proc *stop;        /**< The real time buffer's stop function. */
+  s_rtbuf_lib_proc_in *in;   /**< Description for the buffer's inputs. Must end with NULL. */
+  s_rtbuf_lib_proc_out *out; /**< Description for the buffer's outputs. Must end with NULL. */
 };
 
 struct rtbuf_lib {
@@ -57,17 +89,19 @@ extern s_data_alloc g_rtbuf_lib_alloc;
 extern s_rtbuf_lib *g_rtbuf_lib;
 
 void          rtbuf_lib_delete (s_rtbuf_lib *rl);
+void          rtbuf_lib_delete_all ();
 int           rtbuf_lib_find (const char *str);
 void          rtbuf_lib_init_ ();
+void          rtbuf_lib_shutdown ();
 s_rtbuf_lib * rtbuf_lib_load (const char *path);
 s_rtbuf_lib * rtbuf_lib_new ();
 void          rtbuf_lib_print (const s_rtbuf_lib *lib);
 void          rtbuf_lib_print_long (unsigned int i);
 
-void rtbuf_lib_proc_var_init_proc (s_rtbuf_proc *proc,
-                                   s_rtbuf_lib_proc_in *in);
-void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
-                                   s_rtbuf_lib_proc_out *out);
-void rtbuf_lib_proc_init_proc (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x);
+void rtbuf_lib_proc_init_in (s_rtbuf_proc *proc,
+                             s_rtbuf_lib_proc_in *in);
+void rtbuf_lib_proc_init_out (s_rtbuf_proc *proc,
+                              s_rtbuf_lib_proc_out *out);
+void rtbuf_lib_proc_init (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x);
 
 #endif
diff --git a/librtbuf/proc.h b/librtbuf/proc.h
index 1650b90..21f9971 100644
--- a/librtbuf/proc.h
+++ b/librtbuf/proc.h
@@ -62,13 +62,15 @@ struct rtbuf_proc {
 extern s_data_alloc  g_rtbuf_proc_alloc;
 extern s_rtbuf_proc *g_rtbuf_proc;
 
-void           rtbuf_proc_init ();
-int            rtbuf_proc_p (s_rtbuf_proc *proc);
-s_rtbuf_proc * rtbuf_proc_new ();
 void           rtbuf_proc_delete (s_rtbuf_proc *proc);
+void           rtbuf_proc_delete_all ();
 s_rtbuf_proc * rtbuf_proc_find (const char *x);
+void           rtbuf_proc_init ();
+s_rtbuf_proc * rtbuf_proc_new ();
 int            rtbuf_proc_out_find (s_rtbuf_proc *proc,
                                     const char *name);
+int            rtbuf_proc_p (s_rtbuf_proc *proc);
 void           rtbuf_proc_print (s_rtbuf_proc *proc);
+void           rtbuf_proc_shutdown ();
 
 #endif
diff --git a/librtbuf/rtbuf.c b/librtbuf/rtbuf.c
index e9fb1b4..c570bb7 100644
--- a/librtbuf/rtbuf.c
+++ b/librtbuf/rtbuf.c
@@ -13,7 +13,10 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
-
+/**
+ * @file
+ * @brief real time buffer implementation
+ */
 #include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -55,6 +58,16 @@ int librtbuf_init ()
   return 0;
 }
 
+void librtbuf_shutdown ()
+{
+  rtbuf_var_shutdown();
+  rtbuf_lib_shutdown();
+  rtbuf_proc_shutdown();
+  rtbuf_type_shutdown();
+  g_rtbuf = 0;
+  libdata_shutdown();
+}
+
 int rtbuf_new (s_rtbuf_proc *rp)
 {
   return rtbuf_new_ptr(rp, NULL);
diff --git a/librtbuf/rtbuf.h b/librtbuf/rtbuf.h
index e7e6c66..2f2097d 100644
--- a/librtbuf/rtbuf.h
+++ b/librtbuf/rtbuf.h
@@ -13,6 +13,16 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+/**
+ * @file
+ * @brief rtbuf main header.
+ *
+ * Main include file for librtbuf. Include this file in your project
+ * to use librtbuf.
+ *
+ * Use librtbuf_init to initialize librtbuf.
+ * You can then load libraries using rtbuf_lib_*
+ */
 #ifndef RTBUF_H
 #define RTBUF_H
 
@@ -26,34 +36,80 @@
 #define RTBUF_NEW      0x0004
 #define RTBUF_READY    0x0008
 
+/**
+ * @brief Binding to an rtbuf output.
+ *
+ * s_rtbuf_binding is used to bind to an arbitrary output of an
+ * arbitrary rtbuf.
+ */
 struct rtbuf_binding
 {
-  int rtb;
-  unsigned int out;
+  int rtb;          /**< The source rtbuf index in g_rtbuf. */
+  unsigned int out; /**< The source rtbuf output index. */
 };
 
+/**
+ * @brief Real-time buffer.
+ *
+ * s_rtbuf is a real-time buffer with a procedure (start, run, stop).
+ * Use rtbuf_new or rtbuf_new_ptr to allocate and initialize.
+ */
 struct rtbuf
 {
-  void           *data;
-  unsigned int    flags;
-  s_rtbuf_proc   *proc;
-  unsigned int    refc;
-  s_rtbuf_binding in[RTBUF_PROC_IN_MAX];
-  unsigned int    in_n;
-  void           *user_ptr;
+  void           *data;                  /**< Pointer to buffer memory. */
+  unsigned int    flags;                 /**< Flags for buffer state. */
+  s_rtbuf_proc   *proc;                  /**< The procedure for the buffer (start, run, stop). */
+  unsigned int    refc;                  /**< Reference count. */
+  s_rtbuf_binding in[RTBUF_PROC_IN_MAX]; /**< Inputs are bindings to other buffers outputs. */
+  unsigned int    in_n;                  /**< Number of inputs. */
+  void           *user_ptr;              /**< User pointer. */
 };
 
+/**
+ * Maximum number of s_rtbuf allocated at the same time globally.
+ */
 #define RTBUF_MAX         10000
+
+/**
+ * Maximum number of s_rtbuf allocated at the same time for each
+ * procedure.
+ */
 #define RTBUF_INSTANCE_MAX  100
 
+/**
+ * @brief Real time allocator for g_rtbuf.
+ */
 extern s_data_alloc g_rtbuf_alloc;
+
+/**
+ * @brief Global index of s_rtbuf.
+ */
 extern s_rtbuf     *g_rtbuf;
+
+/**
+ * @brief Run loop should exit when g_rtbuf_run is zero.
+ */
 extern int          g_rtbuf_run;
 
+/**
+ * @brief Callback function for rtbuf_new.
+ */
 typedef void (*f_rtbuf_new_cb) (s_rtbuf *rtb);
+
+/**
+ * @brief Callback function for rtbuf_delete.
+ */
 typedef void (*f_rtbuf_delete_cb) (s_rtbuf *rtb);
+
+/**
+ * @brief Callback function for rtbuf_bind.
+ */
 typedef void (*f_rtbuf_bind_cb) (s_rtbuf *src, unsigned int out,
                                  s_rtbuf *dest, unsigned int in);
+
+/**
+ * @brief Callback function for rtbuf_unbind.
+ */
 typedef void (*f_rtbuf_unbind_cb) (s_rtbuf *src, unsigned int out,
                                    s_rtbuf *dest, unsigned int in);
 
@@ -62,10 +118,39 @@ extern f_rtbuf_delete_cb g_rtbuf_delete_cb;
 extern f_rtbuf_bind_cb   g_rtbuf_bind_cb;
 extern f_rtbuf_unbind_cb g_rtbuf_unbind_cb;
 
-int   librtbuf_init ();
+/**
+ * Initialize librtbuf.
+ *
+ * Should be called before any other rtbuf function.
+ *
+ * @sa librtbuf_shutdown
+ */
+int librtbuf_init ();
+
+/**
+ * Shutdown librtbuf.
+ *
+ * Should be called only after any other rtbuf function, when the
+ * program shuts down.
+ *
+ * @sa librtbuf_init
+ */
+void librtbuf_shutdown ();
+
+int rtbuf_err (const char *msg);
+
+/**
+ * Create a new real time buffer.
+ *
+ * The buffer is allocated in real time and ready to be bound.
+ * This is equivalent to calling rtbuf_new_ptr with user_ptr
+ * set to NULL.
+ *
+ * @param rp The procedure for the new rtbuf.
+ * @return The index of the new rtbuf in g_rtbuf.
+ */
+int rtbuf_new (s_rtbuf_proc *rp);
 
-int   rtbuf_err (const char *msg);
-int   rtbuf_new (s_rtbuf_proc *rp);
 int   rtbuf_new_ptr (s_rtbuf_proc *rp, void *user_ptr);
 void  rtbuf_in_unbind (s_rtbuf *rtb, unsigned int in);
 void  rtbuf_out_unbind (s_rtbuf *rtb, unsigned int out);
diff --git a/librtbuf/rtbuf_lib.c b/librtbuf/rtbuf_lib.c
index d5392dd..8161020 100644
--- a/librtbuf/rtbuf_lib.c
+++ b/librtbuf/rtbuf_lib.c
@@ -56,6 +56,15 @@ void rtbuf_lib_init_ ()
   *out = 0;
 }
 
+void rtbuf_lib_shutdown ()
+{
+  if (g_rtbuf_lib) {
+    rtbuf_lib_delete_all();
+    g_rtbuf_lib = 0;
+    data_alloc_clean(&g_rtbuf_lib_alloc);
+  }
+}
+
 int rtbuf_lib_p (s_rtbuf_lib *lib)
 {
   return lib->lib ? 1 : 0;
@@ -101,6 +110,19 @@ void rtbuf_lib_delete (s_rtbuf_lib *rl)
   data_delete(&g_rtbuf_lib_alloc, rl);
 }
 
+void rtbuf_lib_delete_all ()
+{
+  unsigned i = 0;
+  int n = g_rtbuf_lib_alloc.n;
+  while (i < g_rtbuf_lib_alloc.max && n > 0) {
+    if (g_rtbuf_lib[i].name) {
+      rtbuf_lib_delete(g_rtbuf_lib + i);
+      n--;
+    }
+    i++;
+  }
+}
+
 int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
 {
   char **path = g_rtbuf_lib_path;
@@ -110,7 +132,7 @@ int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
     lib_path = g_str_append(*path, strlen(*path));
     g_str_append(name, strlen(name));
     ext = g_str_append(".so", 4);
-    printf("lib find in path \"%s\"\n", lib_path);
+    /*printf("lib find in path \"%s\"\n", lib_path);*/
     if (access(lib_path, R_OK) == 0 &&
         (lib->lib = dlopen(lib_path, RTLD_NOW))) {
       lib->path = lib_path;
@@ -118,7 +140,7 @@ int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
     }
     g_str_reset(ext);
     g_str_append(".so.0.0", 8);
-    printf("lib find in path \"%s\"\n", lib_path);
+    /*printf("lib find in path \"%s\"\n", lib_path);*/
     if (access(lib_path, R_OK) == 0 &&
         (lib->lib = dlopen(lib_path, RTLD_NOW))) {
       lib->path = lib_path;
@@ -126,7 +148,7 @@ int rtbuf_lib_load_path (s_rtbuf_lib *lib, const char *name)
     }
     g_str_reset(ext);
     g_str_append("-0.dll", 7);
-    printf("lib find in path \"%s\"\n", lib_path);
+    /*printf("lib find in path \"%s\"\n", lib_path);*/
     if (access(lib_path, R_OK) == 0 &&
         (lib->lib = dlopen(lib_path, RTLD_NOW))) {
       lib->path = lib_path;
@@ -175,7 +197,7 @@ s_rtbuf_lib * rtbuf_lib_load (const char *name)
   proc = dlsym(lib->lib, "rtbuf_lib_proc");
   lib->proc = rtbuf_proc_new();
   assert(lib->proc);
-  rtbuf_lib_proc_init_proc(lib->proc, proc);
+  rtbuf_lib_proc_init(lib->proc, proc);
   lib->proc->lib = lib;
   return lib;
 }
@@ -194,8 +216,8 @@ unsigned int add_padding (unsigned int offset, unsigned int size)
   return (offset + align - 1) / align * align;
 }
 
-void rtbuf_lib_proc_in_init_proc (s_rtbuf_proc *proc,
-                                  s_rtbuf_lib_proc_in *in)
+void rtbuf_lib_proc_init_in (s_rtbuf_proc *proc,
+                             s_rtbuf_lib_proc_in *in)
 {
   unsigned int i = 0;
   unsigned int offset = proc->out_bytes;
@@ -233,8 +255,8 @@ void rtbuf_lib_proc_in_init_proc (s_rtbuf_proc *proc,
                   NULL, NULL);
 }
 
-void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
-                                   s_rtbuf_lib_proc_out *out)
+void rtbuf_lib_proc_init_out (s_rtbuf_proc *proc,
+                              s_rtbuf_lib_proc_out *out)
 {
   unsigned int i = 0;
   bzero(proc->out, sizeof(proc->out));
@@ -264,14 +286,14 @@ void rtbuf_lib_proc_out_init_proc (s_rtbuf_proc *proc,
   proc->out_n = i;
 }
 
-void rtbuf_lib_proc_init_proc (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x)
+void rtbuf_lib_proc_init (s_rtbuf_proc *proc, s_rtbuf_lib_proc *x)
 {
   proc->name = symbol_intern(x->name);
   proc->f = x->f;
   proc->start = x->start;
   proc->stop = x->stop;
-  rtbuf_lib_proc_out_init_proc(proc, x->out);
-  rtbuf_lib_proc_in_init_proc(proc, x->in);
+  rtbuf_lib_proc_init_out(proc, x->out);
+  rtbuf_lib_proc_init_in(proc, x->in);
 }
 
 void rtbuf_lib_print (const s_rtbuf_lib *lib)
diff --git a/librtbuf/rtbuf_proc.c b/librtbuf/rtbuf_proc.c
index eb3d8eb..bb25e8e 100644
--- a/librtbuf/rtbuf_proc.c
+++ b/librtbuf/rtbuf_proc.c
@@ -37,6 +37,15 @@ void rtbuf_proc_init ()
   assert(g_rtbuf_proc);
 }
 
+void rtbuf_proc_shutdown ()
+{
+  if (g_rtbuf_proc) {
+    rtbuf_proc_delete_all();
+    data_alloc_clean(&g_rtbuf_proc_alloc);
+    g_rtbuf_proc = 0;
+  }
+}
+
 int rtbuf_proc_p (s_rtbuf_proc *proc)
 {
   return proc && proc->name;
@@ -54,6 +63,19 @@ void rtbuf_proc_delete (s_rtbuf_proc *proc)
   data_delete(&g_rtbuf_proc_alloc, proc);
 }
 
+void rtbuf_proc_delete_all ()
+{
+  unsigned i = 0;
+  int n = g_rtbuf_proc_alloc.n;
+  while (i < g_rtbuf_proc_alloc.max && n > 0) {
+    if (g_rtbuf_proc[i].name) {
+      rtbuf_proc_delete(g_rtbuf_proc + i);
+      n--;
+    }
+    i++;
+  }
+}
+
 s_rtbuf_proc * rtbuf_proc_find (const char *x)
 {
   const char *sym = symbol_find(x);
diff --git a/librtbuf/rtbuf_type.c b/librtbuf/rtbuf_type.c
index e07f7e2..09b78d2 100644
--- a/librtbuf/rtbuf_type.c
+++ b/librtbuf/rtbuf_type.c
@@ -47,6 +47,15 @@ void rtbuf_type_init ()
   rtbuf_type_define("double"        , sizeof(double));
 }
 
+void rtbuf_type_shutdown ()
+{
+  if (g_rtbuf_data_type) {
+    rtbuf_type_delete_all();
+    g_rtbuf_data_type = 0;
+    data_alloc_clean(&g_rtbuf_data_type_alloc);
+  }
+}
+
 s_rtbuf_type * rtbuf_type_new (const char *name, unsigned int size)
 {
   s_rtbuf_type *rt = data_new(&g_rtbuf_data_type_alloc);
@@ -64,6 +73,19 @@ void rtbuf_type_delete (s_rtbuf_type *rt)
   data_delete(&g_rtbuf_data_type_alloc, rt);
 }
 
+void rtbuf_type_delete_all ()
+{
+  unsigned i = 0;
+  int n = g_rtbuf_data_type_alloc.n;
+  while (i < g_rtbuf_data_type_alloc.max && n > 0) {
+    if (g_rtbuf_data_type[i].name) {
+      rtbuf_type_delete(g_rtbuf_data_type + i);
+      n--;
+    }
+    i++;
+  }
+}
+
 s_rtbuf_type * rtbuf_type_find (symbol name)
 {
   unsigned int i = 0;
diff --git a/librtbuf/rtbuf_var.c b/librtbuf/rtbuf_var.c
index 1eaeb45..a96fc6e 100644
--- a/librtbuf/rtbuf_var.c
+++ b/librtbuf/rtbuf_var.c
@@ -34,12 +34,39 @@ void rtbuf_var_init (void)
   assert(g_rtbuf_var);
 }
 
+void rtbuf_var_shutdown (void)
+{
+  if (g_rtbuf_var) {
+    rtbuf_var_delete_all();
+    g_rtbuf_var = 0;
+    data_alloc_clean(&g_rtbuf_var_alloc);
+  }
+}
+
 s_rtbuf_var * rtbuf_var_new (const char *name)
 {
-  s_rtbuf_var *v = data_new(&g_rtbuf_var_alloc);
-  if (v)
-    v->name = symbol_intern(name);
-  return v;
+  s_rtbuf_var *var = data_new(&g_rtbuf_var_alloc);
+  if (var)
+    var->name = symbol_intern(name);
+  return var;
+}
+
+void rtbuf_var_delete (s_rtbuf_var *var)
+{
+  data_delete(&g_rtbuf_var_alloc, var);
+}
+
+void rtbuf_var_delete_all ()
+{
+  unsigned i = 0;
+  int n = g_rtbuf_var_alloc.n;
+  while (i < g_rtbuf_var_alloc.max) {
+    if (g_rtbuf_var[i].name) {
+      rtbuf_var_delete(g_rtbuf_var + i);
+      n--;
+    }
+    i++;
+  }
 }
 
 s_rtbuf_var * rtbuf_var_find (const char *name)
diff --git a/librtbuf/type.h b/librtbuf/type.h
index 3c3713b..39a1b8d 100644
--- a/librtbuf/type.h
+++ b/librtbuf/type.h
@@ -28,9 +28,11 @@ struct rtbuf_type {
 #define RTBUF_TYPE_MAX 1024
 
 void           rtbuf_type_init ();
+void           rtbuf_type_shutdown ();
 s_rtbuf_type * rtbuf_type_new (const char *name,
                                unsigned int size);
 void           rtbuf_type_delete (s_rtbuf_type *rt);
+void           rtbuf_type_delete_all ();
 s_rtbuf_type * rtbuf_type_find (symbol name);
 s_rtbuf_type * rtbuf_type_define (const char *name,
                                   unsigned int size);
diff --git a/librtbuf/var.h b/librtbuf/var.h
index 5e7ce75..54e6fd8 100644
--- a/librtbuf/var.h
+++ b/librtbuf/var.h
@@ -27,6 +27,9 @@ struct rtbuf_var {
 };
 
 void          rtbuf_var_init (void);
+void          rtbuf_var_shutdown (void);
+void          rtbuf_var_delete (s_rtbuf_var *var);
+void          rtbuf_var_delete_all ();
 s_rtbuf_var * rtbuf_var_find (const char *name);
 s_rtbuf_var * rtbuf_var_rtbuf_set (const char *name, unsigned i);
 void          rtbuf_var_print (const s_rtbuf_var *v);