src/audio/bsd/SDL_bsdaudio.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 04 Oct 2006 21:27:53 +0000
branchSDL-ryan-multiple-audio-device
changeset 3798 c8b3d3d13ed1
parent 1982 3b4ce57c6215
child 3816 9d070c1a45fa
permissions -rw-r--r--
Audio bootstraps can now specify that a driver is only to be used if explicitly requested (for things like the "disk" driver that is always available but you would never want to default to using). Trimmed out code that can be handled by stubs in the core. The "dummy" driver is pretty damned small now. :)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
    SDL - Simple DirectMedia Layer
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
    Copyright (C) 1997-2004 Sam Lantinga
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
    This library is free software; you can redistribute it and/or
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
    modify it under the terms of the GNU Library General Public
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
    License as published by the Free Software Foundation; either
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
    version 2 of the License, or (at your option) any later version.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     9
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    10
    This library is distributed in the hope that it will be useful,
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
    Library General Public License for more details.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
    You should have received a copy of the GNU Library General Public
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
    License along with this library; if not, write to the Free
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
    Sam Lantinga
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
    slouken@libsdl.org
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
*/
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#include "SDL_config.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
/*
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
 * Driver for native OpenBSD/NetBSD audio(4).
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
 * vedge@vedge.com.ar.
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
 */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
#include <errno.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
#include <unistd.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
#include <fcntl.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
#include <sys/time.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
#include <sys/ioctl.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#include <sys/stat.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
#include <sys/types.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
#include <sys/audioio.h>
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
#include "SDL_timer.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
#include "SDL_audio.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
#include "../SDL_audiomem.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
#include "../SDL_audio_c.h"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
#include "../SDL_audiodev_c.h"
1583
95451df282c3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1567
diff changeset
    43
#include "SDL_bsdaudio.h"
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
/* The tag name used by NetBSD/OpenBSD audio */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
#ifdef __NetBSD__
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
#define BSD_AUDIO_DRIVER_NAME         "netbsd"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
#define BSD_AUDIO_DRIVER_DESC         "Native NetBSD audio"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
#else
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
#define BSD_AUDIO_DRIVER_NAME         "openbsd"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
#define BSD_AUDIO_DRIVER_DESC         "Native OpenBSD audio"
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
#endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
/* Open the audio device for playback, and don't block if busy */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
/* #define USE_BLOCKING_WRITES */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
/* Use timer for synchronization */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
/* #define USE_TIMER_SYNC */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
/* #define DEBUG_AUDIO */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
/* #define DEBUG_AUDIO_STREAM */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
#ifdef USE_BLOCKING_WRITES
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
#define OPEN_FLAGS	O_WRONLY
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
#else
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
#define OPEN_FLAGS	(O_WRONLY|O_NONBLOCK)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
#endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
/* Audio driver functions */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
static void OBSD_WaitAudio(_THIS);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
    71
