[3725] | 1 | //driver_rsound.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 |
---|
[3725] | 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 | #define _DRV_NEED_RSOUND_H |
---|
| 27 | #include "roard.h" |
---|
| 28 | |
---|
[3753] | 29 | #ifdef ROAR_HAVE_LIBRSOUND |
---|
| 30 | |
---|
[3725] | 31 | int driver_rsound_open (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
[5107] | 32 | rsound_t * self = NULL; |
---|
| 33 | int autoconfig = 0; |
---|
[3725] | 34 | int tmp, tmp2; |
---|
| 35 | |
---|
| 36 | if ( fh != -1 ) |
---|
| 37 | return -1; |
---|
| 38 | |
---|
[5107] | 39 | if ( ROAR_STREAM(sstream)->id != -1 ) { |
---|
| 40 | autoconfig = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF); |
---|
| 41 | } |
---|
| 42 | |
---|
[3726] | 43 | if ( rsd_init(&self) == -1 ) { |
---|
| 44 | ROAR_DBG("driver_rsound_open(*): rsd_init(&self) failed."); |
---|
[3725] | 45 | return -1; |
---|
[3726] | 46 | } |
---|
[3725] | 47 | |
---|
| 48 | if ( device != NULL ) { |
---|
| 49 | if ( rsd_set_param(self, RSD_HOST, device) == -1 ) { |
---|
[3726] | 50 | ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_HOST, device) failed."); |
---|
[3725] | 51 | rsd_free(self); |
---|
| 52 | return -1; |
---|
| 53 | } |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | tmp = info->channels; |
---|
| 57 | if ( rsd_set_param(self, RSD_CHANNELS, &tmp) == -1 ) { |
---|
[3726] | 58 | ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_CHANNELS, &tmp) failed."); |
---|
[3725] | 59 | rsd_free(self); |
---|
| 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if ( tmp != info->channels ) { |
---|
| 64 | rsd_free(self); |
---|
| 65 | return -1; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | tmp = info->rate; |
---|
| 69 | if ( rsd_set_param(self, RSD_SAMPLERATE, &tmp) == -1 ) { |
---|
[3726] | 70 | ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_SAMPLERATE, &tmp) failed."); |
---|
[3725] | 71 | rsd_free(self); |
---|
| 72 | return -1; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | if ( tmp != info->rate ) { |
---|
| 76 | rsd_free(self); |
---|
| 77 | return -1; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | tmp = -1; // unknown by RSound |
---|
| 81 | |
---|
[5107] | 82 | if ( info->bits > 16 && autoconfig ) { |
---|
[5056] | 83 | info->bits = 32; |
---|
| 84 | } |
---|
| 85 | |
---|
[3725] | 86 | switch (info->codec) { |
---|
| 87 | case ROAR_CODEC_PCM_S_LE: |
---|
| 88 | switch (info->bits) { |
---|
| 89 | case 8: tmp = RSD_S8; break; |
---|
| 90 | case 16: tmp = RSD_S16_LE; break; |
---|
[5056] | 91 | #ifdef RSD_S32_LE |
---|
| 92 | case 32: tmp = RSD_S32_LE; break; |
---|
| 93 | #endif |
---|
[3725] | 94 | } |
---|
| 95 | break; |
---|
| 96 | case ROAR_CODEC_PCM_S_BE: |
---|
| 97 | switch (info->bits) { |
---|
| 98 | case 8: tmp = RSD_S8; break; |
---|
| 99 | case 16: tmp = RSD_S16_BE; break; |
---|
[5056] | 100 | #ifdef RSD_S32_BE |
---|
| 101 | case 32: tmp = RSD_S32_BE; break; |
---|
| 102 | #endif |
---|
[3725] | 103 | } |
---|
| 104 | break; |
---|
[3766] | 105 | case ROAR_CODEC_PCM_S_PDP: |
---|
| 106 | switch (info->bits) { |
---|
| 107 | case 8: tmp = RSD_S8; break; |
---|
| 108 | } |
---|
| 109 | break; |
---|
[3725] | 110 | case ROAR_CODEC_PCM_U_LE: |
---|
| 111 | switch (info->bits) { |
---|
[3765] | 112 | case 8: tmp = RSD_U8; break; |
---|
[3725] | 113 | case 16: tmp = RSD_U16_LE; break; |
---|
[5056] | 114 | #ifdef RSD_U32_LE |
---|
| 115 | case 32: tmp = RSD_U32_LE; break; |
---|
| 116 | #endif |
---|
[3725] | 117 | } |
---|
| 118 | break; |
---|
| 119 | case ROAR_CODEC_PCM_U_BE: |
---|
| 120 | switch (info->bits) { |
---|
[3765] | 121 | case 8: tmp = RSD_U8; break; |
---|
[3725] | 122 | case 16: tmp = RSD_U16_BE; break; |
---|
[5056] | 123 | #ifdef RSD_U32_BE |
---|
| 124 | case 32: tmp = RSD_U32_BE; break; |
---|
| 125 | #endif |
---|
[3725] | 126 | } |
---|
| 127 | break; |
---|
[3766] | 128 | case ROAR_CODEC_PCM_U_PDP: |
---|
| 129 | switch (info->bits) { |
---|
| 130 | case 8: tmp = RSD_U8; break; |
---|
| 131 | } |
---|
| 132 | break; |
---|
[3725] | 133 | } |
---|
| 134 | |
---|
[5056] | 135 | #ifdef RSD_S16_NE |
---|
[5107] | 136 | if ( tmp == -1 && autoconfig ) { |
---|
[5056] | 137 | info->bits = 16; |
---|
| 138 | info->codec = ROAR_CODEC_DEFAULT; |
---|
| 139 | tmp = RSD_S16_NE; |
---|
| 140 | } |
---|
| 141 | #endif |
---|
| 142 | |
---|
[3725] | 143 | if ( tmp == -1 ) { |
---|
[3726] | 144 | ROAR_DBG("driver_rsound_open(*): Codec/Bits not supported by RSound"); |
---|
[3725] | 145 | rsd_free(self); |
---|
| 146 | return -1; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | tmp2 = tmp; |
---|
| 150 | |
---|
| 151 | if ( rsd_set_param(self, RSD_FORMAT, &tmp) == -1 ) { |
---|
[3726] | 152 | ROAR_DBG("driver_rsound_open(*): rsd_set_param(self, RSD_FORMAT, &tmp={0x%x->0x%x}) failed.", tmp2, tmp); |
---|
[3725] | 153 | rsd_free(self); |
---|
| 154 | return -1; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | if ( tmp != tmp2 ) { |
---|
| 158 | rsd_free(self); |
---|
| 159 | return -1; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | if ( rsd_start(self) == -1 ) { |
---|
[3726] | 163 | ROAR_DBG("driver_rsound_open(*): rsd_start(self) failed."); |
---|
[3725] | 164 | rsd_free(self); |
---|
| 165 | return -1; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
[5388] | 169 | inst->flags = ROAR_VIO_FLAGS_NONE; |
---|
| 170 | inst->refc = 1; |
---|
[3725] | 171 | |
---|
[5012] | 172 | inst->inst = self; |
---|
| 173 | inst->close = driver_rsound_close; |
---|
| 174 | inst->write = driver_rsound_write; |
---|
[5276] | 175 | inst->ctl = driver_dummy_ctl; |
---|
[3725] | 176 | |
---|
| 177 | return 0; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | int driver_rsound_close (struct roar_vio_calls * vio) { |
---|
| 181 | int r = 0; |
---|
| 182 | |
---|
| 183 | if ( rsd_stop(vio->inst) == -1 ) |
---|
| 184 | r = -1; |
---|
| 185 | |
---|
| 186 | if ( rsd_free(vio->inst) == -1 ) |
---|
| 187 | r = -1; |
---|
| 188 | |
---|
| 189 | return r; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | ssize_t driver_rsound_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 193 | size_t ret; |
---|
| 194 | |
---|
| 195 | ret = rsd_write(vio->inst, buf, count); |
---|
| 196 | |
---|
| 197 | if ( ret == 0 ) |
---|
| 198 | return -1; |
---|
| 199 | |
---|
| 200 | return ret; |
---|
| 201 | } |
---|
| 202 | |
---|
[3753] | 203 | #endif |
---|
| 204 | |
---|
[3725] | 205 | //ll |
---|