source: roaraudio/roard/sample.c @ 3358:7f9d211148e0

Last change on this file since 3358:7f9d211148e0 was 668:71ac426690da, checked in by phi, 16 years ago

added license statements

File size: 2.2 KB
Line 
1//sample.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008
5 *
6 *  This file is part of roard a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  RoarAudio is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "roard.h"
26
27int samples_init      (void) {
28 int i;
29
30 for (i = 0; i < ROAR_SAMPLES_MAX; i++)
31  g_samples[i] = NULL;
32
33 return 0;
34}
35
36
37int samples_free      (void) {
38 int i;
39
40 for (i = 0; i < ROAR_SAMPLES_MAX; i++)
41  if ( g_samples[i] != NULL )
42   samples_delete(i);
43
44 return 0;
45}
46
47int samples_new       (void) {
48 struct roar_sample * c = malloc(sizeof(struct roar_sample));
49 int i;
50
51 if ( c == NULL )
52  return -1;
53
54 c->name[0] = 0;
55 c->data    = NULL;
56
57 for (i = 0; i < ROAR_SAMPLES_MAX; i++) {
58  if ( g_samples[i] == NULL ) {
59   g_samples[i] = c;
60   return i;
61  }
62 }
63
64 free(c);
65
66 return -1;
67}
68
69int samples_delete    (int id) {
70 struct roar_sample * c = g_samples[id];
71
72 if ( c == NULL )
73  return -1;
74
75 if (c->data != NULL )
76  roar_buffer_free(c->data);
77
78 free(c);
79
80 g_samples[id] = NULL;
81
82 return 0;
83}
84
85int samples_set_name  (int id, char * name) {
86 struct roar_sample * c = g_samples[id];
87
88 if ( c == NULL )
89  return -1;
90
91 strncpy(c->name, name, ROAR_BUFFER_NAME-1);
92
93 c->name[ROAR_BUFFER_NAME-1] = 0;
94
95 return 0;
96}
97
98int samples_add_data  (int id, void * data, size_t len) {
99 struct roar_buffer * new;
100 struct roar_sample * c = g_samples[id];
101
102 if ( c == NULL )
103  return -1;
104
105 if ( roar_buffer_new(&new, len) == -1 )
106  return -1;
107
108 if ( c->data == NULL ) {
109  c->data = new;
110 } else {
111  roar_buffer_add(c->data, new);
112 }
113
114 return 0;
115}
116
117//ll
Note: See TracBrowser for help on using the repository browser.