1 | //codecfilter_wave.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 | |
---|
27 | int cf_wave_open(CODECFILTER_USERDATA_T * inst, int codec, |
---|
28 | struct roar_stream_server * info, |
---|
29 | struct roar_codecfilter * filter) { |
---|
30 | struct codecfilter_wave_inst * self = malloc(sizeof(struct codecfilter_wave_inst)); |
---|
31 | struct roar_stream * s = ROAR_STREAM(info); |
---|
32 | |
---|
33 | if ( !self ) |
---|
34 | return -1; |
---|
35 | |
---|
36 | self->stream = info; |
---|
37 | self->opened = 0; |
---|
38 | |
---|
39 | *inst = (CODECFILTER_USERDATA_T) self; |
---|
40 | |
---|
41 | memcpy(&(s->info), g_sa, sizeof(struct roar_audio_info)); |
---|
42 | return 0; |
---|
43 | } |
---|
44 | |
---|
45 | int cf_wave_close(CODECFILTER_USERDATA_T inst) { |
---|
46 | // struct codecfilter_wave_inst * self = (struct codecfilter_wave_inst *) inst; |
---|
47 | |
---|
48 | if ( !inst ) |
---|
49 | return -1; |
---|
50 | |
---|
51 | free(inst); |
---|
52 | return 0; |
---|
53 | } |
---|
54 | |
---|
55 | int cf_wave_read(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
56 | struct codecfilter_wave_inst * self = (struct codecfilter_wave_inst *) inst; |
---|
57 | int r = -1; |
---|
58 | char tbuf[44]; |
---|
59 | struct roar_stream * s = ROAR_STREAM(self->stream); |
---|
60 | |
---|
61 | if ( self->opened ) { |
---|
62 | return stream_vio_s_read(self->stream, buf, len); |
---|
63 | } else { |
---|
64 | if (stream_vio_s_read(self->stream, tbuf, 44) != 44) { |
---|
65 | return -1; |
---|
66 | } |
---|
67 | |
---|
68 | // TODO: write better code here! |
---|
69 | |
---|
70 | memcpy(&(s->info.rate ), tbuf+24, 4); |
---|
71 | memcpy(&(s->info.channels), tbuf+22, 2); |
---|
72 | memcpy(&(s->info.bits ), tbuf+34, 2); |
---|
73 | |
---|
74 | self->opened = 1; |
---|
75 | |
---|
76 | errno = EAGAIN; |
---|
77 | return -1; |
---|
78 | } |
---|
79 | |
---|
80 | return r; |
---|
81 | } |
---|
82 | |
---|
83 | int cf_wave_write(CODECFILTER_USERDATA_T inst, char * buf, int len) { |
---|
84 | struct codecfilter_wave_inst * self = (struct codecfilter_wave_inst *) inst; |
---|
85 | |
---|
86 | return 0; |
---|
87 | } |
---|
88 | |
---|
89 | //ll |
---|