]> git.mxchange.org Git - simgear.git/blobdiff - src/sl.h
added a working() method.
[simgear.git] / src / sl.h
index 79b63e65f44ed42d678e577a2adc1fc9e785cce7..dd026b7f074c3e57db6d8efa588827c72410878b 100644 (file)
--- a/src/sl.h
+++ b/src/sl.h
@@ -24,6 +24,9 @@ typedef unsigned short Ushort ;
 
 #define SL_DEFAULT_SAMPLING_RATE 11025
 
+/* Set if the next slScheduler::update will die */
+extern char *__slPendingError ;
+
 class slSample       ;
 class slSamplePlayer ;
 class slEnvelope     ;
@@ -109,6 +112,7 @@ public:
 
   void play ( void *buffer, size_t length ) { write ( buffer, length ) ; } 
 
+  int working () { return !error ; }
   int not_working () { return error ; }
 
   int getBps   () { return bps    ; }
@@ -165,9 +169,9 @@ public:
   {
     if ( ref_count != 0 )
     {
-      fprintf ( stderr,
-        "slSample: FATAL ERROR - Application deleted a sample while it was playing.\n" ) ;
-      exit ( 1 ) ;
+    if ( __slPendingError == NULL )
+      __slPendingError =
+            "slXXXX: FATAL ERROR - Application deleted a sample while it was playing.\n" ;
     }
 
     delete buffer ;
@@ -224,9 +228,10 @@ public:
   int loadAUFile  ( char *fname ) ;
   int loadWavFile ( char *fname ) ;
 
-  void changeRate   ( int r ) ;
-  void changeBps    ( int b ) ;
-  void changeStereo ( int s ) ;
+  void changeRate       ( int r ) ;
+  void changeBps        ( int b ) ;
+  void changeStereo     ( int s ) ;
+  void changeToUnsigned () ;
 
   void adjustVolume ( float vol ) ;
 
@@ -285,6 +290,8 @@ typedef void (*slCallBack) ( slSample *, slEvent, int ) ;
 
 class slEnvelope
 {
+public:  /* SJB TESTING! */
+
   float *time  ;
   float *value ;
   int   nsteps ;
@@ -326,9 +333,9 @@ public:
   {
     if ( ref_count != 0 )
     {
-      fprintf ( stderr,
-        "slEnvelope: FATAL ERROR - Application deleted an envelope while it was playing.\n" ) ;
-      exit ( 1 ) ;
+    if ( __slPendingError == NULL )
+      __slPendingError =
+            "slXXXX: FATAL ERROR - Application deleted an envelope while it was playing.\n" ;
     }
 
     delete time ;
@@ -356,6 +363,8 @@ public:
 
   float getValue ( float _time ) ;
 
+  void applyToPitch     ( Uchar *dst, slSamplePlayer *src, int nframes, int start, int next_env ) ;
+  void applyToInvPitch  ( Uchar *dst, slSamplePlayer *src, int nframes, int start, int next_env ) ;
   void applyToVolume    ( Uchar *dst, Uchar *src, int nframes, int start ) ;
   void applyToInvVolume ( Uchar *dst, Uchar *src, int nframes, int start ) ;
 } ;
@@ -386,8 +395,8 @@ struct slPendingCallBack
 
 class slSamplePlayer
 {
-  int            lengthRemaining ;
-  Uchar         *bufferPos       ;
+  int            lengthRemaining ;  /* Sample frames remaining until repeat */
+  Uchar         *bufferPos       ;  /* Sample frame to replay next */
   slSample      *sample          ;
 
   slEnvelope    *env            [ SL_MAX_ENVELOPES ] ;
@@ -402,6 +411,8 @@ class slSamplePlayer
   slCallBack     callback ;
   int            magic ;
 
+  void  low_read ( int nframes, Uchar *dest ) ;
+
 public:
 
   slSamplePlayer ( slSample *s, slReplayMode  rp_mode = SL_SAMPLE_ONE_SHOT, 
@@ -429,11 +440,6 @@ public:
 
   ~slSamplePlayer () ;
 
-  int getAmountLeft ()
-  {
-    return lengthRemaining ;
-  }
-
   slPreemptMode getPreemptMode () { return preempt_mode ; }
 
   int getPriority ()
@@ -488,8 +494,8 @@ public:
   int isRunning () { return status == SL_SAMPLE_RUNNING ; } 
   int isDone    () { return status == SL_SAMPLE_DONE    ; }
 
-  void   skip ( int nframes ) ;
-  Uchar *read ( int nframes, Uchar *spare1, Uchar *spare2 ) ;
+  void skip ( int nframes ) ;
+  void read ( int nframes, Uchar *dest, int next_env = 0 ) ;
 } ;
 
 
@@ -499,29 +505,24 @@ class slScheduler : public slDSP
   int num_pending_callbacks ;
 
   float safety_margin ;
+
   int mixer_buffer_size ;
-  Uchar *mixer_buffer ;
+
+  Uchar *mixer_buffer  ;
+  Uchar *spare_buffer0 ;
+  Uchar *spare_buffer1 ;
+  Uchar *spare_buffer2 ;
+  
   Uchar *mixer ;
   int amount_left ;
 
   slSamplePlayer *samplePlayer [ SL_MAX_SAMPLES ] ;
 
-  Uchar *spare_buffer1 [ 3 ] ;
-  Uchar *spare_buffer2 [ 3 ] ;
-  
   void init () ;
 
-  Uchar *mergeBlock ( Uchar *d ) ;
-  Uchar *mergeBlock ( Uchar *d, slSamplePlayer *spa ) ;
-  Uchar *mergeBlock ( Uchar *d, slSamplePlayer *spa,
-                                slSamplePlayer *spb ) ;
-  Uchar *mergeBlock ( Uchar *d, slSamplePlayer *spa,
-                                slSamplePlayer *spb,
-                                slSamplePlayer *spc ) ;
-  void mixBuffer () ;
-  void mixBuffer ( slSamplePlayer *a ) ;
   void mixBuffer ( slSamplePlayer *a,
                    slSamplePlayer *b ) ;
+
   void mixBuffer ( slSamplePlayer *a,
                    slSamplePlayer *b,
                    slSamplePlayer *c ) ;