[3725] | 1 | //driver_rsound.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010 |
---|
| 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 | |
---|
| 29 | int driver_rsound_open (struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
| 30 | rsound_t * self; |
---|
| 31 | int tmp, tmp2; |
---|
| 32 | |
---|
| 33 | if ( fh != -1 ) |
---|
| 34 | return -1; |
---|
| 35 | |
---|
| 36 | if ( rsd_init(&self) == -1 ) |
---|
| 37 | return -1; |
---|
| 38 | |
---|
| 39 | if ( device != NULL ) { |
---|
| 40 | if ( rsd_set_param(self, RSD_HOST, device) == -1 ) { |
---|
| 41 | rsd_free(self); |
---|
| 42 | return -1; |
---|
| 43 | } |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | tmp = info->channels; |
---|
| 47 | if ( rsd_set_param(self, RSD_CHANNELS, &tmp) == -1 ) { |
---|
| 48 | rsd_free(self); |
---|
| 49 | return -1; |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | if ( tmp != info->channels ) { |
---|
| 53 | rsd_free(self); |
---|
| 54 | return -1; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | tmp = info->rate; |
---|
| 58 | if ( rsd_set_param(self, RSD_SAMPLERATE, &tmp) == -1 ) { |
---|
| 59 | rsd_free(self); |
---|
| 60 | return -1; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | if ( tmp != info->rate ) { |
---|
| 64 | rsd_free(self); |
---|
| 65 | return -1; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | tmp = -1; // unknown by RSound |
---|
| 69 | |
---|
| 70 | switch (info->codec) { |
---|
| 71 | case ROAR_CODEC_PCM_S_LE: |
---|
| 72 | switch (info->bits) { |
---|
| 73 | case 8: tmp = RSD_S8; break; |
---|
| 74 | case 16: tmp = RSD_S16_LE; break; |
---|
| 75 | } |
---|
| 76 | break; |
---|
| 77 | case ROAR_CODEC_PCM_S_BE: |
---|
| 78 | switch (info->bits) { |
---|
| 79 | case 8: tmp = RSD_S8; break; |
---|
| 80 | case 16: tmp = RSD_S16_BE; break; |
---|
| 81 | } |
---|
| 82 | break; |
---|
| 83 | case ROAR_CODEC_PCM_U_LE: |
---|
| 84 | switch (info->bits) { |
---|
| 85 | case 8: tmp = RSD_S8; break; |
---|
| 86 | case 16: tmp = RSD_U16_LE; break; |
---|
| 87 | } |
---|
| 88 | break; |
---|
| 89 | case ROAR_CODEC_PCM_U_BE: |
---|
| 90 | switch (info->bits) { |
---|
| 91 | case 8: tmp = RSD_S8; break; |
---|
| 92 | case 16: tmp = RSD_U16_BE; break; |
---|
| 93 | } |
---|
| 94 | break; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if ( tmp == -1 ) { |
---|
| 98 | rsd_free(self); |
---|
| 99 | return -1; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | tmp2 = tmp; |
---|
| 103 | |
---|
| 104 | if ( rsd_set_param(self, RSD_FORMAT, &tmp) == -1 ) { |
---|
| 105 | rsd_free(self); |
---|
| 106 | return -1; |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | if ( tmp != tmp2 ) { |
---|
| 110 | rsd_free(self); |
---|
| 111 | return -1; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | if ( rsd_start(self) == -1 ) { |
---|
| 115 | rsd_free(self); |
---|
| 116 | return -1; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 120 | |
---|
| 121 | inst->inst = self; |
---|
| 122 | inst->close = driver_rsound_close; |
---|
| 123 | inst->write = driver_rsound_write; |
---|
| 124 | |
---|
| 125 | return 0; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | int driver_rsound_close (struct roar_vio_calls * vio) { |
---|
| 129 | int r = 0; |
---|
| 130 | |
---|
| 131 | if ( rsd_stop(vio->inst) == -1 ) |
---|
| 132 | r = -1; |
---|
| 133 | |
---|
| 134 | if ( rsd_free(vio->inst) == -1 ) |
---|
| 135 | r = -1; |
---|
| 136 | |
---|
| 137 | return r; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | ssize_t driver_rsound_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 141 | size_t ret; |
---|
| 142 | |
---|
| 143 | ret = rsd_write(vio->inst, buf, count); |
---|
| 144 | |
---|
| 145 | if ( ret == 0 ) |
---|
| 146 | return -1; |
---|
| 147 | |
---|
| 148 | return ret; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | //ll |
---|