/[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 1800 - (show annotations) (download) (as text)
Sun Dec 7 01:26:46 2008 UTC (15 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 6705 byte(s)
* maximum voices and disk streams can now be altered at runtime (added new
  LSCP commands "GET VOICES", "SET VOICES", "GET STREAMS", "SET STREAMS"
  and accordingly new LSCP events "GLOBAL_INFO:VOICES" and
  "GLOBAL_INFO:STREAMS")
* bumped version to 0.5.1.8cvs

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005 - 2008 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_private.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 * There is also a function for releasing parts of instruments not
46 * in use anymore (as this is not real time safe, the audio thread
47 * cannot do it directly).
48 */
49 class DiskThread : public Thread {
50 public:
51 // Methods
52 DiskThread(int MaxStreams, uint BufferWrapElements, InstrumentResourceManager* pInstruments);
53 virtual ~DiskThread();
54 void Reset();
55 String GetBufferFillBytes();
56 String GetBufferFillPercentage();
57 int OrderNewStream(Stream::reference_t* pStreamRef, ::gig::DimensionRegion* pDimRgn, unsigned long SampleOffset, bool DoLoop);
58 int OrderDeletionOfStream(Stream::reference_t* pStreamRef, bool bRequestNotification = false);
59 int OrderDeletionOfDimreg(::gig::DimensionRegion* dimreg);
60 Stream* AskForCreatedStream(Stream::OrderID_t StreamOrderID);
61 Stream::Handle AskForDeletedStream();
62
63 // the number of streams currently in usage
64 // printed on the console the main thread (along with the active voice count)
65 uint GetActiveStreamCount() { return atomic_read(&ActiveStreamCount); }
66 void SetActiveStreamCount(uint Streams) { atomic_set(&ActiveStreamCount, Streams); }
67 int ActiveStreamCountMax;
68
69 protected:
70 ::gig::buffer_t DecompressionBuffer; ///< Used for thread safe streaming.
71
72 int Main(); ///< Implementation of virtual method from class Thread
73
74 friend class Stream;
75 private:
76 // Private Types
77 struct create_command_t {
78 Stream::OrderID_t OrderID;
79 Stream::Handle hStream;
80 Stream::reference_t* pStreamRef;
81 ::gig::DimensionRegion* pDimRgn;
82 unsigned long SampleOffset;
83 bool DoLoop;
84 };
85 struct delete_command_t {
86 Stream* pStream;
87 Stream::Handle hStream;
88 Stream::OrderID_t OrderID;
89 bool bNotify;
90 };
91
92 // Attributes
93 bool IsIdle;
94 uint Streams;
95 RingBuffer<create_command_t,false>* CreationQueue; ///< Contains commands to create streams
96 RingBuffer<delete_command_t,false>* DeletionQueue; ///< Contains commands to delete streams
97 RingBuffer<delete_command_t,false>* GhostQueue; ///< Contains handles to streams that are not used anymore and weren't deletable immediately
98 RingBuffer<Stream::Handle,false> DeletionNotificationQueue; ///< In case the original sender requested a notification for its stream deletion order, this queue will receive the handle of the respective stream once actually be deleted by the disk thread.
99 RingBuffer< ::gig::DimensionRegion*,false>* DeleteDimregQueue; ///< Contains dimension regions that are not used anymore and should be handed back to the instrument resource manager
100 unsigned int RefillStreamsPerRun; ///< How many streams should be refilled in each loop run
101 Stream** pStreams; ///< Contains all disk streams (whether used or unused)
102 Stream** pCreatedStreams; ///< This is where the voice (audio thread) picks up it's meanwhile hopefully created disk stream.
103 static Stream* SLOT_RESERVED; ///< This value is used to mark an entry in pCreatedStreams[] as reserved.
104 InstrumentResourceManager* pInstruments; ///< The instrument resource manager of the engine that is using this disk thread. Used by the dimension region deletion feature.
105
106 // Methods
107 void CreateStream(create_command_t& Command);
108 void DeleteStream(delete_command_t& Command);
109 void RefillStreams();
110 Stream::Handle CreateHandle();
111 Stream::OrderID_t CreateOrderID();
112
113 atomic_t ActiveStreamCount;
114 };
115
116 }} // namespace LinuxSampler::gig
117
118 #endif // __LS_GIG_DISKTHREAD_H__

  ViewVC Help
Powered by ViewVC