source: roaraudio/libroarsndio/libroarsndio.c @ 2372:39399989a0ee

Last change on this file since 2372:39399989a0ee was 2372:39399989a0ee, checked in by phi, 15 years ago

added a privarte function to convert sndio device names to names for roard

File size: 3.0 KB
Line 
1//libroarsndio.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
5 *  The code (may) include prototypes and comments (and maybe
6 *  other code fragements) from EsounD.
7 *  They are mostly copyrighted by Eric B. Mitchell (aka 'Ricdude)
8 *  <ericmit@ix.netcom.com>. For more information see AUTHORS.esd.
9 *
10 *  This file is part of libroaresd a part of RoarAudio,
11 *  a cross-platform sound system for both, home and professional use.
12 *  See README for details.
13 *
14 *  This file is free software; you can redistribute it and/or modify
15 *  it under the terms of the GNU General Public License version 3
16 *  as published by the Free Software Foundation.
17 *
18 *  RoarAudio is distributed in the hope that it will be useful,
19 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 *  GNU General Public License for more details.
22 *
23 *  You should have received a copy of the GNU General Public License
24 *  along with this software; see the file COPYING.  If not, write to
25 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 *  NOTE for everyone want's to change something and send patches:
28 *  read README and HACKING! There a addition information on
29 *  the license of this document you need to read before you send
30 *  any patches.
31 */
32
33#define ROAR_USE_OWN_SNDIO_HDL
34#include "libroarsndio.h"
35
36static char * sndio_to_roar_names (char * name) {
37
38 if ( name == NULL )
39  return NULL;
40
41 return name;
42}
43
44struct sio_hdl * sio_open(char * name, unsigned mode, int nbio_flag) {
45 struct sio_hdl * hdl = NULL;
46 int is_midi = 0;
47
48 if ( (hdl = malloc(sizeof(struct sio_hdl))) == NULL )
49  return NULL;
50
51 memset(hdl, 0, sizeof(struct sio_hdl));
52
53 switch (mode) {
54  case SIO_PLAY:
55    hdl->dir = ROAR_DIR_PLAY;
56   break;
57  case MIO_OUT:
58    is_midi = 1;
59    hdl->dir = ROAR_DIR_MIDI_IN;
60   break;
61  case MIO_IN:
62    is_midi = 1;
63    hdl->dir = ROAR_DIR_MIDI_OUT;
64   break;
65
66  // unsupported:
67  case SIO_REC:
68  case SIO_PLAY|SIO_REC:
69  case MIO_OUT|MIO_IN:
70
71  // illigal:
72  default:
73    free(hdl);
74    return NULL;
75 }
76
77 if ( name == NULL ) {
78  if ( is_midi ) {
79   name = getenv("MIDIDEVICE");
80  } else {
81   name = getenv("AUDIODEVICE");
82  }
83 }
84
85 name = sndio_to_roar_names(name);
86
87 if ( roar_simple_connect(&(hdl->con), name, "libroarsndio") == -1 ) {
88  free(hdl);
89  return NULL;
90 }
91
92 sio_initpar(&(hdl->para));
93
94 hdl->stream_opened = 0;
95
96 if ( name != NULL )
97  hdl->device = strdup(name);
98
99 if ( is_midi ) {
100  hdl->info.codec    = ROAR_CODEC_MIDI;
101  hdl->info.bits     = 8;
102  hdl->info.channels = 16;
103  hdl->info.rate     = 96;
104  if ( !sio_start(hdl) ) {
105   sio_close(hdl);
106   return NULL;
107  }
108 }
109
110 return hdl;
111}
112
113void   sio_close  (struct sio_hdl * hdl) {
114 if ( hdl == NULL )
115  return;
116
117 sio_stop(hdl);
118
119 roar_disconnect(&(hdl->con));
120
121 free(hdl);
122}
123
124int    sio_eof    (struct sio_hdl * hdl) {
125 return 0;
126}
127
128void   sio_onmove (struct sio_hdl * hdl, void (*cb)(void * arg, int delta), void * arg) {
129 if ( hdl == NULL )
130  return;
131
132 hdl->on_move     = cb;
133 hdl->on_move_arg = arg;
134}
135
136//ll
Note: See TracBrowser for help on using the repository browser.