1 | //driver_pulsesimple.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-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 | #ifdef ROAR_HAVE_LIBPULSE |
---|
29 | |
---|
30 | int driver_pulsesimple_open (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
31 | struct driver_pulsesimple * self; |
---|
32 | const char * subdev = NULL; |
---|
33 | int pulseerror = -1; |
---|
34 | pa_stream_direction_t dir = PA_STREAM_PLAYBACK; |
---|
35 | pa_sample_spec ss; |
---|
36 | |
---|
37 | // pa_sample_format_t format; /**< The sample format */ |
---|
38 | |
---|
39 | switch (info->codec) { |
---|
40 | case ROAR_CODEC_ALAW: |
---|
41 | ss.format = PA_SAMPLE_ALAW; |
---|
42 | break; |
---|
43 | case ROAR_CODEC_MULAW: |
---|
44 | ss.format = PA_SAMPLE_ULAW; |
---|
45 | break; |
---|
46 | case ROAR_CODEC_PCM_S_LE: |
---|
47 | switch (info->bits) { |
---|
48 | case 16: |
---|
49 | ss.format = PA_SAMPLE_S16LE; |
---|
50 | break; |
---|
51 | default: |
---|
52 | return -1; |
---|
53 | break; |
---|
54 | } |
---|
55 | break; |
---|
56 | case ROAR_CODEC_PCM_S_BE: |
---|
57 | switch (info->bits) { |
---|
58 | case 16: |
---|
59 | ss.format = PA_SAMPLE_S16BE; |
---|
60 | break; |
---|
61 | default: |
---|
62 | return -1; |
---|
63 | break; |
---|
64 | } |
---|
65 | break; |
---|
66 | case ROAR_CODEC_PCM_U_LE: |
---|
67 | case ROAR_CODEC_PCM_U_BE: |
---|
68 | case ROAR_CODEC_PCM_U_PDP: |
---|
69 | if ( info->bits == 8 ) { |
---|
70 | ss.format = PA_SAMPLE_U8; |
---|
71 | } else { |
---|
72 | return -1; |
---|
73 | } |
---|
74 | break; |
---|
75 | default: |
---|
76 | return -1; |
---|
77 | break; |
---|
78 | } |
---|
79 | |
---|
80 | ss.rate = info->rate; |
---|
81 | ss.channels = info->channels; |
---|
82 | |
---|
83 | if ( (self = roar_mm_malloc(sizeof(struct driver_pulsesimple))) == NULL ) |
---|
84 | return -1; |
---|
85 | |
---|
86 | self->handle = pa_simple_new(device, "roard", dir, subdev, "RoarAudio Sound Server", &ss, NULL, NULL, &pulseerror); |
---|
87 | |
---|
88 | if ( self->handle == NULL ) { |
---|
89 | ROAR_ERR("driver_pulsesimple_open(inst=%p, device='%s', info=%p, fh=%i, sstream=%p): can not open device: %s", inst, device, info, fh, sstream, pa_strerror(pulseerror)); |
---|
90 | roar_mm_free(self); |
---|
91 | ROAR_DBG("driver_pulsesimple_open(inst=%p, device='%s', info=%p, fh=%i, sstream=%p) = -1", inst, device, info, fh, sstream); |
---|
92 | return -1; |
---|
93 | } |
---|
94 | |
---|
95 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
96 | |
---|
97 | inst->inst = self; |
---|
98 | inst->close = driver_pulsesimple_close; |
---|
99 | inst->write = driver_pulsesimple_write; |
---|
100 | inst->sync = driver_pulsesimple_sync; |
---|
101 | inst->ctl = driver_pulsesimple_ctl; |
---|
102 | |
---|
103 | return 0; |
---|
104 | } |
---|
105 | |
---|
106 | int driver_pulsesimple_close (struct roar_vio_calls * vio) { |
---|
107 | struct driver_pulsesimple * self = vio->inst; |
---|
108 | |
---|
109 | ROAR_DBG("driver_pulsesimple_close(vio=%p) = ?", vio); |
---|
110 | |
---|
111 | pa_simple_free(self->handle); |
---|
112 | |
---|
113 | roar_mm_free(self); |
---|
114 | |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | ssize_t driver_pulsesimple_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
119 | struct driver_pulsesimple * self = vio->inst; |
---|
120 | |
---|
121 | ROAR_DBG("driver_pulsesimple_write(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count); |
---|
122 | |
---|
123 | return pa_simple_write(self->handle, buf, count, NULL) == 0 ? count : -1; |
---|
124 | } |
---|
125 | |
---|
126 | int driver_pulsesimple_sync (struct roar_vio_calls * vio) { |
---|
127 | struct driver_pulsesimple * self = vio->inst; |
---|
128 | |
---|
129 | ROAR_DBG("driver_pulsesimple_sync(vio=%p) = ?", vio); |
---|
130 | |
---|
131 | return pa_simple_drain(self->handle, NULL); |
---|
132 | } |
---|
133 | |
---|
134 | int driver_pulsesimple_ctl (struct roar_vio_calls * vio, int cmd, void * data) { |
---|
135 | struct driver_pulsesimple * self = vio->inst; |
---|
136 | |
---|
137 | (void)self; |
---|
138 | |
---|
139 | ROAR_DBG("driver_pulsesimple_ctl(vio=%p) = ?", vio); |
---|
140 | |
---|
141 | return -1; |
---|
142 | } |
---|
143 | |
---|
144 | #endif |
---|
145 | |
---|
146 | //ll |
---|