comparison src/Input/timidity/libtimidity/output.c @ 0:13389e613d67 trunk

[svn] - initial import of audacious-plugins tree (lots to do)
author nenolod
date Mon, 18 Sep 2006 01:11:49 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:13389e613d67
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 "timidity.h"
30 #include "timidity_internal.h"
31 #include "options.h"
32 #include "output.h"
33
34 /*****************************************************************/
35 /* Some functions to convert signed 32-bit data to other formats */
36
37 void s32tos8(void *dp, sint32 *lp, sint32 c)
38 {
39 sint8 *cp=(sint8 *)(dp);
40 sint32 l;
41 while (c--)
42 {
43 l=(*lp++)>>(32-8-GUARD_BITS);
44 if (l>127) l=127;
45 else if (l<-128) l=-128;
46 *cp++ = (sint8) (l);
47 }
48 }
49
50 void s32tou8(void *dp, sint32 *lp, sint32 c)
51 {
52 uint8 *cp=(uint8 *)(dp);
53 sint32 l;
54 while (c--)
55 {
56 l=(*lp++)>>(32-8-GUARD_BITS);
57 if (l>127) l=127;
58 else if (l<-128) l=-128;
59 *cp++ = 0x80 ^ ((uint8) l);
60 }
61 }
62
63 void s32tos16(void *dp, sint32 *lp, sint32 c)
64 {
65 sint16 *sp=(sint16 *)(dp);
66 sint32 l;
67 while (c--)
68 {
69 l=(*lp++)>>(32-16-GUARD_BITS);
70 if (l > 32767) l=32767;
71 else if (l<-32768) l=-32768;
72 *sp++ = (sint16)(l);
73 }
74 }
75
76 void s32tou16(void *dp, sint32 *lp, sint32 c)
77 {
78 uint16 *sp=(uint16 *)(dp);
79 sint32 l;
80 while (c--)
81 {
82 l=(*lp++)>>(32-16-GUARD_BITS);
83 if (l > 32767) l=32767;
84 else if (l<-32768) l=-32768;
85 *sp++ = 0x8000 ^ (uint16)(l);
86 }
87 }
88
89 void s32tos16x(void *dp, sint32 *lp, sint32 c)
90 {
91 sint16 *sp=(sint16 *)(dp);
92 sint32 l;
93 while (c--)
94 {
95 l=(*lp++)>>(32-16-GUARD_BITS);
96 if (l > 32767) l=32767;
97 else if (l<-32768) l=-32768;
98 *sp++ = XCHG_SHORT((sint16)(l));
99 }
100 }
101
102 void s32tou16x(void *dp, sint32 *lp, sint32 c)
103 {
104 uint16 *sp=(uint16 *)(dp);
105 sint32 l;
106 while (c--)
107 {
108 l=(*lp++)>>(32-16-GUARD_BITS);
109 if (l > 32767) l=32767;
110 else if (l<-32768) l=-32768;
111 *sp++ = XCHG_SHORT(0x8000 ^ (uint16)(l));
112 }
113 }