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

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

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

revision 393 by persson, Sun Feb 20 12:30:36 2005 UTC revision 903 by persson, Sat Jul 22 14:22:53 2006 UTC
# Line 35  namespace LinuxSampler { namespace gig { Line 35  namespace LinuxSampler { namespace gig {
35          if (!SampleCount)                return  0;          if (!SampleCount)                return  0;
36          if (!pRingBuffer->write_space()) return  0;          if (!pRingBuffer->write_space()) return  0;
37    
38            ::gig::Sample* pSample = pDimRgn->pSample;
39          long total_readsamples = 0, readsamples = 0;          long total_readsamples = 0, readsamples = 0;
40          long samplestoread = SampleCount / pSample->Channels;          long samplestoread = SampleCount / pSample->Channels;
41          sample_t* pBuf = pRingBuffer->get_write_ptr();          uint8_t* pBuf = pRingBuffer->get_write_ptr();
42          bool endofsamplereached;          bool endofsamplereached;
43    
44          // refill the disk stream buffer          // refill the disk stream buffer
45          if (this->DoLoop) { // honor looping          if (this->DoLoop) { // honor looping
46              total_readsamples  = pSample->ReadAndLoop(pBuf, samplestoread, &this->PlaybackState, pDecompressionBuffer);              total_readsamples  = pSample->ReadAndLoop(pBuf, samplestoread, &this->PlaybackState, pDimRgn, pDecompressionBuffer);
47              endofsamplereached = (this->PlaybackState.position >= pSample->SamplesTotal);              endofsamplereached = (this->PlaybackState.position >= pSample->SamplesTotal);
48              dmsg(5,("Refilled stream %d with %d (SamplePos: %d)", this->hThis, total_readsamples, this->PlaybackState.position));              dmsg(5,("Refilled stream %d with %d (SamplePos: %d)", this->hThis, total_readsamples, this->PlaybackState.position));
49          }          }
# Line 51  namespace LinuxSampler { namespace gig { Line 52  namespace LinuxSampler { namespace gig {
52              pSample->SetPos(this->SampleOffset); // recover old position              pSample->SetPos(this->SampleOffset); // recover old position
53    
54              do {              do {
55                  readsamples        = pSample->Read(&pBuf[total_readsamples * pSample->Channels], samplestoread, pDecompressionBuffer);                  readsamples        = pSample->Read(&pBuf[total_readsamples * pSample->FrameSize], samplestoread, pDecompressionBuffer);
56                  samplestoread     -= readsamples;                  samplestoread     -= readsamples;
57                  total_readsamples += readsamples;                  total_readsamples += readsamples;
58              } while (samplestoread && readsamples > 0);              } while (samplestoread && readsamples > 0);
# Line 65  namespace LinuxSampler { namespace gig { Line 66  namespace LinuxSampler { namespace gig {
66    
67          // we must delay the increment_write_ptr_with_wrap() after the while() loop because we need to          // we must delay the increment_write_ptr_with_wrap() after the while() loop because we need to
68          // ensure that we read exactly SampleCount sample, otherwise the buffer wrapping code will fail          // ensure that we read exactly SampleCount sample, otherwise the buffer wrapping code will fail
69          pRingBuffer->increment_write_ptr_with_wrap(total_readsamples * pSample->Channels);          pRingBuffer->increment_write_ptr_with_wrap(total_readsamples * pSample->FrameSize);
70    
71          // update stream state          // update stream state
72          if (endofsamplereached) SetState(state_end);          if (endofsamplereached) SetState(state_end);
# Line 75  namespace LinuxSampler { namespace gig { Line 76  namespace LinuxSampler { namespace gig {
76      }      }
77    
78      void Stream::WriteSilence(unsigned long SilenceSampleWords) {      void Stream::WriteSilence(unsigned long SilenceSampleWords) {
79          memset(pRingBuffer->get_write_ptr(), 0, SilenceSampleWords * 2);          memset(pRingBuffer->get_write_ptr(), 0, SilenceSampleWords * BytesPerSample);
80          pRingBuffer->increment_write_ptr_with_wrap(SilenceSampleWords * 2);          pRingBuffer->increment_write_ptr_with_wrap(SilenceSampleWords * BytesPerSample);
81      }      }
82    
83      Stream::Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements) {      Stream::Stream( ::gig::buffer_t* pDecompressionBuffer, uint BufferSize, uint BufferWrapElements) {
84          this->pExportReference       = NULL;          this->pExportReference       = NULL;
85          this->State                  = state_unused;          this->State                  = state_unused;
86          this->hThis                  = 0;          this->hThis                  = 0;
87          this->pSample                = NULL;          this->pDimRgn                = NULL;
88          this->SampleOffset           = 0;          this->SampleOffset           = 0;
89          this->PlaybackState.position = 0;          this->PlaybackState.position = 0;
90          this->PlaybackState.reverse  = false;          this->PlaybackState.reverse  = false;
91          this->pRingBuffer            = new RingBuffer<sample_t>(BufferSize, BufferWrapElements);          this->pRingBuffer            = new RingBuffer<uint8_t>(BufferSize * 3, BufferWrapElements * 3);
92          this->pDecompressionBuffer   = pDecompressionBuffer;          this->pDecompressionBuffer   = pDecompressionBuffer;
93          UnusedStreams++;          UnusedStreams++;
94          TotalStreams++;          TotalStreams++;
# Line 101  namespace LinuxSampler { namespace gig { Line 102  namespace LinuxSampler { namespace gig {
102      }      }
103    
104      /// Called by disk thread to activate the disk stream.      /// Called by disk thread to activate the disk stream.
105      void Stream::Launch(Stream::Handle hStream, reference_t* pExportReference, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop) {      void Stream::Launch(Stream::Handle hStream, reference_t* pExportReference, ::gig::DimensionRegion* pDimRgn, unsigned long SampleOffset, bool DoLoop) {
106          UnusedStreams--;          UnusedStreams--;
107          this->pExportReference               = pExportReference;          this->pExportReference               = pExportReference;
108          this->hThis                          = hStream;          this->hThis                          = hStream;
109          this->pSample                        = pSample;          this->pDimRgn                        = pDimRgn;
110          this->SampleOffset                   = SampleOffset;          this->SampleOffset                   = SampleOffset;
111          this->PlaybackState.position         = SampleOffset;          this->PlaybackState.position         = SampleOffset;
112          this->PlaybackState.reverse          = false;          this->PlaybackState.reverse          = false;
113          this->PlaybackState.loop_cycles_left = pSample->LoopPlayCount;          this->PlaybackState.loop_cycles_left = pDimRgn->pSample->LoopPlayCount;
114          this->DoLoop                         = DoLoop;          this->DoLoop                         = DoLoop;
115            BytesPerSample                       = pDimRgn->pSample->BitDepth / 8;
116          SetState(state_active);          SetState(state_active);
117      }      }
118    

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

  ViewVC Help
Powered by ViewVC