/[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 385 by schoenebeck, Thu Feb 17 02:53:45 2005 UTC revision 903 by persson, Sat Jul 22 14:22:53 2006 UTC
# Line 30  Line 30 
30  # warning Stream.h included  # warning Stream.h included
31  #endif // DEBUG_HEADERS  #endif // DEBUG_HEADERS
32    
33    #include <gig.h>
34    
35  #include "../../common/RingBuffer.h"  #include "../../common/RingBuffer.h"
 #include "../../lib/fileloader/libgig/gig.h"  
36    
37  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
38    
39        /** @brief Buffered Disk Stream
40         *
41         * This encapsulation of a disk stream uses a ring buffer to allow
42         * thread safe refilling the stream's buffer with one thread (disk
43         * thread) and actual use / extraction of the audio data from the
44         * stream's buffer with another thread (audio thread).
45         */
46      class Stream {      class Stream {
47          public:          public:
48              // Member Types              // Member Types
# Line 54  namespace LinuxSampler { namespace gig { Line 62  namespace LinuxSampler { namespace gig {
62    
63              // Methods              // Methods
64              Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements);              Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements);
65             ~Stream();              virtual ~Stream();
66              int  ReadAhead(unsigned long SampleCount);              int  ReadAhead(unsigned long SampleCount);
67              void WriteSilence(unsigned long SilenceSampleWords);              void WriteSilence(unsigned long SilenceSampleWords);
68    
69              inline int GetReadSpace() {              inline int GetReadSpace() {
70                  return (pRingBuffer && State != state_unused) ? pRingBuffer->read_space()  : 0;                  return (pRingBuffer && State != state_unused) ? pRingBuffer->read_space() / BytesPerSample : 0;
71              }              }
72    
73              inline int GetWriteSpace() {              inline int GetWriteSpace() {
# Line 67  namespace LinuxSampler { namespace gig { Line 75  namespace LinuxSampler { namespace gig {
75              }              }
76    
77              inline int GetWriteSpaceToEnd() {              inline int GetWriteSpaceToEnd() {
78                  return (pRingBuffer && State == state_active) ? pRingBuffer->write_space_to_end_with_wrap() : 0;                  return (pRingBuffer && State == state_active) ? pRingBuffer->write_space_to_end_with_wrap() / BytesPerSample : 0;
79              }              }
80    
81              // adjusts the write space to avoid buffer boundaries which would lead to the wrap space              // adjusts the write space to avoid buffer boundaries which would lead to the wrap space
82              // within the buffer (needed for interpolation) getting filled only partially              // within the buffer (needed for interpolation) getting filled only partially
83              // for more infos see the docs in ringbuffer.h at adjust_write_space_to_avoid_boundary()              // for more infos see the docs in ringbuffer.h at adjust_write_space_to_avoid_boundary()
84              inline int AdjustWriteSpaceToAvoidBoundary(int cnt, int capped_cnt) {              inline int AdjustWriteSpaceToAvoidBoundary(int cnt, int capped_cnt) {
85                return pRingBuffer->adjust_write_space_to_avoid_boundary(cnt, capped_cnt);                return pRingBuffer->adjust_write_space_to_avoid_boundary(cnt * BytesPerSample, capped_cnt * BytesPerSample) / BytesPerSample;
             }  
   
             inline sample_t* GetReadPointer() {  
                 return pRingBuffer->get_read_ptr();  
86              }              }
87    
88              // gets the current read_ptr within the ringbuffer              // gets the current read_ptr within the ringbuffer
89              inline sample_t* GetReadPtr(void) {              inline uint8_t* GetReadPtr(void) {
90                  return pRingBuffer->get_read_ptr();                  return pRingBuffer->get_read_ptr();
91              }              }
92    
93              inline void IncrementReadPos(uint Count)  {              inline void IncrementReadPos(uint Count)  {
94                    Count *= BytesPerSample;
95                  uint leftspace = pRingBuffer->read_space();                  uint leftspace = pRingBuffer->read_space();
96                  pRingBuffer->increment_read_ptr(Min(Count, leftspace));                  pRingBuffer->increment_read_ptr(Min(Count, leftspace));
97                  if (State == state_end && Count >= leftspace) {                  if (State == state_end && Count >= leftspace) {
# Line 98  namespace LinuxSampler { namespace gig { Line 103  namespace LinuxSampler { namespace gig {
103              inline static uint       GetUnusedStreams() { return UnusedStreams; }              inline static uint       GetUnusedStreams() { return UnusedStreams; }
104          protected:          protected:
105              // Methods              // Methods
106              void                     Launch(Stream::Handle hStream, reference_t* pExportReference, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop);              void                     Launch(Stream::Handle hStream, reference_t* pExportReference, ::gig::DimensionRegion* pDimRgn, unsigned long SampleOffset, bool DoLoop);
107              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 void              Kill()      { pExportReference = NULL; Reset(); } ///< Will be called by disk thread after a 'deletion' command from the audio thread (within the voice class)
108              inline Stream::Handle    GetHandle() { return hThis; }              inline Stream::Handle    GetHandle() { return hThis; }
109              inline Stream::state_t   GetState()  { return State; }              inline Stream::state_t   GetState()  { return State; }
# Line 109  namespace LinuxSampler { namespace gig { Line 114  namespace LinuxSampler { namespace gig {
114              state_t                  State;              state_t                  State;
115              Stream::Handle           hThis;              Stream::Handle           hThis;
116              unsigned long            SampleOffset;              unsigned long            SampleOffset;
117              ::gig::Sample*           pSample;              ::gig::DimensionRegion*  pDimRgn;
118              ::gig::playback_state_t  PlaybackState;              ::gig::playback_state_t  PlaybackState;
119              RingBuffer<sample_t>*    pRingBuffer;              RingBuffer<uint8_t>*     pRingBuffer;
120              bool                     DoLoop;              bool                     DoLoop;
121              ::gig::buffer_t*         pDecompressionBuffer;              ::gig::buffer_t*         pDecompressionBuffer;
122                int                      BytesPerSample;
123    
124              // Static Attributes              // Static Attributes
125              static uint              UnusedStreams; //< Reflects how many stream objects of all stream instances are currently not in use.              static uint              UnusedStreams; //< Reflects how many stream objects of all stream instances are currently not in use.
# Line 122  namespace LinuxSampler { namespace gig { Line 128  namespace LinuxSampler { namespace gig {
128              // Methods              // Methods
129              inline void Reset() {              inline void Reset() {
130                  SampleOffset                   = 0;                  SampleOffset                   = 0;
131                  pSample                        = NULL;                  pDimRgn                        = NULL;
132                  PlaybackState.position         = 0;                  PlaybackState.position         = 0;
133                  PlaybackState.reverse          = false;                  PlaybackState.reverse          = false;
134                  hThis                          = 0;                  hThis                          = 0;

Legend:
Removed from v.385  
changed lines
  Added in v.903

  ViewVC Help
Powered by ViewVC