source: roaraudio/roard/sample.c @ 3517:1a3218a3fc5b

Last change on this file since 3517:1a3218a3fc5b was 3517:1a3218a3fc5b, checked in by phi, 14 years ago

updated license headers, FSF moved office

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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "roard.h"
27
28int samples_init      (void) {
29 int i;
30
31 for (i = 0; i < ROAR_SAMPLES_MAX; i++)
32  g_samples[i] = NULL;
33
34 return 0;
35}
36
37
38int samples_free      (void) {
39 int i;
40
41 for (i = 0; i < ROAR_SAMPLES_MAX; i++)
42  if ( g_samples[i] != NULL )
43   samples_delete(i);
44
45 return 0;
46}
47
48int samples_new       (void) {
49 struct roar_sample * c = malloc(sizeof(struct roar_sample));
50 int i;
51
52 if ( c == NULL )
53  return -1;
54
55 c->name[0] = 0;
56 c->data    = NULL;
57
58 for (i = 0; i < ROAR_SAMPLES_MAX; i++) {
59  if ( g_samples[i] == NULL ) {
60   g_samples[i] = c;
61   return i;
62  }
63 }
64
65 free(c);
66
67 return -1;
68}
69
70int samples_delete    (int id) {
71 struct roar_sample * c = g_samples[id];
72
73 if ( c == NULL )
74  return -1;
75
76 if (c->data != NULL )
77  roar_buffer_free(c->data);
78
79 free(c);
80
81 g_samples[id] = NULL;
82
83 return 0;
84}
85
86int samples_set_name  (int id, char * name) {
87 struct roar_sample * c = g_samples[id];
88
89 if ( c == NULL )
90  return -1;
91
92 strncpy(c->name, name, ROAR_BUFFER_NAME-1);
93
94 c->name[ROAR_BUFFER_NAME-1] = 0;
95
96 return 0;
97}
98
99int samples_add_data  (int id, void * data, size_t len) {
100 struct roar_buffer * new;
101 struct roar_sample * c = g_samples[id];
102
103 if ( c == NULL )
104  return -1;
105
106 if ( roar_buffer_new(&new, len) == -1 )
107  return -1;
108
109 if ( c->data == NULL ) {
110  c->data = new;
111 } else {
112  roar_buffer_add(c->data, new);
113 }
114
115 return 0;
116}
117
118//ll
Note: See TracBrowser for help on using the repository browser.