annotate src/audio/nto/SDL_nto_audio.c @ 693:6c119628180d

Date: Sat, 16 Aug 2003 16:22:56 +0300 From: "Mike Gorchak" Subject: Package building for QNX6 I'm just completed the package description file for QNX6 - qpg, it is like a\ .spec files for Linux. Please place SDL.qpg.in file in the root of the proj\ ect, where .spec file is placed. And sdl12qpg.diff - just adding the SDL.qpg\ .in. The same for the SDL_image. I'm planning to add .qpg files creation for\ all SDL* projects. As for shared library building for QNX6. It is very hard to improve the exis\ ting libtool code to support QNX shared libraries. Much easyiest is to remov\ e libtool.m4 code from the acinclude.m4 for those persons, who building shar\ ed libraries for QNX6. I'm described all what they need to do with .so under\ QNX6 in the README.QNX file. And 90% of people used the precompiled librari\ es, so I think it is not big problem :)
author Sam Lantinga <slouken@libsdl.org>
date Sat, 23 Aug 2003 23:25:46 +0000
parents 8bedd6d61642
children cbc0f7fabd1c
rev   line source
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
1 /*
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
297
f6ffac90895c Updated copyright information for 2002
Sam Lantinga <slouken@libsdl.org>
parents: 283
diff changeset
3 Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002 Sam Lantinga
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
4
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
6 modify it under the terms of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
8 version 2 of the License, or (at your option) any later version.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
9
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
13 Library General Public License for more details.
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
14
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
16 License along with this library; if not, write to the Free
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
18
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
19 Sam Lantinga
252
e8157fcb3114 Updated the source with the correct e-mail address
Sam Lantinga <slouken@libsdl.org>
parents: 0
diff changeset
20 slouken@libsdl.org
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
21 */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
22
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
23 #include <stdlib.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
24 #include <stdio.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
25 #include <string.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
26 #include <errno.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
27 #include <unistd.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
28 #include <fcntl.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
29 #include <signal.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
30 #include <sys/types.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
31 #include <sys/time.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
32 #include <sched.h>
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
33 #include <sys/asoundlib.h>
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
34 #include <sys/select.h>
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
35
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
36 #include "SDL_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
37 #include "SDL_error.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
38 #include "SDL_audiomem.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
39 #include "SDL_audio_c.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
40 #include "SDL_timer.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
41 #include "SDL_nto_audio.h"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
42
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
43 /* The tag name used by NTO audio */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
44 #define DRIVER_NAME "nto"
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
45
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
46 /* default channel communication parameters */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
47 #define DEFAULT_CPARAMS_RATE 22050
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
48 #define DEFAULT_CPARAMS_VOICES 1
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
49 #define DEFAULT_CPARAMS_FRAG_SIZE 4096
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
50 #define DEFAULT_CPARAMS_FRAGS_MIN 1
283
3d8b6b9f1e18 Date: Mon, 18 Feb 2002 16:46:59 +1200
Sam Lantinga <slouken@libsdl.org>
parents: 252
diff changeset
51 #define DEFAULT_CPARAMS_FRAGS_MAX 1
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
52
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
53 /* Open the audio device for playback, and don't block if busy */
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
54 #define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
55
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
56 /* Audio driver functions */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
57 static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
58 static void NTO_WaitAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
59 static void NTO_PlayAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
60 static Uint8 *NTO_GetAudioBuf(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
61 static void NTO_CloseAudio(_THIS);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
62
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
63 static snd_pcm_channel_status_t cstatus;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
64 static snd_pcm_channel_params_t cparams;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
65 static snd_pcm_channel_setup_t csetup;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
66
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
67 /* PCM transfer channel parameters initialize function */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
68 static void init_pcm_cparams(snd_pcm_channel_params_t* cparams)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
69 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
70 memset(cparams,0,sizeof(snd_pcm_channel_params_t));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
71
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
72 cparams->channel = SND_PCM_CHANNEL_PLAYBACK;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
73 cparams->mode = SND_PCM_MODE_BLOCK;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
74 cparams->start_mode = SND_PCM_START_DATA;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
75 cparams->stop_mode = SND_PCM_STOP_STOP;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
76 cparams->format.format = SND_PCM_SFMT_S16_LE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
77 cparams->format.interleave = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
78 cparams->format.rate = DEFAULT_CPARAMS_RATE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
79 cparams->format.voices = DEFAULT_CPARAMS_VOICES;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
80 cparams->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
81 cparams->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
82 cparams->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
83 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
84
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
85 static int Audio_Available(void)
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
86 {
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
87 /*
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
88 See if we can open a nonblocking channel.
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
89 Return value '1' means we can.
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
90 Return value '0' means we cannot.
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
91 */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
92
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
93 int available;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
94 int rval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
95 snd_pcm_t *handle;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
96
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
97 available = 0;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
98 handle = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
99
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
100 rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
101
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
102 if (rval >= 0){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
103 available = 1;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
104
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
105 if ((rval = snd_pcm_close(handle)) < 0){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
106 SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
107 available = 0;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
108 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
109 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
110 else{
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
111 SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
112 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
113
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
114 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
115 fprintf(stderr,"AudioAvailable rtns %d\n", available);
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
116 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
117
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
118 return(available);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
119 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
120
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
121 static void Audio_DeleteDevice(SDL_AudioDevice *device)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
122 {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
123 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
124 fprintf(stderr,"Audio_DeleteDevice\n");
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
125 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
126
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
127 free(device->hidden);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
128 free(device);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
129 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
130
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
131 static SDL_AudioDevice *Audio_CreateDevice(int devindex)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
132 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
133 SDL_AudioDevice *this;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
134 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
135 fprintf(stderr,"Audio_CreateDevice\n");
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
136 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
137 /* Initialize all variables that we clean on shutdown */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
138 this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
139 if ( this ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
140 memset(this, 0, (sizeof *this));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
141 this->hidden = (struct SDL_PrivateAudioData *)
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
142 malloc((sizeof *this->hidden));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
143 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
144 if ( (this == NULL) || (this->hidden == NULL) ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
145 SDL_OutOfMemory();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
146 if ( this ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
147 free(this);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
148 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
149 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
150 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
151 memset(this->hidden, 0, (sizeof *this->hidden));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
152 audio_handle = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
153
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
154 /* Set the function pointers */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
155 this->OpenAudio = NTO_OpenAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
156 this->WaitAudio = NTO_WaitAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
157 this->PlayAudio = NTO_PlayAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
158 this->GetAudioBuf = NTO_GetAudioBuf;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
159 this->CloseAudio = NTO_CloseAudio;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
160
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
161 this->free = Audio_DeleteDevice;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
162
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
163 return this;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
164 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
165
663
8bedd6d61642 Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 424
diff changeset
166 AudioBootStrap QNXNTOAUDIO_bootstrap = {
8bedd6d61642 Date: Sat, 2 Aug 2003 16:22:51 +0300
Sam Lantinga <slouken@libsdl.org>
parents: 424
diff changeset
167 DRIVER_NAME, "QNX6 NTO PCM audio",
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
168 Audio_Available, Audio_CreateDevice
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
169 };
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
170
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
171 /* This function waits until it is possible to write a full sound buffer */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
172 static void NTO_WaitAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
173 {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
174 fd_set wfds;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
175
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
176 FD_SET( audio_fd, &wfds );
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
177 switch( select( audio_fd + 1, NULL, &wfds, NULL, NULL ) )
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
178 {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
179 case -1:
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
180 case 0:
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
181 /* Error */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
182 SDL_SetError("select() in NTO_WaitAudio failed: %s\n", strerror(errno));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
183 break;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
184 default:
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
185 if(FD_ISSET(audio_fd, &wfds))
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
186 return;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
187 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
188 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
189
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
190 static void NTO_PlayAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
191 {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
192 int written, rval;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
193 int towrite;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
194
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
195 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
196 fprintf(stderr, "NTO_PlayAudio\n");
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
197 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
198
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
199 if( !this->enabled){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
200 return;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
201 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
202
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
203 towrite = pcm_len;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
204
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
205 /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
206 do {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
207 written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite);
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
208 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
209 fprintf(stderr, "NTO_PlayAudio: written = %d towrite = %d\n",written,towrite);
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
210 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
211 if (written != towrite){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
212 if ((errno == EAGAIN) || (errno == EWOULDBLOCK)){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
213 SDL_Delay(1); /* Let a little CPU time go by and try to write again */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
214 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
215 fprintf(stderr, "errno == EAGAIN written %d\n", written);
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
216 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
217 towrite -= written; //we wrote some data
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
218 continue;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
219 }
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
220 else if((errno == EINVAL) || (errno == EIO)){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
221 if(errno == EIO){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
222 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
223 fprintf(stderr,"snd_pcm_plugin_write failed EIO: %s\n", snd_strerror(written));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
224 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
225 }
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
226 if(errno == EINVAL){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
227 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
228 fprintf(stderr,"snd_pcm_plugin_write failed EINVAL: %s\n", snd_strerror(written));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
229 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
230 }
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
231
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
232 memset(&cstatus, 0, sizeof(cstatus));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
233 if( (rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0 ){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
234 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
235 fprintf(stderr, "snd_pcm_plugin_status failed %s\n",snd_strerror(rval));
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
236 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
237 SDL_SetError("snd_pcm_plugin_status failed: %s\n", snd_strerror(rval));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
238 return;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
239 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
240
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
241 if ( (cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY) ){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
242 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
243 fprintf(stderr, "buffer underrun\n");
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
244 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
245 if ( (rval = snd_pcm_plugin_prepare (audio_handle,SND_PCM_CHANNEL_PLAYBACK)) < 0 ){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
246 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
247 fprintf(stderr, "NTO_PlayAudio: prepare failed %s\n",snd_strerror(rval));
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
248 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
249 SDL_SetError("snd_pcm_plugin_prepare failed: %s\n",snd_strerror(rval) );
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
250 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
251 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
252 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
253 continue;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
254 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
255 else{
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
256 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
257 fprintf(stderr, "NTO_PlayAudio: snd_pcm_plugin_write failed unknown errno %d %s\n",errno, snd_strerror(rval));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
258 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
259 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
260 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
261
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
262 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
263 else
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
264 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
265 towrite -= written; //we wrote all remaining data
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
266 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
267 } while ( (towrite > 0) && (this->enabled) );
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
268
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
269 /* If we couldn't write, assume fatal error for now */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
270 if ( towrite != 0 ) {
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
271 this->enabled = 0;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
272 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
273 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
274 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
275
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
276 static Uint8 *NTO_GetAudioBuf(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
277 {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
278 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
279 fprintf(stderr, "NTO_GetAudioBuf: pcm_buf %X\n",(Uint8 *)pcm_buf);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
280 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
281 return(pcm_buf);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
282 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
283
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
284 static void NTO_CloseAudio(_THIS)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
285 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
286 int rval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
287
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
288 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
289 fprintf(stderr, "NTO_CloseAudio\n");
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
290 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
291
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
292 this->enabled = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
293
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
294 if ( audio_handle != NULL ) {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
295 if ((rval = snd_pcm_plugin_flush(audio_handle,SND_PCM_CHANNEL_PLAYBACK)) < 0){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
296 SDL_SetError("snd_pcm_plugin_flush failed: %s\n",snd_strerror(rval));
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
297 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
298 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
299 if ((rval = snd_pcm_close(audio_handle)) < 0){
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
300 SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
301 return;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
302 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
303 audio_handle = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
304 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
305 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
306
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
307 static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec)
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
308 {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
309 int rval;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
310 int format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
311 Uint16 test_format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
312 int twidth;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
313 int found;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
314
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
315 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
316 fprintf(stderr, "NTO_OpenAudio\n");
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
317 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
318
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
319 audio_handle = NULL;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
320 this->enabled = 0;
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
321
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
322 if ( pcm_buf != NULL ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
323 free((Uint8 *)pcm_buf);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
324 pcm_buf = NULL;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
325 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
326
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
327 /* initialize channel transfer parameters to default */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
328 init_pcm_cparams(&cparams);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
329
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
330 /* Open the audio device */
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
331 rval = snd_pcm_open_preferred(&audio_handle, NULL, NULL, OPEN_FLAGS);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
332 if ( rval < 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
333 SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
334 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
335 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
336
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
337 /* enable count status parameter */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
338 if ((rval = snd_pcm_plugin_set_disable(audio_handle, PLUGIN_DISABLE_MMAP))<0){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
339 SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n", snd_strerror(rval));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
340 return(-1);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
341 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
342
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
343 /* Try for a closest match on audio format */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
344 format = 0;
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
345 found = 0; /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
346 for ( test_format = SDL_FirstAudioFormat(spec->format); !found ; )
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
347 {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
348 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
349 fprintf(stderr, "Trying format 0x%4.4x spec->samples %d\n", test_format,spec->samples);
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
350 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
351
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
352 /* if match found set format to equivalent ALSA format */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
353 switch ( test_format ) {
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
354 case AUDIO_U8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
355 format = SND_PCM_SFMT_U8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
356 found = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
357 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
358 case AUDIO_S8:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
359 format = SND_PCM_SFMT_S8;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
360 found = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
361 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
362 case AUDIO_S16LSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
363 format = SND_PCM_SFMT_S16_LE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
364 found = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
365 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
366 case AUDIO_S16MSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
367 format = SND_PCM_SFMT_S16_BE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
368 found = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
369 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
370 case AUDIO_U16LSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
371 format = SND_PCM_SFMT_U16_LE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
372 found = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
373 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
374 case AUDIO_U16MSB:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
375 format = SND_PCM_SFMT_U16_BE;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
376 found = 1;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
377 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
378 default:
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
379 break;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
380 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
381 if ( ! found ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
382 test_format = SDL_NextAudioFormat();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
383 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
384 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
385
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
386 /* assumes test_format not 0 on success */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
387 if ( test_format == 0 ) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
388 SDL_SetError("Couldn't find any hardware audio formats");
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
389 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
390 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
391
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
392 spec->format = test_format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
393
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
394 /* Set the audio format */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
395 cparams.format.format = format;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
396
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
397 /* Set mono or stereo audio (currently only two channels supported) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
398 cparams.format.voices = spec->channels;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
399
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
400 #ifdef DEBUG_AUDIO
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
401 fprintf(stderr,"intializing channels %d\n", cparams.format.voices);
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
402 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
403
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
404 /* Set rate */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
405 cparams.format.rate = spec->freq ;
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
406
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
407 /* Setup the transfer parameters according to cparams */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
408 rval = snd_pcm_plugin_params(audio_handle, &cparams);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
409 if (rval < 0) {
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
410 SDL_SetError("snd_pcm_channel_params failed: %s\n", snd_strerror (rval));
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
411 return(-1);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
412 }
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
413
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
414 /* Make sure channel is setup right one last time */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
415 memset( &csetup, 0, sizeof( csetup ) );
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
416 csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
417 if ( snd_pcm_plugin_setup( audio_handle, &csetup ) < 0 )
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
418 {
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
419 SDL_SetError("Unable to setup playback channel\n" );
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
420 return(-1);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
421 }
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
422 else
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
423 {
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
424 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
425 fprintf(stderr,"requested format: %d\n",cparams.format.format);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
426 fprintf(stderr,"requested frag size: %d\n",cparams.buf.block.frag_size);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
427 fprintf(stderr,"requested max frags: %d\n\n",cparams.buf.block.frags_max);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
428
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
429 fprintf(stderr,"real format: %d\n", csetup.format.format );
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
430 fprintf(stderr,"real frag size : %d\n", csetup.buf.block.frag_size );
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
431 fprintf(stderr,"real max frags : %d\n", csetup.buf.block.frags_max );
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
432 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
433 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
434
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
435 /*
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
436 Allocate memory to the audio buffer and initialize with silence (Note that
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
437 buffer size must be a multiple of fragment size, so find closest multiple)
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
438 */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
439
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
440 twidth = snd_pcm_format_width(format);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
441 if (twidth < 0) {
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
442 printf("snd_pcm_format_width failed\n");
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
443 twidth = 0;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
444 }
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
445
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
446 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
447 fprintf(stderr,"format is %d bits wide\n",twidth);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
448 #endif
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
449
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
450 pcm_len = spec->size ;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
451
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
452 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
453 fprintf(stderr,"pcm_len set to %d\n", pcm_len);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
454 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
455
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
456 if (pcm_len == 0){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
457 pcm_len = csetup.buf.block.frag_size;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
458 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
459
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
460 pcm_buf = (Uint8*)malloc(pcm_len);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
461 if (pcm_buf == NULL) {
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
462 SDL_SetError("pcm_buf malloc failed\n");
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
463 return(-1);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
464 }
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
465 memset(pcm_buf,spec->silence,pcm_len);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
466
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
467 #ifdef DEBUG_AUDIO
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
468 fprintf(stderr,"pcm_buf malloced and silenced.\n");
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
469 #endif
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
470
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
471 /* get the file descriptor */
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
472 if( (audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0){
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
473 fprintf(stderr, "snd_pcm_file_descriptor failed with error code: %d\n", audio_fd);
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
474 }
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
475
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
476 /* Trigger audio playback */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
477 rval = snd_pcm_plugin_prepare( audio_handle, SND_PCM_CHANNEL_PLAYBACK);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
478 if (rval < 0) {
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
479 SDL_SetError("snd_pcm_plugin_prepare failed: %s\n", snd_strerror (rval));
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
480 return(-1);
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
481 }
418
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
482
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
483 this->enabled = 1;
337f3ec4c385 Updated the QNX audio code for QNX 6.2 (thanks Travis!)
Sam Lantinga <slouken@libsdl.org>
parents: 297
diff changeset
484
0
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
485 /* Get the parent process id (we're the parent of the audio thread) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
486 parent = getpid();
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
487
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
488 /* We're ready to rock and roll. :-) */
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
489 return(0);
74212992fb08 Initial revision
Sam Lantinga <slouken@lokigames.com>
parents:
diff changeset
490 }