/[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 724 - (show annotations) (download) (as text)
Mon Jul 25 09:28:00 2005 UTC (15 years, 8 months ago) by iliev
File MIME type: text/x-c++hdr
File size: 5416 byte(s)
- Fixed some typos

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 #include <gig.h>
30
31 #include "../../common/Thread.h"
32 #include "../../common/RingBuffer.h"
33 #include "Stream.h"
34 #include "Voice.h"
35
36 namespace LinuxSampler { namespace gig {
37
38 int CompareStreamWriteSpace(const void* a, const void* b);
39
40 /** @brief Disk Reader Thread
41 *
42 * The disk reader thread is responsible for periodically refilling
43 * disk streams in parallel to the audio thread's rendering process.
44 */
45 class DiskThread : public Thread {
46 public:
47 // Methods
48 DiskThread(uint BufferWrapElements);
49 virtual ~DiskThread();
50 void Reset();
51 String GetBufferFillBytes();
52 String GetBufferFillPercentage();
53 int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::Sample* pSample, unsigned long SampleOffset, bool DoLoop);
54 int OrderDeletionOfStream(Stream::reference_t* pStreamRef);
55 Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID);
56
57 // the number of streams currently in usage
58 // printed on the console the main thread (along with the active voice count)
59 int ActiveStreamCount;
60 int ActiveStreamCountMax;
61
62 protected:
63 ::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming.
64
65 int Main(); ///< Implementation of virtual method from class Thread
66
67 friend class Stream;
68 private:
69 // Private Types
70 struct create_command_t {
71 Stream::OrderID_t OrderID;
72 Stream::Handle hStream;
73 Stream::reference_t* pStreamRef;
74 ::gig::Sample* pSample;
75 unsigned long SampleOffset;
76 bool DoLoop;
77 };
78 struct delete_command_t {
79 Stream* pStream;
80 Stream::Handle hStream;
81 Stream::OrderID_t OrderID;
82 };
83
84 // Attributes
85 bool IsIdle;
86 uint Streams;
87 RingBuffer<create_command_t>* CreationQueue; ///< Contains commands to create streams
88 RingBuffer<delete_command_t>* DeletionQueue; ///< Contains commands to delete streams
89 RingBuffer<Stream::Handle>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately
90 unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run
91 Stream* pStreams[CONFIG_MAX_STREAMS]; ///< Contains all disk streams (whether used or unused)
92 Stream* pCreatedStreams[CONFIG_MAX_STREAMS + 1]; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream.
93 static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved.
94
95 // Methods
96 void CreateStream(create_command_t& Command);
97 void DeleteStream(delete_command_t& Command);
98 void RefillStreams();
99 Stream::Handle CreateHandle();
100 Stream::OrderID_t CreateOrderID();
101 };
102
103 }} // namespace LinuxSampler::gig
104
105 #endif // __LS_GIG_DISKTHREAD_H__

  ViewVC Help
Powered by ViewVC