/[svn]/linuxsampler/trunk/src/engines/gig/Stream.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/Stream.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 3052 by schoenebeck, Wed Dec 14 17:34:54 2016 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003 by Benno Senoner                                   *   *   Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck    *
6     *   Copyright (C) 2005-2009 Christian Schoenebeck                         *
7     *   Copyright (C) 2009 Grigor Iliev                                       *
8   *                                                                         *   *                                                                         *
9   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
10   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 21  Line 23 
23   ***************************************************************************/   ***************************************************************************/
24    
25  #ifndef __LS_GIG_STREAM_H__  #ifndef __LS_GIG_STREAM_H__
26  #define __LS_GIG_STREAM_H__  #define __LS_GIG_STREAM_H__
27    
28  #include "../../common/global.h"  #include "../common/StreamBase.h"
29    
30  #if DEBUG_HEADERS  #if AC_APPLE_UNIVERSAL_BUILD
31  # warning Stream.h included  # include <libgig/gig.h>
32  #endif // DEBUG_HEADERS  #else
33    # include <gig.h>
34  #include "../../common/RingBuffer.h"  #endif
 #include "../../lib/fileloader/libgig/gig.h"  
35    
36  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
37    
38      class Stream {      class Stream: public LinuxSampler::StreamBase< ::gig::DimensionRegion> {
         public:  
             // Member Types  
             typedef uint32_t OrderID_t;  
             typedef uint32_t Handle; ///< unique identifier of a relationship between one stream and a consumer (Voice)  
             enum state_t {           ///< streams go through severe cyclic state transition (unused->active->end->unused->...)  
                 state_unused,        ///< stream is not in use, thus can still be launched  
                 state_active,        ///< stream provides data in it's buffer to be read and hasn't reached the end yet (this is the usual case)  
                 state_end            ///< stream end reached but still providing data in it's buffer to be read (after the client read all remaining data from the stream buffer, state will change automatically to state_unused)  
             };  
             struct reference_t {     ///< Defines the current relationship between the stream and a client (voice).  
                 OrderID_t OrderID;   ///< Unique identifier that identifies the creation order of a stream requested by a voice.  
                 Handle    hStream;   ///< Unique identifier of the relationship between stream and client.  
                 state_t   State;     ///< Current state of the stream that will be pretended to the client (the actual state of the stream might differ though, because the stream might already be in use by another client).  
                 Stream*   pStream;   ///< Points to the assigned and activated stream or is NULL if the disk thread hasn't launched a stream yet.  
             };  
   
             // Methods  
             Stream(uint BufferSize, uint BufferWrapElements);  
            ~Stream();  
             int  ReadAhead(unsigned long SampleCount);  
             void WriteSilence(unsigned long SilenceSampleWords);  
   
             inline int GetReadSpace() {  
                 return (pRingBuffer && State == state_active) ? pRingBuffer->read_space()  : 0;  
             }  
   
             inline int GetWriteSpace() {  
                 return (pRingBuffer && State == state_active) ? pRingBuffer->write_space() : 0;  
             }  
   
             inline int GetWriteSpaceToEnd() {  
                 return (pRingBuffer && State == state_active) ? pRingBuffer->write_space_to_end_with_wrap() : 0;  
             }  
   
             // adjusts the write space to avoid buffer boundaries which would lead to the wrap space  
             // within the buffer (needed for interpolation) getting filled only partially  
             // for more infos see the docs in ringbuffer.h at adjust_write_space_to_avoid_boundary()  
             inline int AdjustWriteSpaceToAvoidBoundary(int cnt, int capped_cnt) {  
               return pRingBuffer->adjust_write_space_to_avoid_boundary(cnt, capped_cnt);  
             }  
   
             inline sample_t* GetReadPointer() {  
                 return pRingBuffer->get_read_ptr();  
             }  
   
             // gets the current read_ptr within the ringbuffer  
             inline sample_t* GetReadPtr(void) {  
                 return pRingBuffer->get_read_ptr();  
             }  
   
             inline void IncrementReadPos(uint Count)  {  
                 uint leftspace = pRingBuffer->read_space();  
                 pRingBuffer->increment_read_ptr(Min(Count, leftspace));  
                 if (State == state_end && Count >= leftspace) {  
                     Reset(); // quit relation between consumer (voice) and stream and reset stream right after  
                 }  
             }  
   
             // Static Method  
             inline static uint       GetUnusedStreams() { return UnusedStreams; }  
         protected:  
             // Methods  
             void                     Launch(Stream::Handle hStream, reference_t* pExportReference, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop);  
             inline void              Kill()      { pExportReference = NULL; Reset(); } ///< Will be called by disk thread after a 'deletion' command from the audio thread (within the voice class)  
             inline Stream::Handle    GetHandle() { return hThis; }  
             inline Stream::state_t   GetState()  { return State; }  
             friend class DiskThread; // only the disk thread should be able to launch and most important kill a disk stream to avoid race conditions  
39          private:          private:
40              // Attributes              ::gig::buffer_t* pDecompressionBuffer;
41              reference_t*             pExportReference;  
42              state_t                  State;          public:
43              Stream::Handle           hThis;              Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements);
44              unsigned long            SampleOffset;              virtual long Read(uint8_t* pBuf, long SamplesToRead);
45              ::gig::Sample*           pSample;  
46              ::gig::playback_state_t  PlaybackState;              void Launch (
47              RingBuffer<sample_t>*    pRingBuffer;                  Stream::Handle           hStream,
48              bool                     DoLoop;                  reference_t*             pExportReference,
49                    ::gig::DimensionRegion*  pRgn,
50              // Static Attributes                  unsigned long            SampleOffset,
51              static uint              UnusedStreams; //< Reflects how many stream objects of all stream instances are currently not in use.                  bool                     DoLoop
52                );
             // Methods  
             inline void Reset() {  
                 SampleOffset                   = 0;  
                 pSample                        = NULL;  
                 PlaybackState.position         = 0;  
                 PlaybackState.reverse          = false;  
                 hThis                          = 0;  
                 pRingBuffer->init(); // reset ringbuffer  
                 if (State != state_unused) {  
                     // we can't do 'SetPos(state_unused)' here, due to possible race conditions)  
                     if (pExportReference) {  
                         pExportReference->State = state_unused;  
                         pExportReference        = NULL;  
                     }  
                     State = state_unused;  
                     UnusedStreams++;  
                 }  
             }  
             inline void SetState(state_t State) {  
                 if (pExportReference) pExportReference->State = State;  
                 this->State = State;  
             }  
             inline long Min(long a, long b) { return (a < b) ? a : b; }  
53      };      };
54    
55    
56  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig
57    
58  #endif // __LS_GIG_STREAM_H__  #endif  /* __LS_GIG_STREAM_H__ */
59    

Legend:
Removed from v.53  
changed lines
  Added in v.3052

  ViewVC Help
Powered by ViewVC