Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
153 lines (129 loc) · 4.48 KB

SDL_dummyaudio.c

File metadata and controls

153 lines (129 loc) · 4.48 KB
 
Mar 14, 2006
Mar 14, 2006
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
SDL - Simple DirectMedia Layer
Copyright (C) 1997-2006 Sam Lantinga
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Sam Lantinga
slouken@libsdl.org
Mar 14, 2006
Mar 14, 2006
22
This file written by Ryan C. Gordon (icculus@icculus.org)
Mar 14, 2006
Mar 14, 2006
23
24
25
*/
#include "SDL_config.h"
Mar 14, 2006
Mar 14, 2006
26
/* Output audio to nowhere... */
Mar 14, 2006
Mar 14, 2006
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "SDL_rwops.h"
#include "SDL_timer.h"
#include "SDL_audio.h"
#include "../SDL_audiomem.h"
#include "../SDL_audio_c.h"
#include "../SDL_audiodev_c.h"
#include "SDL_dummyaudio.h"
/* The tag name used by DUMMY audio */
#define DUMMYAUD_DRIVER_NAME "dummy"
/* Audio driver functions */
Oct 3, 2006
Oct 3, 2006
40
41
42
43
44
static int DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture);
static void DUMMYAUD_WaitDevice(_THIS);
static void DUMMYAUD_PlayDevice(_THIS);
static Uint8 *DUMMYAUD_GetDeviceBuf(_THIS);
static void DUMMYAUD_CloseDevice(_THIS);
Mar 14, 2006
Mar 14, 2006
45
46
/* Audio driver bootstrap functions */
Jul 10, 2006
Jul 10, 2006
47
48
static int
DUMMYAUD_Available(void)
Mar 14, 2006
Mar 14, 2006
49
{
Oct 1, 2006
Oct 1, 2006
50
51
/* !!! FIXME: check this at a higher level... */
/* only ever use this driver if explicitly requested. */
Jul 10, 2006
Jul 10, 2006
52
53
54
55
56
const char *envr = SDL_getenv("SDL_AUDIODRIVER");
if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) {
return (1);
}
return (0);
Mar 14, 2006
Mar 14, 2006
57
58
}
Oct 1, 2006
Oct 1, 2006
59
60
static int
DUMMYAUD_Init(SDL_AudioDriverImpl *impl)
Mar 14, 2006
Mar 14, 2006
61
{
Jul 10, 2006
Jul 10, 2006
62
/* Set the function pointers */
Oct 3, 2006
Oct 3, 2006
63
64
65
66
67
impl->OpenDevice = DUMMYAUD_OpenDevice;
impl->WaitDevice = DUMMYAUD_WaitDevice;
impl->PlayDevice = DUMMYAUD_PlayDevice;
impl->GetDeviceBuf = DUMMYAUD_GetDeviceBuf;
impl->CloseDevice = DUMMYAUD_CloseDevice;
Oct 4, 2006
Oct 4, 2006
68
impl->OnlyHasDefaultOutputDevice = 1;
Jul 10, 2006
Jul 10, 2006
69
Oct 1, 2006
Oct 1, 2006
70
return 1;
Mar 14, 2006
Mar 14, 2006
71
72
73
}
AudioBootStrap DUMMYAUD_bootstrap = {
Jul 10, 2006
Jul 10, 2006
74
DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
Oct 1, 2006
Oct 1, 2006
75
DUMMYAUD_Available, DUMMYAUD_Init
Mar 14, 2006
Mar 14, 2006
76
77
78
};
/* This function waits until it is possible to write a full sound buffer */
Jul 10, 2006
Jul 10, 2006
79
static void
Oct 3, 2006
Oct 3, 2006
80
DUMMYAUD_WaitDevice(_THIS)
Mar 14, 2006
Mar 14, 2006
81
{
Jul 10, 2006
Jul 10, 2006
82
83
84
85
86
/* Don't block on first calls to simulate initial fragment filling. */
if (this->hidden->initial_calls)
this->hidden->initial_calls--;
else
SDL_Delay(this->hidden->write_delay);
Mar 14, 2006
Mar 14, 2006
87
88
}
Jul 10, 2006
Jul 10, 2006
89
static void
Oct 3, 2006
Oct 3, 2006
90
DUMMYAUD_PlayDevice(_THIS)
Mar 14, 2006
Mar 14, 2006
91
{
Jul 10, 2006
Jul 10, 2006
92
/* no-op...this is a null driver. */
Mar 14, 2006
Mar 14, 2006
93
94
}
Jul 10, 2006
Jul 10, 2006
95
static Uint8 *
Oct 3, 2006
Oct 3, 2006
96
DUMMYAUD_GetDeviceBuf(_THIS)
Mar 14, 2006
Mar 14, 2006
97
{
Jul 10, 2006
Jul 10, 2006
98
return (this->hidden->mixbuf);
Mar 14, 2006
Mar 14, 2006
99
100
}
Jul 10, 2006
Jul 10, 2006
101
static void
Oct 3, 2006
Oct 3, 2006
102
DUMMYAUD_CloseDevice(_THIS)
Mar 14, 2006
Mar 14, 2006
103
{
Jul 10, 2006
Jul 10, 2006
104
105
106
107
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
Oct 1, 2006
Oct 1, 2006
108
109
SDL_free(this->hidden);
this->hidden = NULL;
Mar 14, 2006
Mar 14, 2006
110
111
}
Jul 10, 2006
Jul 10, 2006
112
static int
Oct 3, 2006
Oct 3, 2006
113
DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture)
Mar 14, 2006
Mar 14, 2006
114
{
Jul 10, 2006
Jul 10, 2006
115
116
float bytes_per_sec = 0.0f;
Oct 1, 2006
Oct 1, 2006
117
118
119
120
121
122
123
124
125
/* Initialize all variables that we clean on shutdown */
this->hidden = (struct SDL_PrivateAudioData *)
SDL_malloc((sizeof *this->hidden));
if (this->hidden == NULL) {
SDL_OutOfMemory();
return 0;
}
SDL_memset(this->hidden, 0, (sizeof *this->hidden));
Jul 10, 2006
Jul 10, 2006
126
/* Allocate mixing buffer */
Oct 1, 2006
Oct 1, 2006
127
this->hidden->mixlen = this->spec.size;
Jul 10, 2006
Jul 10, 2006
128
129
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
Oct 3, 2006
Oct 3, 2006
130
DUMMYAUD_CloseDevice(this);
Oct 1, 2006
Oct 1, 2006
131
return 0;
Jul 10, 2006
Jul 10, 2006
132
}
Oct 1, 2006
Oct 1, 2006
133
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
Jul 10, 2006
Jul 10, 2006
134
Oct 1, 2006
Oct 1, 2006
135
136
bytes_per_sec = (float) (SDL_AUDIO_BITSIZE(this->spec.format) / 8) *
this->spec.channels * this->spec.freq;
Jul 10, 2006
Jul 10, 2006
137
138
139
140
141
142
143
144
145
146
/*
* We try to make this request more audio at the correct rate for
* a given audio spec, so timing stays fairly faithful.
* Also, we have it not block at all for the first two calls, so
* it seems like we're filling two audio fragments right out of the
* gate, like other SDL drivers tend to do.
*/
this->hidden->initial_calls = 2;
this->hidden->write_delay =
Oct 1, 2006
Oct 1, 2006
147
(Uint32) ((((float) this->spec.size) / bytes_per_sec) * 1000.0f);
Jul 10, 2006
Jul 10, 2006
148
149
/* We're ready to rock and roll. :-) */
Oct 1, 2006
Oct 1, 2006
150
return 1;
Mar 14, 2006
Mar 14, 2006
151
152
}
Jul 10, 2006
Jul 10, 2006
153
/* vi: set ts=4 sw=4 expandtab: */