source: roaraudio/roard/sample.c @ 5301:f3e9cd30574d

Last change on this file since 5301:f3e9cd30574d was 5301:f3e9cd30574d, checked in by phi, 12 years ago

move away from roar_buffer_add() (See: #126)

File size: 2.4 KB
Line 
1//sample.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2011
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
28// declared 'extern'
29struct roar_sample * g_samples[ROAR_SAMPLES_MAX];
30
31int samples_init      (void) {
32 int i;
33
34 for (i = 0; i < ROAR_SAMPLES_MAX; i++)
35  g_samples[i] = NULL;
36
37 return 0;
38}
39
40
41int samples_free      (void) {
42 int i;
43
44 for (i = 0; i < ROAR_SAMPLES_MAX; i++)
45  if ( g_samples[i] != NULL )
46   samples_delete(i);
47
48 return 0;
49}
50
51int samples_new       (void) {
52 struct roar_sample * c = roar_mm_malloc(sizeof(struct roar_sample));
53 int i;
54
55 if ( c == NULL )
56  return -1;
57
58 c->name[0] = 0;
59 c->data    = NULL;
60
61 for (i = 0; i < ROAR_SAMPLES_MAX; i++) {
62  if ( g_samples[i] == NULL ) {
63   g_samples[i] = c;
64   return i;
65  }
66 }
67
68 roar_mm_free(c);
69
70 return -1;
71}
72
73int samples_delete    (int id) {
74 struct roar_sample * c = g_samples[id];
75
76 if ( c == NULL )
77  return -1;
78
79 if (c->data != NULL )
80  roar_buffer_free(c->data);
81
82 roar_mm_free(c);
83
84 g_samples[id] = NULL;
85
86 return 0;
87}
88
89int samples_set_name  (int id, char * name) {
90 struct roar_sample * c = g_samples[id];
91
92 if ( c == NULL )
93  return -1;
94
95 strncpy(c->name, name, ROAR_BUFFER_NAME-1);
96
97 c->name[ROAR_BUFFER_NAME-1] = 0;
98
99 return 0;
100}
101
102int samples_add_data  (int id, void * data, size_t len) {
103 struct roar_buffer * new;
104 struct roar_sample * c = g_samples[id];
105 int save_err;
106
107 if ( c == NULL )
108  return -1;
109
110 if ( roar_buffer_new(&new, len) == -1 )
111  return -1;
112
113 if ( c->data == NULL ) {
114  c->data = new;
115 } else {
116  if ( roar_buffer_moveinto(c->data, &new) == -1 ) {
117   save_err = roar_error;
118   roar_buffer_free(new);
119   roar_err_set(save_err);
120   return -1;
121  }
122 }
123
124 return 0;
125}
126
127//ll
Note: See TracBrowser for help on using the repository browser.