SDL  2.0
SDL_audiodev.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../SDL_internal.h"
22 
23 /* Get the name of the audio device we use for output */
24 
25 #if SDL_AUDIO_DRIVER_NETBSD || SDL_AUDIO_DRIVER_OSS || SDL_AUDIO_DRIVER_SUNAUDIO
26 
27 #include <fcntl.h>
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #include <unistd.h> /* For close() */
31 
32 #include "SDL_stdinc.h"
33 #include "SDL_audiodev_c.h"
34 
35 #ifndef _PATH_DEV_DSP
36 #if defined(__NETBSD__) || defined(__OPENBSD__)
37 #define _PATH_DEV_DSP "/dev/audio"
38 #else
39 #define _PATH_DEV_DSP "/dev/dsp"
40 #endif
41 #endif
42 #ifndef _PATH_DEV_DSP24
43 #define _PATH_DEV_DSP24 "/dev/sound/dsp"
44 #endif
45 #ifndef _PATH_DEV_AUDIO
46 #define _PATH_DEV_AUDIO "/dev/audio"
47 #endif
48 
49 static void
50 test_device(const int iscapture, const char *fname, int flags, int (*test) (int fd))
51 {
52  struct stat sb;
53  if ((stat(fname, &sb) == 0) && (S_ISCHR(sb.st_mode))) {
54  const int audio_fd = open(fname, flags, 0);
55  if (audio_fd >= 0) {
56  const int okay = test(audio_fd);
57  close(audio_fd);
58  if (okay) {
59  static size_t dummyhandle = 0;
60  dummyhandle++;
61  SDL_assert(dummyhandle != 0);
62  SDL_AddAudioDevice(iscapture, fname, (void *) dummyhandle);
63  }
64  }
65  }
66 }
67 
68 static int
69 test_stub(int fd)
70 {
71  return 1;
72 }
73 
74 static void
75 SDL_EnumUnixAudioDevices_Internal(const int iscapture, const int classic, int (*test)(int))
76 {
77  const int flags = iscapture ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT;
78  const char *audiodev;
79  char audiopath[1024];
80 
81  if (test == NULL)
82  test = test_stub;
83 
84  /* Figure out what our audio device is */
85  if (((audiodev = SDL_getenv("SDL_PATH_DSP")) == NULL) &&
86  ((audiodev = SDL_getenv("AUDIODEV")) == NULL)) {
87  if (classic) {
88  audiodev = _PATH_DEV_AUDIO;
89  } else {
90  struct stat sb;
91 
92  /* Added support for /dev/sound/\* in Linux 2.4 */
93  if (((stat("/dev/sound", &sb) == 0) && S_ISDIR(sb.st_mode))
94  && ((stat(_PATH_DEV_DSP24, &sb) == 0)
95  && S_ISCHR(sb.st_mode))) {
96  audiodev = _PATH_DEV_DSP24;
97  } else {
98  audiodev = _PATH_DEV_DSP;
99  }
100  }
101  }
102  test_device(iscapture, audiodev, flags, test);
103 
104  if (SDL_strlen(audiodev) < (sizeof(audiopath) - 3)) {
105  int instance = 0;
106  while (instance <= 64) {
107  SDL_snprintf(audiopath, SDL_arraysize(audiopath),
108  "%s%d", audiodev, instance);
109  instance++;
110  test_device(iscapture, audiopath, flags, test);
111  }
112  }
113 }
114 
115 void
116 SDL_EnumUnixAudioDevices(const int classic, int (*test)(int))
117 {
118  SDL_EnumUnixAudioDevices_Internal(SDL_TRUE, classic, test);
119  SDL_EnumUnixAudioDevices_Internal(SDL_FALSE, classic, test);
120 }
121 
122 #endif /* Audio driver selection */
123 
124 /* vi: set ts=4 sw=4 expandtab: */
OPEN_FLAGS_INPUT
#define OPEN_FLAGS_INPUT
Definition: SDL_audiodev_c.h:37
fname
set set set set set set set macro pixldst1 abits if abits op else op endif endm macro pixldst2 abits if abits op else op endif endm macro pixldst4 abits if abits op else op endif endm macro pixldst0 abits op endm macro pixldst3 mem_operand op endm macro pixldst30 mem_operand op endm macro pixldst abits if abits elseif abits elseif abits elseif abits elseif abits pixldst0 abits else pixldst0 abits pixldst0 abits pixldst0 abits pixldst0 abits endif elseif abits else pixldst0 abits pixldst0 abits endif elseif abits else error unsupported bpp *numpix else pixst endif endm macro pixld1_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl mov asr adds SRC_WIDTH_FIXED bpl add asl else error unsupported endif endm macro pixld2_s mem_operand if mov asr add asl add asl mov asr sub UNIT_X add asl mov asr add asl add asl mov asr add UNIT_X add asl else pixld1_s mem_operand pixld1_s mem_operand endif endm macro pixld0_s mem_operand if asr adds SRC_WIDTH_FIXED bpl add asl elseif asr adds SRC_WIDTH_FIXED bpl add asl endif endm macro pixld_s_internal mem_operand if mem_operand pixld2_s mem_operand pixdeinterleave basereg elseif mem_operand elseif mem_operand elseif mem_operand elseif mem_operand pixld0_s mem_operand else pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else pixld0_s mem_operand pixld0_s mem_operand endif elseif mem_operand else error unsupported mem_operand if bpp mem_operand endif endm macro vuzp8 reg2 vuzp d d &reg2 endm macro vzip8 reg2 vzip d d &reg2 endm macro pixdeinterleave basereg basereg basereg basereg basereg endif endm macro pixinterleave basereg basereg basereg basereg basereg endif endm macro PF boost_increment endif if endif PF tst PF addne PF subne PF cmp ORIG_W if endif if endif if endif PF subge ORIG_W PF subges if endif if endif if endif endif endm macro cache_preload_simple endif if dst_r_bpp pld[DST_R, #(PREFETCH_DISTANCE_SIMPLE *dst_r_bpp/8)] endif if mask_bpp pld fname[MASK, #(PREFETCH_DISTANCE_SIMPLE *mask_bpp/8)] endif endif endm macro fetch_mask_pixblock pixld mask_basereg pixblock_size MASK endm macro ensure_destination_ptr_alignment process_pixblock_tail_head if beq irp skip1 beq endif SRC MASK if dst_r_bpp DST_R else add endif PF add sub src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head pixblock_size cache_preload_simple process_pixblock_tail pixinterleave dst_w_basereg irp beq endif process_pixblock_tail_head tst beq irp if pixblock_size chunk_size tst beq pixld_src SRC pixld MASK if DST_R else pixld DST_R endif if src_basereg pixdeinterleave mask_basereg pixdeinterleave dst_r_basereg process_pixblock_head if pixblock_size cache_preload_simple endif process_pixblock_tail pixinterleave dst_w_basereg irp if pixblock_size chunk_size tst beq if DST_W else pixst DST_W else mov ORIG_W endif add lsl if lsl endif if lsl endif lsl endif lsl endif lsl endif subs mov DST_W if regs_shortage str endif bge start_of_loop_label endm macro generate_composite_function
Definition: pixman-arm-neon-asm.h:617
NULL
#define NULL
Definition: begin_code.h:167
SDL_EnumUnixAudioDevices
void SDL_EnumUnixAudioDevices(const int classic, int(*test)(int))
OPEN_FLAGS_OUTPUT
#define OPEN_FLAGS_OUTPUT
Definition: SDL_audiodev_c.h:36
SDL_TRUE
@ SDL_TRUE
Definition: SDL_stdinc.h:164
SDL_assert
#define SDL_assert(condition)
Definition: SDL_assert.h:169
SDL_arraysize
#define SDL_arraysize(array)
Definition: SDL_stdinc.h:115
SDL_getenv
#define SDL_getenv
Definition: SDL_dynapi_overrides.h:378
SDL_snprintf
#define SDL_snprintf
Definition: SDL_dynapi_overrides.h:40
SDL_stdinc.h
SDL_audiodev_c.h
SDL_strlen
#define SDL_strlen
Definition: SDL_dynapi_overrides.h:393
SDL_FALSE
@ SDL_FALSE
Definition: SDL_stdinc.h:163
fd
GLuint64 GLenum GLint fd
Definition: gl2ext.h:1508
flags
GLbitfield flags
Definition: SDL_opengl_glext.h:1483
SDL_AddAudioDevice
void SDL_AddAudioDevice(const int iscapture, const char *name, void *handle)
Definition: SDL_audio.c:469