Date: Sat, 13 Sep 2003 15:50:43 +0300
authorSam Lantinga <slouken@libsdl.org>
Sun, 21 Sep 2003 18:13:48 +0000
changeset 718cbc0f7fabd1c
parent 717 42ed44b2c8b6
child 719 269c97e24da6
Date: Sat, 13 Sep 2003 15:50:43 +0300
From: "Mike Gorchak"
Subject: QNX fixes

improved sound code for the QNX, added workarounds for known bugs, fixed photon detect code. Update .qpg file.
README.QNX
SDL.qpg.in
src/audio/nto/SDL_nto_audio.c
src/audio/nto/SDL_nto_audio.h
src/video/photon/SDL_ph_video.c
     1.1 --- a/README.QNX	Mon Sep 15 13:51:25 2003 +0000
     1.2 +++ b/README.QNX	Sun Sep 21 18:13:48 2003 +0000
     1.3 @@ -78,7 +78,7 @@
     1.4  de.m4 file (it comes after the ESD detection code up to the end of the
     1.5  file), because the libtool stuff in the acinclude.m4 file is very  old
     1.6  and  doesn't  know  anything  about  QNX. Just   remove  it, then  run
     1.7 -"libtoolize --force --copy" and after that run autogen.sh.
     1.8 +"libtoolize --force --copy" and after that run the autogen.sh script.
     1.9  
    1.10  ======================================================================
    1.11  Some building issues:
     2.1 --- a/SDL.qpg.in	Mon Sep 15 13:51:25 2003 +0000
     2.2 +++ b/SDL.qpg.in	Sun Sep 21 18:13:48 2003 +0000
     2.3 @@ -52,6 +52,7 @@
     2.4        </QPG:Files>
     2.5        <QPG:PackageFilter>
     2.6           <QPM:PackageManifest>
     2.7 +
     2.8              <QPM:PackageDescription>
     2.9                 <QPM:PackageType>Library</QPM:PackageType>
    2.10                 <QPM:PackageName>SDL</QPM:PackageName>
    2.11 @@ -59,6 +60,7 @@
    2.12                 <QPM:PackageRepository>http://qnx.org.ru/repository</QPM:PackageRepository>
    2.13                 <QPM:FileVersion>2.0</QPM:FileVersion>
    2.14              </QPM:PackageDescription>
    2.15 +
    2.16              <QPM:ProductDescription>
    2.17                 <QPM:ProductName>SDL</QPM:ProductName>
    2.18                 <QPM:ProductIdentifier>SDL</QPM:ProductIdentifier>
    2.19 @@ -74,11 +76,12 @@
    2.20                 <QPM:AuthorEmail>slouken@libsdl.org</QPM:AuthorEmail>
    2.21                 <QPM:ProductIconSmall/>
    2.22                 <QPM:ProductIconLarge/>
    2.23 -               <QPM:ProductDescriptionShort>This is the Simple DirectMedia Layer, a generic API that provides low level access to audio, keyboard, mouse, and display framebuffer across multiple platforms.</QPM:ProductDescriptionShort>
    2.24 -               <QPM:ProductDescriptionLong>This is the Simple DirectMedia Layer, a generic API that provides low level access to audio, keyboard, mouse, and display framebuffer across multiple platforms. This is the libraries, include files and other resources you can use to develop and run SDL applications.</QPM:ProductDescriptionLong>
    2.25 +               <QPM:ProductDescriptionShort>This is the Simple DirectMedia Layer (SDL), a generic API that provides low level access to audio, keyboard, mouse, and display framebuffer across multiple platforms.</QPM:ProductDescriptionShort>
    2.26 +               <QPM:ProductDescriptionLong>This is the Simple DirectMedia Layer (SDL), a generic API that provides low level access to audio, keyboard, mouse, and display framebuffer across multiple platforms. This is the libraries, include files and other resources you can use to develop and run SDL applications.</QPM:ProductDescriptionLong>
    2.27                 <QPM:ProductDescriptionURL>http://www.libsdl.org</QPM:ProductDescriptionURL>
    2.28                 <QPM:ProductDescriptionEmbedURL/>
    2.29              </QPM:ProductDescription>
    2.30 +
    2.31              <QPM:ReleaseDescription>
    2.32                 <QPM:ReleaseVersion>@VERSION@</QPM:ReleaseVersion>
    2.33                 <QPM:ReleaseUrgency>High</QPM:ReleaseUrgency>
    2.34 @@ -87,25 +90,53 @@
    2.35                 <QPM:ReleaseNoteMajor/>
    2.36                 <QPM:ReleaseBuild>1</QPM:ReleaseBuild>
    2.37                 <QPM:CountryExclude/>
    2.38 -               <QPM:ReleaseCopyright>GNU General Public License</QPM:ReleaseCopyright>
    2.39 +               <QPM:ReleaseCopyright>GNU Lesser General Public License</QPM:ReleaseCopyright>
    2.40              </QPM:ReleaseDescription>
    2.41 +
    2.42              <QPM:ContentDescription>
    2.43 -               <QPM:ContentTopic>Software Development/Libraries and Extensions/C Libraries</QPM:ContentTopic>
    2.44 +               <QPM:ContentTopic xmlmultiple="true">Software Development/Libraries and Extensions/C Libraries</QPM:ContentTopic>
    2.45                 <QPM:ContentKeyword>SDL, audio, graphics, demos, games, emulators, media, layer</QPM:ContentKeyword>
    2.46 -               <QPM:Processor/>
    2.47 -               <QPM:TargetProcessor/>
    2.48                 <QPM:TargetOS>qnx6</QPM:TargetOS>
    2.49 -               <QPM:HostOS>qnx6</QPM:HostOS>
    2.50 -               <QPM:DisplayEnvironment>Photon</QPM:DisplayEnvironment>
    2.51 -               <QPM:TargetAudience>Developer</QPM:TargetAudience>
    2.52 -               <QPM:TargetAudience>User</QPM:TargetAudience>
    2.53 +               <QPM:HostOS>none</QPM:HostOS>
    2.54 +               <QPM:DisplayEnvironment xmlmultiple="true">Photon</QPM:DisplayEnvironment>
    2.55 +               <QPM:TargetAudience xmlmultiple="true">Developer</QPM:TargetAudience>
    2.56 +               <QPM:TargetAudience xmlmultiple="true">User</QPM:TargetAudience>
    2.57              </QPM:ContentDescription>
    2.58              <QPM:LicenseUrl>repdata://LicenseUrl/COPYING</QPM:LicenseUrl>
    2.59 +         </QPM:PackageManifest>
    2.60 +      </QPG:PackageFilter>
    2.61 +
    2.62 +      <QPG:PackageFilter proc="none" target="none">
    2.63 +         <QPM:PackageManifest>
    2.64              <QPM:ProductInstallationDependencies>
    2.65 -               <QPM:ProductRequirements/>
    2.66 +               <QPM:ProductRequirements></QPM:ProductRequirements>
    2.67              </QPM:ProductInstallationDependencies>
    2.68           </QPM:PackageManifest>
    2.69        </QPG:PackageFilter>
    2.70 +
    2.71 +      <QPG:PackageFilter proc="x86" target="none">
    2.72 +         <QPM:PackageManifest>
    2.73 +            <QPM:ProductInstallationDependencies>
    2.74 +               <QPM:ProductRequirements></QPM:ProductRequirements>
    2.75 +            </QPM:ProductInstallationDependencies>
    2.76 +         </QPM:PackageManifest>
    2.77 +      </QPG:PackageFilter>
    2.78 +
    2.79 +      <QPG:PackageFilter proc="none" target="x86">
    2.80 +         <QPM:PackageManifest>
    2.81 +            <QPM:ProductInstallationDependencies>
    2.82 +               <QPM:ProductRequirements></QPM:ProductRequirements>
    2.83 +            </QPM:ProductInstallationDependencies>
    2.84 +         </QPM:PackageManifest>
    2.85 +      </QPG:PackageFilter>
    2.86 +
    2.87 +      <QPG:PackageFilter proc="x86" target="x86">
    2.88 +         <QPM:PackageManifest>
    2.89 +            <QPM:ProductInstallationDependencies>
    2.90 +               <QPM:ProductRequirements></QPM:ProductRequirements>
    2.91 +            </QPM:ProductInstallationDependencies>
    2.92 +         </QPM:PackageManifest>
    2.93 +      </QPG:PackageFilter>
    2.94 +
    2.95     </QPG:Values>
    2.96  </QPG:Generation>
    2.97 -
     3.1 --- a/src/audio/nto/SDL_nto_audio.c	Mon Sep 15 13:51:25 2003 +0000
     3.2 +++ b/src/audio/nto/SDL_nto_audio.c	Sun Sep 21 18:13:48 2003 +0000
     3.3 @@ -30,8 +30,9 @@
     3.4  #include <sys/types.h>
     3.5  #include <sys/time.h>
     3.6  #include <sched.h>
     3.7 +#include <sys/select.h>
     3.8 +#include <sys/neutrino.h>
     3.9  #include <sys/asoundlib.h>
    3.10 -#include <sys/select.h>
    3.11  
    3.12  #include "SDL_audio.h"
    3.13  #include "SDL_error.h"
    3.14 @@ -41,11 +42,12 @@
    3.15  #include "SDL_nto_audio.h"
    3.16  
    3.17  /* The tag name used by NTO audio */
    3.18 -#define DRIVER_NAME         "nto"
    3.19 +#define DRIVER_NAME "qsa-nto"
    3.20  
    3.21  /* default channel communication parameters */
    3.22  #define DEFAULT_CPARAMS_RATE 22050
    3.23  #define DEFAULT_CPARAMS_VOICES 1
    3.24 +/* FIXME: need to add in the near future flexible logic with frag_size and frags count */
    3.25  #define DEFAULT_CPARAMS_FRAG_SIZE 4096
    3.26  #define DEFAULT_CPARAMS_FRAGS_MIN 1
    3.27  #define DEFAULT_CPARAMS_FRAGS_MAX 1
    3.28 @@ -53,438 +55,456 @@
    3.29  /* Open the audio device for playback, and don't block if busy */
    3.30  #define OPEN_FLAGS SND_PCM_OPEN_PLAYBACK
    3.31  
    3.32 +#define QSA_NO_WORKAROUNDS  0x00000000
    3.33 +#define QSA_MMAP_WORKAROUND 0x00000001
    3.34 +
    3.35 +struct BuggyCards
    3.36 +{
    3.37 +   char* cardname;
    3.38 +   unsigned long bugtype;
    3.39 +};
    3.40 +
    3.41 +#define QSA_WA_CARDS 3
    3.42 +
    3.43 +struct BuggyCards buggycards[QSA_WA_CARDS]=
    3.44 +{
    3.45 +   {"Sound Blaster Live!", QSA_MMAP_WORKAROUND},
    3.46 +   {"Vortex 8820",         QSA_MMAP_WORKAROUND},
    3.47 +   {"Vortex 8830",         QSA_MMAP_WORKAROUND},
    3.48 +};
    3.49 +
    3.50  /* Audio driver functions */
    3.51 -static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec);
    3.52 +static void NTO_ThreadInit(_THIS);
    3.53 +static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec);
    3.54  static void NTO_WaitAudio(_THIS);
    3.55  static void NTO_PlayAudio(_THIS);
    3.56 -static Uint8 *NTO_GetAudioBuf(_THIS);
    3.57 +static Uint8* NTO_GetAudioBuf(_THIS);
    3.58  static void NTO_CloseAudio(_THIS);
    3.59  
    3.60 -static snd_pcm_channel_status_t cstatus;
    3.61 -static snd_pcm_channel_params_t cparams;
    3.62 -static snd_pcm_channel_setup_t  csetup;
    3.63 +/* card names check to apply the workarounds */
    3.64 +static int NTO_CheckBuggyCards(_THIS, unsigned long checkfor)
    3.65 +{
    3.66 +    char scardname[33];
    3.67 +    int it;
    3.68 +    
    3.69 +    if (snd_card_get_name(cardno, scardname, 32)<0)
    3.70 +    {
    3.71 +        return 0;
    3.72 +    }
    3.73 +
    3.74 +    for (it=0; it<QSA_WA_CARDS; it++)
    3.75 +    {
    3.76 +       if (strcmp(buggycards[it].cardname, scardname)==0)
    3.77 +       {
    3.78 +          if (buggycards[it].bugtype==checkfor)
    3.79 +          {
    3.80 +              return 1;
    3.81 +          }
    3.82 +       }
    3.83 +    }
    3.84 +
    3.85 +    return 0;
    3.86 +}
    3.87 +
    3.88 +static void NTO_ThreadInit(_THIS)
    3.89 +{
    3.90 +   int status;
    3.91 +   struct sched_param param;
    3.92 +
    3.93 +   /* increasing default 10 priority to 25 to avoid jerky sound */
    3.94 +   status=SchedGet(0, 0, &param);
    3.95 +   param.sched_priority=param.sched_curpriority+15;
    3.96 +   status=SchedSet(0, 0, SCHED_NOCHANGE, &param);
    3.97 +}
    3.98  
    3.99  /* PCM transfer channel parameters initialize function */
   3.100 -static void init_pcm_cparams(snd_pcm_channel_params_t* cparams)
   3.101 +static void NTO_InitAudioParams(snd_pcm_channel_params_t* cpars)
   3.102  {
   3.103 -	memset(cparams,0,sizeof(snd_pcm_channel_params_t));
   3.104 +    memset(cpars, 0, sizeof(snd_pcm_channel_params_t));
   3.105  
   3.106 -	cparams->channel = SND_PCM_CHANNEL_PLAYBACK;
   3.107 -	cparams->mode = SND_PCM_MODE_BLOCK;
   3.108 -	cparams->start_mode = SND_PCM_START_DATA;
   3.109 -	cparams->stop_mode  = SND_PCM_STOP_STOP;
   3.110 -	cparams->format.format = SND_PCM_SFMT_S16_LE;
   3.111 -	cparams->format.interleave = 1;
   3.112 -	cparams->format.rate = DEFAULT_CPARAMS_RATE;
   3.113 -	cparams->format.voices = DEFAULT_CPARAMS_VOICES;
   3.114 -	cparams->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
   3.115 -	cparams->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
   3.116 -	cparams->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
   3.117 +    cpars->channel = SND_PCM_CHANNEL_PLAYBACK;
   3.118 +    cpars->mode = SND_PCM_MODE_BLOCK;
   3.119 +    cpars->start_mode = SND_PCM_START_DATA;
   3.120 +    cpars->stop_mode  = SND_PCM_STOP_STOP;
   3.121 +    cpars->format.format = SND_PCM_SFMT_S16_LE;
   3.122 +    cpars->format.interleave = 1;
   3.123 +    cpars->format.rate = DEFAULT_CPARAMS_RATE;
   3.124 +    cpars->format.voices = DEFAULT_CPARAMS_VOICES;
   3.125 +    cpars->buf.block.frag_size = DEFAULT_CPARAMS_FRAG_SIZE;
   3.126 +    cpars->buf.block.frags_min = DEFAULT_CPARAMS_FRAGS_MIN;
   3.127 +    cpars->buf.block.frags_max = DEFAULT_CPARAMS_FRAGS_MAX;
   3.128  }
   3.129  
   3.130 -static int Audio_Available(void)
   3.131 +static int NTO_AudioAvailable(void)
   3.132  {
   3.133 -	/*
   3.134 -		See if we can open a nonblocking channel.
   3.135 -		Return value '1' means we can.
   3.136 -		Return value '0' means we cannot.
   3.137 -	*/
   3.138 +    /*  See if we can open a nonblocking channel.
   3.139 +        Return value '1' means we can.
   3.140 +        Return value '0' means we cannot. */
   3.141  
   3.142 -	int available;
   3.143 -	int rval;
   3.144 -	snd_pcm_t *handle;
   3.145 +    int available;
   3.146 +    int rval;
   3.147 +    snd_pcm_t* handle;
   3.148  
   3.149 -	available = 0;
   3.150 -	handle = NULL;
   3.151 +    available = 0;
   3.152 +    handle = NULL;
   3.153  
   3.154 -	rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
   3.155 +    rval = snd_pcm_open_preferred(&handle, NULL, NULL, OPEN_FLAGS);
   3.156  
   3.157 -	if (rval >= 0){
   3.158 -		available = 1;
   3.159 -		
   3.160 -		if ((rval = snd_pcm_close(handle)) < 0){
   3.161 -			SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval));
   3.162 -			available = 0;
   3.163 -		}
   3.164 -	}
   3.165 -	else{
   3.166 -		SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval));
   3.167 -	}
   3.168 -	
   3.169 -	#ifdef DEBUG_AUDIO
   3.170 -	fprintf(stderr,"AudioAvailable rtns %d\n", available);
   3.171 -	#endif
   3.172 -	
   3.173 -	return(available);
   3.174 +    if (rval >= 0)
   3.175 +    {
   3.176 +        available = 1;
   3.177 +
   3.178 +        if ((rval = snd_pcm_close(handle)) < 0)
   3.179 +        {
   3.180 +            SDL_SetError("NTO_AudioAvailable(): snd_pcm_close failed: %s\n", snd_strerror(rval));
   3.181 +            available = 0;
   3.182 +        }
   3.183 +    }
   3.184 +    else
   3.185 +    {
   3.186 +        SDL_SetError("NTO_AudioAvailable(): there are no available audio devices.\n");
   3.187 +    }
   3.188 +
   3.189 +    return (available);
   3.190  }
   3.191  
   3.192 -static void Audio_DeleteDevice(SDL_AudioDevice *device)
   3.193 +static void NTO_DeleteAudioDevice(SDL_AudioDevice *device)
   3.194  {
   3.195 -	#ifdef DEBUG_AUDIO
   3.196 -	fprintf(stderr,"Audio_DeleteDevice\n");
   3.197 -	#endif
   3.198 -
   3.199 -	free(device->hidden);
   3.200 -	free(device);
   3.201 +    if ((device)&&(device->hidden))
   3.202 +    {
   3.203 +        free(device->hidden);
   3.204 +    }
   3.205 +    if (device)
   3.206 +    {
   3.207 +        free(device);
   3.208 +    }
   3.209  }
   3.210  
   3.211 -static SDL_AudioDevice *Audio_CreateDevice(int devindex)
   3.212 +static SDL_AudioDevice* NTO_CreateAudioDevice(int devindex)
   3.213  {
   3.214 -	SDL_AudioDevice *this;
   3.215 -	#ifdef DEBUG_AUDIO
   3.216 -	fprintf(stderr,"Audio_CreateDevice\n");
   3.217 -	#endif
   3.218 -	/* Initialize all variables that we clean on shutdown */
   3.219 -	this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
   3.220 -	if ( this ) {
   3.221 -		memset(this, 0, (sizeof *this));
   3.222 -		this->hidden = (struct SDL_PrivateAudioData *)
   3.223 -		malloc((sizeof *this->hidden));
   3.224 +    SDL_AudioDevice *this;
   3.225 +
   3.226 +    /* Initialize all variables that we clean on shutdown */
   3.227 +    this = (SDL_AudioDevice *)malloc(sizeof(SDL_AudioDevice));
   3.228 +    if (this)
   3.229 +    {
   3.230 +        memset(this, 0, sizeof(SDL_AudioDevice));
   3.231 +        this->hidden = (struct SDL_PrivateAudioData *)malloc(sizeof(struct SDL_PrivateAudioData));
   3.232 +    }
   3.233 +    if ((this == NULL) || (this->hidden == NULL))
   3.234 +    {
   3.235 +        SDL_OutOfMemory();
   3.236 +        if (this)
   3.237 +        {
   3.238 +            free(this);
   3.239  	}
   3.240 -	if ( (this == NULL) || (this->hidden == NULL) ) {
   3.241 -		SDL_OutOfMemory();
   3.242 -		if ( this ) {
   3.243 -			free(this);
   3.244 -		}
   3.245 -		return(0);
   3.246 -	}
   3.247 -	memset(this->hidden, 0, (sizeof *this->hidden));
   3.248 -	audio_handle = NULL;
   3.249 +        return (0);
   3.250 +    }
   3.251 +    memset(this->hidden, 0, sizeof(struct SDL_PrivateAudioData));
   3.252 +    audio_handle = NULL;
   3.253  
   3.254 -	/* Set the function pointers */
   3.255 -	this->OpenAudio = NTO_OpenAudio;
   3.256 -	this->WaitAudio = NTO_WaitAudio;
   3.257 -	this->PlayAudio = NTO_PlayAudio;
   3.258 -	this->GetAudioBuf = NTO_GetAudioBuf;
   3.259 -	this->CloseAudio = NTO_CloseAudio;
   3.260 +    /* Set the function pointers */
   3.261 +    this->ThreadInit = NTO_ThreadInit;
   3.262 +    this->OpenAudio = NTO_OpenAudio;
   3.263 +    this->WaitAudio = NTO_WaitAudio;
   3.264 +    this->PlayAudio = NTO_PlayAudio;
   3.265 +    this->GetAudioBuf = NTO_GetAudioBuf;
   3.266 +    this->CloseAudio = NTO_CloseAudio;
   3.267  
   3.268 -	this->free = Audio_DeleteDevice;
   3.269 +    this->free = NTO_DeleteAudioDevice;
   3.270  
   3.271 -	return this;
   3.272 +    return this;
   3.273  }
   3.274  
   3.275 -AudioBootStrap QNXNTOAUDIO_bootstrap = {
   3.276 -	DRIVER_NAME, "QNX6 NTO PCM audio",
   3.277 -	Audio_Available, Audio_CreateDevice
   3.278 +AudioBootStrap QNXNTOAUDIO_bootstrap =
   3.279 +{
   3.280 +    DRIVER_NAME, "QNX6 QSA-NTO Audio",
   3.281 +    NTO_AudioAvailable,
   3.282 +    NTO_CreateAudioDevice
   3.283  };
   3.284  
   3.285  /* This function waits until it is possible to write a full sound buffer */
   3.286  static void NTO_WaitAudio(_THIS)
   3.287  {
   3.288 -	fd_set wfds;
   3.289 +    fd_set wfds;
   3.290 +    int selectret;
   3.291  
   3.292 -	FD_SET( audio_fd, &wfds );
   3.293 -	switch( select( audio_fd + 1, NULL, &wfds, NULL, NULL ) )
   3.294 -	{
   3.295 -		case -1:
   3.296 -		case 0:
   3.297 -			/* Error */
   3.298 -			SDL_SetError("select() in NTO_WaitAudio failed: %s\n", strerror(errno));
   3.299 -			break;
   3.300 -		default:
   3.301 -			if(FD_ISSET(audio_fd, &wfds))
   3.302 -				return;
   3.303 -	}
   3.304 +    FD_ZERO(&wfds);
   3.305 +    FD_SET(audio_fd, &wfds);
   3.306 +
   3.307 +    do {
   3.308 +        selectret=select(audio_fd + 1, NULL, &wfds, NULL, NULL);
   3.309 +        switch (selectret)
   3.310 +        {
   3.311 +            case -1:
   3.312 +            case  0: SDL_SetError("NTO_WaitAudio(): select() failed: %s\n", strerror(errno));
   3.313 +                     return;
   3.314 +            default: if (FD_ISSET(audio_fd, &wfds))
   3.315 +                     {
   3.316 +                         return;
   3.317 +                     }
   3.318 +                     break;
   3.319 +        }
   3.320 +    } while(1);
   3.321  }
   3.322  
   3.323  static void NTO_PlayAudio(_THIS)
   3.324  {
   3.325 -	int written, rval;
   3.326 -	int towrite;
   3.327 +    int written, rval;
   3.328 +    int towrite;
   3.329 +    void* pcmbuffer;
   3.330  
   3.331 -	#ifdef DEBUG_AUDIO
   3.332 -	fprintf(stderr, "NTO_PlayAudio\n");
   3.333 -	#endif
   3.334 +    if (!this->enabled)
   3.335 +    {
   3.336 +        return;
   3.337 +    }
   3.338 +    
   3.339 +    towrite = this->spec.size;
   3.340 +    pcmbuffer = pcm_buf;
   3.341  
   3.342 -	if( !this->enabled){
   3.343 -		return;
   3.344 -	}
   3.345 +    /* Write the audio data, checking for EAGAIN (buffer full) and underrun */
   3.346 +    do {
   3.347 +        written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite);
   3.348 +        if (written != towrite)
   3.349 +        {
   3.350 +            if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
   3.351 +            {
   3.352 +                /* Let a little CPU time go by and try to write again */
   3.353 +                SDL_Delay(1);
   3.354 +                /* if we wrote some data */
   3.355 +                towrite -= written;
   3.356 +                pcmbuffer += written * this->spec.channels;
   3.357 +                continue;
   3.358 +            }		
   3.359 +            else
   3.360 +            {
   3.361 +                if ((errno == EINVAL) || (errno == EIO))
   3.362 +                {
   3.363 +                    memset(&cstatus, 0, sizeof(cstatus));
   3.364 +                    cstatus.channel = SND_PCM_CHANNEL_PLAYBACK;
   3.365 +                    if ((rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0)
   3.366 +                    {
   3.367 +                        SDL_SetError("NTO_PlayAudio(): snd_pcm_plugin_status failed: %s\n", snd_strerror(rval));
   3.368 +                        return;
   3.369 +                    }	
   3.370 +                    if ((cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY))
   3.371 +                    {
   3.372 +                        if ((rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
   3.373 +                        {
   3.374 +                            SDL_SetError("NTO_PlayAudio(): snd_pcm_plugin_prepare failed: %s\n", snd_strerror(rval));
   3.375 +                            return;
   3.376 +                        }
   3.377 +                    }		        		
   3.378 +                    continue;
   3.379 +                }
   3.380 +                else
   3.381 +                {
   3.382 +                    return;
   3.383 +                }
   3.384 +            }
   3.385 +        }
   3.386 +        else
   3.387 +        {
   3.388 +            /* we wrote all remaining data */
   3.389 +            towrite -= written;
   3.390 +            pcmbuffer += written * this->spec.channels;
   3.391 +        }
   3.392 +    } while ((towrite > 0)  && (this->enabled));
   3.393  
   3.394 -	towrite = pcm_len;
   3.395 -	
   3.396 -	/* Write the audio data, checking for EAGAIN (buffer full) and underrun */
   3.397 -	do {
   3.398 -		written = snd_pcm_plugin_write(audio_handle, pcm_buf, towrite);
   3.399 -		#ifdef DEBUG_AUDIO
   3.400 -		fprintf(stderr, "NTO_PlayAudio: written = %d towrite = %d\n",written,towrite);
   3.401 -		#endif
   3.402 -		if (written != towrite){
   3.403 -			if ((errno == EAGAIN) || (errno == EWOULDBLOCK)){
   3.404 -				SDL_Delay(1);   /* Let a little CPU time go by and try to write again */
   3.405 -				#ifdef DEBUG_AUDIO
   3.406 -				fprintf(stderr, "errno == EAGAIN written %d\n", written);
   3.407 -				#endif
   3.408 -				towrite -= written; //we wrote some data
   3.409 -				continue;
   3.410 -			}		
   3.411 -			else if((errno == EINVAL) || (errno == EIO)){
   3.412 -				if(errno == EIO){
   3.413 -					#ifdef DEBUG_AUDIO
   3.414 -					fprintf(stderr,"snd_pcm_plugin_write failed EIO: %s\n", snd_strerror(written));
   3.415 -					#endif
   3.416 -				}
   3.417 -				if(errno == EINVAL){
   3.418 -					#ifdef DEBUG_AUDIO
   3.419 -					fprintf(stderr,"snd_pcm_plugin_write failed EINVAL: %s\n", snd_strerror(written));	
   3.420 -					#endif
   3.421 -				}
   3.422 -				
   3.423 -				memset(&cstatus, 0, sizeof(cstatus));
   3.424 -				if( (rval = snd_pcm_plugin_status(audio_handle, &cstatus)) < 0 ){
   3.425 -					#ifdef DEBUG_AUDIO
   3.426 -					fprintf(stderr, "snd_pcm_plugin_status failed %s\n",snd_strerror(rval));
   3.427 -					#endif
   3.428 -					SDL_SetError("snd_pcm_plugin_status failed: %s\n", snd_strerror(rval));
   3.429 -					return;
   3.430 -				}	
   3.431 -		        
   3.432 -				if ( (cstatus.status == SND_PCM_STATUS_UNDERRUN) || (cstatus.status == SND_PCM_STATUS_READY) ){
   3.433 -					#ifdef DEBUG_AUDIO
   3.434 -					fprintf(stderr, "buffer underrun\n");
   3.435 -					#endif
   3.436 -					if ( (rval = snd_pcm_plugin_prepare (audio_handle,SND_PCM_CHANNEL_PLAYBACK)) < 0 ){
   3.437 -						#ifdef DEBUG_AUDIO
   3.438 -						fprintf(stderr, "NTO_PlayAudio: prepare failed %s\n",snd_strerror(rval));
   3.439 -						#endif
   3.440 -						SDL_SetError("snd_pcm_plugin_prepare failed: %s\n",snd_strerror(rval) );
   3.441 -						return;
   3.442 -					}
   3.443 -				}		        		
   3.444 - 				continue;
   3.445 -			}
   3.446 -			else{
   3.447 -				#ifdef DEBUG_AUDIO
   3.448 -				fprintf(stderr, "NTO_PlayAudio: snd_pcm_plugin_write failed unknown errno %d %s\n",errno, snd_strerror(rval));
   3.449 -				#endif
   3.450 -				return;
   3.451 -			}
   3.452 -			
   3.453 -		}
   3.454 -		else
   3.455 -		{
   3.456 -			towrite -= written; //we wrote all remaining data
   3.457 -		}
   3.458 -	} while ( (towrite > 0)  && (this->enabled) );
   3.459 +    /* If we couldn't write, assume fatal error for now */
   3.460 +    if (towrite != 0)
   3.461 +    {
   3.462 +        this->enabled = 0;
   3.463 +    }
   3.464  
   3.465 -	/* If we couldn't write, assume fatal error for now */
   3.466 -	if ( towrite != 0 ) {
   3.467 -		this->enabled = 0;
   3.468 -	}
   3.469 -	return;
   3.470 +    return;
   3.471  }
   3.472  
   3.473 -static Uint8 *NTO_GetAudioBuf(_THIS)
   3.474 +static Uint8* NTO_GetAudioBuf(_THIS)
   3.475  {
   3.476 -	#ifdef DEBUG_AUDIO
   3.477 -	fprintf(stderr, "NTO_GetAudioBuf: pcm_buf %X\n",(Uint8 *)pcm_buf);
   3.478 -	#endif
   3.479 -	return(pcm_buf);
   3.480 +    return pcm_buf;
   3.481  }
   3.482  
   3.483  static void NTO_CloseAudio(_THIS)
   3.484  {
   3.485 -	int rval;
   3.486 +    int rval;
   3.487  
   3.488 -	#ifdef DEBUG_AUDIO
   3.489 -	fprintf(stderr, "NTO_CloseAudio\n");
   3.490 -	#endif
   3.491 +    this->enabled = 0;
   3.492  
   3.493 -	this->enabled = 0;
   3.494 -
   3.495 -	if ( audio_handle != NULL ) {
   3.496 -		if ((rval = snd_pcm_plugin_flush(audio_handle,SND_PCM_CHANNEL_PLAYBACK)) < 0){
   3.497 -			SDL_SetError("snd_pcm_plugin_flush failed: %s\n",snd_strerror(rval));
   3.498 -			return;
   3.499 -		}
   3.500 -		if ((rval = snd_pcm_close(audio_handle)) < 0){
   3.501 -			SDL_SetError("snd_pcm_close failed: %s\n",snd_strerror(rval));
   3.502 -			return;
   3.503 -		}
   3.504 -		audio_handle = NULL;
   3.505 -	}
   3.506 +    if (audio_handle != NULL)
   3.507 +    {
   3.508 +        if ((rval = snd_pcm_plugin_flush(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
   3.509 +        {
   3.510 +            SDL_SetError("NTO_CloseAudio(): snd_pcm_plugin_flush failed: %s\n", snd_strerror(rval));
   3.511 +            return;
   3.512 +        }
   3.513 +        if ((rval = snd_pcm_close(audio_handle)) < 0)
   3.514 +        {
   3.515 +            SDL_SetError("NTO_CloseAudio(): snd_pcm_close failed: %s\n",snd_strerror(rval));
   3.516 +            return;
   3.517 +        }
   3.518 +        audio_handle = NULL;
   3.519 +    }
   3.520  }
   3.521  
   3.522 -static int NTO_OpenAudio(_THIS, SDL_AudioSpec *spec)
   3.523 +static int NTO_OpenAudio(_THIS, SDL_AudioSpec* spec)
   3.524  {
   3.525 -	int rval;
   3.526 -	int format;
   3.527 -	Uint16 test_format;
   3.528 -	int twidth;
   3.529 -	int found;
   3.530 +    int rval;
   3.531 +    int format;
   3.532 +    Uint16 test_format;
   3.533 +    int found;
   3.534  
   3.535 -	#ifdef DEBUG_AUDIO
   3.536 -	fprintf(stderr, "NTO_OpenAudio\n");
   3.537 -	#endif
   3.538 +    audio_handle = NULL;
   3.539 +    this->enabled = 0;
   3.540 +
   3.541 +    if (pcm_buf != NULL)
   3.542 +    {
   3.543 +        SDL_FreeAudioMem(pcm_buf); 
   3.544 +        pcm_buf = NULL;
   3.545 +    }
   3.546 +
   3.547 +    /* initialize channel transfer parameters to default */
   3.548 +    NTO_InitAudioParams(&cparams);
   3.549 +
   3.550 +    /* Open the audio device */
   3.551 +    rval = snd_pcm_open_preferred(&audio_handle, &cardno, &deviceno, OPEN_FLAGS);
   3.552 +    if (rval < 0)
   3.553 +    {
   3.554 +        SDL_SetError("NTO_OpenAudio(): snd_pcm_open failed: %s\n", snd_strerror(rval));
   3.555 +        return (-1);
   3.556 +    }
   3.557 +
   3.558 +    if (!NTO_CheckBuggyCards(this, QSA_MMAP_WORKAROUND))
   3.559 +    {
   3.560 +        /* enable count status parameter */
   3.561 +        if ((rval = snd_pcm_plugin_set_disable(audio_handle, PLUGIN_DISABLE_MMAP)) < 0)
   3.562 +        {
   3.563 +            SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n", snd_strerror(rval));
   3.564 +            return (-1);
   3.565 +        }
   3.566 +    }
   3.567 +
   3.568 +    /* Try for a closest match on audio format */
   3.569 +    format = 0;
   3.570 +    /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */
   3.571 +    found = 0;
   3.572 +
   3.573 +    for (test_format=SDL_FirstAudioFormat(spec->format); !found ;)
   3.574 +    {
   3.575 +        /* if match found set format to equivalent ALSA format */
   3.576 +        switch (test_format)
   3.577 +        {
   3.578 +            case AUDIO_U8:
   3.579 +                           format = SND_PCM_SFMT_U8;
   3.580 +                           found = 1;
   3.581 +                           break;
   3.582 +            case AUDIO_S8:
   3.583 +                           format = SND_PCM_SFMT_S8;
   3.584 +                           found = 1;
   3.585 +                           break;
   3.586 +            case AUDIO_S16LSB:
   3.587 +                           format = SND_PCM_SFMT_S16_LE;
   3.588 +                           found = 1;
   3.589 +                           break;
   3.590 +            case AUDIO_S16MSB:
   3.591 +                           format = SND_PCM_SFMT_S16_BE;
   3.592 +                           found = 1;
   3.593 +                           break;
   3.594 +            case AUDIO_U16LSB:
   3.595 +                           format = SND_PCM_SFMT_U16_LE;
   3.596 +                           found = 1;
   3.597 +                           break;
   3.598 +            case AUDIO_U16MSB:
   3.599 +                           format = SND_PCM_SFMT_U16_BE;
   3.600 +                           found = 1;
   3.601 +                           break;
   3.602 +            default:
   3.603 +                           break;
   3.604 +        }
   3.605 +
   3.606 +        if (!found)
   3.607 +        {
   3.608 +            test_format = SDL_NextAudioFormat();
   3.609 +        }
   3.610 +    }
   3.611 +
   3.612 +    /* assumes test_format not 0 on success */
   3.613 +    if (test_format == 0)
   3.614 +    {
   3.615 +        SDL_SetError("NTO_OpenAudio(): Couldn't find any hardware audio formats");
   3.616 +        return (-1);
   3.617 +    }
   3.618 +
   3.619 +    spec->format = test_format;
   3.620 +
   3.621 +    /* Set the audio format */
   3.622 +    cparams.format.format = format;
   3.623 +
   3.624 +    /* Set mono or stereo audio (currently only two channels supported) */
   3.625 +    cparams.format.voices = spec->channels;
   3.626  	
   3.627 -	audio_handle = NULL;
   3.628 -	this->enabled = 0;
   3.629 +    /* Set rate */
   3.630 +    cparams.format.rate = spec->freq;
   3.631  
   3.632 -	if ( pcm_buf != NULL ) {
   3.633 -		free((Uint8 *)pcm_buf); 
   3.634 -		pcm_buf = NULL;
   3.635 -	}
   3.636 -	 
   3.637 -	/* initialize channel transfer parameters to default */
   3.638 -	init_pcm_cparams(&cparams);
   3.639 +    /* Setup the transfer parameters according to cparams */
   3.640 +    rval = snd_pcm_plugin_params(audio_handle, &cparams);
   3.641 +    if (rval < 0)
   3.642 +    {
   3.643 +        SDL_SetError("NTO_OpenAudio(): snd_pcm_channel_params failed: %s\n", snd_strerror(rval));
   3.644 +        return (-1);
   3.645 +    }
   3.646  
   3.647 -	/* Open the audio device */
   3.648 -	rval = snd_pcm_open_preferred(&audio_handle, NULL, NULL, OPEN_FLAGS);
   3.649 -	if ( rval < 0 ) {
   3.650 -		SDL_SetError("snd_pcm_open failed: %s\n", snd_strerror(rval));
   3.651 -		return(-1);
   3.652 -	}
   3.653 +    /* Make sure channel is setup right one last time */
   3.654 +    memset(&csetup, 0x00, sizeof(csetup));
   3.655 +    csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
   3.656 +    if (snd_pcm_plugin_setup(audio_handle, &csetup) < 0)
   3.657 +    {
   3.658 +        SDL_SetError("NTO_OpenAudio(): Unable to setup playback channel\n");
   3.659 +        return -1;
   3.660 +    }
   3.661  
   3.662 -	/* enable count status parameter */
   3.663 -	if ((rval = snd_pcm_plugin_set_disable(audio_handle, PLUGIN_DISABLE_MMAP))<0){
   3.664 -		SDL_SetError("snd_pcm_plugin_set_disable failed: %s\n", snd_strerror(rval));
   3.665 -		return(-1);
   3.666 -	}
   3.667  
   3.668 -	/* Try for a closest match on audio format */
   3.669 -	format = 0;
   3.670 - 	found = 0; /* can't use format as SND_PCM_SFMT_U8 = 0 in nto */
   3.671 -	for ( test_format = SDL_FirstAudioFormat(spec->format);	!found ; ) 
   3.672 -	{
   3.673 -		#ifdef DEBUG_AUDIO
   3.674 -		fprintf(stderr, "Trying format 0x%4.4x spec->samples %d\n", test_format,spec->samples);
   3.675 -		#endif
   3.676 -		
   3.677 -		/* if match found set format to equivalent ALSA format */
   3.678 -		switch ( test_format ) {
   3.679 -			case AUDIO_U8:
   3.680 -				format = SND_PCM_SFMT_U8;
   3.681 -				found = 1;
   3.682 -				break;
   3.683 -			case AUDIO_S8:
   3.684 -				format = SND_PCM_SFMT_S8;
   3.685 -				found = 1;
   3.686 -				break;
   3.687 -			case AUDIO_S16LSB:
   3.688 -				format = SND_PCM_SFMT_S16_LE;
   3.689 -				found = 1;
   3.690 -				break;
   3.691 -			case AUDIO_S16MSB:
   3.692 -				format = SND_PCM_SFMT_S16_BE;
   3.693 -				found = 1;
   3.694 -				break;
   3.695 -			case AUDIO_U16LSB:
   3.696 -				format = SND_PCM_SFMT_U16_LE;
   3.697 -				found = 1;
   3.698 -				break;
   3.699 -			case AUDIO_U16MSB:
   3.700 -				format = SND_PCM_SFMT_U16_BE;
   3.701 -				found = 1;
   3.702 -				break;
   3.703 -			default:
   3.704 -				break;
   3.705 -		}
   3.706 -		if ( ! found ) {
   3.707 -			test_format = SDL_NextAudioFormat();
   3.708 -		}
   3.709 -	}
   3.710 +    /* Calculate the final parameters for this audio specification */
   3.711 +    SDL_CalculateAudioSpec(spec);
   3.712  
   3.713 -	/* assumes test_format not 0 on success */
   3.714 -	if ( test_format == 0 ) {
   3.715 -		SDL_SetError("Couldn't find any hardware audio formats");
   3.716 -		return(-1);
   3.717 -	}
   3.718 +    pcm_len = spec->size;
   3.719  
   3.720 -	spec->format = test_format;
   3.721 +    if (pcm_len==0)
   3.722 +    {
   3.723 +        pcm_len = csetup.buf.block.frag_size * spec->channels * (snd_pcm_format_width(format)/8);
   3.724 +    }
   3.725  
   3.726 -	/* Set the audio format */
   3.727 -	cparams.format.format = format;
   3.728 +    /* Allocate memory to the audio buffer and initialize with silence (Note that
   3.729 +       buffer size must be a multiple of fragment size, so find closest multiple)
   3.730 +    */
   3.731 +    pcm_buf = (Uint8*)SDL_AllocAudioMem(pcm_len);
   3.732 +    if (pcm_buf == NULL)
   3.733 +    {
   3.734 +        SDL_SetError("NTO_OpenAudio(): pcm buffer allocation failed\n");
   3.735 +        return (-1);
   3.736 +    }
   3.737 +    memset(pcm_buf, spec->silence, pcm_len);
   3.738  
   3.739 -	/* Set mono or stereo audio (currently only two channels supported) */
   3.740 -	cparams.format.voices = spec->channels;
   3.741 -	
   3.742 -	#ifdef DEBUG_AUDIO
   3.743 -	fprintf(stderr,"intializing channels %d\n", cparams.format.voices);
   3.744 -	#endif
   3.745 +    /* get the file descriptor */
   3.746 +    if ((audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0)
   3.747 +    {
   3.748 +        SDL_SetError("NTO_OpenAudio(): snd_pcm_file_descriptor failed with error code: %s\n", snd_strerror(rval));
   3.749 +        return (-1);
   3.750 +    }
   3.751  
   3.752 -	/* Set rate */
   3.753 -	cparams.format.rate = spec->freq ;
   3.754 +    /* Trigger audio playback */
   3.755 +    rval = snd_pcm_plugin_prepare(audio_handle, SND_PCM_CHANNEL_PLAYBACK);
   3.756 +    if (rval < 0)
   3.757 +    {
   3.758 +        SDL_SetError("snd_pcm_plugin_prepare failed: %s\n", snd_strerror(rval));
   3.759 +        return (-1);
   3.760 +    }
   3.761  
   3.762 -	/* Setup the transfer parameters according to cparams */
   3.763 -	rval = snd_pcm_plugin_params(audio_handle, &cparams);
   3.764 -	if (rval < 0) {
   3.765 -		SDL_SetError("snd_pcm_channel_params failed: %s\n", snd_strerror (rval));
   3.766 -		return(-1);
   3.767 -	}
   3.768 +    this->enabled = 1;
   3.769  
   3.770 -	/*  Make sure channel is setup right one last time */
   3.771 -	memset( &csetup, 0, sizeof( csetup ) );
   3.772 -	csetup.channel = SND_PCM_CHANNEL_PLAYBACK;
   3.773 -	if ( snd_pcm_plugin_setup( audio_handle, &csetup ) < 0 )
   3.774 -	{
   3.775 -		SDL_SetError("Unable to setup playback channel\n" );
   3.776 -		return(-1);
   3.777 -	}
   3.778 -	else
   3.779 -	{
   3.780 -		#ifdef DEBUG_AUDIO
   3.781 -		fprintf(stderr,"requested format: %d\n",cparams.format.format);
   3.782 -		fprintf(stderr,"requested frag size: %d\n",cparams.buf.block.frag_size);
   3.783 -		fprintf(stderr,"requested max frags: %d\n\n",cparams.buf.block.frags_max);
   3.784 +    /* Get the parent process id (we're the parent of the audio thread) */
   3.785 +    parent = getpid();
   3.786  
   3.787 -		fprintf(stderr,"real format: %d\n", csetup.format.format );
   3.788 -		fprintf(stderr,"real frag size : %d\n", csetup.buf.block.frag_size );
   3.789 -		fprintf(stderr,"real max frags : %d\n", csetup.buf.block.frags_max );
   3.790 -		#endif
   3.791 -	}
   3.792 -
   3.793 -	/*
   3.794 -		Allocate memory to the audio buffer and initialize with silence (Note that
   3.795 -		buffer size must be a multiple of fragment size, so find closest multiple)
   3.796 -	*/
   3.797 -	
   3.798 -	twidth = snd_pcm_format_width(format);
   3.799 -	if (twidth < 0) {
   3.800 -		printf("snd_pcm_format_width failed\n");
   3.801 -		twidth = 0;
   3.802 -	}
   3.803 -
   3.804 -	#ifdef DEBUG_AUDIO
   3.805 -	fprintf(stderr,"format is %d bits wide\n",twidth);
   3.806 -	#endif
   3.807 -
   3.808 -	pcm_len = spec->size ;
   3.809 -	
   3.810 -	#ifdef DEBUG_AUDIO
   3.811 -	fprintf(stderr,"pcm_len set to %d\n", pcm_len);
   3.812 -	#endif
   3.813 -
   3.814 -	if (pcm_len == 0){
   3.815 -		pcm_len = csetup.buf.block.frag_size;
   3.816 -	}
   3.817 -
   3.818 -	pcm_buf = (Uint8*)malloc(pcm_len);
   3.819 -	if (pcm_buf == NULL) {
   3.820 -		SDL_SetError("pcm_buf malloc failed\n");
   3.821 -		return(-1);
   3.822 -	}
   3.823 -	memset(pcm_buf,spec->silence,pcm_len);
   3.824 -
   3.825 -	#ifdef DEBUG_AUDIO
   3.826 -	fprintf(stderr,"pcm_buf malloced and silenced.\n");
   3.827 -	#endif
   3.828 -
   3.829 -	/* get the file descriptor */
   3.830 -	if( (audio_fd = snd_pcm_file_descriptor(audio_handle, SND_PCM_CHANNEL_PLAYBACK)) < 0){
   3.831 -		fprintf(stderr, "snd_pcm_file_descriptor failed with error code: %d\n", audio_fd);
   3.832 -	}
   3.833 -
   3.834 -	/* Trigger audio playback */
   3.835 -	rval = snd_pcm_plugin_prepare( audio_handle, SND_PCM_CHANNEL_PLAYBACK);
   3.836 -	if (rval < 0) {
   3.837 -		SDL_SetError("snd_pcm_plugin_prepare failed: %s\n", snd_strerror (rval));
   3.838 -		return(-1);
   3.839 -	}
   3.840 -
   3.841 -	this->enabled = 1;
   3.842 -
   3.843 -	/* Get the parent process id (we're the parent of the audio thread) */
   3.844 -	parent = getpid();
   3.845 -
   3.846 -	/* We're ready to rock and roll. :-) */
   3.847 -	return(0);
   3.848 +    /* We're really ready to rock and roll. :-) */
   3.849 +    return (0);
   3.850  }
     4.1 --- a/src/audio/nto/SDL_nto_audio.h	Mon Sep 15 13:51:25 2003 +0000
     4.2 +++ b/src/audio/nto/SDL_nto_audio.h	Sun Sep 21 18:13:48 2003 +0000
     4.3 @@ -20,36 +20,47 @@
     4.4      slouken@libsdl.org
     4.5  */
     4.6  
     4.7 -#ifndef _NTO_PCM_audio_h
     4.8 -#define _NTO_PCM_audio_h
     4.9 +#ifndef __SDL_NTO_AUDIO_H__
    4.10 +#define __SDL_NTO_AUDIO_H__
    4.11  
    4.12  #include "SDL_sysaudio.h"
    4.13  #include <sys/asoundlib.h>
    4.14  
    4.15 -/* Hidden "this" pointer for the video functions */
    4.16 +/* Hidden "this" pointer for the audio functions */
    4.17  #define _THIS	SDL_AudioDevice *this
    4.18  
    4.19 -struct SDL_PrivateAudioData {
    4.20 -	/* The audio device handle */
    4.21 -	 snd_pcm_t *audio_handle;
    4.22 +struct SDL_PrivateAudioData
    4.23 +{
    4.24 +    /* The audio device handle */
    4.25 +    int cardno;
    4.26 +    int deviceno;
    4.27 +    snd_pcm_t* audio_handle;
    4.28  
    4.29 -	/* The audio file descriptor */
    4.30 -	int audio_fd;
    4.31 +    /* The audio file descriptor */
    4.32 +    int audio_fd;
    4.33  
    4.34 -	/* The parent process id, to detect when application quits */
    4.35 -	pid_t parent;
    4.36 +    /* The parent process id, to detect when application quits */
    4.37 +    pid_t parent;
    4.38  
    4.39 -	/* Raw mixing buffer */
    4.40 -	Uint8 *pcm_buf;
    4.41 -	int    pcm_len;
    4.42 +    /* Raw mixing buffer */
    4.43 +    Uint8* pcm_buf;
    4.44 +    Uint32 pcm_len;
    4.45 +
    4.46 +    /* QSA parameters */
    4.47 +    snd_pcm_channel_status_t cstatus;
    4.48 +    snd_pcm_channel_params_t cparams;
    4.49 +    snd_pcm_channel_setup_t  csetup;
    4.50  };
    4.51 -#define FUDGE_TICKS	10	/* The scheduler overhead ticks per frame */
    4.52  
    4.53 -/* Old variable names */
    4.54 -#define audio_handle	(this->hidden->audio_handle)
    4.55 -#define audio_fd		(this->hidden->audio_fd)
    4.56 -#define parent			(this->hidden->parent)
    4.57 -#define pcm_buf			(this->hidden->pcm_buf)
    4.58 -#define pcm_len			(this->hidden->pcm_len)
    4.59 +#define cardno          (this->hidden->cardno)
    4.60 +#define deviceno        (this->hidden->deviceno)
    4.61 +#define audio_handle    (this->hidden->audio_handle)
    4.62 +#define audio_fd        (this->hidden->audio_fd)
    4.63 +#define parent          (this->hidden->parent)
    4.64 +#define pcm_buf         (this->hidden->pcm_buf)
    4.65 +#define pcm_len         (this->hidden->pcm_len)
    4.66 +#define cstatus         (this->hidden->cstatus)
    4.67 +#define cparams         (this->hidden->cparams)
    4.68 +#define csetup          (this->hidden->csetup)
    4.69  
    4.70 -#endif /* _NTO_PCM_audio_h */
    4.71 +#endif /* __SDL_NTO_AUDIO_H__ */
     5.1 --- a/src/video/photon/SDL_ph_video.c	Mon Sep 15 13:51:25 2003 +0000
     5.2 +++ b/src/video/photon/SDL_ph_video.c	Sun Sep 21 18:13:48 2003 +0000
     5.3 @@ -64,19 +64,23 @@
     5.4  static int   ph_GL_MakeCurrent(_THIS);
     5.5  #endif /* HAVE_OPENGL */
     5.6  
     5.7 +static int phstatus=-1;
     5.8 +
     5.9  static int ph_Available(void)
    5.10  {
    5.11 -    int phstat=-1;
    5.12 -
    5.13 -    phstat=PtInit(0);
    5.14 -    if (phstat==0)
    5.15 +    if (phstatus==-1)
    5.16      {
    5.17 -       return 1;
    5.18 +        phstatus=PtInit(NULL);
    5.19 +        if (phstatus==0)
    5.20 +        {
    5.21 +           return 1;
    5.22 +        }
    5.23 +        else
    5.24 +        {
    5.25 +           return 0;
    5.26 +        }
    5.27      }
    5.28 -    else
    5.29 -    {
    5.30 -       return 0;
    5.31 -    }
    5.32 +    return 1;
    5.33  }
    5.34  
    5.35  static SDL_VideoDevice *ph_CreateDevice(int devindex)