1 /*
2 PLIB - A Suite of Portable Game Libraries
3 Copyright (C) 1998,2002 Steve Baker
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 For further information visit http://plib.sourceforge.net
20
21 $Id: slPlayer.cxx 1924 2004-04-06 13:32:26Z sjbaker $
22 */
23
24
25 #include "sl.h"
26
addEnvelope(int i,slEnvelope * _env,slEnvelopeType _type)27 void slPlayer::addEnvelope ( int i, slEnvelope *_env, slEnvelopeType _type )
28 {
29 if ( i < 0 || i >= SL_MAX_ENVELOPES ) return ;
30
31 if ( env [ i ] != NULL )
32 env [ i ] -> unRef () ;
33
34 env [ i ] = _env ;
35
36 if ( _env != NULL )
37 env [ i ] -> ref () ;
38
39 env_type [ i ] = _type ;
40 env_start_time [ i ] = slScheduler::getCurrent() -> getTimeNow () ;
41 }
42
preempt(int delay)43 int slPlayer::preempt ( int delay )
44 {
45 switch ( preempt_mode )
46 {
47 case SL_SAMPLE_CONTINUE: if ( isRunning() )
48 return SL_FALSE ;
49 /* FALLTHROUGH! */
50 case SL_SAMPLE_DELAY : break ;
51 case SL_SAMPLE_MUTE : skip ( delay ) ; break ;
52 case SL_SAMPLE_ABORT : stop () ; break ;
53 case SL_SAMPLE_RESTART : reset () ; break ;
54 default : break ;
55 }
56
57 return SL_TRUE ;
58 }
59
~slPlayer()60 slPlayer::~slPlayer ()
61 {
62 }
63
64
read(int nframes,Uchar * dst,int next_env)65 void slPlayer::read ( int nframes, Uchar *dst, int next_env )
66 {
67 /*
68 WARNING:
69
70 CO-RECURSIVE!
71 */
72
73 /* Find the next envelope */
74
75 while ( next_env < SL_MAX_ENVELOPES && env [ next_env ] == NULL )
76 next_env++ ;
77
78 /*
79 If there are no fancy envelopes to process then return
80 the raw data.
81 */
82
83 if ( next_env >= SL_MAX_ENVELOPES ) /* No fancy envelopes left */
84 {
85 low_read ( nframes, dst ) ;
86 return ;
87 }
88
89 /*
90 Envelope processing required...
91
92 Process the next envelope using data read recursively through
93 the remaining envelopes.
94 */
95
96 switch ( env_type [ next_env ] )
97 {
98 /* For Volume envelopes, SRC and DST can be the same buffer */
99
100 case SL_INVERSE_VOLUME_ENVELOPE:
101 read ( nframes, dst, next_env+1 ) ;
102 env[ next_env ]->applyToInvVolume ( dst,dst,nframes,env_start_time[ next_env ] ) ;
103 break ;
104
105 case SL_VOLUME_ENVELOPE :
106 read ( nframes, dst, next_env+1 ) ;
107 env[ next_env ]->applyToVolume ( dst,dst,nframes,env_start_time[ next_env ] ) ;
108 break ;
109
110 case SL_INVERSE_PITCH_ENVELOPE :
111 env[ next_env ]->applyToInvPitch ( dst,this,nframes,env_start_time[ next_env ], next_env+1 ) ;
112 break ;
113
114 case SL_PITCH_ENVELOPE :
115 env[ next_env ]->applyToPitch ( dst,this,nframes,env_start_time[ next_env ], next_env+1 ) ;
116 break ;
117
118 case SL_INVERSE_FILTER_ENVELOPE:
119 case SL_FILTER_ENVELOPE :
120 read ( nframes, dst, next_env+1 ) ;
121 env [ next_env ] -> applyToLPFilter ( dst, dst, nframes,
122 env_start_time [ next_env ] ) ;
123 break ;
124
125 case SL_INVERSE_PAN_ENVELOPE :
126 case SL_PAN_ENVELOPE :
127 read ( nframes, dst, next_env+1 ) ;
128 break ;
129
130 case SL_INVERSE_ECHO_ENVELOPE :
131 case SL_ECHO_ENVELOPE :
132 read ( nframes, dst, next_env+1 ) ;
133 break ;
134
135 default :
136 break ;
137 }
138 }
139
140