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 Uchar *slSamplePlayer::read ( int nframes, Uchar *spare1, Uchar *spare2 )
73 if ( isWaiting() ) start () ;
75 if ( nframes > lengthRemaining ) /* This is an error */
77 fprintf ( stderr, "slSamplePlayer: FATAL ERROR - Mixer Requested too much data.\n" ) ;
81 Uchar *src = bufferPos ;
84 for ( int i = 0 ; i < SL_MAX_ENVELOPES ; i++ )
88 switch ( env_type [ i ] )
90 case SL_INVERSE_PITCH_ENVELOPE :
91 case SL_PITCH_ENVELOPE :
92 memcpy ( dst, src, nframes ) /* Tricky! */ ;
95 case SL_INVERSE_VOLUME_ENVELOPE:
96 env[i]->applyToInvVolume ( dst,src,nframes,env_start_time[i] ) ;
99 case SL_VOLUME_ENVELOPE :
100 env[i]->applyToVolume ( dst,src,nframes,env_start_time[i] ) ;
103 case SL_INVERSE_FILTER_ENVELOPE:
104 case SL_FILTER_ENVELOPE :
105 memcpy ( dst, src, nframes ) /* Tricky! */ ;
108 case SL_INVERSE_PAN_ENVELOPE :
109 case SL_PAN_ENVELOPE :
110 memcpy ( dst, src, nframes ) /* Tricky! */ ;
113 case SL_INVERSE_ECHO_ENVELOPE :
114 case SL_ECHO_ENVELOPE :
115 memcpy ( dst, src, nframes ) /* Tricky! */ ;
132 if ( nframes < lengthRemaining ) /* Less data than there is left... */
134 lengthRemaining -= nframes ;
135 bufferPos += nframes ;
137 else /* Read it all */
139 if ( replay_mode == SL_SAMPLE_ONE_SHOT )
143 slScheduler::getCurrent() -> addCallBack ( callback, sample, SL_EVENT_LOOPED, magic ) ;