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

Latest commit

 

History

History
152 lines (128 loc) · 4.42 KB

SDL_dummyaudio.c

File metadata and controls

152 lines (128 loc) · 4.42 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 1, 2006
Oct 1, 2006
40
static int DUMMYAUD_OpenAudio(_THIS, const char *devname, int iscapture);
Mar 14, 2006
Mar 14, 2006
41
42
43
44
45
46
static void DUMMYAUD_WaitAudio(_THIS);
static void DUMMYAUD_PlayAudio(_THIS);
static Uint8 *DUMMYAUD_GetAudioBuf(_THIS);
static void DUMMYAUD_CloseAudio(_THIS);
/* 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 1, 2006
Oct 1, 2006
63
64
65
66
67
impl->OpenAudio = DUMMYAUD_OpenAudio;
impl->WaitAudio = DUMMYAUD_WaitAudio;
impl->PlayAudio = DUMMYAUD_PlayAudio;
impl->GetAudioBuf = DUMMYAUD_GetAudioBuf;
impl->CloseAudio = DUMMYAUD_CloseAudio;
Jul 10, 2006
Jul 10, 2006
68
Oct 1, 2006
Oct 1, 2006
69
return 1;
Mar 14, 2006
Mar 14, 2006
70
71
72
}
AudioBootStrap DUMMYAUD_bootstrap = {
Jul 10, 2006
Jul 10, 2006
73
DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver",
Oct 1, 2006
Oct 1, 2006
74
DUMMYAUD_Available, DUMMYAUD_Init
Mar 14, 2006
Mar 14, 2006
75
76
77
};
/* This function waits until it is possible to write a full sound buffer */
Jul 10, 2006
Jul 10, 2006
78
79
static void
DUMMYAUD_WaitAudio(_THIS)
Mar 14, 2006
Mar 14, 2006
80
{
Jul 10, 2006
Jul 10, 2006
81
82
83
84
85
/* 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
86
87
}
Jul 10, 2006
Jul 10, 2006
88
89
static void
DUMMYAUD_PlayAudio(_THIS)
Mar 14, 2006
Mar 14, 2006
90
{
Jul 10, 2006
Jul 10, 2006
91
/* no-op...this is a null driver. */
Mar 14, 2006
Mar 14, 2006
92
93
}
Jul 10, 2006
Jul 10, 2006
94
95
static Uint8 *
DUMMYAUD_GetAudioBuf(_THIS)
Mar 14, 2006
Mar 14, 2006
96
{
Jul 10, 2006
Jul 10, 2006
97
return (this->hidden->mixbuf);
Mar 14, 2006
Mar 14, 2006
98
99
}
Jul 10, 2006
Jul 10, 2006
100
101
static void
DUMMYAUD_CloseAudio(_THIS)
Mar 14, 2006
Mar 14, 2006
102
{
Jul 10, 2006
Jul 10, 2006
103
104
105
106
if (this->hidden->mixbuf != NULL) {
SDL_FreeAudioMem(this->hidden->mixbuf);
this->hidden->mixbuf = NULL;
}
Oct 1, 2006
Oct 1, 2006
107
108
SDL_free(this->hidden);
this->hidden = NULL;
Mar 14, 2006
Mar 14, 2006
109
110
}
Jul 10, 2006
Jul 10, 2006
111
static int
Oct 1, 2006
Oct 1, 2006
112
DUMMYAUD_OpenAudio(_THIS, const char *devname, int iscapture)
Mar 14, 2006
Mar 14, 2006
113
{
Jul 10, 2006
Jul 10, 2006
114
115
float bytes_per_sec = 0.0f;
Oct 1, 2006
Oct 1, 2006
116
117
118
119
120
121
122
123
124
/* 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
125
/* Allocate mixing buffer */
Oct 1, 2006
Oct 1, 2006
126
this->hidden->mixlen = this->spec.size;
Jul 10, 2006
Jul 10, 2006
127
128
this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen);
if (this->hidden->mixbuf == NULL) {
Oct 1, 2006
Oct 1, 2006
129
130
DUMMYAUD_CloseAudio(this);
return 0;
Jul 10, 2006
Jul 10, 2006
131
}
Oct 1, 2006
Oct 1, 2006
132
SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size);
Jul 10, 2006
Jul 10, 2006
133
Oct 1, 2006
Oct 1, 2006
134
135
bytes_per_sec = (float) (SDL_AUDIO_BITSIZE(this->spec.format) / 8) *
this->spec.channels * this->spec.freq;
Jul 10, 2006
Jul 10, 2006
136
137
138
139
140
141
142
143
144
145
/*
* 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
146
(Uint32) ((((float) this->spec.size) / bytes_per_sec) * 1000.0f);
Jul 10, 2006
Jul 10, 2006
147
148
/* We're ready to rock and roll. :-) */
Oct 1, 2006
Oct 1, 2006
149
return 1;
Mar 14, 2006
Mar 14, 2006
150
151
}
Jul 10, 2006
Jul 10, 2006
152
/* vi: set ts=4 sw=4 expandtab: */