Atlas - SDL_ngageaudio.c
Home / ext / SDL / src / audio / ngage Lines: 1 | Size: 2954 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21 22#include "SDL_internal.h" 23 24#ifdef SDL_AUDIO_DRIVER_NGAGE 25 26#include "../SDL_sysaudio.h" 27#include "SDL_ngageaudio.h" 28 29static SDL_AudioDevice *devptr = NULL; 30 31SDL_AudioDevice *NGAGE_GetAudioDeviceAddr() 32{ 33 return devptr; 34} 35 36static bool NGAGEAUDIO_OpenDevice(SDL_AudioDevice *device) 37{ 38 SDL_PrivateAudioData *phdata = SDL_calloc(1, sizeof(SDL_PrivateAudioData)); 39 if (!phdata) { 40 SDL_OutOfMemory(); 41 return false; 42 } 43 device->hidden = phdata; 44 45 phdata->buffer = SDL_calloc(1, device->buffer_size); 46 if (!phdata->buffer) { 47 SDL_OutOfMemory(); 48 SDL_free(phdata); 49 return false; 50 } 51 devptr = device; 52 53 // Since the phone can change the sample rate during a phone call, 54 // we set the sample rate to 8KHz to be safe. Even though it 55 // might be possible to adjust the sample rate dynamically, it's 56 // not supported by the current implementation. 57 58 device->spec.format = SDL_AUDIO_S16LE; 59 device->spec.channels = 1; 60 device->spec.freq = 8000; 61 62 SDL_UpdatedAudioDeviceFormat(device); 63 64 return true; 65} 66 67static Uint8 *NGAGEAUDIO_GetDeviceBuf(SDL_AudioDevice *device, int *buffer_size) 68{ 69 SDL_PrivateAudioData *phdata = (SDL_PrivateAudioData *)device->hidden; 70 if (!phdata) { 71 *buffer_size = 0; 72 return 0; 73 } 74 75 *buffer_size = device->buffer_size; 76 return phdata->buffer; 77} 78 79static void NGAGEAUDIO_CloseDevice(SDL_AudioDevice *device) 80{ 81 if (device->hidden) { 82 SDL_free(device->hidden->buffer); 83 SDL_free(device->hidden); 84 } 85 86 return; 87} 88 89static bool NGAGEAUDIO_Init(SDL_AudioDriverImpl *impl) 90{ 91 impl->OpenDevice = NGAGEAUDIO_OpenDevice; 92 impl->GetDeviceBuf = NGAGEAUDIO_GetDeviceBuf; 93 impl->CloseDevice = NGAGEAUDIO_CloseDevice; 94 95 impl->ProvidesOwnCallbackThread = true; 96 impl->OnlyHasDefaultPlaybackDevice = true; 97 98 return true; 99} 100 101AudioBootStrap NGAGEAUDIO_bootstrap = { "N-Gage", "N-Gage audio driver", NGAGEAUDIO_Init, false }; 102 103#endif // SDL_AUDIO_DRIVER_NGAGE 104[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.