Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5131 clevermous 1
 
2
#include "SDL_audio.h"
3
#include "SDL_byteorder.h"
4
#include "quakedef.h"
5
6
 
7
static int snd_inited;
8
9
 
10
extern int desired_bits;
11
12
 
13
{
14
	if ( shm ) {
15
		shm->buffer = stream;
16
		shm->samplepos += len/(shm->samplebits/8)/2;
17
		// Check for samplepos overflow?
18
		S_PaintChannels (shm->samplepos);
19
	}
20
}
21
22
 
23
{
24
	SDL_AudioSpec desired, obtained;
25
26
 
27
28
 
29
	desired.freq = desired_speed;
30
	switch (desired_bits) {
31
		case 8:
32
			desired.format = AUDIO_U8;
33
			break;
34
		case 16:
35
			if ( SDL_BYTEORDER == SDL_BIG_ENDIAN )
36
				desired.format = AUDIO_S16MSB;
37
			else
38
				desired.format = AUDIO_S16LSB;
39
			break;
40
		default:
41
        		Con_Printf("Unknown number of audio bits: %d\n",
42
								desired_bits);
43
			return 0;
44
	}
45
	desired.channels = 2;
46
	desired.samples = 512;
47
	desired.callback = paint_audio;
48
49
 
50
	if ( SDL_OpenAudio(&desired, &obtained) < 0 ) {
51
        	Con_Printf("Couldn't open SDL audio: %s\n", SDL_GetError());
52
		return 0;
53
	}
54
55
 
56
	switch (obtained.format) {
57
		case AUDIO_U8:
58
			/* Supported */
59
			break;
60
		case AUDIO_S16LSB:
61
		case AUDIO_S16MSB:
62
			if ( ((obtained.format == AUDIO_S16LSB) &&
63
			     (SDL_BYTEORDER == SDL_LIL_ENDIAN)) ||
64
			     ((obtained.format == AUDIO_S16MSB) &&
65
			     (SDL_BYTEORDER == SDL_BIG_ENDIAN)) ) {
66
				/* Supported */
67
				break;
68
			}
69
			/* Unsupported, fall through */;
70
		default:
71
			/* Not supported -- force SDL to do our bidding */
72
			SDL_CloseAudio();
73
			if ( SDL_OpenAudio(&desired, NULL) < 0 ) {
74
        			Con_Printf("Couldn't open SDL audio: %s\n",
75
							SDL_GetError());
76
				return 0;
77
			}
78
			memcpy(&obtained, &desired, sizeof(desired));
79
			break;
80
	}
81
	SDL_PauseAudio(0);
82
83
 
84
	shm = &the_shm;
85
	shm->splitbuffer = 0;
86
	shm->samplebits = (obtained.format & 0xFF);
87
	shm->speed = obtained.freq;
88
	shm->channels = obtained.channels;
89
	shm->samples = obtained.samples*shm->channels;
90
	shm->samplepos = 0;
91
	shm->submission_chunk = 1;
92
	shm->buffer = NULL;
93
94
 
95
	return 1;
96
}
97
98
 
99
{
100
	return shm->samplepos;
101
}
102
103
 
104
{
105
	if (snd_inited)
106
	{
107
		SDL_CloseAudio();
108
		snd_inited = 0;
109
	}
110
}
111