4 void slSamplePlayer::addEnvelope ( int i, slEnvelope *_env, slEnvelopeType _type )
6 if ( i < 0 || i >= SL_MAX_ENVELOPES ) return ;
8 if ( env [ i ] != NULL )
9 env [ i ] -> unRef () ;
16 env_type [ i ] = _type ;
17 env_start_time [ i ] = slScheduler::getCurrent() -> getTimeNow () ;
20 int slSamplePlayer::preempt ( int delay )
22 slScheduler::getCurrent() -> addCallBack ( callback, sample, SL_EVENT_PREEMPTED, magic ) ;
24 switch ( preempt_mode )
26 case SL_SAMPLE_CONTINUE: if ( isRunning() )
29 case SL_SAMPLE_DELAY : break ;
30 case SL_SAMPLE_MUTE : skip ( delay ) ; break ;
31 case SL_SAMPLE_ABORT : stop () ; break ;
32 case SL_SAMPLE_RESTART : reset () ; break ;
38 slSamplePlayer::~slSamplePlayer ()
43 slScheduler::getCurrent() -> addCallBack ( callback, sample, SL_EVENT_COMPLETE, magic ) ;
46 void slSamplePlayer::skip ( int nframes )
48 if ( nframes < lengthRemaining )
50 lengthRemaining -= nframes ;
51 bufferPos += nframes ;
54 if ( replay_mode == SL_SAMPLE_LOOP )
56 slScheduler::getCurrent() -> addCallBack ( callback, sample, SL_EVENT_LOOPED, magic ) ;
58 nframes -= lengthRemaining ;
60 while ( nframes >= sample->getLength () )
61 nframes -= sample->getLength () ;
63 lengthRemaining = sample->getLength() - nframes ;
64 bufferPos = & ( sample->getBuffer() [ nframes ] ) ;
71 void slSamplePlayer::read ( int nframes, Uchar *dst, int next_env )
79 /* Find the next envelope */
81 while ( next_env < SL_MAX_ENVELOPES && env [ next_env ] == NULL )
85 If there are no fancy envelopes to process then return
89 if ( next_env >= SL_MAX_ENVELOPES ) /* No fancy envelopes left */
91 low_read ( nframes, dst ) ;
96 Envelope processing required...
98 Process the next envelope using data read recursively through
99 the remaining envelopes.
102 switch ( env_type [ next_env ] )
104 /* For Volume envelopes, SRC and DST can be the same buffer */
106 case SL_INVERSE_VOLUME_ENVELOPE:
107 read ( nframes, dst, next_env+1 ) ;
108 env[ next_env ]->applyToInvVolume ( dst,dst,nframes,env_start_time[ next_env ] ) ;
111 case SL_VOLUME_ENVELOPE :
112 read ( nframes, dst, next_env+1 ) ;
113 env[ next_env ]->applyToVolume ( dst,dst,nframes,env_start_time[ next_env ] ) ;
116 case SL_INVERSE_PITCH_ENVELOPE :
117 env[ next_env ]->applyToInvPitch ( dst,this,nframes,env_start_time[ next_env ], next_env+1 ) ;
120 case SL_PITCH_ENVELOPE :
121 env[ next_env ]->applyToPitch ( dst,this,nframes,env_start_time[ next_env ], next_env+1 ) ;
124 case SL_INVERSE_FILTER_ENVELOPE:
125 case SL_FILTER_ENVELOPE :
126 read ( nframes, dst, next_env+1 ) ;
129 case SL_INVERSE_PAN_ENVELOPE :
130 case SL_PAN_ENVELOPE :
131 read ( nframes, dst, next_env+1 ) ;
134 case SL_INVERSE_ECHO_ENVELOPE :
135 case SL_ECHO_ENVELOPE :
136 read ( nframes, dst, next_env+1 ) ;
142 void slSamplePlayer::low_read ( int nframes, Uchar *dst )
144 if ( isWaiting() ) start () ;
146 if ( bufferPos == NULL ) /* Run out of sample & no repeats */
148 memset ( dst, 0x80, nframes ) ;
155 If we can satisfy this request in one read (with data left in
156 the sample buffer ready for next time around) - then we are done...
159 if ( nframes < lengthRemaining )
161 memcpy ( dst, bufferPos, nframes ) ;
162 bufferPos += nframes ;
163 lengthRemaining -= nframes ;
167 memcpy ( dst, bufferPos, lengthRemaining ) ;
168 bufferPos += lengthRemaining ;
169 dst += lengthRemaining ;
170 nframes -= lengthRemaining ;
171 lengthRemaining = 0 ;
173 if ( replay_mode == SL_SAMPLE_ONE_SHOT )
176 memset ( dst, 0x80, nframes ) ;
181 slScheduler::getCurrent() -> addCallBack ( callback, sample, SL_EVENT_LOOPED, magic ) ;