source: roaraudio/libroardsp/filter_speex_prep.c @ 3003:9d0935291fca

Last change on this file since 3003:9d0935291fca was 3003:9d0935291fca, checked in by phi, 15 years ago

run data thru preprep

File size: 2.8 KB
Line 
1//filter_speex_prep.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *
6 *  This file is part of libroardsp 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 *  libroardsp 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 "libroardsp.h"
26
27#ifdef _SPEEX_TYPES_H
28
29#if defined(ROAR_HAVE_LIBSPEEX) && !defined(ROAR_HAVE_LIBSPEEXDSP)
30#define _SPEEX_API_OLD
31#elif defined(ROAR_HAVE_LIBSPEEX) && defined(ROAR_HAVE_LIBSPEEXDSP)
32#define _SPEEX_API_NEW
33#endif
34
35// TODO: check parameters we allready know:
36int roardsp_speex_prep_init   (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
37 struct roardsp_speex_prep * self;
38
39 if ( filter->channels != 1 )
40  return -1;
41
42 if ( filter->bits != 16 )
43  return -1;
44
45 self = roar_mm_malloc(sizeof(struct roardsp_speex_prep));
46
47 if ( self == NULL )
48  return -1;
49
50 memset(self, 0, sizeof(struct roardsp_speex_prep));
51
52 return 0;
53}
54
55int roardsp_speex_prep_uninit (struct roardsp_filter * filter) {
56 struct roardsp_speex_prep * self = filter->inst;
57
58 if ( self->preprocess != NULL )
59  speex_preprocess_state_destroy(self->preprocess);
60
61 roar_mm_free(self);
62
63 return 0;
64}
65
66int roardsp_speex_prep_calc161(struct roardsp_filter * filter, void * data, size_t samples) {
67 struct roardsp_speex_prep * self = filter->inst;
68
69 if ( self->preprocess == NULL )
70  return -1;
71
72 if ( samples != self->frame_size )
73  return -1;
74
75#ifdef _SPEEX_API_OLD
76 speex_preprocess(self->preprocess, data, NULL);
77#elif defined(_SPEEX_API_NEW)
78 speex_preprocess_run(self->preprocess, data);
79#else
80 return -1;
81#endif
82
83 return 0;
84}
85
86int roardsp_speex_prep_ctl    (struct roardsp_filter * filter, int cmd, void * data) {
87 struct roardsp_speex_prep * self = filter->inst;
88 size_t * val;
89
90 switch (cmd) {
91  case ROARDSP_FCTL_PACKET_SIZE:
92    val = data;
93    self->frame_size = *val;
94
95    self->preprocess = speex_preprocess_state_init(self->frame_size, filter->rate);
96    if ( self->preprocess == NULL )
97     return -1;
98
99    return 0;
100   break;
101 }
102
103 return -1;
104}
105
106int roardsp_speex_prep_reset  (struct roardsp_filter * filter, int what) {
107 if ( what == ROARDSP_RESET_NONE )
108  return 0;
109
110 return -1;
111}
112#endif
113
114//ll
Note: See TracBrowser for help on using the repository browser.