Mercurial > sdl-ios-xcode
comparison src/audio/dummy/SDL_dummyaudio.c @ 3798:c8b3d3d13ed1 SDL-ryan-multiple-audio-device
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. :)
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Wed, 04 Oct 2006 21:27:53 +0000 |
parents | b19680c84cdf |
children | 7852b5b78af5 |
comparison
equal
deleted
inserted
replaced
3797:9dc81c6acaf5 | 3798:c8b3d3d13ed1 |
---|---|
45 | 45 |
46 /* Audio driver bootstrap functions */ | 46 /* Audio driver bootstrap functions */ |
47 static int | 47 static int |
48 DUMMYAUD_Available(void) | 48 DUMMYAUD_Available(void) |
49 { | 49 { |
50 /* !!! FIXME: check this at a higher level... */ | 50 return 1; /* always available. */ |
51 /* only ever use this driver if explicitly requested. */ | |
52 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); | |
53 if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) { | |
54 return (1); | |
55 } | |
56 return (0); | |
57 } | 51 } |
58 | 52 |
59 static int | 53 static int |
60 DUMMYAUD_Init(SDL_AudioDriverImpl *impl) | 54 DUMMYAUD_Init(SDL_AudioDriverImpl *impl) |
61 { | 55 { |
62 /* Set the function pointers */ | 56 /* Set the function pointers */ |
63 impl->OpenDevice = DUMMYAUD_OpenDevice; | 57 impl->OpenDevice = DUMMYAUD_OpenDevice; |
64 impl->WaitDevice = DUMMYAUD_WaitDevice; | |
65 impl->PlayDevice = DUMMYAUD_PlayDevice; | |
66 impl->GetDeviceBuf = DUMMYAUD_GetDeviceBuf; | |
67 impl->CloseDevice = DUMMYAUD_CloseDevice; | |
68 impl->OnlyHasDefaultOutputDevice = 1; | 58 impl->OnlyHasDefaultOutputDevice = 1; |
69 | 59 |
70 return 1; | 60 return 1; |
71 } | 61 } |
72 | 62 |
73 AudioBootStrap DUMMYAUD_bootstrap = { | 63 AudioBootStrap DUMMYAUD_bootstrap = { |
74 DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", | 64 DUMMYAUD_DRIVER_NAME, "SDL dummy audio driver", |
75 DUMMYAUD_Available, DUMMYAUD_Init | 65 DUMMYAUD_Available, DUMMYAUD_Init, 1 |
76 }; | 66 }; |
77 | |
78 /* This function waits until it is possible to write a full sound buffer */ | |
79 static void | |
80 DUMMYAUD_WaitDevice(_THIS) | |
81 { | |
82 /* Don't block on first calls to simulate initial fragment filling. */ | |
83 if (this->hidden->initial_calls) | |
84 this->hidden->initial_calls--; | |
85 else | |
86 SDL_Delay(this->hidden->write_delay); | |
87 } | |
88 | |
89 static void | |
90 DUMMYAUD_PlayDevice(_THIS) | |
91 { | |
92 /* no-op...this is a null driver. */ | |
93 } | |
94 | |
95 static Uint8 * | |
96 DUMMYAUD_GetDeviceBuf(_THIS) | |
97 { | |
98 return (this->hidden->mixbuf); | |
99 } | |
100 | |
101 static void | |
102 DUMMYAUD_CloseDevice(_THIS) | |
103 { | |
104 if (this->hidden->mixbuf != NULL) { | |
105 SDL_FreeAudioMem(this->hidden->mixbuf); | |
106 this->hidden->mixbuf = NULL; | |
107 } | |
108 SDL_free(this->hidden); | |
109 this->hidden = NULL; | |
110 } | |
111 | 67 |
112 static int | 68 static int |
113 DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture) | 69 DUMMYAUD_OpenDevice(_THIS, const char *devname, int iscapture) |
114 { | 70 { |
115 float bytes_per_sec = 0.0f; | 71 return 1; /* always succeeds. */ |
116 | |
117 /* Initialize all variables that we clean on shutdown */ | |
118 this->hidden = (struct SDL_PrivateAudioData *) | |
119 SDL_malloc((sizeof *this->hidden)); | |
120 if (this->hidden == NULL) { | |
121 SDL_OutOfMemory(); | |
122 return 0; | |
123 } | |
124 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); | |
125 | |
126 /* Allocate mixing buffer */ | |
127 this->hidden->mixlen = this->spec.size; | |
128 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); | |
129 if (this->hidden->mixbuf == NULL) { | |
130 DUMMYAUD_CloseDevice(this); | |
131 return 0; | |
132 } | |
133 SDL_memset(this->hidden->mixbuf, this->spec.silence, this->spec.size); | |
134 | |
135 bytes_per_sec = (float) (SDL_AUDIO_BITSIZE(this->spec.format) / 8) * | |
136 this->spec.channels * this->spec.freq; | |
137 | |
138 /* | |
139 * We try to make this request more audio at the correct rate for | |
140 * a given audio spec, so timing stays fairly faithful. | |
141 * Also, we have it not block at all for the first two calls, so | |
142 * it seems like we're filling two audio fragments right out of the | |
143 * gate, like other SDL drivers tend to do. | |
144 */ | |
145 this->hidden->initial_calls = 2; | |
146 this->hidden->write_delay = | |
147 (Uint32) ((((float) this->spec.size) / bytes_per_sec) * 1000.0f); | |
148 | |
149 /* We're ready to rock and roll. :-) */ | |
150 return 1; | |
151 } | 72 } |
152 | 73 |
153 /* vi: set ts=4 sw=4 expandtab: */ | 74 /* vi: set ts=4 sw=4 expandtab: */ |