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