199
|
1 /*
|
|
2
|
|
3 TiMidity -- Experimental MIDI to WAVE converter
|
|
4 Copyright (C) 1995 Tuukka Toivonen <toivonen@clinet.fi>
|
|
5
|
|
6 This program is free software; you can redistribute it and/or modify
|
|
7 it under the terms of the GNU General Public License as published by
|
|
8 the Free Software Foundation; either version 2 of the License, or
|
|
9 (at your option) any later version.
|
|
10
|
|
11 This program is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with this program; if not, write to the Free Software
|
|
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
19
|
|
20 output.c
|
|
21
|
|
22 Audio output (to file / device) functions.
|
|
23 */
|
|
24
|
|
25 #if HAVE_CONFIG_H
|
|
26 # include <config.h>
|
|
27 #endif
|
|
28
|
|
29 #include "SDL_sound.h"
|
|
30
|
|
31 #define __SDL_SOUND_INTERNAL__
|
|
32 #include "SDL_sound_internal.h"
|
|
33
|
|
34 #include "options.h"
|
|
35 #include "output.h"
|
|
36
|
|
37 /*****************************************************************/
|
|
38 /* Some functions to convert signed 32-bit data to other formats */
|
|
39
|
|
40 void s32tos8(void *dp, Sint32 *lp, Sint32 c)
|
|
41 {
|
|
42 Sint8 *cp=(Sint8 *)(dp);
|
|
43 Sint32 l;
|
|
44 while (c--)
|
|
45 {
|
|
46 l=(*lp++)>>(32-8-GUARD_BITS);
|
|
47 if (l>127) l=127;
|
|
48 else if (l<-128) l=-128;
|
|
49 *cp++ = (Sint8) (l);
|
|
50 }
|
|
51 }
|
|
52
|
|
53 void s32tou8(void *dp, Sint32 *lp, Sint32 c)
|
|
54 {
|
|
55 Uint8 *cp=(Uint8 *)(dp);
|
|
56 Sint32 l;
|
|
57 while (c--)
|
|
58 {
|
|
59 l=(*lp++)>>(32-8-GUARD_BITS);
|
|
60 if (l>127) l=127;
|
|
61 else if (l<-128) l=-128;
|
|
62 *cp++ = 0x80 ^ ((Uint8) l);
|
|
63 }
|
|
64 }
|
|
65
|
|
66 void s32tos16(void *dp, Sint32 *lp, Sint32 c)
|
|
67 {
|
|
68 Sint16 *sp=(Sint16 *)(dp);
|
|
69 Sint32 l;
|
|
70 while (c--)
|
|
71 {
|
|
72 l=(*lp++)>>(32-16-GUARD_BITS);
|
|
73 if (l > 32767) l=32767;
|
|
74 else if (l<-32768) l=-32768;
|
|
75 *sp++ = (Sint16)(l);
|
|
76 }
|
|
77 }
|
|
78
|
|
79 void s32tou16(void *dp, Sint32 *lp, Sint32 c)
|
|
80 {
|
|
81 Uint16 *sp=(Uint16 *)(dp);
|
|
82 Sint32 l;
|
|
83 while (c--)
|
|
84 {
|
|
85 l=(*lp++)>>(32-16-GUARD_BITS);
|
|
86 if (l > 32767) l=32767;
|
|
87 else if (l<-32768) l=-32768;
|
|
88 *sp++ = 0x8000 ^ (Uint16)(l);
|
|
89 }
|
|
90 }
|
|
91
|
|
92 void s32tos16x(void *dp, Sint32 *lp, Sint32 c)
|
|
93 {
|
|
94 Sint16 *sp=(Sint16 *)(dp);
|
|
95 Sint32 l;
|
|
96 while (c--)
|
|
97 {
|
|
98 l=(*lp++)>>(32-16-GUARD_BITS);
|
|
99 if (l > 32767) l=32767;
|
|
100 else if (l<-32768) l=-32768;
|
|
101 *sp++ = SDL_Swap16((Sint16)(l));
|
|
102 }
|
|
103 }
|
|
104
|
|
105 void s32tou16x(void *dp, Sint32 *lp, Sint32 c)
|
|
106 {
|
|
107 Uint16 *sp=(Uint16 *)(dp);
|
|
108 Sint32 l;
|
|
109 while (c--)
|
|
110 {
|
|
111 l=(*lp++)>>(32-16-GUARD_BITS);
|
|
112 if (l > 32767) l=32767;
|
|
113 else if (l<-32768) l=-32768;
|
|
114 *sp++ = SDL_Swap16(0x8000 ^ (Uint16)(l));
|
|
115 }
|
|
116 }
|