/[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 53 by schoenebeck, Mon Apr 26 17:15:51 2004 UTC revision 392 by schoenebeck, Sat Feb 19 02:40:24 2005 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 Christian Schoenebeck                              *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   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 109  namespace LinuxSampler { namespace gig { Line 110  namespace LinuxSampler { namespace gig {
110              return -1;              return -1;
111          }          }
112    
113            const Stream::OrderID_t newOrder = CreateOrderID();
114            if (!newOrder) {
115                    dmsg(1,("DiskThread: there was no free slot\n"));
116                    return -1; // there was no free slot
117            }
118    
119          pStreamRef->State   = Stream::state_active;          pStreamRef->State   = Stream::state_active;
120          pStreamRef->OrderID = CreateOrderID();          pStreamRef->OrderID = newOrder;
121          pStreamRef->hStream = CreateHandle();          pStreamRef->hStream = CreateHandle();
122          pStreamRef->pStream = NULL; // a stream has to be activated by the disk thread first          pStreamRef->pStream = NULL; // a stream has to be activated by the disk thread first
123    
         if (!pStreamRef->OrderID) return -1; // there was no free slot  
   
124          create_command_t cmd;          create_command_t cmd;
125          cmd.OrderID      = pStreamRef->OrderID;          cmd.OrderID      = pStreamRef->OrderID;
126          cmd.hStream      = pStreamRef->hStream;          cmd.hStream      = pStreamRef->hStream;
# Line 180  namespace LinuxSampler { namespace gig { Line 185  namespace LinuxSampler { namespace gig {
185      // #         (following code should only be executed by the disk thread)      // #         (following code should only be executed by the disk thread)
186    
187    
188      DiskThread::DiskThread(uint BufferWrapElements) : Thread(false, 1, -2) {      DiskThread::DiskThread(uint BufferWrapElements) : Thread(true, false, 1, -2) {
189            DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(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>(MAX_INPUT_STREAMS);
193          Streams             = MAX_INPUT_STREAMS;          Streams             = MAX_INPUT_STREAMS;
194          RefillStreamsPerRun = REFILL_STREAMS_PER_RUN;          RefillStreamsPerRun = REFILL_STREAMS_PER_RUN;
195          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {
196              pStreams[i] = new Stream(STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words              pStreams[i] = new Stream(&DecompressionBuffer, STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words
197          }          }
198          for (int i = 1; i <= MAX_INPUT_STREAMS; i++) {          for (int i = 1; i <= MAX_INPUT_STREAMS; i++) {
199              pCreatedStreams[i] = NULL;              pCreatedStreams[i] = NULL;
# Line 201  namespace LinuxSampler { namespace gig { Line 207  namespace LinuxSampler { namespace gig {
207          if (CreationQueue) delete CreationQueue;          if (CreationQueue) delete CreationQueue;
208          if (DeletionQueue) delete DeletionQueue;          if (DeletionQueue) delete DeletionQueue;
209          if (GhostQueue)    delete GhostQueue;          if (GhostQueue)    delete GhostQueue;
210            ::gig::Sample::DestroyDecompressionBuffer(DecompressionBuffer);
211      }      }
212    
213      int DiskThread::Main() {      int DiskThread::Main() {
214          dmsg(3,("Disk thread running\n"));          dmsg(3,("Disk thread running\n"));
215          while (true) {          while (true) {
216                pthread_testcancel(); // mandatory for OSX
217              IsIdle = true; // will be set to false if a stream got filled              IsIdle = true; // will be set to false if a stream got filled
218    
219              // if there are ghost streams, delete them              // if there are ghost streams, delete them
# Line 231  namespace LinuxSampler { namespace gig { Line 239  namespace LinuxSampler { namespace gig {
239              }              }
240    
241              // if there are deletion commands, delete those streams              // if there are deletion commands, delete those streams
242              while (Stream::UnusedStreams < Streams && DeletionQueue->read_space() > 0) {              while (Stream::UnusedStreams < Stream::TotalStreams && DeletionQueue->read_space() > 0) {
243                  delete_command_t command;                  delete_command_t command;
244                  DeletionQueue->pop(&command);                  DeletionQueue->pop(&command);
245                  DeleteStream(command);                  DeleteStream(command);
# Line 335  namespace LinuxSampler { namespace gig { Line 343  namespace LinuxSampler { namespace gig {
343    
344      /// order ID Generator      /// order ID Generator
345      Stream::OrderID_t DiskThread::CreateOrderID() {      Stream::OrderID_t DiskThread::CreateOrderID() {
346          static uint32_t counter = 0;          static Stream::OrderID_t counter(0);
347          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {          for (int i = 0; i < MAX_INPUT_STREAMS; i++) {
348              if (counter == MAX_INPUT_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0              if (counter == MAX_INPUT_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0
349              else                              counter++;              else                              counter++;

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

  ViewVC Help
Powered by ViewVC