[916] | 1 | //driver_oss.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 | #if defined(ROAR_HAVE_OSS_BSD) || defined(ROAR_HAVE_OSS) |
---|
| 27 | |
---|
[919] | 28 | #define er() close(fh); return -1 |
---|
| 29 | |
---|
[930] | 30 | int driver_oss_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh) { |
---|
[919] | 31 | int tmp; |
---|
| 32 | |
---|
[924] | 33 | #ifdef ROAR_DEFAULT_OSS_DEV |
---|
[919] | 34 | if ( device == NULL ) |
---|
| 35 | device = ROAR_DEFAULT_OSS_DEV; |
---|
[924] | 36 | #endif |
---|
| 37 | |
---|
| 38 | if ( device == NULL ) { |
---|
| 39 | ROAR_ERR("driver_oss_open(*): no default device found, you need to specify one manuelly"); |
---|
| 40 | return -1; |
---|
| 41 | } |
---|
[919] | 42 | |
---|
| 43 | roar_vio_init_calls(inst); |
---|
| 44 | |
---|
[930] | 45 | if ( fh == -1 ) { |
---|
| 46 | if ( (fh = open(device, O_WRONLY, 0644)) == -1 ) { |
---|
| 47 | ROAR_ERR("driver_oss_open(*): Can not open OSS device: %s: %s", device, strerror(errno)); |
---|
| 48 | return -1; |
---|
| 49 | } |
---|
[919] | 50 | } |
---|
| 51 | |
---|
| 52 | roar_vio_set_fh(inst, fh); |
---|
| 53 | |
---|
| 54 | switch (info->channels) { |
---|
| 55 | case 1: tmp = 0; break; |
---|
| 56 | case 2: tmp = 1; break; |
---|
| 57 | default: er(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | if ( ioctl(fh, SNDCTL_DSP_STEREO, &tmp) == -1 ) { |
---|
| 61 | er(); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | switch (info->bits) { |
---|
| 65 | case 8: tmp = AFMT_S8; break; |
---|
| 66 | case 16: |
---|
| 67 | switch (info->codec) { |
---|
| 68 | case ROAR_CODEC_PCM_S_LE: tmp = AFMT_S16_LE; break; |
---|
| 69 | case ROAR_CODEC_PCM_S_BE: tmp = AFMT_S16_BE; break; |
---|
| 70 | default : er(); |
---|
| 71 | } |
---|
| 72 | break; |
---|
| 73 | default: er(); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | if ( ioctl(fh, SNDCTL_DSP_SAMPLESIZE, &tmp) == -1 ) { |
---|
| 77 | er(); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | tmp = info->rate; |
---|
| 81 | |
---|
| 82 | if ( ioctl(fh, SNDCTL_DSP_SPEED, &tmp) == -1 ) { |
---|
| 83 | er(); |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | if ( tmp < info->rate * 0.98 || tmp > info->rate * 1.02 ) { |
---|
| 87 | er(); |
---|
| 88 | } |
---|
| 89 | |
---|
[934] | 90 | ROAR_WARN("driver_oss_open(*): OSS devices opened :)"); |
---|
| 91 | |
---|
[919] | 92 | return 0; |
---|
[917] | 93 | } |
---|
| 94 | |
---|
| 95 | int driver_oss_close(DRIVER_USERDATA_T inst) { |
---|
[919] | 96 | return close(roar_vio_get_fh((struct roar_vio_calls *)inst)); |
---|
[917] | 97 | } |
---|
| 98 | |
---|
[916] | 99 | |
---|
| 100 | #endif |
---|
| 101 | //ll |
---|