Mercurial > sdl-ios-xcode
comparison src/audio/dummy/SDL_dummyaudio.c @ 1668:4da1ee79c9af SDL-1.3
more tweaking indent options
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 29 May 2006 04:04:35 +0000 |
parents | 782fd950bd46 |
children |
comparison
equal
deleted
inserted
replaced
1667:1fddae038bc8 | 1668:4da1ee79c9af |
---|---|
35 | 35 |
36 /* The tag name used by DUMMY audio */ | 36 /* The tag name used by DUMMY audio */ |
37 #define DUMMYAUD_DRIVER_NAME "dummy" | 37 #define DUMMYAUD_DRIVER_NAME "dummy" |
38 | 38 |
39 /* Audio driver functions */ | 39 /* Audio driver functions */ |
40 static int DUMMYAUD_OpenAudio (_THIS, SDL_AudioSpec * spec); | 40 static int DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec); |
41 static void DUMMYAUD_WaitAudio (_THIS); | 41 static void DUMMYAUD_WaitAudio(_THIS); |
42 static void DUMMYAUD_PlayAudio (_THIS); | 42 static void DUMMYAUD_PlayAudio(_THIS); |
43 static Uint8 *DUMMYAUD_GetAudioBuf (_THIS); | 43 static Uint8 *DUMMYAUD_GetAudioBuf(_THIS); |
44 static void DUMMYAUD_CloseAudio (_THIS); | 44 static void DUMMYAUD_CloseAudio(_THIS); |
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 const char *envr = SDL_getenv ("SDL_AUDIODRIVER"); | 50 const char *envr = SDL_getenv("SDL_AUDIODRIVER"); |
51 if (envr && (SDL_strcmp (envr, DUMMYAUD_DRIVER_NAME) == 0)) { | 51 if (envr && (SDL_strcmp(envr, DUMMYAUD_DRIVER_NAME) == 0)) { |
52 return (1); | 52 return (1); |
53 } | 53 } |
54 return (0); | 54 return (0); |
55 } | 55 } |
56 | 56 |
57 static void | 57 static void |
58 DUMMYAUD_DeleteDevice (SDL_AudioDevice * device) | 58 DUMMYAUD_DeleteDevice(SDL_AudioDevice * device) |
59 { | 59 { |
60 SDL_free (device->hidden); | 60 SDL_free(device->hidden); |
61 SDL_free (device); | 61 SDL_free(device); |
62 } | 62 } |
63 | 63 |
64 static SDL_AudioDevice * | 64 static SDL_AudioDevice * |
65 DUMMYAUD_CreateDevice (int devindex) | 65 DUMMYAUD_CreateDevice(int devindex) |
66 { | 66 { |
67 SDL_AudioDevice *this; | 67 SDL_AudioDevice *this; |
68 | 68 |
69 /* Initialize all variables that we clean on shutdown */ | 69 /* Initialize all variables that we clean on shutdown */ |
70 this = (SDL_AudioDevice *) SDL_malloc (sizeof (SDL_AudioDevice)); | 70 this = (SDL_AudioDevice *) SDL_malloc(sizeof(SDL_AudioDevice)); |
71 if (this) { | 71 if (this) { |
72 SDL_memset (this, 0, (sizeof *this)); | 72 SDL_memset(this, 0, (sizeof *this)); |
73 this->hidden = (struct SDL_PrivateAudioData *) | 73 this->hidden = (struct SDL_PrivateAudioData *) |
74 SDL_malloc ((sizeof *this->hidden)); | 74 SDL_malloc((sizeof *this->hidden)); |
75 } | 75 } |
76 if ((this == NULL) || (this->hidden == NULL)) { | 76 if ((this == NULL) || (this->hidden == NULL)) { |
77 SDL_OutOfMemory (); | 77 SDL_OutOfMemory(); |
78 if (this) { | 78 if (this) { |
79 SDL_free (this); | 79 SDL_free(this); |
80 } | 80 } |
81 return (0); | 81 return (0); |
82 } | 82 } |
83 SDL_memset (this->hidden, 0, (sizeof *this->hidden)); | 83 SDL_memset(this->hidden, 0, (sizeof *this->hidden)); |
84 | 84 |
85 /* Set the function pointers */ | 85 /* Set the function pointers */ |
86 this->OpenAudio = DUMMYAUD_OpenAudio; | 86 this->OpenAudio = DUMMYAUD_OpenAudio; |
87 this->WaitAudio = DUMMYAUD_WaitAudio; | 87 this->WaitAudio = DUMMYAUD_WaitAudio; |
88 this->PlayAudio = DUMMYAUD_PlayAudio; | 88 this->PlayAudio = DUMMYAUD_PlayAudio; |
99 DUMMYAUD_Available, DUMMYAUD_CreateDevice | 99 DUMMYAUD_Available, DUMMYAUD_CreateDevice |
100 }; | 100 }; |
101 | 101 |
102 /* This function waits until it is possible to write a full sound buffer */ | 102 /* This function waits until it is possible to write a full sound buffer */ |
103 static void | 103 static void |
104 DUMMYAUD_WaitAudio (_THIS) | 104 DUMMYAUD_WaitAudio(_THIS) |
105 { | 105 { |
106 /* Don't block on first calls to simulate initial fragment filling. */ | 106 /* Don't block on first calls to simulate initial fragment filling. */ |
107 if (this->hidden->initial_calls) | 107 if (this->hidden->initial_calls) |
108 this->hidden->initial_calls--; | 108 this->hidden->initial_calls--; |
109 else | 109 else |
110 SDL_Delay (this->hidden->write_delay); | 110 SDL_Delay(this->hidden->write_delay); |
111 } | 111 } |
112 | 112 |
113 static void | 113 static void |
114 DUMMYAUD_PlayAudio (_THIS) | 114 DUMMYAUD_PlayAudio(_THIS) |
115 { | 115 { |
116 /* no-op...this is a null driver. */ | 116 /* no-op...this is a null driver. */ |
117 } | 117 } |
118 | 118 |
119 static Uint8 * | 119 static Uint8 * |
120 DUMMYAUD_GetAudioBuf (_THIS) | 120 DUMMYAUD_GetAudioBuf(_THIS) |
121 { | 121 { |
122 return (this->hidden->mixbuf); | 122 return (this->hidden->mixbuf); |
123 } | 123 } |
124 | 124 |
125 static void | 125 static void |
126 DUMMYAUD_CloseAudio (_THIS) | 126 DUMMYAUD_CloseAudio(_THIS) |
127 { | 127 { |
128 if (this->hidden->mixbuf != NULL) { | 128 if (this->hidden->mixbuf != NULL) { |
129 SDL_FreeAudioMem (this->hidden->mixbuf); | 129 SDL_FreeAudioMem(this->hidden->mixbuf); |
130 this->hidden->mixbuf = NULL; | 130 this->hidden->mixbuf = NULL; |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 static int | 134 static int |
135 DUMMYAUD_OpenAudio (_THIS, SDL_AudioSpec * spec) | 135 DUMMYAUD_OpenAudio(_THIS, SDL_AudioSpec * spec) |
136 { | 136 { |
137 float bytes_per_sec = 0.0f; | 137 float bytes_per_sec = 0.0f; |
138 | 138 |
139 /* Allocate mixing buffer */ | 139 /* Allocate mixing buffer */ |
140 this->hidden->mixlen = spec->size; | 140 this->hidden->mixlen = spec->size; |
141 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem (this->hidden->mixlen); | 141 this->hidden->mixbuf = (Uint8 *) SDL_AllocAudioMem(this->hidden->mixlen); |
142 if (this->hidden->mixbuf == NULL) { | 142 if (this->hidden->mixbuf == NULL) { |
143 return (-1); | 143 return (-1); |
144 } | 144 } |
145 SDL_memset (this->hidden->mixbuf, spec->silence, spec->size); | 145 SDL_memset(this->hidden->mixbuf, spec->silence, spec->size); |
146 | 146 |
147 bytes_per_sec = (float) (((spec->format & 0xFF) / 8) * | 147 bytes_per_sec = (float) (((spec->format & 0xFF) / 8) * |
148 spec->channels * spec->freq); | 148 spec->channels * spec->freq); |
149 | 149 |
150 /* | 150 /* |