Line | |
---|
1 | //sample.c: |
---|
2 | |
---|
3 | #include "roard.h" |
---|
4 | |
---|
5 | int samples_init (void) { |
---|
6 | int i; |
---|
7 | |
---|
8 | for (i = 0; i < ROAR_SAMPLES_MAX; i++) |
---|
9 | g_samples[i] = NULL; |
---|
10 | |
---|
11 | return 0; |
---|
12 | } |
---|
13 | |
---|
14 | |
---|
15 | int samples_free (void) { |
---|
16 | int i; |
---|
17 | |
---|
18 | for (i = 0; i < ROAR_SAMPLES_MAX; i++) |
---|
19 | if ( g_samples[i] != NULL ) |
---|
20 | samples_delete(i); |
---|
21 | |
---|
22 | return 0; |
---|
23 | } |
---|
24 | |
---|
25 | int samples_new (void) { |
---|
26 | struct roar_sample * c = malloc(sizeof(struct roar_sample)); |
---|
27 | int i; |
---|
28 | |
---|
29 | if ( c == NULL ) |
---|
30 | return -1; |
---|
31 | |
---|
32 | c->name[0] = 0; |
---|
33 | c->data = NULL; |
---|
34 | |
---|
35 | for (i = 0; i < ROAR_SAMPLES_MAX; i++) { |
---|
36 | if ( g_samples[i] == NULL ) { |
---|
37 | g_samples[i] = c; |
---|
38 | return i; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | free(c); |
---|
43 | |
---|
44 | return -1; |
---|
45 | } |
---|
46 | |
---|
47 | int samples_delete (int id) { |
---|
48 | struct roar_sample * c = g_samples[id]; |
---|
49 | |
---|
50 | if ( c == NULL ) |
---|
51 | return -1; |
---|
52 | |
---|
53 | if (c->data != NULL ) |
---|
54 | roar_buffer_free(c->data); |
---|
55 | |
---|
56 | free(c); |
---|
57 | |
---|
58 | g_samples[id] = NULL; |
---|
59 | |
---|
60 | return 0; |
---|
61 | } |
---|
62 | |
---|
63 | int samples_set_name (int id, char * name) { |
---|
64 | struct roar_sample * c = g_samples[id]; |
---|
65 | |
---|
66 | if ( c == NULL ) |
---|
67 | return -1; |
---|
68 | |
---|
69 | strncpy(c->name, name, ROAR_BUFFER_NAME-1); |
---|
70 | |
---|
71 | c->name[ROAR_BUFFER_NAME-1] = 0; |
---|
72 | |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | int samples_add_data (int id, void * data, size_t len) { |
---|
77 | struct roar_buffer * new; |
---|
78 | struct roar_sample * c = g_samples[id]; |
---|
79 | |
---|
80 | if ( c == NULL ) |
---|
81 | return -1; |
---|
82 | |
---|
83 | if ( roar_buffer_new(&new, len) == -1 ) |
---|
84 | return -1; |
---|
85 | |
---|
86 | if ( c->data == NULL ) { |
---|
87 | c->data = new; |
---|
88 | } else { |
---|
89 | roar_buffer_add(c->data, new); |
---|
90 | } |
---|
91 | |
---|
92 | return 0; |
---|
93 | } |
---|
94 | |
---|
95 | //ll |
---|
Note: See
TracBrowser
for help on using the repository browser.