source: roaraudio/roard/codecfilter_sndfile.c @ 928:8d756b820e71

Last change on this file since 928:8d756b820e71 was 928:8d756b820e71, checked in by phi, 15 years ago

got codecfilter sndfile working with sources driver cf

File size: 2.9 KB
Line 
1//codecfilter_sndfile.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#ifdef ROAR_HAVE_LIBSNDFILE
28
29int cf_sndfile_open(CODECFILTER_USERDATA_T * inst, int codec,
30                                            struct roar_stream_server * info,
31                                            struct roar_codecfilter   * filter) {
32 struct codecfilter_sndfile_inst * obj;
33
34 if ( (obj = (struct codecfilter_sndfile_inst *) malloc(sizeof(struct codecfilter_sndfile_inst))) == NULL )
35  return -1;
36
37 memset(obj, 0, sizeof(struct codecfilter_sndfile_inst));
38
39 obj->stream = info;
40
41 *inst = (CODECFILTER_USERDATA_T) obj;
42
43/*
44 s->info.bits  = 16;
45 s->info.codec = ROAR_CODEC_DEFAULT;
46*/
47
48 return 0;
49}
50
51int cf_sndfile_close(CODECFILTER_USERDATA_T   inst) {
52 struct codecfilter_sndfile_inst * obj = (struct codecfilter_sndfile_inst *) inst;
53
54 if ( obj->state != NULL )
55  sf_close(obj->state);
56
57 free(obj);
58
59 return 0;
60}
61
62int cf_sndfile_read(CODECFILTER_USERDATA_T   inst, char * buf, int len) {
63 struct codecfilter_sndfile_inst * obj = (struct codecfilter_sndfile_inst *) inst;
64 struct roar_stream * s = ROAR_STREAM(obj->stream);
65 int ret;
66
67 if ( obj->opened ) {
68  len /= obj->bytes;
69
70  if ( obj->bytes == 2 ) {
71   if ( (ret = sf_read_short(obj->state, (short*)buf, len)) == -1 )
72    return -1;
73  } else if ( obj->bytes == 4 ) {
74   if ( (ret = sf_read_int(obj->state, (int*)buf, len)) == -1 )
75    return -1;
76  } else {
77   errno = ENOSYS;
78   return -1;
79  }
80
81  return ret * obj->bytes;
82 } else {
83  if ( (obj->state = sf_open_fd(s->fh, SFM_READ, &(obj->info), 0)) == NULL ) {
84   ROAR_ERR("cf_sndfile_read(*): can not sf_open_fd(*)!");
85   return -1;
86  }
87
88  s->info.codec    = ROAR_CODEC_DEFAULT;
89  s->info.rate     = obj->info.samplerate;
90  s->info.channels = obj->info.channels;
91
92  obj->bytes       = 2;
93  if ( (obj->info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_PCM_24 ||
94       (obj->info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_PCM_32   ) {
95   obj->bytes      = 4;
96  }
97
98  s->info.bits     = obj->bytes * 8;
99
100  obj->opened      = 1;
101  errno = EAGAIN;
102 }
103
104 return -1;
105}
106
107int cf_sndfile_write(CODECFILTER_USERDATA_T   inst, char * buf, int len) {
108 return -1;
109}
110
111#endif
112
113//ll
Note: See TracBrowser for help on using the repository browser.