static int OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
static void OBSD_PlayAudio(_THIS);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
static Uint8 *OBSD_GetAudioBuf(_THIS);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
static void OBSD_CloseAudio(_THIS);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
#ifdef DEBUG_AUDIO
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
static void OBSD_Status(_THIS);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
#endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
/* Audio driver bootstrap functions */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
static int
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
Audio_Available(void)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
{
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
    int fd;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    int available;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
    available = 0;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
    fd = SDL_OpenAudioPath(NULL, 0, OPEN_FLAGS, 0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
    90
    if (fd >= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
    91
        available = 1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
    92
        close(fd);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
    94
    return (available);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
static void
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
    98
Audio_DeleteDevice(SDL_AudioDevice * device)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
{
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
    SDL_free(device->hidden);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    SDL_free(device);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   104
static SDL_AudioDevice *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   105
Audio_CreateDevice(int devindex)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
{
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
    SDL_AudioDevice *this;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
    /* Initialize all variables that we clean on shutdown */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   110
    this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   111
    if (this) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   112
        SDL_memset(this, 0, (sizeof *this));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   113
        this->hidden = (struct SDL_PrivateAudioData *)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   114
            SDL_malloc((sizeof *this->hidden));
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   116
    if ((this == NULL) || (this->hidden == NULL)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   117
        SDL_OutOfMemory();
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   118
        if (this)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   119
            SDL_free(this);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   120
        return (0);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
    }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
    SDL_memset(this->hidden, 0, (sizeof *this->hidden));
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
    audio_fd = -1;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
    /* Set the function pointers */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    this->OpenAudio = OBSD_OpenAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
    this->WaitAudio = OBSD_WaitAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
    this->PlayAudio = OBSD_PlayAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
    this->GetAudioBuf = OBSD_GetAudioBuf;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
    this->CloseAudio = OBSD_CloseAudio;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
    this->free = Audio_DeleteDevice;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   133
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
    return this;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
1583
95451df282c3 *** empty log message ***
Sam Lantinga <slouken@libsdl.org>
parents: 1567
diff changeset
   137
AudioBootStrap BSD_AUDIO_bootstrap = {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   138
    BSD_AUDIO_DRIVER_NAME, BSD_AUDIO_DRIVER_DESC,
3798
c8b3d3d13ed1 Audio bootstraps can now specify that a driver is only to be used if
Ryan C. Gordon <icculus@icculus.org>
parents: 1982
diff changeset
   139
    Audio_Available, Audio_CreateDevice, 0
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
};
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
/* This function waits until it is possible to write a full sound buffer */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
static void
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
OBSD_WaitAudio(_THIS)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   146
#ifndef USE_BLOCKING_WRITES     /* Not necessary when using blocking writes */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   147
    /* See if we need to use timed audio synchronization */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   148
    if (frame_ticks) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   149
        /* Use timer for general audio synchronization */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   150
        Sint32 ticks;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   152
        ticks = ((Sint32) (next_frame - SDL_GetTicks())) - FUDGE_TICKS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   153
        if (ticks > 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   154
            SDL_Delay(ticks);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   155
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   156
    } else {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   157
        /* Use select() for audio synchronization */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   158
        fd_set fdset;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   159
        struct timeval timeout;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   161
        FD_ZERO(&fdset);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   162
        FD_SET(audio_fd, &fdset);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   163
        timeout.tv_sec = 10;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   164
        timeout.tv_usec = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
#ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   166
        fprintf(stderr, "Waiting for audio to get ready\n");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   168
        if (select(audio_fd + 1, NULL, &fdset, NULL, &timeout) <= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   169
            const char *message =
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   170
                "Audio timeout - buggy audio driver? (disabled)";
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   171
            /* In general we should never print to the screen,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   172
               but in this case we have no other way of letting
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   173
               the user know what happened.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   174
             */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   175
            fprintf(stderr, "SDL: %s\n", message);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   176
            this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   177
            /* Don't try to close - may hang */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   178
            audio_fd = -1;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
#ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   180
            fprintf(stderr, "Done disabling audio\n");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   182
        }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
#ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   184
        fprintf(stderr, "Ready!\n");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
#endif
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   186
    }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
#endif /* !USE_BLOCKING_WRITES */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
static void
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
OBSD_PlayAudio(_THIS)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   193
    int written, p = 0;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   195
    /* Write the audio data, checking for EAGAIN on broken audio drivers */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   196
    do {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   197
        written = write(audio_fd, &mixbuf[p], mixlen - p);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   198
        if (written > 0)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   199
            p += written;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   200
        if (written == -1 && errno != 0 && errno != EAGAIN && errno != EINTR) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   201
            /* Non recoverable error has occurred. It should be reported!!! */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   202
            perror("audio");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   203
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   204
        }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   206
        if (p < written
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   207
            || ((written < 0) && ((errno == 0) || (errno == EAGAIN)))) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   208
            SDL_Delay(1);       /* Let a little CPU time go by */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   209
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   210
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   211
    while (p < written);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   213
    /* If timer synchronization is enabled, set the next write frame */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   214
    if (frame_ticks) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   215
        next_frame += frame_ticks;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   216
    }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   218
    /* If we couldn't write, assume fatal error for now */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   219
    if (written < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   220
        this->enabled = 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   221
    }
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
#ifdef DEBUG_AUDIO
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   223
    fprintf(stderr, "Wrote %d bytes of audio data\n", written);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
#endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   227
static Uint8 *
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   228
OBSD_GetAudioBuf(_THIS)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   230
    return (mixbuf);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
static void
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
OBSD_CloseAudio(_THIS)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
{
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   236
    if (mixbuf != NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   237
        SDL_FreeAudioMem(mixbuf);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   238
        mixbuf = NULL;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   240
    if (audio_fd >= 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   241
        close(audio_fd);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   242
        audio_fd = -1;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
    }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
#ifdef DEBUG_AUDIO
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
void
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
OBSD_Status(_THIS)
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
{
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
    audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   252
    if (ioctl(audio_fd, AUDIO_GETINFO, &info) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   253
        fprintf(stderr, "AUDIO_GETINFO failed.\n");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   254
        return;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
    }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   257
    fprintf(stderr, "\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   258
            "[play/record info]\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   259
            "buffer size	:   %d bytes\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   260
            "sample rate	:   %i Hz\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   261
            "channels	:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   262
            "precision	:   %i-bit\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   263
            "encoding	:   0x%x\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   264
            "seek		:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   265
            "sample count	:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   266
            "EOF count	:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   267
            "paused		:   %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   268
            "error occured	:   %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   269
            "waiting		:   %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   270
            "active		:   %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   271
            "",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   272
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   273
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   274
            buffer_size,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   275
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   276
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   277
            sample_rate,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   278
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   279
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   280
            channels,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   281
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   282
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   283
            precision,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   284
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   285
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   286
            encoding,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   287
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   288
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   289
            seek,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   290
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   291
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   292
            samples,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   293
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   294
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   295
            eof,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   296
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   297
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   298
            pause
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   299
            ?
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   300
            "yes"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   301
            :
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   302
            "no",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   303
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   304
            play.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   305
            error
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   306
            ?
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   307
            "yes"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   308
            :
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   309
            "no",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   310
            info.
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   311
            play.waiting ? "yes" : "no", info.play.active ? "yes" : "no");
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   312
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   313
    fprintf(stderr, "\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   314
            "[audio info]\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   315
            "monitor_gain	:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   316
            "hw block size	:   %d bytes\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   317
            "hi watermark	:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   318
            "lo watermark	:   %i\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   319
            "audio mode	:   %s\n"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   320
            "",
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   321
            info.monitor_gain,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   322
            info.blocksize,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   323
            info.hiwat, info.lowat,
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   324
            (info.mode == AUMODE_PLAY) ? "PLAY"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   325
            : (info.mode = AUMODE_RECORD) ? "RECORD"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   326
            : (info.mode == AUMODE_PLAY_ALL ? "PLAY_ALL" : "?"));
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   327
}
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   328
#endif /* DEBUG_AUDIO */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   329
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   330
static int
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   331
OBSD_OpenAudio(_THIS, SDL_AudioSpec * spec)
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   332
{
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   333
    char audiodev[64];
1982
3b4ce57c6215 First shot at new audio data types (int32 and float32).
Ryan C. Gordon <icculus@icculus.org>
parents: 1895
diff changeset
   334
    SDL_AudioFormat format;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   335
    audio_info_t info;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   336
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   337
    AUDIO_INITINFO(&info);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   338
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   339
    /* Calculate the final parameters for this audio specification */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   340
    SDL_CalculateAudioSpec(spec);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   341
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   342
#ifdef USE_TIMER_SYNC
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   343
    frame_ticks = 0.0;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   344
#endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   345
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   346
    /* Open the audio device */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   347
    audio_fd = SDL_OpenAudioPath(audiodev, sizeof(audiodev), OPEN_FLAGS, 0);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   348
    if (audio_fd < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   349
        SDL_SetError("Couldn't open %s: %s", audiodev, strerror(errno));
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   350
        return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   351
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   352
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   353
    /* Set to play mode */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   354
    info.mode = AUMODE_PLAY;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   355
    if (ioctl(audio_fd, AUDIO_SETINFO, &info) < 0) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   356
        SDL_SetError("Couldn't put device into play mode");
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   357
        return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   358
    }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   359
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   360
    mixbuf = NULL;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   361
    AUDIO_INITINFO(&info);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   362
    for (format = SDL_FirstAudioFormat(spec->format);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   363
         format; format = SDL_NextAudioFormat()) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   364
        switch (format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   365
        case AUDIO_U8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   366
            info.play.encoding = AUDIO_ENCODING_ULINEAR;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   367
            info.play.precision = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   368
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   369
        case AUDIO_S8:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   370
            info.play.encoding = AUDIO_ENCODING_SLINEAR;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   371
            info.play.precision = 8;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   372
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   373
        case AUDIO_S16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   374
            info.play.encoding = AUDIO_ENCODING_SLINEAR_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   375
            info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   376
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   377
        case AUDIO_S16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   378
            info.play.encoding = AUDIO_ENCODING_SLINEAR_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   379
            info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   380
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   381
        case AUDIO_U16LSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   382
            info.play.encoding = AUDIO_ENCODING_ULINEAR_LE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   383
            info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   384
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   385
        case AUDIO_U16MSB:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   386
            info.play.encoding = AUDIO_ENCODING_ULINEAR_BE;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   387
            info.play.precision = 16;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   388
            break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   389
        default:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   390
            continue;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   391
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   392
        if (ioctl(audio_fd, AUDIO_SETINFO, &info) == 0)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   393
            break;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   394
    }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   395
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   396
    if (!format) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   397
        SDL_SetError("No supported encoding for 0x%x", spec->format);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   398
        return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   399
    }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   400
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   401
    spec->format = format;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   402
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   403
    AUDIO_INITINFO(&info);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   404
    info.play.channels = spec->channels;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   405
    if (ioctl(audio_fd, AUDIO_SETINFO, &info) == -1)
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   406
        spec->channels = 1;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   407
    AUDIO_INITINFO(&info);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   408
    info.play.sample_rate = spec->freq;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   409
    info.blocksize = spec->size;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   410
    info.hiwat = 5;
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   411
    info.lowat = 3;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   412
    (void) ioctl(audio_fd, AUDIO_SETINFO, &info);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   413
    (void) ioctl(audio_fd, AUDIO_GETINFO, &info);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   414
    spec->freq = info.play.sample_rate;
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   415
    /* Allocate mixing buffer */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   416
    mixlen = spec->size;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   417
    mixbuf = (Uint8 *) SDL_AllocAudioMem(mixlen);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   418
    if (mixbuf == NULL) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   419
        return (-1);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   420
    }
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   421
    SDL_memset(mixbuf, spec->silence, spec->size);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   422
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   423
    /* Get the parent process id (we're the parent of the audio thread) */
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   424
    parent = getpid();
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   425
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   426
#ifdef DEBUG_AUDIO
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   427
    OBSD_Status(this);
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   428
#endif
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   429
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   430
    /* We're ready to rock and roll. :-) */
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   431
    return (0);
1567
12b6d331d82a Good idea, renaming OpenBSD audio to BSD audio.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   432
}
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   433
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents: 1583
diff changeset
   434
/* vi: set ts=4 sw=4 expandtab: */