summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/progs/quake/snd_sdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/progs/quake/snd_sdl.c')
-rw-r--r--apps/plugins/sdl/progs/quake/snd_sdl.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/apps/plugins/sdl/progs/quake/snd_sdl.c b/apps/plugins/sdl/progs/quake/snd_sdl.c
index 644d4e1acf..5ebf081241 100644
--- a/apps/plugins/sdl/progs/quake/snd_sdl.c
+++ b/apps/plugins/sdl/progs/quake/snd_sdl.c
@@ -2,6 +2,7 @@
2#include <stdio.h> 2#include <stdio.h>
3#include "SDL_audio.h" 3#include "SDL_audio.h"
4#include "SDL_byteorder.h" 4#include "SDL_byteorder.h"
5#include "SDL_mixer.h"
5#include "quakedef.h" 6#include "quakedef.h"
6 7
7static dma_t the_shm; 8static dma_t the_shm;
@@ -11,7 +12,7 @@ extern int desired_speed;
11extern int desired_bits; 12extern int desired_bits;
12 13
13// SDL hereby demands `len' samples in stream, *NOW*! 14// SDL hereby demands `len' samples in stream, *NOW*!
14static void paint_audio(void *unused, Uint8 *stream, int len) 15static void paint_audio(int chan, Uint8 *stream, int len, void *unused)
15{ 16{
16 if ( shm ) { 17 if ( shm ) {
17 shm->buffer = stream; 18 shm->buffer = stream;
@@ -46,49 +47,40 @@ qboolean SNDDMA_Init(void)
46 } 47 }
47 desired.channels = 2; 48 desired.channels = 2;
48 desired.samples = 1024; 49 desired.samples = 1024;
49 desired.callback = paint_audio; 50 //desired.callback = paint_audio;
50 51
52 if( Mix_OpenAudio(desired_speed, desired.format, desired.channels, desired.samples) < 0 )
53 {
54 Con_Printf("Couldn't open SDL audio: %s\n", Mix_GetError());
55 return 0;
56 }
57
58 Mix_RegisterEffect(0, paint_audio, NULL, NULL);
59
60#if 0
51 /* Open the audio device */ 61 /* Open the audio device */
52 if ( SDL_OpenAudio(&desired, &obtained) < 0 ) { 62 if ( SDL_OpenAudio(&desired, &obtained) < 0 ) {
53 Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError()); 63 Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError());
54 return 0; 64 return 0;
55 } 65 }
66#endif
67
68 void *blank_buf = (Uint8 *)malloc(4096);
69 memset(blank_buf, 0, 4096);
70
71 Mix_Chunk *blank = Mix_QuickLoad_RAW(blank_buf, 4096);
72
73 Mix_PlayChannel(0, blank, -1);
56 74
57 /* Make sure we can support the audio format */
58 switch (obtained.format) {
59 case AUDIO_U8:
60 /* Supported */
61 break;
62 case AUDIO_S16LSB:
63 case AUDIO_S16MSB:
64 if ( ((obtained.format == AUDIO_S16LSB) &&
65 (SDL_BYTEORDER == SDL_LIL_ENDIAN)) ||
66 ((obtained.format == AUDIO_S16MSB) &&
67 (SDL_BYTEORDER == SDL_BIG_ENDIAN)) ) {
68 /* Supported */
69 break;
70 }
71 /* Unsupported, fall through */;
72 default:
73 /* Not supported -- force SDL to do our bidding */
74 SDL_CloseAudio();
75 if ( SDL_OpenAudio(&desired, NULL) < 0 ) {
76 Con_Printf("Couldn't open SDL audio: %s\n",
77 SDL_GetError());
78 return 0;
79 }
80 memcpy(&obtained, &desired, sizeof(desired));
81 break;
82 }
83 SDL_PauseAudio(0); 75 SDL_PauseAudio(0);
84 76
85 /* Fill the audio DMA information block */ 77 /* Fill the audio DMA information block */
86 shm = &the_shm; 78 shm = &the_shm;
87 shm->splitbuffer = 0; 79 shm->splitbuffer = 0;
88 shm->samplebits = (obtained.format & 0xFF); 80 shm->samplebits = (desired.format & 0xFF);
89 shm->speed = obtained.freq; 81 shm->speed = desired.freq;
90 shm->channels = obtained.channels; 82 shm->channels = desired.channels;
91 shm->samples = obtained.samples*shm->channels; 83 shm->samples = desired.samples*shm->channels;
92 shm->samplepos = 0; 84 shm->samplepos = 0;
93 shm->submission_chunk = 1; 85 shm->submission_chunk = 1;
94 shm->buffer = NULL; 86 shm->buffer = NULL;