2 Copyright (c) 2002,2003, Christian Nowak <chnowak@web.de>
5 Modified by Francisco Mu�oz 'Hermes' MAY 2008
7 Redistribution and use in source and binary forms, with or without modification, are
8 permitted provided that the following conditions are met:
10 - Redistributions of source code must retain the above copyright notice, this list of
11 conditions and the following disclaimer.
12 - Redistributions in binary form must reproduce the above copyright notice, this list
13 of conditions and the following disclaimer in the documentation and/or other
14 materials provided with the distribution.
15 - The names of the contributors may not be used to endorse or promote products derived
16 from this software without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
19 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
21 THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
26 THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #if defined(DREAMCAST)
35 #define PREFILL_WORD 0
37 #define PREFILL_WORD 32768
38 #elif defined(ALLEGRO)
39 #define PREFILL_WORD 32768
41 #define PREFILL_WORD 32768
43 #define PREFILL_WORD 0
45 #define PREFILL_WORD 32768
50 accum = (s32)b[i] + (s32)((((s32)data[playpos.aword.high]*volume)>>6) << shiftval); \
51 if(accum<-32768) accum = -32768; if(accum>32767) accum = 32767; \
53 playpos.adword+=incval; \
54 if ( playpos.adword>=loop_end ) \
56 if (mod->instrument[mod->instnum[voice]].looped) \
57 playpos.adword -= mod->instrument[mod->instnum[voice]].loop_length<<16; \
60 playpos.adword = (mod->instrument[mod->instnum[voice]].loop_end-1)<<16; \
61 mod->channel_active[voice] = FALSE; \
66 s32
mix_mono_16bit ( MOD
* mod
, s16
* buf
, s32 numSamples
)
71 s32 shiftval
= mod
->shiftval
;
73 s32 numIterationsRest
;
75 numIterations
= numSamples
>>4;
76 numIterationsRest
= numSamples
&((1<<4)-1);
79 for (i
=j
=0;j
<numIterations
;j
++)
81 buf
[i
] = PREFILL_WORD
;i
++;
82 buf
[i
] = PREFILL_WORD
;i
++;
83 buf
[i
] = PREFILL_WORD
;i
++;
84 buf
[i
] = PREFILL_WORD
;i
++;
85 buf
[i
] = PREFILL_WORD
;i
++;
86 buf
[i
] = PREFILL_WORD
;i
++;
87 buf
[i
] = PREFILL_WORD
;i
++;
88 buf
[i
] = PREFILL_WORD
;i
++;
89 buf
[i
] = PREFILL_WORD
;i
++;
90 buf
[i
] = PREFILL_WORD
;i
++;
91 buf
[i
] = PREFILL_WORD
;i
++;
92 buf
[i
] = PREFILL_WORD
;i
++;
93 buf
[i
] = PREFILL_WORD
;i
++;
94 buf
[i
] = PREFILL_WORD
;i
++;
95 buf
[i
] = PREFILL_WORD
;i
++;
96 buf
[i
] = PREFILL_WORD
;i
++;
98 for (j
=0;j
<numIterationsRest
;j
++,i
++)
99 buf
[i
] = PREFILL_WORD
;
102 for (voice
=0;voice
<mod
->num_channels
;++voice
)
104 if (mod
->instrument
[mod
->instnum
[voice
]].data
!= NULL
&& mod
->channel_active
[voice
])
108 noteidx
= (mod
->chanfreq
[voice
] - mod
->chanfreq
[voice
]*2*(mod
->instrument
[mod
->instnum
[voice
]].finetune
-8)/256);
109 incval
= mod
->inctab
[noteidx
];
111 s8
* data
= mod
->instrument
[mod
->instnum
[voice
]].data
;
113 u32 loop_end
= mod
->instrument
[mod
->instnum
[voice
]].loop_end
<<16;
114 s32 volume
= mod
->volume
[voice
];
115 playpos
.adword
= mod
->playpos
[voice
];
117 if ( voice
<mod
->num_voices
)
118 volume
= (volume
*(s32
)mod
->musicvolume
)>>6;
120 volume
= (volume
*(s32
)mod
->sfxvolume
)>>6;
122 if (mod
->freq
==32000 || mod
->freq
==48000)
125 for (j
=i
=0;j
<numIterations
;j
++)
144 for (j
=0;j
<numIterationsRest
;j
++,i
++)
148 mod
->playpos
[voice
] = playpos
.adword
;
154 s32
mix_stereo_16bit ( MOD
* mod
, s16
* buf
, s32 numSamples
)
159 s32 shiftval
= mod
->shiftval
+1;
160 s32 numIterations
, numIterationsRest
;
162 numIterations
= (numSamples
)>>2;
163 numIterationsRest
= (numSamples
)&((1<<2)-1);
165 for (i
=j
=0;j
<numIterations
;j
++)
167 buf
[i
] = buf
[i
+1] = PREFILL_WORD
;i
+=2;
168 buf
[i
] = buf
[i
+1] = PREFILL_WORD
;i
+=2;
169 buf
[i
] = buf
[i
+1] = PREFILL_WORD
;i
+=2;
170 buf
[i
] = buf
[i
+1] = PREFILL_WORD
;i
+=2;
172 for (j
=0;j
<numIterationsRest
;j
++,i
+=2)
173 buf
[i
] = buf
[i
+1] = PREFILL_WORD
;
175 /* for (j=0;j<numSamples*2;j+=2)
176 buf[j] = buf[j+1] = PREFILL_WORD;*/
178 for (voice
=0;voice
<mod
->num_channels
;++voice
)
180 s32 lrofs
= (((voice
-1)>>1)&1)^1;
181 if (mod
->instrument
[mod
->instnum
[voice
]].data
!= NULL
&& mod
->channel_active
[voice
])
185 noteidx
= (mod
->chanfreq
[voice
] - mod
->chanfreq
[voice
]*2*(mod
->instrument
[mod
->instnum
[voice
]].finetune
-8)/256);
186 incval
= mod
->inctab
[noteidx
];
188 s8
* data
= mod
->instrument
[mod
->instnum
[voice
]].data
;
190 u32 loop_end
= mod
->instrument
[mod
->instnum
[voice
]].loop_end
<<16;
191 s32 volume
= mod
->volume
[voice
];
193 if ( voice
<mod
->num_voices
)
194 volume
= (volume
*(s32
)mod
->musicvolume
)>>6;
196 volume
= (volume
*(s32
)mod
->sfxvolume
)>>6;
198 playpos
.adword
= mod
->playpos
[voice
];
199 if (mod
->freq
==32000 || mod
->freq
==48000)
203 for (j
=0;j
<numIterations
;j
++)
210 for (j
=0;j
<numIterationsRest
;j
++)
214 /* for (i=0;i<numSamples*2;i+=2)
218 mod
->playpos
[voice
] = playpos
.adword
;