Moved more audio drivers to 1.3 API (all 5 MiNT backends, BSD, IRIX...), and SDL-ryan-multiple-audio-device
authorRyan C. Gordon <icculus@icculus.org>
Sat, 07 Oct 2006 05:36:36 +0000
branchSDL-ryan-multiple-audio-device
changeset 38201f156fd874fa
parent 3819 b225d9820ee3
child 3821 18393b045759
Moved more audio drivers to 1.3 API (all 5 MiNT backends, BSD, IRIX...), and
some other tweaks in already-converted drivers.
src/audio/bsd/SDL_bsdaudio.c
src/audio/bsd/SDL_bsdaudio.h
src/audio/dmedia/SDL_irixaudio.c
src/audio/dmedia/SDL_irixaudio.h
src/audio/dsp/SDL_dspaudio.c
src/audio/macrom/SDL_romaudio.c
src/audio/mint/SDL_mintaudio_dma8.c
src/audio/mint/SDL_mintaudio_gsxb.c
src/audio/mint/SDL_mintaudio_mcsn.c
src/audio/mint/SDL_mintaudio_stfa.c
src/audio/mint/SDL_mintaudio_xbios.c
     1.1 --- a/src/audio/bsd/SDL_bsdaudio.c	Fri Oct 06 20:36:23 2006 +0000
     1.2 +++ b/src/audio/bsd/SDL_bsdaudio.c	Sat Oct 07 05:36:36 2006 +0000
     1.3 @@ -61,195 +61,102 @@
     1.4  /* #define DEBUG_AUDIO_STREAM */
     1.5  
     1.6  #ifdef USE_BLOCKING_WRITES
     1.7 -#define OPEN_FLAGS	O_WRONLY
     1.8 +#define OPEN_FLAGS_OUTPUT O_WRONLY
     1.9 +#define OPEN_FLAGS_INPUT O_RDONLY
    1.10  #else
    1.11 -#define OPEN_FLAGS	(O_WRONLY|O_NONBLOCK)
    1.12 -#endif
    1.13 -
    1.14 -/* Audio driver functions */
    1.15 -static void OBSD_WaitAudio(_THIS);
    1.16 -static int OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec);
    1.17 -static void OBSD_PlayAudio(_THIS);
    1.18 -static Uint8 *OBSD_GetAudioBuf(_THIS);
    1.19 -static void OBSD_CloseAudio(_THIS);
    1.20 -
    1.21 -#ifdef DEBUG_AUDIO
    1.22 -static void OBSD_Status(_THIS);
    1.23 +#define OPEN_FLAGS_OUTPUT (O_WRONLY|O_NONBLOCK)
    1.24 +#define OPEN_FLAGS_INPUT (O_RDONLY|O_NONBLOCK)
    1.25  #endif
    1.26  
    1.27 -/* Audio driver bootstrap functions */
    1.28 -
    1.29 -static int
    1.30 -Audio_Available(void)
    1.31 -{
    1.32 -    int fd;
    1.33 -    int available;
    1.34 +/* !!! FIXME: so much cut and paste with dsp/dma drivers... */
    1.35 +static char **outputDevices = NULL;
    1.36 +static int outputDeviceCount = 0;
    1.37 +static char **inputDevices = NULL;
    1.38 +static int inputDeviceCount = 0;
    1.39  
    1.40 -    available = 0;
    1.41 -    fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
    1.42 -    if (fd >= 0) {
    1.43 -        available = 1;
    1.44 -        close(fd);
    1.45 -    }
    1.46 -    return (available);
    1.47 +static inline void
    1.48 +free_device_list(char ***devs, int *count)
    1.49 +{
    1.50 +    SDL_FreeUnixAudioDevices(devs, count);
    1.51  }
    1.52  
    1.53 -static void
    1.54 -Audio_DeleteDevice(SDL_AudioDevice * device)
    1.55 +static inline void
    1.56 +build_device_list(int iscapture, char ***devs, int *count)
    1.57  {
    1.58 -    SDL_free(device->hidden);
    1.59 -    SDL_free(device);
    1.60 +    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
    1.61 +    free_device_list(devs, count);
    1.62 +    SDL_EnumUnixAudioDevices(flags, 0, NULL, devs, count);
    1.63  }
    1.64  
    1.65 -static SDL_AudioDevice *
    1.66 -Audio_CreateDevice(int devindex)
    1.67 +static inline void
    1.68 +build_device_lists(void)
    1.69  {
    1.70 -    SDL_AudioDevice *this;
    1.71 +    build_device_list(0, &outputDevices, &outputDeviceCount);
    1.72 +    build_device_list(1, &inputDevices, &inputDeviceCount);
    1.73 +}
    1.74  
    1.75 -    /* Initialize all variables that we clean on shutdown */
    1.76 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    1.77 -    if (this) {
    1.78 -        SDL_memset(this, 0, (sizeof *this));
    1.79 -        this->hidden = (struct SDL_PrivateAudioData *)
    1.80 -            SDL_malloc((sizeof *this->hidden));
    1.81 -    }
    1.82 -    if ((this == NULL) || (this->hidden == NULL)) {
    1.83 -        SDL_OutOfMemory();
    1.84 -        if (this)
    1.85 -            SDL_free(this);
    1.86 -        return (0);
    1.87 -    }
    1.88 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    1.89 -    audio_fd = -1;
    1.90  
    1.91 -    /* Set the function pointers */
    1.92 -    this->OpenAudio = OBSD_OpenAudio;
    1.93 -    this->WaitAudio = OBSD_WaitAudio;
    1.94 -    this->PlayAudio = OBSD_PlayAudio;
    1.95 -    this->GetAudioBuf = OBSD_GetAudioBuf;
    1.96 -    this->CloseAudio = OBSD_CloseAudio;
    1.97 -
    1.98 -    this->free = Audio_DeleteDevice;
    1.99 -
   1.100 -    return this;
   1.101 +static inline void
   1.102 +free_device_lists(void)
   1.103 +{
   1.104 +    free_device_list(&outputDevices, &outputDeviceCount);
   1.105 +    free_device_list(&inputDevices, &inputDeviceCount);
   1.106  }
   1.107  
   1.108 -AudioBootStrap BSD_AUDIO_bootstrap = {
   1.109 -    BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
   1.110 -    Audio_Available, Audio_CreateDevice, 0
   1.111 -};
   1.112 -
   1.113 -/* This function waits until it is possible to write a full sound buffer */
   1.114 -static void
   1.115 -OBSD_WaitAudio(_THIS)
   1.116 -{
   1.117 -#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
   1.118 -    /* See if we need to use timed audio synchronization */
   1.119 -    if (frame_ticks) {
   1.120 -        /* Use timer for general audio synchronization */
   1.121 -        Sint32 ticks;
   1.122 -
   1.123 -        ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
   1.124 -        if (ticks > 0) {
   1.125 -            SDL_Delay(ticks);
   1.126 -        }
   1.127 -    } else {
   1.128 -        /* Use select() for audio synchronization */
   1.129 -        fd_set fdset;
   1.130 -        struct timeval timeout;
   1.131  
   1.132 -        FD_ZERO(&fdset);
   1.133 -        FD_SET(audio_fd, &fdset);
   1.134 -        timeout.tv_sec = 10;
   1.135 -        timeout.tv_usec = 0;
   1.136 -#ifdef DEBUG_AUDIO
   1.137 -        fprintf(stderr, "Waiting for audio to get ready\n");
   1.138 -#endif
   1.139 -        if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
   1.140 -            const char *message =
   1.141 -                "Audio timeout - buggy audio driver? (disabled)";
   1.142 -            /* In general we should never print to the screen,
   1.143 -               but in this case we have no other way of letting
   1.144 -               the user know what happened.
   1.145 -             */
   1.146 -            fprintf(stderr, "SDL: %s\n", message);
   1.147 -            this->enabled = 0;
   1.148 -            /* Don't try to close - may hang */
   1.149 -            audio_fd = -1;
   1.150 -#ifdef DEBUG_AUDIO
   1.151 -            fprintf(stderr, "Done disabling audio\n");
   1.152 -#endif
   1.153 -        }
   1.154 -#ifdef DEBUG_AUDIO
   1.155 -        fprintf(stderr, "Ready!\n");
   1.156 -#endif
   1.157 -    }
   1.158 -#endif /* !USE_BLOCKING_WRITES */
   1.159 +static int
   1.160 +BSDAUDIO_Available(void)
   1.161 +{
   1.162 +    int available = 0;
   1.163 +    build_device_lists();
   1.164 +    available = ((outputDeviceCount > 0) || (inputDeviceCount > 0));
   1.165 +    free_device_lists();
   1.166 +    return available;
   1.167  }
   1.168  
   1.169 +
   1.170  static void
   1.171 -OBSD_PlayAudio(_THIS)
   1.172 +BSDAUDIO_Deinitialize(void)
   1.173  {
   1.174 -    int written, p = 0;
   1.175 +    free_device_lists();
   1.176 +}
   1.177 +
   1.178  
   1.179 -    /* Write the audio data, checking for EAGAIN on broken audio drivers */
   1.180 -    do {
   1.181 -        written = write(audio_fd, &mixbuf[p], mixlen - p);
   1.182 -        if (written > 0)
   1.183 -            p += written;
   1.184 -        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
   1.185 -            /* Non recoverable error has occurred. It should be reported!!! */
   1.186 -            perror("audio");
   1.187 -            break;
   1.188 -        }
   1.189 -
   1.190 -        if (p < written
   1.191 -            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
   1.192 -            SDL_Delay(1);       /* Let a little CPU time go by */
   1.193 -        }
   1.194 -    }
   1.195 -    while (p < written);
   1.196 -
   1.197 -    /* If timer synchronization is enabled, set the next write frame */
   1.198 -    if (frame_ticks) {
   1.199 -        next_frame += frame_ticks;
   1.200 +static int
   1.201 +BSDAUDIO_DetectDevices(int iscapture)
   1.202 +{
   1.203 +    if (iscapture) {
   1.204 +        build_device_list(1, &inputDevices, &inputDeviceCount);
   1.205 +        return inputDeviceCount;
   1.206 +    } else {
   1.207 +        build_device_list(0, &outputDevices, &outputDeviceCount);
   1.208 +        return outputDeviceCount;
   1.209      }
   1.210  
   1.211 -    /* If we couldn't write, assume fatal error for now */
   1.212 -    if (written < 0) {
   1.213 -        this->enabled = 0;
   1.214 -    }
   1.215 -#ifdef DEBUG_AUDIO
   1.216 -    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
   1.217 -#endif
   1.218 +    return 0;  /* shouldn't ever hit this. */
   1.219  }
   1.220  
   1.221 -static Uint8 *
   1.222 -OBSD_GetAudioBuf(_THIS)
   1.223 +static const char *
   1.224 +BSDAUDIO_GetDeviceName(int index, int iscapture)
   1.225  {
   1.226 -    return (mixbuf);
   1.227 +    if ((iscapture) && (index < inputDeviceCount)) {
   1.228 +        return inputDevices[index];
   1.229 +    } else if ((!iscapture) && (index < outputDeviceCount)) {
   1.230 +        return outputDevices[index];
   1.231 +    }
   1.232 +
   1.233 +    SDL_SetError("No such device");
   1.234 +    return NULL;
   1.235  }
   1.236  
   1.237 +
   1.238  static void
   1.239 -OBSD_CloseAudio(_THIS)
   1.240 +BSDAUDIO_Status(_THIS)
   1.241  {
   1.242 -    if (mixbuf != NULL) {
   1.243 -        SDL_FreeAudioMem(mixbuf);
   1.244 -        mixbuf = NULL;
   1.245 -    }
   1.246 -    if (audio_fd >= 0) {
   1.247 -        close(audio_fd);
   1.248 -        audio_fd = -1;
   1.249 -    }
   1.250 -}
   1.251 -
   1.252  #ifdef DEBUG_AUDIO
   1.253 -void
   1.254 -OBSD_Status(_THIS)
   1.255 -{
   1.256      audio_info_t info;
   1.257  
   1.258 -    if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
   1.259 +    if (ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info) < 0) {
   1.260          fprintf(stderr, "AUDIO_GETINFO failed.\n");
   1.261          return;
   1.262      }
   1.263 @@ -296,42 +203,170 @@
   1.264              (info.mode == AUMODE_PLAY) ? "PLAY"
   1.265              : (info.mode = AUMODE_RECORD) ? "RECORD"
   1.266              : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
   1.267 +#endif /* DEBUG_AUDIO */
   1.268  }
   1.269 -#endif /* DEBUG_AUDIO */
   1.270 +
   1.271 +
   1.272 +/* This function waits until it is possible to write a full sound buffer */
   1.273 +static void
   1.274 +BSDAUDIO_WaitDevice(_THIS)
   1.275 +{
   1.276 +#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
   1.277 +    /* See if we need to use timed audio synchronization */
   1.278 +    if (this->hidden->frame_ticks) {
   1.279 +        /* Use timer for general audio synchronization */
   1.280 +        Sint32 ticks;
   1.281 +
   1.282 +        ticks = ((Sint32)(this->hidden->next_frame-SDL_GetTicks()))-FUDGE_TICKS;
   1.283 +        if (ticks > 0) {
   1.284 +            SDL_Delay(ticks);
   1.285 +        }
   1.286 +    } else {
   1.287 +        /* Use select() for audio synchronization */
   1.288 +        fd_set fdset;
   1.289 +        struct timeval timeout;
   1.290 +
   1.291 +        FD_ZERO(&fdset);
   1.292 +        FD_SET(this->hidden->audio_fd, &fdset);
   1.293 +        timeout.tv_sec = 10;
   1.294 +        timeout.tv_usec = 0;
   1.295 +#ifdef DEBUG_AUDIO
   1.296 +        fprintf(stderr, "Waiting for audio to get ready\n");
   1.297 +#endif
   1.298 +        if (select(this->hidden->audio_fd+1,NULL,&fdset,NULL,&timeout) <= 0) {
   1.299 +            const char *message =
   1.300 +                "Audio timeout - buggy audio driver? (disabled)";
   1.301 +            /* In general we should never print to the screen,
   1.302 +               but in this case we have no other way of letting
   1.303 +               the user know what happened.
   1.304 +             */
   1.305 +            fprintf(stderr, "SDL: %s\n", message);
   1.306 +            this->enabled = 0;
   1.307 +            /* Don't try to close - may hang */
   1.308 +            this->hidden->audio_fd = -1;
   1.309 +#ifdef DEBUG_AUDIO
   1.310 +            fprintf(stderr, "Done disabling audio\n");
   1.311 +#endif
   1.312 +        }
   1.313 +#ifdef DEBUG_AUDIO
   1.314 +        fprintf(stderr, "Ready!\n");
   1.315 +#endif
   1.316 +    }
   1.317 +#endif /* !USE_BLOCKING_WRITES */
   1.318 +}
   1.319 +
   1.320 +static void
   1.321 +BSDAUDIO_PlayDevice(_THIS)
   1.322 +{
   1.323 +    int written, p = 0;
   1.324 +
   1.325 +    /* Write the audio data, checking for EAGAIN on broken audio drivers */
   1.326 +    do {
   1.327 +        written = write(this->hidden->audio_fd,
   1.328 +                        &this->hidden->mixbuf[p],
   1.329 +                        this->hidden->mixlen - p);
   1.330 +
   1.331 +        if (written > 0)
   1.332 +            p += written;
   1.333 +        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
   1.334 +            /* Non recoverable error has occurred. It should be reported!!! */
   1.335 +            perror("audio");
   1.336 +            break;
   1.337 +        }
   1.338 +
   1.339 +        if (p < written
   1.340 +            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
   1.341 +            SDL_Delay(1);       /* Let a little CPU time go by */
   1.342 +        }
   1.343 +    }
   1.344 +    while (p < written);
   1.345 +
   1.346 +    /* If timer synchronization is enabled, set the next write frame */
   1.347 +    if (this->hidden->frame_ticks) {
   1.348 +        this->hidden->next_frame += this->hidden->frame_ticks;
   1.349 +    }
   1.350 +
   1.351 +    /* If we couldn't write, assume fatal error for now */
   1.352 +    if (written < 0) {
   1.353 +        this->enabled = 0;
   1.354 +    }
   1.355 +#ifdef DEBUG_AUDIO
   1.356 +    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
   1.357 +#endif
   1.358 +}
   1.359 +
   1.360 +static Uint8 *
   1.361 +BSDAUDIO_GetDeviceBuf(_THIS)
   1.362 +{
   1.363 +    return (this->hidden->mixbuf);
   1.364 +}
   1.365 +
   1.366 +static void
   1.367 +BSDAUDIO_CloseDevice(_THIS)
   1.368 +{
   1.369 +    if (this->hidden != NULL) {
   1.370 +        if (this->hidden->mixbuf != NULL) {
   1.371 +            SDL_FreeAudioMem(this->hidden->mixbuf);
   1.372 +            this->hidden->mixbuf = NULL;
   1.373 +        }
   1.374 +        if (this->hidden->audio_fd >= 0) {
   1.375 +            close(this->hidden->audio_fd);
   1.376 +            this->hidden->audio_fd = -1;
   1.377 +        }
   1.378 +        SDL_free(this->hidden);
   1.379 +        this->hidden = NULL;
   1.380 +    }
   1.381 +}
   1.382  
   1.383  static int
   1.384 -OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec)
   1.385 +BSDAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
   1.386  {
   1.387 -    char audiodev[64];
   1.388 -    SDL_AudioFormat format;
   1.389 +    const int flags = ((iscapture) ? OPEN_FLAGS_INPUT : OPEN_FLAGS_OUTPUT);
   1.390 +    SDL_AudioFormat format = 0;
   1.391      audio_info_t info;
   1.392  
   1.393 +    /* We don't care what the devname is...we'll try to open anything. */
   1.394 +    /*  ...but default to first name in the list... */
   1.395 +    if (devname == NULL) {
   1.396 +        if ( ((iscapture) && (inputDeviceCount == 0)) ||
   1.397 +             ((!iscapture) && (outputDeviceCount == 0)) ) {
   1.398 +            SDL_SetError("No such audio device");
   1.399 +            return 0;
   1.400 +        }
   1.401 +        devname = ((iscapture) ? inputDevices[0] : outputDevices[0]);
   1.402 +    }
   1.403 +
   1.404 +    /* Initialize all variables that we clean on shutdown */
   1.405 +    this->hidden = (struct SDL_PrivateAudioData *)
   1.406 +                        SDL_malloc((sizeof *this->hidden));
   1.407 +    if (this->hidden == NULL) {
   1.408 +        SDL_OutOfMemory();
   1.409 +        return 0;
   1.410 +    }
   1.411 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   1.412 +
   1.413 +    /* Open the audio device */
   1.414 +    this->hidden->audio_fd = open(devname, flags, 0);
   1.415 +    if (this->hidden->audio_fd < 0) {
   1.416 +        SDL_SetError("Couldn't open %s: %s", devname, strerror(errno));
   1.417 +        return 0;
   1.418 +    }
   1.419 +
   1.420      AUDIO_INITINFO(&info);
   1.421  
   1.422      /* Calculate the final parameters for this audio specification */
   1.423 -    SDL_CalculateAudioSpec(spec);
   1.424 -
   1.425 -#ifdef USE_TIMER_SYNC
   1.426 -    frame_ticks = 0.0;
   1.427 -#endif
   1.428 -
   1.429 -    /* Open the audio device */
   1.430 -    audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
   1.431 -    if (audio_fd < 0) {
   1.432 -        SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
   1.433 -        return (-1);
   1.434 -    }
   1.435 +    SDL_CalculateAudioSpec(&this->spec);
   1.436  
   1.437      /* Set to play mode */
   1.438      info.mode = AUMODE_PLAY;
   1.439 -    if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
   1.440 +    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) < 0) {
   1.441 +        BSDAUDIO_CloseDevice(this);
   1.442          SDL_SetError("Couldn't put device into play mode");
   1.443 -        return (-1);
   1.444 +        return 0;
   1.445      }
   1.446  
   1.447 -    mixbuf = NULL;
   1.448      AUDIO_INITINFO(&info);
   1.449 -    for (format = SDL_FirstAudioFormat(spec->format);
   1.450 +    for (format = SDL_FirstAudioFormat(this->spec.format);
   1.451           format; format = SDL_NextAudioFormat()) {
   1.452          switch (format) {
   1.453          case AUDIO_U8:
   1.454 @@ -361,46 +396,70 @@
   1.455          default:
   1.456              continue;
   1.457          }
   1.458 -        if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
   1.459 +
   1.460 +        if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == 0) {
   1.461              break;
   1.462 +        }
   1.463      }
   1.464  
   1.465      if (!format) {
   1.466 -        SDL_SetError("No supported encoding for 0x%x", spec->format);
   1.467 -        return (-1);
   1.468 +        BSDAUDIO_CloseDevice(this);
   1.469 +        SDL_SetError("No supported encoding for 0x%x", this->spec.format);
   1.470 +        return 0;
   1.471      }
   1.472  
   1.473 -    spec->format = format;
   1.474 +    this->spec.format = format;
   1.475  
   1.476      AUDIO_INITINFO(&info);
   1.477 -    info.play.channels = spec->channels;
   1.478 -    if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
   1.479 -        spec->channels = 1;
   1.480 +    info.play.channels = this->spec.channels;
   1.481 +    if (ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info) == -1) {
   1.482 +        this->spec.channels = 1;
   1.483 +    }
   1.484      AUDIO_INITINFO(&info);
   1.485 -    info.play.sample_rate = spec->freq;
   1.486 -    info.blocksize = spec->size;
   1.487 +    info.play.sample_rate = this->spec.freq;
   1.488 +    info.blocksize = this->spec.size;
   1.489      info.hiwat = 5;
   1.490      info.lowat = 3;
   1.491 -    (void) ioctl(audio_fd, AUDIO_SETINFO, &info);
   1.492 -    (void) ioctl(audio_fd, AUDIO_GETINFO, &info);
   1.493 -    spec->freq = info.play.sample_rate;
   1.494 +    (void) ioctl(this->hidden->audio_fd, AUDIO_SETINFO, &info);
   1.495 +    (void) ioctl(this->hidden->audio_fd, AUDIO_GETINFO, &info);
   1.496 +    this->spec.freq = info.play.sample_rate;
   1.497      /* Allocate mixing buffer */
   1.498 -    mixlen = spec->size;
   1.499 -    mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
   1.500 -    if (mixbuf == NULL) {
   1.501 -        return (-1);
   1.502 +    this->hidden->mixlen = this->spec.size;
   1.503 +    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
   1.504 +    if (this->hidden->mixbuf == NULL) {
   1.505 +        BSDAUDIO_CloseDevice(this);
   1.506 +        SDL_OutOfMemory();
   1.507 +        return 0;
   1.508      }
   1.509 -    SDL_memset(mixbuf, spec->silence, spec->size);
   1.510 +    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
   1.511  
   1.512 -    /* Get the parent process id (we're the parent of the audio thread) */
   1.513 -    parent = getpid();
   1.514 -
   1.515 -#ifdef DEBUG_AUDIO
   1.516 -    OBSD_Status(this);
   1.517 -#endif
   1.518 +    BSDAUDIO_Status(this);
   1.519  
   1.520      /* We're ready to rock and roll. :-) */
   1.521      return (0);
   1.522  }
   1.523  
   1.524 +static int
   1.525 +BSDAUDIO_Init(SDL_AudioDriverImpl *impl)
   1.526 +{
   1.527 +    /* Set the function pointers */
   1.528 +    impl->DetectDevices = DSP_DetectDevices;
   1.529 +    impl->GetDeviceName = DSP_GetDeviceName;
   1.530 +    impl->OpenDevice = DSP_OpenDevice;
   1.531 +    impl->PlayDevice = DSP_PlayDevice;
   1.532 +    impl->WaitDevice = DSP_WaitDevice;
   1.533 +    impl->GetDeviceBuf = DSP_GetDeviceBuf;
   1.534 +    impl->CloseDevice = DSP_CloseDevice;
   1.535 +    impl->Deinitialize = DSP_Deinitialize;
   1.536 +
   1.537 +    build_device_lists();
   1.538 +    return 1;
   1.539 +}
   1.540 +
   1.541 +
   1.542 +AudioBootStrap BSD_AUDIO_bootstrap = {
   1.543 +    BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
   1.544 +    BSDAUDIO_Available, BSDAUDIO_Init, 0
   1.545 +};
   1.546 +
   1.547  /* vi: set ts=4 sw=4 expandtab: */
     2.1 --- a/src/audio/bsd/SDL_bsdaudio.h	Fri Oct 06 20:36:23 2006 +0000
     2.2 +++ b/src/audio/bsd/SDL_bsdaudio.h	Sat Oct 07 05:36:36 2006 +0000
     2.3 @@ -21,8 +21,8 @@
     2.4  */
     2.5  #include "SDL_config.h"
     2.6  
     2.7 -#ifndef _SDL_openbsdaudio_h
     2.8 -#define _SDL_openbsdaudio_h
     2.9 +#ifndef _SDL_bsdaudio_h
    2.10 +#define _SDL_bsdaudio_h
    2.11  
    2.12  #include "../SDL_sysaudio.h"
    2.13  
    2.14 @@ -47,13 +47,6 @@
    2.15  
    2.16  #define FUDGE_TICKS	10      /* The scheduler overhead ticks per frame */
    2.17  
    2.18 -/* Old variable names */
    2.19 -#define audio_fd		(this->hidden->audio_fd)
    2.20 -#define parent			(this->hidden->parent)
    2.21 -#define mixbuf			(this->hidden->mixbuf)
    2.22 -#define mixlen			(this->hidden->mixlen)
    2.23 -#define frame_ticks		(this->hidden->frame_ticks)
    2.24 -#define next_frame		(this->hidden->next_frame)
    2.25 +#endif /* _SDL_bsdaudio_h */
    2.26  
    2.27 -#endif /* _SDL_openbsdaudio_h */
    2.28  /* vi: set ts=4 sw=4 expandtab: */
     3.1 --- a/src/audio/dmedia/SDL_irixaudio.c	Fri Oct 06 20:36:23 2006 +0000
     3.2 +++ b/src/audio/dmedia/SDL_irixaudio.c	Sat Oct 07 05:36:36 2006 +0000
     3.3 @@ -45,73 +45,18 @@
     3.4  #define alSetWidth(x,y) ALsetwidth(x,y)
     3.5  #endif
     3.6  
     3.7 -/* Audio driver functions */
     3.8 -static int AL_OpenAudio(_THIS, SDL_AudioSpec * spec);
     3.9 -static void AL_WaitAudio(_THIS);
    3.10 -static void AL_PlayAudio(_THIS);
    3.11 -static Uint8 *AL_GetAudioBuf(_THIS);
    3.12 -static void AL_CloseAudio(_THIS);
    3.13 -
    3.14 -/* Audio driver bootstrap functions */
    3.15 -
    3.16  static int
    3.17 -Audio_Available(void)
    3.18 +IRIXAUDIO_Available(void)
    3.19  {
    3.20      return 1;
    3.21  }
    3.22  
    3.23 -static void
    3.24 -Audio_DeleteDevice(SDL_AudioDevice * device)
    3.25 -{
    3.26 -    SDL_free(device->hidden);
    3.27 -    SDL_free(device);
    3.28 -}
    3.29 -
    3.30 -static SDL_AudioDevice *
    3.31 -Audio_CreateDevice(int devindex)
    3.32 -{
    3.33 -    SDL_AudioDevice *this;
    3.34 -
    3.35 -    /* Initialize all variables that we clean on shutdown */
    3.36 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    3.37 -    if (this) {
    3.38 -        SDL_memset(this, 0, (sizeof *this));
    3.39 -        this->hidden = (struct SDL_PrivateAudioData *)
    3.40 -            SDL_malloc((sizeof *this->hidden));
    3.41 -    }
    3.42 -    if ((this == NULL) || (this->hidden == NULL)) {
    3.43 -        SDL_OutOfMemory();
    3.44 -        if (this) {
    3.45 -            SDL_free(this);
    3.46 -        }
    3.47 -        return (0);
    3.48 -    }
    3.49 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    3.50 -
    3.51 -    /* Set the function pointers */
    3.52 -    this->OpenAudio = AL_OpenAudio;
    3.53 -    this->WaitAudio = AL_WaitAudio;
    3.54 -    this->PlayAudio = AL_PlayAudio;
    3.55 -    this->GetAudioBuf = AL_GetAudioBuf;
    3.56 -    this->CloseAudio = AL_CloseAudio;
    3.57 -
    3.58 -    this->free = Audio_DeleteDevice;
    3.59 -
    3.60 -    return this;
    3.61 -}
    3.62 -
    3.63 -AudioBootStrap DMEDIA_bootstrap = {
    3.64 -    "AL", "IRIX DMedia audio",
    3.65 -    Audio_Available, Audio_CreateDevice, 0
    3.66 -};
    3.67 -
    3.68 -
    3.69  void static
    3.70 -AL_WaitAudio(_THIS)
    3.71 +IRIXAUDIO_WaitDevice(_THIS)
    3.72  {
    3.73      Sint32 timeleft;
    3.74  
    3.75 -    timeleft = this->spec.samples - alGetFillable(audio_port);
    3.76 +    timeleft = this->spec.samples - alGetFillable(this->hidden->audio_port);
    3.77      if (timeleft > 0) {
    3.78          timeleft /= (this->spec.freq / 1000);
    3.79          SDL_Delay((Uint32) timeleft);
    3.80 @@ -119,61 +64,78 @@
    3.81  }
    3.82  
    3.83  static void
    3.84 -AL_PlayAudio(_THIS)
    3.85 +IRIXAUDIO_PlayDevice(_THIS)
    3.86  {
    3.87      /* Write the audio data out */
    3.88 -    if (alWriteFrames(audio_port, mixbuf, this->spec.samples) < 0) {
    3.89 +    ALport port = this->hidden->audio_port;
    3.90 +    Uint8 *mixbuf = this->hidden->mixbuf;
    3.91 +    if (alWriteFrames(port, mixbuf, this->spec.samples) < 0) {
    3.92          /* Assume fatal error, for now */
    3.93          this->enabled = 0;
    3.94      }
    3.95  }
    3.96  
    3.97  static Uint8 *
    3.98 -AL_GetAudioBuf(_THIS)
    3.99 +IRIXAUDIO_GetDeviceBuf(_THIS)
   3.100  {
   3.101 -    return (mixbuf);
   3.102 +    return (this->hidden->mixbuf);
   3.103  }
   3.104  
   3.105  static void
   3.106 -AL_CloseAudio(_THIS)
   3.107 +IRIXAUDIO_CloseDevice(_THIS)
   3.108  {
   3.109 -    if (mixbuf != NULL) {
   3.110 -        SDL_FreeAudioMem(mixbuf);
   3.111 -        mixbuf = NULL;
   3.112 -    }
   3.113 -    if (audio_port != NULL) {
   3.114 -        alClosePort(audio_port);
   3.115 -        audio_port = NULL;
   3.116 +    if (this->hidden != NULL) {
   3.117 +        if (this->hidden->mixbuf != NULL) {
   3.118 +            SDL_FreeAudioMem(this->hidden->mixbuf);
   3.119 +            this->hidden->mixbuf = NULL;
   3.120 +        }
   3.121 +        if (this->hidden->audio_port != NULL) {
   3.122 +            alClosePort(this->hidden->audio_port);
   3.123 +            this->hidden->audio_port = NULL;
   3.124 +        }
   3.125 +        SDL_free(this->hidden);
   3.126 +        this->hidden = NULL;
   3.127      }
   3.128  }
   3.129  
   3.130  static int
   3.131 -AL_OpenAudio(_THIS, SDL_AudioSpec * spec)
   3.132 +IRIXAUDIO_OpenDevice(_THIS, const char *devname, int iscapture)
   3.133  {
   3.134 -    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
   3.135 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   3.136      long width = 0;
   3.137      long fmt = 0;
   3.138      int valid = 0;
   3.139  
   3.140 +    /* !!! FIXME: Handle multiple devices and capture? */
   3.141 +
   3.142 +    /* Initialize all variables that we clean on shutdown */
   3.143 +    this->hidden = (struct SDL_PrivateAudioData *)
   3.144 +                        SDL_malloc((sizeof *this->hidden));
   3.145 +    if (this->hidden == NULL) {
   3.146 +        SDL_OutOfMemory();
   3.147 +        return 0;
   3.148 +    }
   3.149 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   3.150 +
   3.151  #ifdef OLD_IRIX_AUDIO
   3.152      {
   3.153          long audio_param[2];
   3.154          audio_param[0] = AL_OUTPUT_RATE;
   3.155 -        audio_param[1] = spec->freq;
   3.156 +        audio_param[1] = this->spec.freq;
   3.157          valid = (ALsetparams(AL_DEFAULT_DEVICE, audio_param, 2) < 0);
   3.158      }
   3.159  #else
   3.160      {
   3.161          ALpv audio_param;
   3.162          audio_param.param = AL_RATE;
   3.163 -        audio_param.value.i = spec->freq;
   3.164 +        audio_param.value.i = this->spec.freq;
   3.165          valid = (alSetParams(AL_DEFAULT_OUTPUT, &audio_param, 1) < 0);
   3.166      }
   3.167  #endif
   3.168  
   3.169      while ((!valid) && (test_format)) {
   3.170          valid = 1;
   3.171 -        spec->format = test_format;
   3.172 +        this->spec.format = test_format;
   3.173  
   3.174          switch (test_format) {
   3.175          case AUDIO_S8:
   3.176 @@ -203,30 +165,31 @@
   3.177              ALconfig audio_config = alNewConfig();
   3.178              valid = 0;
   3.179              if (audio_config) {
   3.180 -                if (alSetChannels(audio_config, spec->channels) < 0) {
   3.181 -                    if (spec->channels > 2) {   /* can't handle > stereo? */
   3.182 -                        spec->channels = 2;     /* try again below. */
   3.183 +                if (alSetChannels(audio_config, this->spec.channels) < 0) {
   3.184 +                    if (this->spec.channels > 2) { /* can't handle > stereo? */
   3.185 +                        this->spec.channels = 2;   /* try again below. */
   3.186                      }
   3.187                  }
   3.188  
   3.189                  if ((alSetSampFmt(audio_config, fmt) >= 0) &&
   3.190                      ((!width) || (alSetWidth(audio_config, width) >= 0)) &&
   3.191 -                    (alSetQueueSize(audio_config, spec->samples * 2) >= 0) &&
   3.192 -                    (alSetChannels(audio_config, spec->channels) >= 0)) {
   3.193 +                    (alSetQueueSize(audio_config,this->spec.samples*2) >= 0) &&
   3.194 +                    (alSetChannels(audio_config, this->spec.channels) >= 0)) {
   3.195  
   3.196 -                    audio_port = alOpenPort("SDL audio", "w", audio_config);
   3.197 -                    if (audio_port == NULL) {
   3.198 +                    this->hidden->audio_port = alOpenPort("SDL audio", "w",
   3.199 +                                                          audio_config);
   3.200 +                    if (this->hidden->audio_port == NULL) {
   3.201                          /* docs say AL_BAD_CHANNELS happens here, too. */
   3.202                          int err = oserror();
   3.203                          if (err == AL_BAD_CHANNELS) {
   3.204 -                            spec->channels = 2;
   3.205 -                            alSetChannels(audio_config, spec->channels);
   3.206 -                            audio_port = alOpenPort("SDL audio", "w",
   3.207 -                                                    audio_config);
   3.208 +                            this->spec.channels = 2;
   3.209 +                            alSetChannels(audio_config, this->spec.channels);
   3.210 +                            this->hidden->audio_port = alOpenPort("SDL audio", "w",
   3.211 +                                                                 audio_config);
   3.212                          }
   3.213                      }
   3.214  
   3.215 -                    if (audio_port != NULL) {
   3.216 +                    if (this->hidden->audio_port != NULL) {
   3.217                          valid = 1;
   3.218                      }
   3.219                  }
   3.220 @@ -237,23 +200,44 @@
   3.221      }
   3.222  
   3.223      if (!valid) {
   3.224 +        IRIXAUDIO_CloseDevice(this);
   3.225          SDL_SetError("Unsupported audio format");
   3.226 -        return (-1);
   3.227 +        return 0;
   3.228      }
   3.229  
   3.230      /* Update the fragment size as size in bytes */
   3.231 -    SDL_CalculateAudioSpec(spec);
   3.232 +    SDL_CalculateAudioSpec(&this->spec);
   3.233  
   3.234      /* Allocate mixing buffer */
   3.235 -    mixbuf = (Uint8 *) SDL_AllocAudioMem(spec->size);
   3.236 -    if (mixbuf == NULL) {
   3.237 +    this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->spec.size);
   3.238 +    if (this->hidden->mixbuf == NULL) {
   3.239 +        IRIXAUDIO_CloseDevice(this);
   3.240          SDL_OutOfMemory();
   3.241 -        return (-1);
   3.242 +        return 0;
   3.243      }
   3.244 -    SDL_memset(mixbuf, spec->silence, spec->size);
   3.245 +    SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
   3.246  
   3.247      /* We're ready to rock and roll. :-) */
   3.248 -    return (0);
   3.249 +    return 1;
   3.250  }
   3.251  
   3.252 +static int
   3.253 +IRIXAUDIO_Init(SDL_AudioDriverImpl *impl)
   3.254 +{
   3.255 +    /* Set the function pointers */
   3.256 +    impl->OpenDevice = DSP_OpenDevice;
   3.257 +    impl->PlayDevice = DSP_PlayDevice;
   3.258 +    impl->WaitDevice = DSP_WaitDevice;
   3.259 +    impl->GetDeviceBuf = DSP_GetDeviceBuf;
   3.260 +    impl->CloseDevice = DSP_CloseDevice;
   3.261 +    impl->OnlyHasDefaultOutputDevice = 1;  /* !!! FIXME: not true, I think. */
   3.262 +
   3.263 +    return 1;
   3.264 +}
   3.265 +
   3.266 +AudioBootStrap IRIXAUDIO_bootstrap = {
   3.267 +    "AL", "IRIX DMedia audio",
   3.268 +    IRIXAUDIO_Available, IRIXAUDIO_Init, 0
   3.269 +};
   3.270 +
   3.271  /* vi: set ts=4 sw=4 expandtab: */
     4.1 --- a/src/audio/dmedia/SDL_irixaudio.h	Fri Oct 06 20:36:23 2006 +0000
     4.2 +++ b/src/audio/dmedia/SDL_irixaudio.h	Sat Oct 07 05:36:36 2006 +0000
     4.3 @@ -33,15 +33,9 @@
     4.4  
     4.5  struct SDL_PrivateAudioData
     4.6  {
     4.7 -    /* The handle for the audio device */
     4.8 -    ALport audio_port;
     4.9 -
    4.10 -    Uint8 *mixbuf;              /* The app mixing buffer */
    4.11 +    ALport audio_port;    /* The handle for the audio device */
    4.12 +    Uint8 *mixbuf;        /* The app mixing buffer */
    4.13  };
    4.14  
    4.15 -/* Old variable names */
    4.16 -#define audio_port		(this->hidden->audio_port)
    4.17 -#define mixbuf			(this->hidden->mixbuf)
    4.18 -
    4.19  #endif /* _SDL_lowaudio_h */
    4.20  /* vi: set ts=4 sw=4 expandtab: */
     5.1 --- a/src/audio/dsp/SDL_dspaudio.c	Fri Oct 06 20:36:23 2006 +0000
     5.2 +++ b/src/audio/dsp/SDL_dspaudio.c	Sat Oct 07 05:36:36 2006 +0000
     5.3 @@ -58,8 +58,6 @@
     5.4  #define OPEN_FLAGS_OUTPUT    (O_WRONLY|O_NONBLOCK)
     5.5  #define OPEN_FLAGS_INPUT    (O_RDONLY|O_NONBLOCK)
     5.6  
     5.7 -/* Audio driver bootstrap functions */
     5.8 -
     5.9  static char **outputDevices = NULL;
    5.10  static int outputDeviceCount = 0;
    5.11  static char **inputDevices = NULL;
    5.12 @@ -106,7 +104,8 @@
    5.13  }
    5.14  
    5.15  
    5.16 -static void DSP_Deinitialize(void)
    5.17 +static void
    5.18 +DSP_Deinitialize(void)
    5.19  {
    5.20      free_device_lists();
    5.21  }
    5.22 @@ -186,7 +185,6 @@
    5.23          return 0;
    5.24      }
    5.25      SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    5.26 -    this->hidden->audio_fd = -1;
    5.27  
    5.28      /* Open the audio device */
    5.29      this->hidden->audio_fd = open(devname, flags, 0);
     6.1 --- a/src/audio/macrom/SDL_romaudio.c	Fri Oct 06 20:36:23 2006 +0000
     6.2 +++ b/src/audio/macrom/SDL_romaudio.c	Sat Oct 07 05:36:36 2006 +0000
     6.3 @@ -309,9 +309,11 @@
     6.4      impl->ProvidesOwnCallbackThread = 1;
     6.5      impl->OnlyHasDefaultOutputDevice = 1;
     6.6  
     6.7 -#ifndef __MACOSX__               /* Mac OS X uses threaded audio, so normal thread code is okay */
     6.8 +/* Mac OS X uses threaded audio, so normal thread code is okay */
     6.9 +#ifndef __MACOSX__
    6.10      impl->LockDevice = SNDMGR_LockDevice;
    6.11      impl->UnlockDevice = SNDMGR_UnlockDevice;
    6.12 +    impl->SkipMixerLock = 1;
    6.13  #endif
    6.14  
    6.15      return 1;
     7.1 --- a/src/audio/mint/SDL_mintaudio_dma8.c	Fri Oct 06 20:36:23 2006 +0000
     7.2 +++ b/src/audio/mint/SDL_mintaudio_dma8.c	Sat Oct 07 05:36:36 2006 +0000
     7.3 @@ -61,30 +61,10 @@
     7.4  
     7.5  static unsigned long cookie_snd, cookie_mch;
     7.6  
     7.7 -/*--- Audio driver functions ---*/
     7.8 -
     7.9 -static void Mint_CloseAudio(_THIS);
    7.10 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
    7.11 -static void Mint_LockAudio(_THIS);
    7.12 -static void Mint_UnlockAudio(_THIS);
    7.13 -
    7.14 -/* To check/init hardware audio */
    7.15 -static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
    7.16 -static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
    7.17 -
    7.18 -/*--- Audio driver bootstrap functions ---*/
    7.19  
    7.20  static int
    7.21 -Audio_Available(void)
    7.22 +MINTDMA8_Available(void)
    7.23  {
    7.24 -    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    7.25 -
    7.26 -    /* Check if user asked a different audio driver */
    7.27 -    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
    7.28 -        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
    7.29 -        return 0;
    7.30 -    }
    7.31 -
    7.32      /* Cookie _MCH present ? if not, assume ST machine */
    7.33      if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
    7.34          cookie_mch = MCH_ST;
    7.35 @@ -116,55 +96,7 @@
    7.36  }
    7.37  
    7.38  static void
    7.39 -Audio_DeleteDevice(SDL_AudioDevice * device)
    7.40 -{
    7.41 -    SDL_free(device->hidden);
    7.42 -    SDL_free(device);
    7.43 -}
    7.44 -
    7.45 -static SDL_AudioDevice *
    7.46 -Audio_CreateDevice(int devindex)
    7.47 -{
    7.48 -    SDL_AudioDevice *this;
    7.49 -
    7.50 -    /* Initialize all variables that we clean on shutdown */
    7.51 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    7.52 -    if (this) {
    7.53 -        SDL_memset(this, 0, (sizeof *this));
    7.54 -        this->hidden = (struct SDL_PrivateAudioData *)
    7.55 -            SDL_malloc((sizeof *this->hidden));
    7.56 -    }
    7.57 -    if ((this == NULL) || (this->hidden == NULL)) {
    7.58 -        SDL_OutOfMemory();
    7.59 -        if (this) {
    7.60 -            SDL_free(this);
    7.61 -        }
    7.62 -        return (0);
    7.63 -    }
    7.64 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    7.65 -
    7.66 -    /* Set the function pointers */
    7.67 -    this->OpenAudio = Mint_OpenAudio;
    7.68 -    this->CloseAudio = Mint_CloseAudio;
    7.69 -    this->LockAudio = Mint_LockAudio;
    7.70 -    this->UnlockAudio = Mint_UnlockAudio;
    7.71 -    this->free = Audio_DeleteDevice;
    7.72 -
    7.73 -    /* Uses interrupt driven audio, without thread */
    7.74 -    #if SDL_THREADS_DISABLED
    7.75 -    this->SkipMixerLock = 1;
    7.76 -    #endif
    7.77 -
    7.78 -    return this;
    7.79 -}
    7.80 -
    7.81 -AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
    7.82 -    MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver",
    7.83 -    Audio_Available, Audio_CreateDevice, 0
    7.84 -};
    7.85 -
    7.86 -static void
    7.87 -Mint_LockAudio(_THIS)
    7.88 +MINTDMA8_LockDevice(_THIS)
    7.89  {
    7.90      void *oldpile;
    7.91  
    7.92 @@ -175,7 +107,7 @@
    7.93  }
    7.94  
    7.95  static void
    7.96 -Mint_UnlockAudio(_THIS)
    7.97 +MINTDMA8_UnlockDevice(_THIS)
    7.98  {
    7.99      void *oldpile;
   7.100  
   7.101 @@ -186,57 +118,59 @@
   7.102  }
   7.103  
   7.104  static void
   7.105 -Mint_CloseAudio(_THIS)
   7.106 +MINTDMA8_CloseDevice(_THIS)
   7.107  {
   7.108 -    void *oldpile;
   7.109 +    if (this->hidden != NULL) {
   7.110 +        /* Stop replay */
   7.111 +        void *oldpile = (void *) Super(0);
   7.112  
   7.113 -    /* Stop replay */
   7.114 -    oldpile = (void *) Super(0);
   7.115 -    DMAAUDIO_IO.control = 0;
   7.116 -    Super(oldpile);
   7.117 +        DMAAUDIO_IO.control = 0;
   7.118 +        Super(oldpile);
   7.119 +
   7.120 +        DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
   7.121  
   7.122 -    DEBUG_PRINT((DEBUG_NAME "closeaudio: replay stopped\n"));
   7.123 +        /* Disable interrupt */
   7.124 +        Jdisint(MFP_DMASOUND);
   7.125  
   7.126 -    /* Disable interrupt */
   7.127 -    Jdisint(MFP_DMASOUND);
   7.128 +        DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
   7.129  
   7.130 -    DEBUG_PRINT((DEBUG_NAME "closeaudio: interrupt disabled\n"));
   7.131 +        /* Wait if currently playing sound */
   7.132 +        while (SDL_MintAudio_mutex != 0) {}
   7.133  
   7.134 -    /* Wait if currently playing sound */
   7.135 -    while (SDL_MintAudio_mutex != 0) {
   7.136 -    }
   7.137 -
   7.138 -    DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
   7.139 +        DEBUG_PRINT((DEBUG_NAME "closeaudio: no more interrupt running\n"));
   7.140  
   7.141 -    /* Clear buffers */
   7.142 -    if (SDL_MintAudio_audiobuf[0]) {
   7.143 -        Mfree(SDL_MintAudio_audiobuf[0]);
   7.144 -        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   7.145 +        /* Clear buffers */
   7.146 +        if (SDL_MintAudio_audiobuf[0]) {
   7.147 +            Mfree(SDL_MintAudio_audiobuf[0]);
   7.148 +            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   7.149 +        }
   7.150 +
   7.151 +        DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
   7.152 +        SDL_free(this->buffer);
   7.153 +        this->buffer = NULL;
   7.154      }
   7.155 -
   7.156 -    DEBUG_PRINT((DEBUG_NAME "closeaudio: buffers freed\n"));
   7.157  }
   7.158  
   7.159  static int
   7.160 -Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
   7.161 +MINTDMA8_CheckAudio(_THIS)
   7.162  {
   7.163      int i, masterprediv, sfreq;
   7.164      unsigned long masterclock;
   7.165  
   7.166      DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
   7.167 -                 SDL_AUDIO_BITSIZE(spec->format)));
   7.168 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
   7.169 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
   7.170 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
   7.171 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
   7.172 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
   7.173 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
   7.174 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
   7.175 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
   7.176 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
   7.177 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
   7.178 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
   7.179  
   7.180 -    if (spec->channels > 2) {
   7.181 -        spec->channels = 2;     /* no more than stereo! */
   7.182 +    if (this->spec.channels > 2) {
   7.183 +        this->spec.channels = 2;     /* no more than stereo! */
   7.184      }
   7.185  
   7.186      /* Check formats available */
   7.187 -    spec->format = AUDIO_S8;
   7.188 +    this->spec.format = AUDIO_S8;
   7.189  
   7.190      /* Calculate and select the closest frequency */
   7.191      sfreq = 0;
   7.192 @@ -277,22 +211,22 @@
   7.193      }
   7.194  #endif
   7.195  
   7.196 -    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
   7.197 -    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   7.198 +    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
   7.199 +    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   7.200  
   7.201      DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
   7.202 -                 SDL_AUDIO_BITSIZE(spec->format)));
   7.203 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
   7.204 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
   7.205 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
   7.206 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
   7.207 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
   7.208 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
   7.209 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
   7.210 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
   7.211 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
   7.212 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
   7.213 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
   7.214  
   7.215      return 0;
   7.216  }
   7.217  
   7.218  static void
   7.219 -Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
   7.220 +MINTDMA8_InitAudio(_THIS)
   7.221  {
   7.222      void *oldpile;
   7.223      unsigned long buffer;
   7.224 @@ -321,7 +255,7 @@
   7.225      DMAAUDIO_IO.end_low = buffer & 255;
   7.226  
   7.227      mode = 3 - MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
   7.228 -    if (spec->channels == 1) {
   7.229 +    if (this->spec.channels == 1) {
   7.230          mode |= 1 << 7;
   7.231      }
   7.232      DMAAUDIO_IO.sound_ctrl = mode;
   7.233 @@ -344,29 +278,40 @@
   7.234  }
   7.235  
   7.236  static int
   7.237 -Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
   7.238 +MINTDMA8_OpenDevice(_THIS, const char *devname, int iscapture)
   7.239  {
   7.240      SDL_MintAudio_device = this;
   7.241  
   7.242      /* Check audio capabilities */
   7.243 -    if (Mint_CheckAudio(this, spec) == -1) {
   7.244 -        return -1;
   7.245 +    if (MINTDMA8_CheckAudio(this) == -1) {
   7.246 +        return 0;
   7.247      }
   7.248  
   7.249 -    SDL_CalculateAudioSpec(spec);
   7.250 +    /* Initialize all variables that we clean on shutdown */
   7.251 +    this->hidden = (struct SDL_PrivateAudioData *)
   7.252 +                        SDL_malloc((sizeof *this->hidden));
   7.253 +    if (this->hidden == NULL) {
   7.254 +        SDL_OutOfMemory();
   7.255 +        return 0;
   7.256 +    }
   7.257 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   7.258 +
   7.259 +    SDL_CalculateAudioSpec(&this->spec);
   7.260  
   7.261      /* Allocate memory for audio buffers in DMA-able RAM */
   7.262 -    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
   7.263 +    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
   7.264  
   7.265 -    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
   7.266 +    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
   7.267      if (SDL_MintAudio_audiobuf[0] == NULL) {
   7.268 -        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
   7.269 -        return (-1);
   7.270 +        SDL_free(this->hidden);
   7.271 +        this->hidden = NULL;
   7.272 +        SDL_OutOfMemory();
   7.273 +        return 0;
   7.274      }
   7.275 -    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
   7.276 +    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
   7.277      SDL_MintAudio_numbuf = 0;
   7.278 -    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
   7.279 -    SDL_MintAudio_audiosize = spec->size;
   7.280 +    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
   7.281 +    SDL_MintAudio_audiosize = this->spec.size;
   7.282      SDL_MintAudio_mutex = 0;
   7.283  
   7.284      DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
   7.285 @@ -377,9 +322,29 @@
   7.286      SDL_MintAudio_CheckFpu();
   7.287  
   7.288      /* Setup audio hardware */
   7.289 -    Mint_InitAudio(this, spec);
   7.290 +    MINTDMA8_InitAudio(this);
   7.291  
   7.292 -    return (1);                 /* We don't use threaded audio */
   7.293 +    return 1;  /* good to go. */
   7.294  }
   7.295  
   7.296 +static int
   7.297 +MINTDMA8_Init(SDL_AudioDriverImpl *impl)
   7.298 +{
   7.299 +    /* Set the function pointers */
   7.300 +    impl->OpenDevice = MINTDMA8_OpenDevice;
   7.301 +    impl->CloseDevice = MINTDMA8_CloseDevice;
   7.302 +    impl->LockAudio = MINTDMA8_LockAudio;
   7.303 +    impl->UnlockAudio = MINTDMA8_UnlockAudio;
   7.304 +    impl->OnlyHasDefaultOutputDevice = 1;
   7.305 +    impl->ProvidesOwnCallbackThread = 1;
   7.306 +    impl->SkipMixerLock = 1;
   7.307 +
   7.308 +    return 1;
   7.309 +}
   7.310 +
   7.311 +AudioBootStrap MINTAUDIO_DMA8_bootstrap = {
   7.312 +    MINT_AUDIO_DRIVER_NAME, "MiNT DMA 8 bits audio driver",
   7.313 +    MINTDMA8_Available, MINTDMA8_Init, 0
   7.314 +};
   7.315 +
   7.316  /* vi: set ts=4 sw=4 expandtab: */
     8.1 --- a/src/audio/mint/SDL_mintaudio_gsxb.c	Fri Oct 06 20:36:23 2006 +0000
     8.2 +++ b/src/audio/mint/SDL_mintaudio_gsxb.c	Sat Oct 07 05:36:36 2006 +0000
     8.3 @@ -63,32 +63,14 @@
     8.4  
     8.5  /*--- Audio driver functions ---*/
     8.6  
     8.7 -static void Mint_CloseAudio(_THIS);
     8.8 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
     8.9 -static void Mint_LockAudio(_THIS);
    8.10 -static void Mint_UnlockAudio(_THIS);
    8.11 +/* GSXB callbacks */
    8.12 +static void MINTGSXB_GsxbInterrupt(void);
    8.13 +static void MINTGSXB_GsxbNullInterrupt(void);
    8.14  
    8.15 -/* To check/init hardware audio */
    8.16 -static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
    8.17 -static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
    8.18 -
    8.19 -/* GSXB callbacks */
    8.20 -static void Mint_GsxbInterrupt(void);
    8.21 -static void Mint_GsxbNullInterrupt(void);
    8.22 -
    8.23 -/*--- Audio driver bootstrap functions ---*/
    8.24  
    8.25  static int
    8.26 -Audio_Available(void)
    8.27 +MINTGSXB_Available(void)
    8.28  {
    8.29 -    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    8.30 -
    8.31 -    /* Check if user asked a different audio driver */
    8.32 -    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
    8.33 -        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
    8.34 -        return (0);
    8.35 -    }
    8.36 -
    8.37      /* Cookie _SND present ? if not, assume ST machine */
    8.38      if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
    8.39          cookie_snd = SND_PSG;
    8.40 @@ -121,123 +103,80 @@
    8.41      return (1);
    8.42  }
    8.43  
    8.44 -static void
    8.45 -Audio_DeleteDevice(SDL_AudioDevice * device)
    8.46 -{
    8.47 -    SDL_free(device->hidden);
    8.48 -    SDL_free(device);
    8.49 -}
    8.50 -
    8.51 -static SDL_AudioDevice *
    8.52 -Audio_CreateDevice(int devindex)
    8.53 -{
    8.54 -    SDL_AudioDevice *this;
    8.55 -
    8.56 -    /* Initialize all variables that we clean on shutdown */
    8.57 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    8.58 -    if (this) {
    8.59 -        SDL_memset(this, 0, (sizeof *this));
    8.60 -        this->hidden = (struct SDL_PrivateAudioData *)
    8.61 -            SDL_malloc((sizeof *this->hidden));
    8.62 -    }
    8.63 -    if ((this == NULL) || (this->hidden == NULL)) {
    8.64 -        SDL_OutOfMemory();
    8.65 -        if (this) {
    8.66 -            SDL_free(this);
    8.67 -        }
    8.68 -        return (0);
    8.69 -    }
    8.70 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    8.71 -
    8.72 -    /* Set the function pointers */
    8.73 -    this->OpenAudio = Mint_OpenAudio;
    8.74 -    this->CloseAudio = Mint_CloseAudio;
    8.75 -    this->LockAudio = Mint_LockAudio;
    8.76 -    this->UnlockAudio = Mint_UnlockAudio;
    8.77 -    this->free = Audio_DeleteDevice;
    8.78 -
    8.79 -    /* Uses interrupt driven audio, without thread */
    8.80 -    #if SDL_THREADS_DISABLED
    8.81 -    this->SkipMixerLock = 1;
    8.82 -    #endif
    8.83 -
    8.84 -    return this;
    8.85 -}
    8.86 -
    8.87 -AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
    8.88 -    MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
    8.89 -    Audio_Available, Audio_CreateDevice, 0
    8.90 -};
    8.91  
    8.92  static void
    8.93 -Mint_LockAudio(_THIS)
    8.94 +MINTGSXB_LockDevice(_THIS)
    8.95  {
    8.96      /* Stop replay */
    8.97      Buffoper(0);
    8.98  }
    8.99  
   8.100  static void
   8.101 -Mint_UnlockAudio(_THIS)
   8.102 +MINTGSXB_UnlockDevice(_THIS)
   8.103  {
   8.104      /* Restart replay */
   8.105      Buffoper(SB_PLA_ENA | SB_PLA_RPT);
   8.106  }
   8.107  
   8.108  static void
   8.109 -Mint_CloseAudio(_THIS)
   8.110 +MINTGSXB_CloseDevice(_THIS)
   8.111  {
   8.112 -    /* Stop replay */
   8.113 -    Buffoper(0);
   8.114 +    if (this->hidden != NULL) {
   8.115 +        /* Stop replay */
   8.116 +        Buffoper(0);
   8.117  
   8.118 -    /* Uninstall interrupt */
   8.119 -    if (NSetinterrupt(2, SI_NONE, Mint_GsxbNullInterrupt) < 0) {
   8.120 -        DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
   8.121 -    }
   8.122 +        /* Uninstall interrupt */
   8.123 +        if (NSetinterrupt(2, SI_NONE, MINTGSXB_GsxbNullInterrupt) < 0) {
   8.124 +            DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed in close\n"));
   8.125 +        }
   8.126  
   8.127 -    /* Wait if currently playing sound */
   8.128 -    while (SDL_MintAudio_mutex != 0) {
   8.129 -    }
   8.130 +        /* Wait if currently playing sound */
   8.131 +        while (SDL_MintAudio_mutex != 0) {}
   8.132  
   8.133 -    /* Clear buffers */
   8.134 -    if (SDL_MintAudio_audiobuf[0]) {
   8.135 -        Mfree(SDL_MintAudio_audiobuf[0]);
   8.136 -        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   8.137 +        /* Clear buffers */
   8.138 +        if (SDL_MintAudio_audiobuf[0]) {
   8.139 +            Mfree(SDL_MintAudio_audiobuf[0]);
   8.140 +            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   8.141 +        }
   8.142 +
   8.143 +        /* Unlock sound system */
   8.144 +        Unlocksnd();
   8.145 +
   8.146 +        SDL_free(this->hidden);
   8.147 +        this->hidden = NULL;
   8.148      }
   8.149 -
   8.150 -    /* Unlock sound system */
   8.151 -    Unlocksnd();
   8.152  }
   8.153  
   8.154  static int
   8.155 -Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
   8.156 +MINTGSXB_CheckAudio(_THIS)
   8.157  {
   8.158      long snd_format;
   8.159      int i, resolution, format_signed, format_bigendian;
   8.160 -    SDL_AudioFormat test_format = SDL_FirstAudioFormat(spec->format);
   8.161 +    SDL_AudioFormat test_format = SDL_FirstAudioFormat(this->spec.format);
   8.162      int valid_datatype = 0;
   8.163  
   8.164 -    resolution = SDL_AUDIO_BITSIZE(spec->format);
   8.165 -    format_signed = SDL_AUDIO_ISSIGNED(spec->format);
   8.166 -    format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format);
   8.167 +    resolution = SDL_AUDIO_BITSIZE(this->spec.format);
   8.168 +    format_signed = SDL_AUDIO_ISSIGNED(this->spec.format);
   8.169 +    format_bigendian = SDL_AUDIO_ISBIGENDIAN(this->spec.format);
   8.170  
   8.171      DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ", resolution));
   8.172 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
   8.173 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
   8.174      DEBUG_PRINT(("signed=%d, ", format_signed));
   8.175      DEBUG_PRINT(("big endian=%d, ", format_bigendian));
   8.176 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
   8.177 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
   8.178 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
   8.179 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
   8.180  
   8.181 -    if (spec->channels > 2) {
   8.182 -        spec->channels = 2;     /* no more than stereo! */
   8.183 +    if (this->spec.channels > 2) {
   8.184 +        this->spec.channels = 2;     /* no more than stereo! */
   8.185      }
   8.186  
   8.187      while ((!valid_datatype) && (test_format)) {
   8.188          /* Check formats available */
   8.189          snd_format = Sndstatus(SND_QUERYFORMATS);
   8.190 -        spec->format = test_format;
   8.191 -        resolution = SDL_AUDIO_BITSIZE(spec->format);
   8.192 -        format_signed = SDL_AUDIO_ISSIGNED(spec->format);
   8.193 -        format_bigendian = SDL_AUDIO_ISBIGENDIAN(spec->format);
   8.194 +        this->spec.format = test_format;
   8.195 +        resolution = SDL_AUDIO_BITSIZE(this->spec.format);
   8.196 +        format_signed = SDL_AUDIO_ISSIGNED(this->spec.format);
   8.197 +        format_bigendian = SDL_AUDIO_ISBIGENDIAN(this->spec.format);
   8.198          switch (test_format) {
   8.199              case AUDIO_U8:
   8.200              case AUDIO_S8:
   8.201 @@ -284,14 +223,14 @@
   8.202              /* Ok */
   8.203          } else if (snd_format & SND_FORMATUNSIGNED) {
   8.204              /* Give unsigned format */
   8.205 -            spec->format = spec->format & (~SDL_AUDIO_MASK_SIGNED);
   8.206 +            this->spec.format = this->spec.format & (~SDL_AUDIO_MASK_SIGNED);
   8.207          }
   8.208      } else {
   8.209          if (snd_format & SND_FORMATUNSIGNED) {
   8.210              /* Ok */
   8.211          } else if (snd_format & SND_FORMATSIGNED) {
   8.212              /* Give signed format */
   8.213 -            spec->format |= SDL_AUDIO_MASK_SIGNED;
   8.214 +            this->spec.format |= SDL_AUDIO_MASK_SIGNED;
   8.215          }
   8.216      }
   8.217  
   8.218 @@ -300,14 +239,14 @@
   8.219              /* Ok */
   8.220          } else if (snd_format & SND_FORMATLITTLEENDIAN) {
   8.221              /* Give little endian format */
   8.222 -            spec->format = spec->format & (~SDL_AUDIO_MASK_ENDIAN);
   8.223 +            this->spec.format = this->spec.format & (~SDL_AUDIO_MASK_ENDIAN);
   8.224          }
   8.225      } else {
   8.226          if (snd_format & SND_FORMATLITTLEENDIAN) {
   8.227              /* Ok */
   8.228          } else if (snd_format & SND_FORMATBIGENDIAN) {
   8.229              /* Give big endian format */
   8.230 -            spec->format |= SDL_AUDIO_MASK_ENDIAN;
   8.231 +            this->spec.format |= SDL_AUDIO_MASK_ENDIAN;
   8.232          }
   8.233      }
   8.234  
   8.235 @@ -329,22 +268,22 @@
   8.236      }
   8.237  #endif
   8.238  
   8.239 -    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
   8.240 -    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   8.241 +    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
   8.242 +    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   8.243  
   8.244      DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
   8.245 -                 SDL_AUDIO_BITSIZE(spec->format)));
   8.246 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
   8.247 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
   8.248 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
   8.249 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
   8.250 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
   8.251 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
   8.252 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
   8.253 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
   8.254 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
   8.255 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
   8.256 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
   8.257  
   8.258      return 0;
   8.259  }
   8.260  
   8.261  static void
   8.262 -Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
   8.263 +MINTGSXB_InitAudio(_THIS)
   8.264  {
   8.265      int channels_mode, prediv;
   8.266      void *buffer;
   8.267 @@ -357,23 +296,23 @@
   8.268      Setmontracks(0);
   8.269  
   8.270      /* Select replay format */
   8.271 -    switch (SDL_AUDIO_BITSIZE(spec->format)) {
   8.272 +    switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
   8.273      case 8:
   8.274 -        if (spec->channels == 2) {
   8.275 +        if (this->spec.channels == 2) {
   8.276              channels_mode = STEREO8;
   8.277          } else {
   8.278              channels_mode = MONO8;
   8.279          }
   8.280          break;
   8.281      case 16:
   8.282 -        if (spec->channels == 2) {
   8.283 +        if (this->spec.channels == 2) {
   8.284              channels_mode = STEREO16;
   8.285          } else {
   8.286              channels_mode = MONO16;
   8.287          }
   8.288          break;
   8.289      case 32:
   8.290 -        if (spec->channels == 2) {
   8.291 +        if (this->spec.channels == 2) {
   8.292              channels_mode = STEREO32;
   8.293          } else {
   8.294              channels_mode = MONO32;
   8.295 @@ -392,12 +331,12 @@
   8.296  
   8.297      /* Set buffer */
   8.298      buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   8.299 -    if (Setbuffer(0, buffer, buffer + spec->size) < 0) {
   8.300 +    if (Setbuffer(0, buffer, buffer + this->spec.size) < 0) {
   8.301          DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
   8.302      }
   8.303  
   8.304      /* Install interrupt */
   8.305 -    if (NSetinterrupt(2, SI_PLAY, Mint_GsxbInterrupt) < 0) {
   8.306 +    if (NSetinterrupt(2, SI_PLAY, MINTGSXB_GsxbInterrupt) < 0) {
   8.307          DEBUG_PRINT((DEBUG_NAME "NSetinterrupt() failed\n"));
   8.308      }
   8.309  
   8.310 @@ -407,35 +346,46 @@
   8.311  }
   8.312  
   8.313  static int
   8.314 -Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
   8.315 +MINTGSXB_OpenDevice(_THIS, const char *devname, int iscapture)
   8.316  {
   8.317      /* Lock sound system */
   8.318      if (Locksnd() != 1) {
   8.319 -        SDL_SetError("Mint_OpenAudio: Audio system already in use");
   8.320 -        return (-1);
   8.321 +        SDL_SetError("MINTGSXB_OpenDevice: Audio system already in use");
   8.322 +        return 0;
   8.323      }
   8.324  
   8.325      SDL_MintAudio_device = this;
   8.326  
   8.327      /* Check audio capabilities */
   8.328 -    if (Mint_CheckAudio(this, spec) == -1) {
   8.329 -        return -1;
   8.330 +    if (MINTGSXB_CheckAudio(this) == -1) {
   8.331 +        return 0;
   8.332      }
   8.333  
   8.334 -    SDL_CalculateAudioSpec(spec);
   8.335 +    /* Initialize all variables that we clean on shutdown */
   8.336 +    this->hidden = (struct SDL_PrivateAudioData *)
   8.337 +                        SDL_malloc((sizeof *this->hidden));
   8.338 +    if (this->hidden == NULL) {
   8.339 +        SDL_OutOfMemory();
   8.340 +        return 0;
   8.341 +    }
   8.342 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   8.343 +
   8.344 +    SDL_CalculateAudioSpec(&this->spec);
   8.345  
   8.346      /* Allocate memory for audio buffers in DMA-able RAM */
   8.347 -    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
   8.348 +    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
   8.349  
   8.350 -    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
   8.351 +    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
   8.352      if (SDL_MintAudio_audiobuf[0] == NULL) {
   8.353 -        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
   8.354 -        return (-1);
   8.355 +        SDL_free(this->hidden);
   8.356 +        this->hidden = NULL;
   8.357 +        SDL_OutOfMemory();
   8.358 +        return 0;
   8.359      }
   8.360 -    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
   8.361 +    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
   8.362      SDL_MintAudio_numbuf = 0;
   8.363 -    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
   8.364 -    SDL_MintAudio_audiosize = spec->size;
   8.365 +    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
   8.366 +    SDL_MintAudio_audiosize = this->spec.size;
   8.367      SDL_MintAudio_mutex = 0;
   8.368  
   8.369      DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
   8.370 @@ -446,13 +396,13 @@
   8.371      SDL_MintAudio_CheckFpu();
   8.372  
   8.373      /* Setup audio hardware */
   8.374 -    Mint_InitAudio(this, spec);
   8.375 +    MINTGSXB_InitAudio(this);
   8.376  
   8.377 -    return (1);                 /* We don't use threaded audio */
   8.378 +    return 1;  /* good to go. */
   8.379  }
   8.380  
   8.381  static void
   8.382 -Mint_GsxbInterrupt(void)
   8.383 +MINTGSXB_GsxbInterrupt(void)
   8.384  {
   8.385      Uint8 *newbuf;
   8.386  
   8.387 @@ -470,8 +420,28 @@
   8.388  }
   8.389  
   8.390  static void
   8.391 -Mint_GsxbNullInterrupt(void)
   8.392 +MINTGSXB_GsxbNullInterrupt(void)
   8.393  {
   8.394  }
   8.395  
   8.396 +static int
   8.397 +MINTGSXB_Init(SDL_AudioDriverImpl *impl)
   8.398 +{
   8.399 +    /* Set the function pointers */
   8.400 +    impl->OpenDevice = MINTGSXB_OpenDevice;
   8.401 +    impl->CloseDevice = MINTGSXB_CloseDevice;
   8.402 +    impl->LockAudio = MINTGSXB_LockAudio;
   8.403 +    impl->UnlockAudio = MINTGSXB_UnlockAudio;
   8.404 +    impl->OnlyHasDefaultOutputDevice = 1;
   8.405 +    impl->ProvidesOwnCallbackThread = 1;
   8.406 +    impl->SkipMixerLock = 1;
   8.407 +
   8.408 +    return 1;
   8.409 +}
   8.410 +
   8.411 +AudioBootStrap MINTAUDIO_GSXB_bootstrap = {
   8.412 +    MINT_AUDIO_DRIVER_NAME, "MiNT GSXB audio driver",
   8.413 +    MINTGSXB_Available, MINTGSXB_Init, 0
   8.414 +};
   8.415 +
   8.416  /* vi: set ts=4 sw=4 expandtab: */
     9.1 --- a/src/audio/mint/SDL_mintaudio_mcsn.c	Fri Oct 06 20:36:23 2006 +0000
     9.2 +++ b/src/audio/mint/SDL_mintaudio_mcsn.c	Sat Oct 07 05:36:36 2006 +0000
     9.3 @@ -61,27 +61,14 @@
     9.4  
     9.5  /*--- Static variables ---*/
     9.6  
     9.7 -static unsigned long cookie_snd, cookie_mch;
     9.8 -static cookie_mcsn_t *cookie_mcsn;
     9.9 -
    9.10 -/*--- Audio driver functions ---*/
    9.11 -
    9.12 -static void Mint_CloseAudio(_THIS);
    9.13 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
    9.14 -static void Mint_LockAudio(_THIS);
    9.15 -static void Mint_UnlockAudio(_THIS);
    9.16 -
    9.17 -/* To check/init hardware audio */
    9.18 -static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
    9.19 -static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
    9.20 -
    9.21 -/*--- Audio driver bootstrap functions ---*/
    9.22 +static unsigned long cookie_snd = 0;
    9.23 +static unsigned long cookie_mch = 0;
    9.24 +static cookie_mcsn_t *cookie_mcsn = NULL;
    9.25  
    9.26  static int
    9.27 -Audio_Available(void)
    9.28 +MINTMCSN_Available(void)
    9.29  {
    9.30 -    unsigned long dummy;
    9.31 -    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
    9.32 +    unsigned long dummy = 0;
    9.33  
    9.34      SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND);
    9.35  
    9.36 @@ -90,12 +77,6 @@
    9.37          return (0);
    9.38      }
    9.39  
    9.40 -    /* Check if user asked a different audio driver */
    9.41 -    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
    9.42 -        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
    9.43 -        return (0);
    9.44 -    }
    9.45 -
    9.46      /* Cookie _MCH present ? if not, assume ST machine */
    9.47      if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
    9.48          cookie_mch = MCH_ST;
    9.49 @@ -137,121 +118,77 @@
    9.50  }
    9.51  
    9.52  static void
    9.53 -Audio_DeleteDevice(SDL_AudioDevice * device)
    9.54 -{
    9.55 -    SDL_free(device->hidden);
    9.56 -    SDL_free(device);
    9.57 -}
    9.58 -
    9.59 -static SDL_AudioDevice *
    9.60 -Audio_CreateDevice(int devindex)
    9.61 -{
    9.62 -    SDL_AudioDevice *this;
    9.63 -
    9.64 -    /* Initialize all variables that we clean on shutdown */
    9.65 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
    9.66 -    if (this) {
    9.67 -        SDL_memset(this, 0, (sizeof *this));
    9.68 -        this->hidden = (struct SDL_PrivateAudioData *)
    9.69 -            SDL_malloc((sizeof *this->hidden));
    9.70 -    }
    9.71 -    if ((this == NULL) || (this->hidden == NULL)) {
    9.72 -        SDL_OutOfMemory();
    9.73 -        if (this) {
    9.74 -            SDL_free(this);
    9.75 -        }
    9.76 -        return (0);
    9.77 -    }
    9.78 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
    9.79 -
    9.80 -    /* Set the function pointers */
    9.81 -    this->OpenAudio = Mint_OpenAudio;
    9.82 -    this->CloseAudio = Mint_CloseAudio;
    9.83 -    this->LockAudio = Mint_LockAudio;
    9.84 -    this->UnlockAudio = Mint_UnlockAudio;
    9.85 -    this->free = Audio_DeleteDevice;
    9.86 -
    9.87 -    /* Uses interrupt driven audio, without thread */
    9.88 -    #if SDL_THREADS_DISABLED
    9.89 -    this->SkipMixerLock = 1;
    9.90 -    #endif
    9.91 -
    9.92 -    return this;
    9.93 -}
    9.94 -
    9.95 -AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
    9.96 -    MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
    9.97 -    Audio_Available, Audio_CreateDevice, 0
    9.98 -};
    9.99 -
   9.100 -static void
   9.101 -Mint_LockAudio(_THIS)
   9.102 +MINTMCSN_LockDevice(_THIS)
   9.103  {
   9.104      /* Stop replay */
   9.105      Buffoper(0);
   9.106  }
   9.107  
   9.108  static void
   9.109 -Mint_UnlockAudio(_THIS)
   9.110 +MINTMCSN_UnlockDevice(_THIS)
   9.111  {
   9.112      /* Restart replay */
   9.113      Buffoper(SB_PLA_ENA | SB_PLA_RPT);
   9.114  }
   9.115  
   9.116  static void
   9.117 -Mint_CloseAudio(_THIS)
   9.118 +MINTMCSN_CloseDevice(_THIS)
   9.119  {
   9.120 -    /* Stop replay */
   9.121 -    SDL_MintAudio_WaitThread();
   9.122 -    Buffoper(0);
   9.123 +    if (this->hidden != NULL) {
   9.124 +        /* Stop replay */
   9.125 +        SDL_MintAudio_WaitThread();
   9.126 +        Buffoper(0);
   9.127  
   9.128 -    if (!SDL_MintAudio_mint_present) {
   9.129 -        /* Uninstall interrupt */
   9.130 -        Jdisint(MFP_DMASOUND);
   9.131 -    }
   9.132 +        if (!SDL_MintAudio_mint_present) {
   9.133 +            /* Uninstall interrupt */
   9.134 +            Jdisint(MFP_DMASOUND);
   9.135 +        }
   9.136  
   9.137 -    /* Wait if currently playing sound */
   9.138 -    while (SDL_MintAudio_mutex != 0) {
   9.139 -    }
   9.140 +        /* Wait if currently playing sound */
   9.141 +        while (SDL_MintAudio_mutex != 0) {}
   9.142  
   9.143 -    /* Clear buffers */
   9.144 -    if (SDL_MintAudio_audiobuf[0]) {
   9.145 -        Mfree(SDL_MintAudio_audiobuf[0]);
   9.146 -        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   9.147 +        /* Clear buffers */
   9.148 +        if (SDL_MintAudio_audiobuf[0]) {
   9.149 +            Mfree(SDL_MintAudio_audiobuf[0]);
   9.150 +            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
   9.151 +        }
   9.152 +
   9.153 +        /* Unlock sound system */
   9.154 +        Unlocksnd();
   9.155 +
   9.156 +        SDL_free(this->hidden);
   9.157 +        this->hidden = NULL;
   9.158      }
   9.159 -
   9.160 -    /* Unlock sound system */
   9.161 -    Unlocksnd();
   9.162  }
   9.163  
   9.164  static int
   9.165 -Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
   9.166 +MINTMCSN_CheckAudio(_THIS)
   9.167  {
   9.168      int i;
   9.169      unsigned long masterclock, masterprediv;
   9.170  
   9.171      DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
   9.172 -                 SDL_AUDIO_BITSIZE(spec->format)));
   9.173 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
   9.174 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
   9.175 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
   9.176 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
   9.177 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
   9.178 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
   9.179 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
   9.180 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
   9.181 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
   9.182 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
   9.183 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
   9.184  
   9.185 -    if (spec->channels > 2) {
   9.186 -        spec->channels = 2;     /* no more than stereo! */
   9.187 +    if (this->spec.channels > 2) {
   9.188 +        this->spec.channels = 2;     /* no more than stereo! */
   9.189      }
   9.190  
   9.191      /* Check formats available */
   9.192      MINTAUDIO_freqcount = 0;
   9.193      switch (cookie_mcsn->play) {
   9.194      case MCSN_ST:
   9.195 -        spec->channels = 1;
   9.196 -        spec->format = AUDIO_S8;        /* FIXME: is it signed or unsigned ? */
   9.197 +        this->spec.channels = 1;
   9.198 +        this->spec.format = AUDIO_S8;  /* FIXME: is it signed or unsigned ? */
   9.199          SDL_MintAudio_AddFrequency(this, 12500, 0, 0, -1);
   9.200          break;
   9.201      case MCSN_TT:              /* Also STE, Mega STE */
   9.202 -        spec->format = AUDIO_S8;
   9.203 +        this->spec.format = AUDIO_S8;
   9.204          masterclock = MASTERCLOCK_STE;
   9.205          masterprediv = MASTERPREDIV_STE;
   9.206          if ((cookie_mch >> 16) == MCH_TT) {
   9.207 @@ -285,10 +222,10 @@
   9.208                                             (1 << i) - 1, -1);
   9.209              }
   9.210          }
   9.211 -        spec->format |= SDL_AUDIO_MASK_SIGNED;  /* Audio is always signed */
   9.212 -        if ((SDL_AUDIO_BITSIZE(spec->format)) == 16) {
   9.213 -            spec->format |= SDL_AUDIO_MASK_ENDIAN;      /* Audio is always big endian */
   9.214 -            spec->channels = 2; /* 16 bits always stereo */
   9.215 +        this->spec.format |= SDL_AUDIO_MASK_SIGNED;  /* Audio is always signed */
   9.216 +        if ((SDL_AUDIO_BITSIZE(this->spec.format)) == 16) {
   9.217 +            this->spec.format |= SDL_AUDIO_MASK_ENDIAN;      /* Audio is always big endian */
   9.218 +            this->spec.channels = 2; /* 16 bits always stereo */
   9.219          }
   9.220          break;
   9.221      }
   9.222 @@ -302,22 +239,22 @@
   9.223      }
   9.224  #endif
   9.225  
   9.226 -    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
   9.227 -    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   9.228 +    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
   9.229 +    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
   9.230  
   9.231      DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
   9.232 -                 SDL_AUDIO_BITSIZE(spec->format)));
   9.233 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
   9.234 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
   9.235 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
   9.236 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
   9.237 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
   9.238 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
   9.239 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
   9.240 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
   9.241 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
   9.242 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
   9.243 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
   9.244  
   9.245      return 0;
   9.246  }
   9.247  
   9.248  static void
   9.249 -Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
   9.250 +MINTMCSN_InitAudio(_THIS)
   9.251  {
   9.252      int channels_mode, prediv, dmaclock;
   9.253      void *buffer;
   9.254 @@ -334,9 +271,9 @@
   9.255  
   9.256      /* Select replay format */
   9.257      channels_mode = STEREO16;
   9.258 -    switch (SDL_AUDIO_BITSIZE(spec->format)) {
   9.259 +    switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
   9.260      case 8:
   9.261 -        if (spec->channels == 2) {
   9.262 +        if (this->spec.channels == 2) {
   9.263              channels_mode = STEREO8;
   9.264          } else {
   9.265              channels_mode = MONO8;
   9.266 @@ -363,7 +300,7 @@
   9.267  
   9.268      /* Set buffer */
   9.269      buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
   9.270 -    if (Setbuffer(0, buffer, buffer + spec->size) < 0) {
   9.271 +    if (Setbuffer(0, buffer, buffer + this->spec.size) < 0) {
   9.272          DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
   9.273      }
   9.274  
   9.275 @@ -386,35 +323,46 @@
   9.276  }
   9.277  
   9.278  static int
   9.279 -Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
   9.280 +MINTMCSN_OpenDevice(_THIS, const char *devname, int iscapture)
   9.281  {
   9.282      /* Lock sound system */
   9.283      if (Locksnd() != 1) {
   9.284 -        SDL_SetError("Mint_OpenAudio: Audio system already in use");
   9.285 -        return (-1);
   9.286 +        SDL_SetError("MINTMCSN_OpenDevice: Audio system already in use");
   9.287 +        return 0;
   9.288      }
   9.289  
   9.290      SDL_MintAudio_device = this;
   9.291  
   9.292      /* Check audio capabilities */
   9.293 -    if (Mint_CheckAudio(this, spec) == -1) {
   9.294 -        return -1;
   9.295 +    if (MINTMCSN_CheckAudio(this) == -1) {
   9.296 +        return 0;
   9.297      }
   9.298  
   9.299 -    SDL_CalculateAudioSpec(spec);
   9.300 +    /* Initialize all variables that we clean on shutdown */
   9.301 +    this->hidden = (struct SDL_PrivateAudioData *)
   9.302 +                        SDL_malloc((sizeof *this->hidden));
   9.303 +    if (this->hidden == NULL) {
   9.304 +        SDL_OutOfMemory();
   9.305 +        return 0;
   9.306 +    }
   9.307 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   9.308 +
   9.309 +    SDL_CalculateAudioSpec(&this->spec);
   9.310  
   9.311      /* Allocate memory for audio buffers in DMA-able RAM */
   9.312 -    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
   9.313 +    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
   9.314  
   9.315 -    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
   9.316 +    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
   9.317      if (SDL_MintAudio_audiobuf[0] == NULL) {
   9.318 -        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
   9.319 -        return (-1);
   9.320 +        SDL_free(this->hidden);
   9.321 +        this->hidden = NULL;
   9.322 +        SDL_OutOfMemory();
   9.323 +        return 0;
   9.324      }
   9.325 -    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
   9.326 +    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
   9.327      SDL_MintAudio_numbuf = 0;
   9.328 -    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
   9.329 -    SDL_MintAudio_audiosize = spec->size;
   9.330 +    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
   9.331 +    SDL_MintAudio_audiosize = this->spec.size;
   9.332      SDL_MintAudio_mutex = 0;
   9.333  
   9.334      DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
   9.335 @@ -425,9 +373,29 @@
   9.336      SDL_MintAudio_CheckFpu();
   9.337  
   9.338      /* Setup audio hardware */
   9.339 -    Mint_InitAudio(this, spec);
   9.340 +    MINTMCSN_InitAudio(this);
   9.341  
   9.342 -    return (1);                 /* We don't use SDL threaded audio */
   9.343 +    return 1;  /* good to go. */
   9.344  }
   9.345  
   9.346 +static int
   9.347 +MINTMCSN_Init(SDL_AudioDriverImpl *impl)
   9.348 +{
   9.349 +    /* Set the function pointers */
   9.350 +    impl->OpenDevice = MINTMCSN_OpenDevice;
   9.351 +    impl->CloseDevice = MINTMCSN_CloseDevice;
   9.352 +    impl->LockAudio = MINTMCSN_LockAudio;
   9.353 +    impl->UnlockAudio = MINTMCSN_UnlockAudio;
   9.354 +    impl->OnlyHasDefaultOutputDevice = 1;
   9.355 +    impl->ProvidesOwnCallbackThread = 1;
   9.356 +    impl->SkipMixerLock = 1;
   9.357 +
   9.358 +    return 1;
   9.359 +}
   9.360 +
   9.361 +AudioBootStrap MINTAUDIO_MCSN_bootstrap = {
   9.362 +    MINT_AUDIO_DRIVER_NAME, "MiNT MCSN audio driver",
   9.363 +    MINTMCSN_Available, MINTMCSN_Init, 0
   9.364 +};
   9.365 +
   9.366  /* vi: set ts=4 sw=4 expandtab: */
    10.1 --- a/src/audio/mint/SDL_mintaudio_stfa.c	Fri Oct 06 20:36:23 2006 +0000
    10.2 +++ b/src/audio/mint/SDL_mintaudio_stfa.c	Sat Oct 07 05:36:36 2006 +0000
    10.3 @@ -59,8 +59,9 @@
    10.4  
    10.5  /*--- Static variables ---*/
    10.6  
    10.7 -static unsigned long cookie_snd, cookie_mch;
    10.8 -static cookie_stfa_t *cookie_stfa;
    10.9 +static unsigned long cookie_snd = 0;
   10.10 +static unsigned long cookie_mch = 0;
   10.11 +static cookie_stfa_t *cookie_stfa = NULL;
   10.12  
   10.13  static const int freqs[16] = {
   10.14      4995, 6269, 7493, 8192,
   10.15 @@ -69,30 +70,9 @@
   10.16      30720, 32336, 43885, 49152
   10.17  };
   10.18  
   10.19 -/*--- Audio driver functions ---*/
   10.20 -
   10.21 -static void Mint_CloseAudio(_THIS);
   10.22 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
   10.23 -static void Mint_LockAudio(_THIS);
   10.24 -static void Mint_UnlockAudio(_THIS);
   10.25 -
   10.26 -/* To check/init hardware audio */
   10.27 -static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
   10.28 -static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
   10.29 -
   10.30 -/*--- Audio driver bootstrap functions ---*/
   10.31 -
   10.32  static int
   10.33 -Audio_Available(void)
   10.34 +MINTSTFA_Available(void)
   10.35  {
   10.36 -    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
   10.37 -
   10.38 -    /* Check if user asked a different audio driver */
   10.39 -    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
   10.40 -        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
   10.41 -        return (0);
   10.42 -    }
   10.43 -
   10.44      /* Cookie _MCH present ? if not, assume ST machine */
   10.45      if (Getcookie(C__MCH, &cookie_mch) == C_NOTFOUND) {
   10.46          cookie_mch = MCH_ST;
   10.47 @@ -116,115 +96,65 @@
   10.48  }
   10.49  
   10.50  static void
   10.51 -Audio_DeleteDevice(SDL_AudioDevice * device)
   10.52 -{
   10.53 -    SDL_free(device->hidden);
   10.54 -    SDL_free(device);
   10.55 -}
   10.56 -
   10.57 -static SDL_AudioDevice *
   10.58 -Audio_CreateDevice(int devindex)
   10.59 +MINTSTFA_LockDevice(_THIS)
   10.60  {
   10.61 -    SDL_AudioDevice *this;
   10.62 -
   10.63 -    /* Initialize all variables that we clean on shutdown */
   10.64 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
   10.65 -    if (this) {
   10.66 -        SDL_memset(this, 0, (sizeof *this));
   10.67 -        this->hidden = (struct SDL_PrivateAudioData *)
   10.68 -            SDL_malloc((sizeof *this->hidden));
   10.69 -    }
   10.70 -    if ((this == NULL) || (this->hidden == NULL)) {
   10.71 -        SDL_OutOfMemory();
   10.72 -        if (this) {
   10.73 -            SDL_free(this);
   10.74 -        }
   10.75 -        return (0);
   10.76 -    }
   10.77 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   10.78 -
   10.79 -    /* Set the function pointers */
   10.80 -    this->OpenAudio = Mint_OpenAudio;
   10.81 -    this->CloseAudio = Mint_CloseAudio;
   10.82 -    this->LockAudio = Mint_LockAudio;
   10.83 -    this->UnlockAudio = Mint_UnlockAudio;
   10.84 -    this->free = Audio_DeleteDevice;
   10.85 -
   10.86 -    /* Uses interrupt driven audio, without thread */
   10.87 -    #if SDL_THREADS_DISABLED
   10.88 -    this->SkipMixerLock = 1;
   10.89 -    #endif
   10.90 -
   10.91 -    return this;
   10.92 -}
   10.93 -
   10.94 -AudioBootStrap MINTAUDIO_STFA_bootstrap = {
   10.95 -    MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
   10.96 -    Audio_Available, Audio_CreateDevice, 0
   10.97 -};
   10.98 -
   10.99 -static void
  10.100 -Mint_LockAudio(_THIS)
  10.101 -{
  10.102 -    void *oldpile;
  10.103 -
  10.104      /* Stop replay */
  10.105 -    oldpile = (void *) Super(0);
  10.106 +    void *oldpile = (void *) Super(0);
  10.107      cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
  10.108      Super(oldpile);
  10.109  }
  10.110  
  10.111  static void
  10.112 -Mint_UnlockAudio(_THIS)
  10.113 +MINTSTFA_UnlockDevice(_THIS)
  10.114  {
  10.115 -    void *oldpile;
  10.116 -
  10.117      /* Restart replay */
  10.118 -    oldpile = (void *) Super(0);
  10.119 +    void *oldpile = (void *) Super(0);
  10.120      cookie_stfa->sound_enable = STFA_PLAY_ENABLE | STFA_PLAY_REPEAT;
  10.121      Super(oldpile);
  10.122  }
  10.123  
  10.124  static void
  10.125 -Mint_CloseAudio(_THIS)
  10.126 +MINTSTFA_CloseDevice(_THIS)
  10.127  {
  10.128 -    void *oldpile;
  10.129 -
  10.130 -    /* Stop replay */
  10.131 -    oldpile = (void *) Super(0);
  10.132 -    cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
  10.133 -    Super(oldpile);
  10.134 +    if (this->hidden != NULL) {
  10.135 +        /* Stop replay */
  10.136 +        void *oldpile = (void *) Super(0);
  10.137 +        cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
  10.138 +        Super(oldpile);
  10.139  
  10.140 -    /* Wait if currently playing sound */
  10.141 -    while (SDL_MintAudio_mutex != 0) {
  10.142 -    }
  10.143 +        /* Wait if currently playing sound */
  10.144 +        while (SDL_MintAudio_mutex != 0) {}
  10.145  
  10.146 -    /* Clear buffers */
  10.147 -    if (SDL_MintAudio_audiobuf[0]) {
  10.148 -        Mfree(SDL_MintAudio_audiobuf[0]);
  10.149 -        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  10.150 +        /* Clear buffers */
  10.151 +        if (SDL_MintAudio_audiobuf[0]) {
  10.152 +            Mfree(SDL_MintAudio_audiobuf[0]);
  10.153 +            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  10.154 +        }
  10.155 +
  10.156 +        SDL_free(this->hidden);
  10.157 +        this->hidden = NULL;
  10.158      }
  10.159  }
  10.160  
  10.161  static int
  10.162 -Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
  10.163 +MINTSTFA_CheckAudio(_THIS)
  10.164  {
  10.165      int i;
  10.166  
  10.167      DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
  10.168 -                 SDL_AUDIO_BITSIZE(spec->format)));
  10.169 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
  10.170 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
  10.171 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
  10.172 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
  10.173 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
  10.174 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
  10.175 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
  10.176 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
  10.177 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
  10.178 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
  10.179 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
  10.180  
  10.181 -    if (SDL_AUDIO_BITSIZE(spec->format) > 16) {
  10.182 -        spec->format = AUDIO_S16SYS;    /* clamp out int32/float32 ... */
  10.183 +    if (SDL_AUDIO_BITSIZE(this->spec.format) > 16) {
  10.184 +        this->spec.format = AUDIO_S16SYS;    /* clamp out int32/float32 ... */
  10.185      }
  10.186  
  10.187 -    if (spec->channels > 2) {
  10.188 -        spec->channels = 2;     /* no more than stereo! */
  10.189 +    if (this->spec.channels > 2) {
  10.190 +        this->spec.channels = 2;     /* no more than stereo! */
  10.191      }
  10.192  
  10.193      /* Check formats available */
  10.194 @@ -242,29 +172,25 @@
  10.195      }
  10.196  #endif
  10.197  
  10.198 -    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
  10.199 -    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
  10.200 +    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
  10.201 +    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
  10.202  
  10.203      DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
  10.204 -                 SDL_AUDIO_BITSIZE(spec->format)));
  10.205 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
  10.206 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
  10.207 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
  10.208 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
  10.209 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
  10.210 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
  10.211 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
  10.212 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
  10.213 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
  10.214 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
  10.215 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
  10.216  
  10.217      return 0;
  10.218  }
  10.219  
  10.220  static void
  10.221 -Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
  10.222 +MINTSTFA_InitAudio(_THIS)
  10.223  {
  10.224 -    void *buffer;
  10.225 -    void *oldpile;
  10.226 -
  10.227 -    buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
  10.228 -
  10.229 -    oldpile = (void *) Super(0);
  10.230 +    void *buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
  10.231 +    void *oldpile = (void *) Super(0);
  10.232  
  10.233      /* Stop replay */
  10.234      cookie_stfa->sound_enable = STFA_PLAY_DISABLE;
  10.235 @@ -272,22 +198,22 @@
  10.236      /* Select replay format */
  10.237      cookie_stfa->sound_control =
  10.238          MINTAUDIO_frequencies[MINTAUDIO_numfreq].predivisor;
  10.239 -    if (SDL_AUDIO_BITSIZE(spec->format) == 8) {
  10.240 +    if (SDL_AUDIO_BITSIZE(this->spec.format) == 8) {
  10.241          cookie_stfa->sound_control |= STFA_FORMAT_8BIT;
  10.242      } else {
  10.243          cookie_stfa->sound_control |= STFA_FORMAT_16BIT;
  10.244      }
  10.245 -    if (spec->channels == 2) {
  10.246 +    if (this->spec.channels == 2) {
  10.247          cookie_stfa->sound_control |= STFA_FORMAT_STEREO;
  10.248      } else {
  10.249          cookie_stfa->sound_control |= STFA_FORMAT_MONO;
  10.250      }
  10.251 -    if (SDL_AUDIO_ISSIGNED(spec->format) != 0) {
  10.252 +    if (SDL_AUDIO_ISSIGNED(this->spec.format) != 0) {
  10.253          cookie_stfa->sound_control |= STFA_FORMAT_SIGNED;
  10.254      } else {
  10.255          cookie_stfa->sound_control |= STFA_FORMAT_UNSIGNED;
  10.256      }
  10.257 -    if (SDL_AUDIO_ISBIGENDIAN(spec->format) != 0) {
  10.258 +    if (SDL_AUDIO_ISBIGENDIAN(this->spec.format) != 0) {
  10.259          cookie_stfa->sound_control |= STFA_FORMAT_BIGENDIAN;
  10.260      } else {
  10.261          cookie_stfa->sound_control |= STFA_FORMAT_LITENDIAN;
  10.262 @@ -295,7 +221,7 @@
  10.263  
  10.264      /* Set buffer */
  10.265      cookie_stfa->sound_start = (unsigned long) buffer;
  10.266 -    cookie_stfa->sound_end = (unsigned long) (buffer + spec->size);
  10.267 +    cookie_stfa->sound_end = (unsigned long) (buffer + this->spec.size);
  10.268  
  10.269      /* Set interrupt */
  10.270      cookie_stfa->stfa_it = SDL_MintAudio_StfaInterrupt;
  10.271 @@ -309,29 +235,40 @@
  10.272  }
  10.273  
  10.274  static int
  10.275 -Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
  10.276 +MINTSTFA_OpenDevice(_THIS, const char *devname, int iscapture)
  10.277  {
  10.278      SDL_MintAudio_device = this;
  10.279  
  10.280      /* Check audio capabilities */
  10.281 -    if (Mint_CheckAudio(this, spec) == -1) {
  10.282 -        return -1;
  10.283 +    if (MINTSTFA_CheckAudio(this) == -1) {
  10.284 +        return 0;
  10.285      }
  10.286  
  10.287 -    SDL_CalculateAudioSpec(spec);
  10.288 +    /* Initialize all variables that we clean on shutdown */
  10.289 +    this->hidden = (struct SDL_PrivateAudioData *)
  10.290 +                        SDL_malloc((sizeof *this->hidden));
  10.291 +    if (this->hidden == NULL) {
  10.292 +        SDL_OutOfMemory();
  10.293 +        return 0;
  10.294 +    }
  10.295 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
  10.296 +
  10.297 +    SDL_CalculateAudioSpec(&this->spec);
  10.298  
  10.299      /* Allocate memory for audio buffers in DMA-able RAM */
  10.300 -    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
  10.301 +    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
  10.302  
  10.303 -    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
  10.304 +    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
  10.305      if (SDL_MintAudio_audiobuf[0] == NULL) {
  10.306 -        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
  10.307 -        return (-1);
  10.308 +        SDL_OutOfMemory()
  10.309 +        SDL_free(this->hidden);
  10.310 +        this->hidden = NULL;
  10.311 +        return 0;
  10.312      }
  10.313 -    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
  10.314 +    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
  10.315      SDL_MintAudio_numbuf = 0;
  10.316 -    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
  10.317 -    SDL_MintAudio_audiosize = spec->size;
  10.318 +    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
  10.319 +    SDL_MintAudio_audiosize = this->spec.size;
  10.320      SDL_MintAudio_mutex = 0;
  10.321  
  10.322      DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
  10.323 @@ -342,9 +279,30 @@
  10.324      SDL_MintAudio_CheckFpu();
  10.325  
  10.326      /* Setup audio hardware */
  10.327 -    Mint_InitAudio(this, spec);
  10.328 +    MINTSTFA_InitAudio(this);
  10.329  
  10.330 -    return (1);                 /* We don't use threaded audio */
  10.331 +    return 1;  /* good to go. */
  10.332  }
  10.333  
  10.334 +
  10.335 +static int
  10.336 +MINTSTFA_Init(SDL_AudioDriverImpl *impl)
  10.337 +{
  10.338 +    /* Set the function pointers */
  10.339 +    impl->OpenDevice = MINTSTFA_OpenDevice;
  10.340 +    impl->CloseDevice = MINTSTFA_CloseDevice;
  10.341 +    impl->LockAudio = MINTSTFA_LockAudio;
  10.342 +    impl->UnlockAudio = MINTSTFA_UnlockAudio;
  10.343 +    impl->OnlyHasDefaultOutputDevice = 1;
  10.344 +    impl->ProvidesOwnCallbackThread = 1;
  10.345 +    impl->SkipMixerLock = 1;
  10.346 +
  10.347 +    return 1;
  10.348 +}
  10.349 +
  10.350 +AudioBootStrap MINTAUDIO_STFA_bootstrap = {
  10.351 +    MINT_AUDIO_DRIVER_NAME, "MiNT STFA audio driver",
  10.352 +    MINTSTFA_Available, MINTSTFA_Init, 0
  10.353 +};
  10.354 +
  10.355  /* vi: set ts=4 sw=4 expandtab: */
    11.1 --- a/src/audio/mint/SDL_mintaudio_xbios.c	Fri Oct 06 20:36:23 2006 +0000
    11.2 +++ b/src/audio/mint/SDL_mintaudio_xbios.c	Sat Oct 07 05:36:36 2006 +0000
    11.3 @@ -60,29 +60,12 @@
    11.4  #define DEBUG_PRINT(what)
    11.5  #endif
    11.6  
    11.7 -/*--- Static variables ---*/
    11.8 -
    11.9 -static unsigned long cookie_snd;
   11.10 -
   11.11 -/*--- Audio driver functions ---*/
   11.12 -
   11.13 -static void Mint_CloseAudio(_THIS);
   11.14 -static int Mint_OpenAudio(_THIS, SDL_AudioSpec * spec);
   11.15 -static void Mint_LockAudio(_THIS);
   11.16 -static void Mint_UnlockAudio(_THIS);
   11.17 -
   11.18 -/* To check/init hardware audio */
   11.19 -static int Mint_CheckAudio(_THIS, SDL_AudioSpec * spec);
   11.20 -static void Mint_InitAudio(_THIS, SDL_AudioSpec * spec);
   11.21 -
   11.22 -/*--- Audio driver bootstrap functions ---*/
   11.23 +static unsigned long cookie_snd = 0;
   11.24  
   11.25  static int
   11.26 -Audio_Available(void)
   11.27 +MINTXBIOS_Available(void)
   11.28  {
   11.29 -    unsigned long dummy;
   11.30 -    const char *envr = SDL_getenv("SDL_AUDIODRIVER");
   11.31 -
   11.32 +    unsigned long dummy = 0;
   11.33      /*SDL_MintAudio_mint_present = (Getcookie(C_MiNT, &dummy) == C_FOUND); */
   11.34      SDL_MintAudio_mint_present = SDL_FALSE;
   11.35  
   11.36 @@ -91,12 +74,6 @@
   11.37          return (0);
   11.38      }
   11.39  
   11.40 -    /* Check if user asked a different audio driver */
   11.41 -    if ((envr) && (SDL_strcmp(envr, MINT_AUDIO_DRIVER_NAME) != 0)) {
   11.42 -        DEBUG_PRINT((DEBUG_NAME "user asked a different audio driver\n"));
   11.43 -        return (0);
   11.44 -    }
   11.45 -
   11.46      /* Cookie _SND present ? if not, assume ST machine */
   11.47      if (Getcookie(C__SND, &cookie_snd) == C_NOTFOUND) {
   11.48          cookie_snd = SND_PSG;
   11.49 @@ -121,91 +98,47 @@
   11.50  }
   11.51  
   11.52  static void
   11.53 -Audio_DeleteDevice(SDL_AudioDevice * device)
   11.54 -{
   11.55 -    SDL_free(device->hidden);
   11.56 -    SDL_free(device);
   11.57 -}
   11.58 -
   11.59 -static SDL_AudioDevice *
   11.60 -Audio_CreateDevice(int devindex)
   11.61 -{
   11.62 -    SDL_AudioDevice *this;
   11.63 -
   11.64 -    /* Initialize all variables that we clean on shutdown */
   11.65 -    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
   11.66 -    if (this) {
   11.67 -        SDL_memset(this, 0, (sizeof *this));
   11.68 -        this->hidden = (struct SDL_PrivateAudioData *)
   11.69 -            SDL_malloc((sizeof *this->hidden));
   11.70 -    }
   11.71 -    if ((this == NULL) || (this->hidden == NULL)) {
   11.72 -        SDL_OutOfMemory();
   11.73 -        if (this) {
   11.74 -            SDL_free(this);
   11.75 -        }
   11.76 -        return (0);
   11.77 -    }
   11.78 -    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
   11.79 -
   11.80 -    /* Set the function pointers */
   11.81 -    this->OpenAudio = Mint_OpenAudio;
   11.82 -    this->CloseAudio = Mint_CloseAudio;
   11.83 -    this->LockAudio = Mint_LockAudio;
   11.84 -    this->UnlockAudio = Mint_UnlockAudio;
   11.85 -    this->free = Audio_DeleteDevice;
   11.86 -
   11.87 -    /* Uses interrupt driven audio, without thread */
   11.88 -    #if SDL_THREADS_DISABLED
   11.89 -    this->SkipMixerLock = 1;
   11.90 -    #endif
   11.91 -
   11.92 -    return this;
   11.93 -}
   11.94 -
   11.95 -AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
   11.96 -    MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
   11.97 -    Audio_Available, Audio_CreateDevice, 0
   11.98 -};
   11.99 -
  11.100 -static void
  11.101 -Mint_LockAudio(_THIS)
  11.102 +MINTXBIOS_LockDevice(_THIS)
  11.103  {
  11.104      /* Stop replay */
  11.105      Buffoper(0);
  11.106  }
  11.107  
  11.108  static void
  11.109 -Mint_UnlockAudio(_THIS)
  11.110 +MINTXBIOS_UnlockDevice(_THIS)
  11.111  {
  11.112      /* Restart replay */
  11.113      Buffoper(SB_PLA_ENA | SB_PLA_RPT);
  11.114  }
  11.115  
  11.116  static void
  11.117 -Mint_CloseAudio(_THIS)
  11.118 +MINTXBIOS_CloseDevice(_THIS)
  11.119  {
  11.120 -    /* Stop replay */
  11.121 -    SDL_MintAudio_WaitThread();
  11.122 -    Buffoper(0);
  11.123 +    if (this->hidden != NULL) {
  11.124 +        /* Stop replay */
  11.125 +        SDL_MintAudio_WaitThread();
  11.126 +        Buffoper(0);
  11.127  
  11.128 -    if (!SDL_MintAudio_mint_present) {
  11.129 -        /* Uninstall interrupt */
  11.130 -        Jdisint(MFP_DMASOUND);
  11.131 -    }
  11.132 +        if (!SDL_MintAudio_mint_present) {
  11.133 +            /* Uninstall interrupt */
  11.134 +            Jdisint(MFP_DMASOUND);
  11.135 +        }
  11.136  
  11.137 -    /* Wait if currently playing sound */
  11.138 -    while (SDL_MintAudio_mutex != 0) {
  11.139 -    }
  11.140 +        /* Wait if currently playing sound */
  11.141 +        while (SDL_MintAudio_mutex != 0) {}
  11.142  
  11.143 -    /* Clear buffers */
  11.144 -    if (SDL_MintAudio_audiobuf[0]) {
  11.145 -        Mfree(SDL_MintAudio_audiobuf[0]);
  11.146 -        SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  11.147 +        /* Clear buffers */
  11.148 +        if (SDL_MintAudio_audiobuf[0]) {
  11.149 +            Mfree(SDL_MintAudio_audiobuf[0]);
  11.150 +            SDL_MintAudio_audiobuf[0] = SDL_MintAudio_audiobuf[1] = NULL;
  11.151 +        }
  11.152 +
  11.153 +        /* Unlock sound system */
  11.154 +        Unlocksnd();
  11.155 +
  11.156 +        SDL_free(this->hidden);
  11.157 +        this->hidden = NULL;
  11.158      }
  11.159 -
  11.160 -    /* Unlock sound system */
  11.161 -    Unlocksnd();
  11.162  }
  11.163  
  11.164  /* Falcon XBIOS implementation of Devconnect() is buggy with external clock */
  11.165 @@ -274,7 +207,7 @@
  11.166  }
  11.167  
  11.168  static void
  11.169 -Mint_CheckExternalClock(_THIS)
  11.170 +MINTXBIOS_CheckExternalClock(_THIS)
  11.171  {
  11.172  #define SIZE_BUF_CLOCK_MEASURE (44100/10)
  11.173  
  11.174 @@ -360,33 +293,33 @@
  11.175  }
  11.176  
  11.177  static int
  11.178 -Mint_CheckAudio(_THIS, SDL_AudioSpec * spec)
  11.179 +MINTXBIOS_CheckAudio(_THIS)
  11.180  {
  11.181      int i;
  11.182      Uint32 extclock;
  11.183  
  11.184      DEBUG_PRINT((DEBUG_NAME "asked: %d bits, ",
  11.185 -                 SDL_AUDIO_BITSIZE(spec->format)));
  11.186 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
  11.187 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
  11.188 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
  11.189 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
  11.190 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
  11.191 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
  11.192 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
  11.193 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
  11.194 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
  11.195 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
  11.196 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
  11.197  
  11.198 -    spec->format |= SDL_AUDIO_MASK_SIGNED;      /* Audio is always signed */
  11.199 +    this->spec.format |= SDL_AUDIO_MASK_SIGNED;   /* Audio is always signed */
  11.200  
  11.201      /* clamp out int32/float32 */
  11.202 -    if (SDL_AUDIO_BITSIZE(spec->format) >= 16) {
  11.203 -        spec->format = AUDIO_S16MSB;    /* Audio is always big endian */
  11.204 -        spec->channels = 2;     /* 16 bits always stereo */
  11.205 -    } else if (spec->channels > 2) {
  11.206 -        spec->channels = 2;     /* no more than stereo! */
  11.207 +    if (SDL_AUDIO_BITSIZE(this->spec.format) >= 16) {
  11.208 +        this->spec.format = AUDIO_S16MSB;    /* Audio is always big endian */
  11.209 +        this->spec.channels = 2;     /* 16 bits always stereo */
  11.210 +    } else if (this->spec.channels > 2) {
  11.211 +        this->spec.channels = 2;     /* no more than stereo! */
  11.212      }
  11.213  
  11.214      MINTAUDIO_freqcount = 0;
  11.215  
  11.216      /* Add external clocks if present */
  11.217 -    Mint_CheckExternalClock(this);
  11.218 +    MINTXBIOS_CheckExternalClock(this);
  11.219  
  11.220      /* Standard clocks */
  11.221      for (i = 1; i < 12; i++) {
  11.222 @@ -409,22 +342,22 @@
  11.223      }
  11.224  #endif
  11.225  
  11.226 -    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, spec->freq);
  11.227 -    spec->freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
  11.228 +    MINTAUDIO_numfreq = SDL_MintAudio_SearchFrequency(this, this->spec.freq);
  11.229 +    this->spec.freq = MINTAUDIO_frequencies[MINTAUDIO_numfreq].frequency;
  11.230  
  11.231      DEBUG_PRINT((DEBUG_NAME "obtained: %d bits, ",
  11.232 -                 SDL_AUDIO_BITSIZE(spec->format)));
  11.233 -    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(spec->format)));
  11.234 -    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(spec->format)));
  11.235 -    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(spec->format)));
  11.236 -    DEBUG_PRINT(("channels=%d, ", spec->channels));
  11.237 -    DEBUG_PRINT(("freq=%d\n", spec->freq));
  11.238 +                 SDL_AUDIO_BITSIZE(this->spec.format)));
  11.239 +    DEBUG_PRINT(("float=%d, ", SDL_AUDIO_ISFLOAT(this->spec.format)));
  11.240 +    DEBUG_PRINT(("signed=%d, ", SDL_AUDIO_ISSIGNED(this->spec.format)));
  11.241 +    DEBUG_PRINT(("big endian=%d, ", SDL_AUDIO_ISBIGENDIAN(this->spec.format)));
  11.242 +    DEBUG_PRINT(("channels=%d, ", this->spec.channels));
  11.243 +    DEBUG_PRINT(("freq=%d\n", this->spec.freq));
  11.244  
  11.245      return 0;
  11.246  }
  11.247  
  11.248  static void
  11.249 -Mint_InitAudio(_THIS, SDL_AudioSpec * spec)
  11.250 +MINTXBIOS_InitAudio(_THIS)
  11.251  {
  11.252      int channels_mode, dmaclock, prediv;
  11.253      void *buffer;
  11.254 @@ -441,9 +374,9 @@
  11.255  
  11.256      /* Select replay format */
  11.257      channels_mode = STEREO16;
  11.258 -    switch (SDL_AUDIO_BITSIZE(spec->format)) {
  11.259 +    switch (SDL_AUDIO_BITSIZE(this->spec.format)) {
  11.260      case 8:
  11.261 -        if (spec->channels == 2) {
  11.262 +        if (this->spec.channels == 2) {
  11.263              channels_mode = STEREO8;
  11.264          } else {
  11.265              channels_mode = MONO8;
  11.266 @@ -466,7 +399,7 @@
  11.267  
  11.268      /* Set buffer */
  11.269      buffer = SDL_MintAudio_audiobuf[SDL_MintAudio_numbuf];
  11.270 -    if (Setbuffer(0, buffer, buffer + spec->size) < 0) {
  11.271 +    if (Setbuffer(0, buffer, buffer + this->spec.size) < 0) {
  11.272          DEBUG_PRINT((DEBUG_NAME "Setbuffer() failed\n"));
  11.273      }
  11.274  
  11.275 @@ -490,35 +423,46 @@
  11.276  }
  11.277  
  11.278  static int
  11.279 -Mint_OpenAudio(_THIS, SDL_AudioSpec * spec)
  11.280 +MINTXBIOS_OpenDevice(_THIS, const char *devname, int iscapture)
  11.281  {
  11.282      /* Lock sound system */
  11.283      if (Locksnd() != 1) {
  11.284 -        SDL_SetError("Mint_OpenAudio: Audio system already in use");
  11.285 -        return (-1);
  11.286 +        SDL_SetError("MINTXBIOS_OpenAudio: Audio system already in use");
  11.287 +        return 0;
  11.288      }
  11.289  
  11.290      SDL_MintAudio_device = this;
  11.291  
  11.292      /* Check audio capabilities */
  11.293 -    if (Mint_CheckAudio(this, spec) == -1) {
  11.294 -        return -1;
  11.295 +    if (MINTXBIOS_CheckAudio(this) == -1) {
  11.296 +        return 0;
  11.297      }
  11.298  
  11.299 -    SDL_CalculateAudioSpec(spec);
  11.300 +    /* Initialize all variables that we clean on shutdown */
  11.301 +    this->hidden = (struct SDL_PrivateAudioData *)
  11.302 +                        SDL_malloc((sizeof *this->hidden));
  11.303 +    if (this->hidden == NULL) {
  11.304 +        SDL_OutOfMemory();
  11.305 +        return 0;
  11.306 +    }
  11.307 +    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
  11.308 +
  11.309 +    SDL_CalculateAudioSpec(&this->spec);
  11.310  
  11.311      /* Allocate memory for audio buffers in DMA-able RAM */
  11.312 -    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", spec->size));
  11.313 +    DEBUG_PRINT((DEBUG_NAME "buffer size=%d\n", this->spec.size));
  11.314  
  11.315 -    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(spec->size * 2, MX_STRAM);
  11.316 +    SDL_MintAudio_audiobuf[0] = Atari_SysMalloc(this->spec.size * 2, MX_STRAM);
  11.317      if (SDL_MintAudio_audiobuf[0] == NULL) {
  11.318 -        SDL_SetError("MINT_OpenAudio: Not enough memory for audio buffer");
  11.319 -        return (-1);
  11.320 +        SDL_free(this->hidden);
  11.321 +        this->hidden = NULL;
  11.322 +        SDL_OutOfMemory();
  11.323 +        return 0;
  11.324      }
  11.325 -    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + spec->size;
  11.326 +    SDL_MintAudio_audiobuf[1] = SDL_MintAudio_audiobuf[0] + this->spec.size;
  11.327      SDL_MintAudio_numbuf = 0;
  11.328 -    SDL_memset(SDL_MintAudio_audiobuf[0], spec->silence, spec->size * 2);
  11.329 -    SDL_MintAudio_audiosize = spec->size;
  11.330 +    SDL_memset(SDL_MintAudio_audiobuf[0],this->spec.silence,this->spec.size*2);
  11.331 +    SDL_MintAudio_audiosize = this->spec.size;
  11.332      SDL_MintAudio_mutex = 0;
  11.333  
  11.334      DEBUG_PRINT((DEBUG_NAME "buffer 0 at 0x%08x\n",
  11.335 @@ -529,9 +473,29 @@
  11.336      SDL_MintAudio_CheckFpu();
  11.337  
  11.338      /* Setup audio hardware */
  11.339 -    Mint_InitAudio(this, spec);
  11.340 +    MINTXBIOS_InitAudio(this);
  11.341  
  11.342 -    return (1);                 /* We don't use SDL threaded audio */
  11.343 +    return 1;  /* good to go. */
  11.344  }
  11.345  
  11.346 +static int
  11.347 +MINTXBIOS_Init(SDL_AudioDriverImpl *impl)
  11.348 +{
  11.349 +    /* Set the function pointers */
  11.350 +    impl->OpenDevice = MINTXBIOS_OpenDevice;
  11.351 +    impl->CloseDevice = MINTXBIOS_CloseDevice;
  11.352 +    impl->LockAudio = MINTXBIOS_LockAudio;
  11.353 +    impl->UnlockAudio = MINTXBIOS_UnlockAudio;
  11.354 +    impl->OnlyHasDefaultOutputDevice = 1;
  11.355 +    impl->ProvidesOwnCallbackThread = 1;
  11.356 +    impl->SkipMixerLock = 1;
  11.357 +
  11.358 +    return 1;
  11.359 +}
  11.360 +
  11.361 +AudioBootStrap MINTAUDIO_XBIOS_bootstrap = {
  11.362 +    MINT_AUDIO_DRIVER_NAME, "MiNT XBIOS audio driver",
  11.363 +    MINTXBIOS_Available, MINTXBIOS_Init, 0
  11.364 +};
  11.365 +
  11.366  /* vi: set ts=4 sw=4 expandtab: */