[3751] | 1 | //driver_portaudio.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-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 | #include "roard.h" |
---|
| 27 | |
---|
| 28 | #ifdef _DRIVER_PORTAUDIO_CAN_OPERATE |
---|
| 29 | |
---|
| 30 | int driver_portaudio_open(struct roar_vio_calls * inst, char * device, struct roar_audio_info * info, int fh, struct roar_stream_server * sstream) { |
---|
| 31 | struct driver_portaudio * self; |
---|
| 32 | PaSampleFormat fmt; |
---|
| 33 | #ifdef ROAR_HAVE_LIBPABLIO |
---|
| 34 | long flags = PABLIO_WRITE; |
---|
| 35 | #endif |
---|
| 36 | |
---|
| 37 | switch (info->bits) { |
---|
| 38 | case 8: |
---|
| 39 | switch (info->codec) { |
---|
| 40 | case ROAR_CODEC_PCM_S_LE: |
---|
| 41 | case ROAR_CODEC_PCM_S_BE: |
---|
| 42 | case ROAR_CODEC_PCM_S_PDP: |
---|
| 43 | fmt = paInt8; |
---|
| 44 | break; |
---|
| 45 | case ROAR_CODEC_PCM_U_LE: |
---|
| 46 | case ROAR_CODEC_PCM_U_BE: |
---|
| 47 | case ROAR_CODEC_PCM_U_PDP: |
---|
| 48 | fmt = paUInt8; |
---|
| 49 | break; |
---|
| 50 | default: |
---|
| 51 | return -1; |
---|
| 52 | break; |
---|
| 53 | } |
---|
| 54 | break; |
---|
| 55 | case 16: |
---|
| 56 | if ( info->codec != ROAR_CODEC_DEFAULT ) |
---|
| 57 | return -1; |
---|
| 58 | fmt = paInt16; |
---|
| 59 | break; |
---|
| 60 | case 24: |
---|
| 61 | if ( info->codec != ROAR_CODEC_DEFAULT ) |
---|
| 62 | return -1; |
---|
| 63 | fmt = paPackedInt24; |
---|
| 64 | break; |
---|
| 65 | case 32: |
---|
| 66 | if ( info->codec != ROAR_CODEC_DEFAULT ) |
---|
| 67 | return -1; |
---|
| 68 | fmt = paInt32; |
---|
| 69 | break; |
---|
| 70 | default: |
---|
| 71 | return -1; |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if ( (self = roar_mm_malloc(sizeof(struct driver_portaudio))) == NULL ) |
---|
| 75 | return -1; |
---|
| 76 | |
---|
| 77 | memset(self, 0, sizeof(struct driver_portaudio)); |
---|
| 78 | |
---|
| 79 | memset(inst, 0, sizeof(struct roar_vio_calls)); |
---|
| 80 | |
---|
| 81 | inst->inst = self; |
---|
| 82 | inst->close = driver_portaudio_close; |
---|
| 83 | inst->write = driver_portaudio_write; |
---|
| 84 | |
---|
| 85 | Pa_Initialize(); |
---|
| 86 | |
---|
| 87 | #ifdef ROAR_HAVE_LIBPABLIO |
---|
| 88 | switch (info->channels) { |
---|
| 89 | case 1: flags |= PABLIO_MONO; break; |
---|
| 90 | case 2: flags |= PABLIO_STEREO; break; |
---|
| 91 | default: |
---|
| 92 | roar_mm_free(self); |
---|
| 93 | Pa_Terminate(); |
---|
| 94 | return -1; |
---|
| 95 | } |
---|
| 96 | |
---|
| 97 | if ( OpenAudioStream(&(self->ostream), info->rate, fmt, flags) != paNoError ) { |
---|
| 98 | roar_mm_free(self); |
---|
| 99 | Pa_Terminate(); |
---|
| 100 | return -1; |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | return 0; |
---|
| 104 | #else |
---|
| 105 | return -1; |
---|
| 106 | #endif |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | int driver_portaudio_close (struct roar_vio_calls * vio) { |
---|
| 110 | struct driver_portaudio * self = vio->inst; |
---|
| 111 | |
---|
| 112 | #ifdef ROAR_HAVE_LIBPABLIO |
---|
| 113 | CloseAudioStream(self->ostream); |
---|
| 114 | |
---|
| 115 | Pa_Terminate(); |
---|
| 116 | |
---|
| 117 | roar_mm_free(self); |
---|
| 118 | |
---|
| 119 | return 0; |
---|
| 120 | #else |
---|
| 121 | return -1; |
---|
| 122 | #endif |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | ssize_t driver_portaudio_write (struct roar_vio_calls * vio, void *buf, size_t count) { |
---|
| 126 | struct driver_portaudio * self = vio->inst; |
---|
| 127 | |
---|
| 128 | ROAR_DBG("driver_portaudio_write(vio=%p, buf=%p, count=%llu) = ?", vio, buf, (long long unsigned int)count); |
---|
| 129 | |
---|
| 130 | #ifdef ROAR_HAVE_LIBPABLIO |
---|
| 131 | count /= self->ostream->bytesPerFrame; // TODO: FIXME: do not access private members |
---|
| 132 | ROAR_DBG("driver_portaudio_write(vio=%p, buf=%p, count=%llu) = ? // PABLIO mode", vio, buf, (long long unsigned int)count); |
---|
| 133 | return WriteAudioStream(self->ostream, buf, count) * self->ostream->bytesPerFrame; |
---|
| 134 | #else |
---|
| 135 | return -1; |
---|
| 136 | #endif |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | #endif |
---|
| 140 | |
---|
| 141 | //ll |
---|