--- linuxsampler/trunk/src/engines/gig/DiskThread.cpp 2005/01/01 08:18:07 333 +++ linuxsampler/trunk/src/engines/gig/DiskThread.cpp 2006/02/26 13:00:08 840 @@ -3,6 +3,7 @@ * LinuxSampler - modular, streaming capable sampler * * * * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * + * Copyright (C) 2005 Christian Schoenebeck * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -48,10 +49,10 @@ void DiskThread::Reset() { bool running = this->IsRunning(); if (running) this->StopThread(); - for (int i = 0; i < MAX_INPUT_STREAMS; i++) { + for (int i = 0; i < CONFIG_MAX_STREAMS; i++) { pStreams[i]->Kill(); } - for (int i = 1; i <= MAX_INPUT_STREAMS; i++) { + for (int i = 1; i <= CONFIG_MAX_STREAMS; i++) { pCreatedStreams[i] = NULL; } GhostQueue->init(); @@ -85,7 +86,7 @@ std::stringstream ss; for (uint i = 0; i < this->Streams; i++) { if (pStreams[i]->GetState() == Stream::state_unused) continue; - 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); uint streamid = (uint) pStreams[i]->GetHandle(); if (!streamid) continue; @@ -184,32 +185,36 @@ // # (following code should only be executed by the disk thread) - DiskThread::DiskThread(uint BufferWrapElements) : Thread(false, 1, -2) { + DiskThread::DiskThread(uint BufferWrapElements) : Thread(true, false, 1, -2) { + DecompressionBuffer = ::gig::Sample::CreateDecompressionBuffer(CONFIG_STREAM_MAX_REFILL_SIZE); CreationQueue = new RingBuffer(1024); DeletionQueue = new RingBuffer(1024); - GhostQueue = new RingBuffer(MAX_INPUT_STREAMS); - Streams = MAX_INPUT_STREAMS; - RefillStreamsPerRun = REFILL_STREAMS_PER_RUN; - for (int i = 0; i < MAX_INPUT_STREAMS; i++) { - pStreams[i] = new Stream(STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words + GhostQueue = new RingBuffer(CONFIG_MAX_STREAMS); + Streams = CONFIG_MAX_STREAMS; + RefillStreamsPerRun = CONFIG_REFILL_STREAMS_PER_RUN; + for (int i = 0; i < CONFIG_MAX_STREAMS; i++) { + pStreams[i] = new Stream(&DecompressionBuffer, CONFIG_STREAM_BUFFER_SIZE, BufferWrapElements); // 131072 sample words } - for (int i = 1; i <= MAX_INPUT_STREAMS; i++) { + for (int i = 1; i <= CONFIG_MAX_STREAMS; i++) { pCreatedStreams[i] = NULL; } + ActiveStreamCountMax = 0; } DiskThread::~DiskThread() { - for (int i = 0; i < MAX_INPUT_STREAMS; i++) { + for (int i = 0; i < CONFIG_MAX_STREAMS; i++) { if (pStreams[i]) delete pStreams[i]; } if (CreationQueue) delete CreationQueue; if (DeletionQueue) delete DeletionQueue; if (GhostQueue) delete GhostQueue; + ::gig::Sample::DestroyDecompressionBuffer(DecompressionBuffer); } int DiskThread::Main() { dmsg(3,("Disk thread running\n")); while (true) { + pthread_testcancel(); // mandatory for OSX IsIdle = true; // will be set to false if a stream got filled // if there are ghost streams, delete them @@ -244,7 +249,7 @@ RefillStreams(); // refill the most empty streams // if nothing was done during this iteration (eg no streambuffer - // filled with data) then sleep for 50ms + // filled with data) then sleep for 30ms if (IsIdle) usleep(30000); int streamsInUsage = 0; @@ -317,14 +322,14 @@ int capped_writespace = writespace; // if there is too much buffer space available then cut the read/write - // size to MAX_REFILL_SIZE which is by default 65536 samples = 256KBytes - if (writespace > MAX_REFILL_SIZE) capped_writespace = MAX_REFILL_SIZE; + // size to CONFIG_STREAM_MAX_REFILL_SIZE which is by default 65536 samples = 256KBytes + if (writespace > CONFIG_STREAM_MAX_REFILL_SIZE) capped_writespace = CONFIG_STREAM_MAX_REFILL_SIZE; // adjust the amount to read in order to ensure that the buffer wraps correctly int read_amount = pStreams[i]->AdjustWriteSpaceToAvoidBoundary(writespace, capped_writespace); // if we wasn't able to refill one of the stream buffers by more than - // MIN_REFILL_SIZE we'll send the disk thread to sleep later - if (pStreams[i]->ReadAhead(read_amount) > MIN_REFILL_SIZE) this->IsIdle = false; + // CONFIG_STREAM_MIN_REFILL_SIZE we'll send the disk thread to sleep later + if (pStreams[i]->ReadAhead(read_amount) > CONFIG_STREAM_MIN_REFILL_SIZE) this->IsIdle = false; } } } @@ -340,8 +345,8 @@ /// order ID Generator Stream::OrderID_t DiskThread::CreateOrderID() { static Stream::OrderID_t counter(0); - for (int i = 0; i < MAX_INPUT_STREAMS; i++) { - if (counter == MAX_INPUT_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0 + for (int i = 0; i < CONFIG_MAX_STREAMS; i++) { + if (counter == CONFIG_MAX_STREAMS) counter = 1; // we use '0' as 'invalid order' only, so we skip 0 else counter++; if (!pCreatedStreams[counter]) { pCreatedStreams[counter] = SLOT_RESERVED; // mark this slot as reserved