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

Contents of /linuxsampler/trunk/src/engines/gig/DiskThread.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 385 - (show annotations) (download) (as text)
Thu Feb 17 02:53:45 2005 UTC (19 years, 2 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5865 byte(s)
* lscpserver: we now only use one instrument loader thread; commands for
  loading instruments in the background wait in a queue to be processed one
  by one to avoid possible race conditions and to improve I/O efficiency
* fixed possible race condition while streaming with multiple disk threads
  by using an own decompression buffer for each disk thread
* libgig: fixed some memory leaks caused by non virtual base constructors

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * 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 *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #ifndef __LS_GIG_DISKTHREAD_H__
25 #define __LS_GIG_DISKTHREAD_H__
26
27 #include "../../common/global.h"
28
29 #if DEBUG_HEADERS
30 # warning DiskThread.h included
31 #endif // DEBUG_HEADERS
32
33 #define REFILL_STREAMS_PER_RUN 4 ///< number of streams that should be refilled with each disk thread cycle
34 #define MIN_REFILL_SIZE 1024 ///< if no buffer was filled up more than this bottom limit, the disk thread will go to sleep
35 #define MAX_REFILL_SIZE 65536 ///< maximum of samples a buffer should be refilled in one cycle (256kB, as 16 bit stereo)
36 #define STREAM_BUFFER_SIZE 131072 ///< the diskstream ringbuffer size (256kB as sample_t is 16bit)
37 #define MAX_INPUT_STREAMS 150 ///< number of streams that should be allocated
38
39 #include "../../common/Thread.h"
40 #include "../../common/RingBuffer.h"
41 #include "../../lib/fileloader/libgig/gig.h"
42 #include "Stream.h"
43 #include "Voice.h"
44
45 namespace LinuxSampler { namespace gig {
46
47 int CompareStreamWriteSpace(const void* a, const void* b);
48
49 class DiskThread : public Thread {
50 public:
51 // Methods
52 DiskThread(uint BufferWrapElements);
53 ~DiskThread();
54 void Reset();
55 String GetBufferFillBytes();
56 String GetBufferFillPercentage();
57 int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop);
58 int OrderDeletionOfStream(Stream::reference_t* pStreamRef);
59 Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID);
60
61 // the number of streams currently in usage
62 // printed on the console the main thread (along with the active voice count)
63 int ActiveStreamCount;
64 int ActiveStreamCountMax;
65
66 protected:
67 ::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming.
68
69 int Main(); ///< Implementation of virtual method from class Thread
70
71 friend class Stream;
72 private:
73 // Private Types
74 struct create_command_t {
75 Stream::OrderID_t OrderID;
76 Stream::Handle hStream;
77 Stream::reference_t* pStreamRef;
78 ::gig::Sample* pSample;
79 unsigned long SampleOffset;
80 bool DoLoop;
81 };
82 struct delete_command_t {
83 Stream* pStream;
84 Stream::Handle hStream;
85 Stream::OrderID_t OrderID;
86 };
87
88 // Attributes
89 bool IsIdle;
90 uint Streams;
91 RingBuffer<create_command_t>* CreationQueue; ///< Contains commands to create streams
92 RingBuffer<delete_command_t>* DeletionQueue; ///< Contains commands to delete streams
93 RingBuffer<Stream::Handle>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately
94 unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run
95 Stream* pStreams[MAX_INPUT_STREAMS]; ///< Contains all disk streams (wether used or unused)
96 Stream* pCreatedStreams[MAX_INPUT_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream.
97 static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved.
98
99 // Methods
100 void CreateStream(create_command_t& Command);
101 void DeleteStream(delete_command_t& Command);
102 void RefillStreams();
103 Stream::Handle CreateHandle();
104 Stream::OrderID_t CreateOrderID();
105 };
106
107 }} // namespace LinuxSampler::gig
108
109 #endif // __LS_GIG_DISKTHREAD_H__

  ViewVC Help
Powered by ViewVC