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

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

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

revision 392 by schoenebeck, Sat Feb 19 02:40:24 2005 UTC revision 554 by schoenebeck, Thu May 19 19:25:14 2005 UTC
# Line 49  namespace LinuxSampler { namespace gig { Line 49  namespace LinuxSampler { namespace gig {
49      void DiskThread::Reset() {      void DiskThread::Reset() {
50          bool running = this->IsRunning();          bool running = this->IsRunning();
51          if (running) this->StopThread();          if (running) this->StopThread();
52          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {          for (int i = 0; i < CONFIG_MAX_STREAMS; i++) {
53              pStreams[i]->Kill();              pStreams[i]->Kill();
54          }          }
55          for (int i = 1; i <= MAX_INPUT_STREAMS; i++) {          for (int i = 1; i <= CONFIG_MAX_STREAMS; i++) {
56              pCreatedStreams[i] = NULL;              pCreatedStreams[i] = NULL;
57          }          }
58          GhostQueue->init();          GhostQueue->init();
# Line 86  namespace LinuxSampler { namespace gig { Line 86  namespace LinuxSampler { namespace gig {
86          std::stringstream ss;          std::stringstream ss;
87          for (uint i = 0; i < this->Streams; i++) {          for (uint i = 0; i < this->Streams; i++) {
88              if (pStreams[i]->GetState() == Stream::state_unused) continue;              if (pStreams[i]->GetState() == Stream::state_unused) continue;
89              uint bufferfill = (uint) ((float) pStreams[i]->GetReadSpace() / (float) STREAM_BUFFER_SIZE * 100);              uint bufferfill = (uint) ((float) pStreams[i]->GetReadSpace() / (float) CONFIG_STREAM_BUFFER_SIZE * 100);
90              uint streamid   = (uint) pStreams[i]->GetHandle();              uint streamid   = (uint) pStreams[i]->GetHandle();
91              if (!streamid) continue;              if (!streamid) continue;
92    
# Line 186  namespace LinuxSampler { namespace gig { Line 186  namespace LinuxSampler { namespace gig {
186    
187    
188      DiskThread::DiskThread(uint BufferWrapElements) : Thread(true, false, 1, -2) {      DiskThread::DiskThread(uint BufferWrapElements) : Thread(true, false, 1, -2) {
189          DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(MAX_REFILL_SIZE);          DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(CONFIG_STREAM_MAX_REFILL_SIZE);
190          CreationQueue       = new RingBuffer<create_command_t>(1024);          CreationQueue       = new RingBuffer<create_command_t>(1024);
191          DeletionQueue       = new RingBuffer<delete_command_t>(1024);          DeletionQueue       = new RingBuffer<delete_command_t>(1024);
192          GhostQueue          = new RingBuffer<Stream::Handle>(MAX_INPUT_STREAMS);          GhostQueue          = new RingBuffer<Stream::Handle>(CONFIG_MAX_STREAMS);
193          Streams             = MAX_INPUT_STREAMS;          Streams             = CONFIG_MAX_STREAMS;
194          RefillStreamsPerRun = REFILL_STREAMS_PER_RUN;          RefillStreamsPerRun = CONFIG_REFILL_STREAMS_PER_RUN;
195          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {          for (int i = 0; i < CONFIG_MAX_STREAMS; i++) {
196              pStreams[i] = new Stream(&DecompressionBuffer, STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words              pStreams[i] = new Stream(&DecompressionBuffer, CONFIG_STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words
197          }          }
198          for (int i = 1; i <= MAX_INPUT_STREAMS; i++) {          for (int i = 1; i <= CONFIG_MAX_STREAMS; i++) {
199              pCreatedStreams[i] = NULL;              pCreatedStreams[i] = NULL;
200          }          }
201      }      }
202    
203      DiskThread::~DiskThread() {      DiskThread::~DiskThread() {
204          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {          for (int i = 0; i < CONFIG_MAX_STREAMS; i++) {
205              if (pStreams[i]) delete pStreams[i];              if (pStreams[i]) delete pStreams[i];
206          }          }
207          if (CreationQueue) delete CreationQueue;          if (CreationQueue) delete CreationQueue;
# Line 321  namespace LinuxSampler { namespace gig { Line 321  namespace LinuxSampler { namespace gig {
321    
322                  int capped_writespace = writespace;                  int capped_writespace = writespace;
323                  // if there is too much buffer space available then cut the read/write                  // if there is too much buffer space available then cut the read/write
324                  // size to MAX_REFILL_SIZE which is by default 65536 samples = 256KBytes                  // size to CONFIG_STREAM_MAX_REFILL_SIZE which is by default 65536 samples = 256KBytes
325                  if (writespace > MAX_REFILL_SIZE) capped_writespace = MAX_REFILL_SIZE;                  if (writespace > CONFIG_STREAM_MAX_REFILL_SIZE) capped_writespace = CONFIG_STREAM_MAX_REFILL_SIZE;
326    
327                  // adjust the amount to read in order to ensure that the buffer wraps correctly                  // adjust the amount to read in order to ensure that the buffer wraps correctly
328                  int read_amount = pStreams[i]->AdjustWriteSpaceToAvoidBoundary(writespace, capped_writespace);                  int read_amount = pStreams[i]->AdjustWriteSpaceToAvoidBoundary(writespace, capped_writespace);
329                  // if we wasn't able to refill one of the stream buffers by more than                  // if we wasn't able to refill one of the stream buffers by more than
330                  // MIN_REFILL_SIZE we'll send the disk thread to sleep later                  // CONFIG_STREAM_MIN_REFILL_SIZE we'll send the disk thread to sleep later
331                  if (pStreams[i]->ReadAhead(read_amount) > MIN_REFILL_SIZE) this->IsIdle = false;                  if (pStreams[i]->ReadAhead(read_amount) > CONFIG_STREAM_MIN_REFILL_SIZE) this->IsIdle = false;
332              }              }
333          }          }
334      }      }
# Line 344  namespace LinuxSampler { namespace gig { Line 344  namespace LinuxSampler { namespace gig {
344      /// order ID Generator      /// order ID Generator
345      Stream::OrderID_t DiskThread::CreateOrderID() {      Stream::OrderID_t DiskThread::CreateOrderID() {
346          static Stream::OrderID_t counter(0);          static Stream::OrderID_t counter(0);
347          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {          for (int i = 0; i < CONFIG_MAX_STREAMS; i++) {
348              if (counter == MAX_INPUT_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0              if (counter == CONFIG_MAX_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0
349              else                              counter++;              else                              counter++;
350              if (!pCreatedStreams[counter]) {              if (!pCreatedStreams[counter]) {
351                  pCreatedStreams[counter] = SLOT_RESERVED; // mark this slot as reserved                  pCreatedStreams[counter] = SLOT_RESERVED; // mark this slot as reserved

Legend:
Removed from v.392  
changed lines
  Added in v.554

  ViewVC Help
Powered by ViewVC