bool TimeStamp::operator!= (TimeStamp const& other) const throw() { plonk_assert (fractionIsValid (this->fraction)); plonk_assert (fractionIsValid (other.fraction)); return (time != other.time) || (fraction != other.fraction); }
PlankResult BinaryFileInternal::dynamicMemoryReadCallback (PlankFileRef p, PlankP ptr, int maximumBytes, int* bytesReadOut) { plonk_assert (p != 0); plonk_assert (ptr != 0); plonk_assert (maximumBytes > 0); PlankResult result; UnsignedChar* src; ByteArray* array = static_cast<ByteArray*> (p->stream); LongLong size = array->length(); int bytesRead; result = PlankResult_OK; bytesRead = int (plonk::min (LongLong (maximumBytes), size - p->position)); if (bytesRead <= 0) { result = PlankResult_FileEOF; goto exit; } src = (UnsignedChar*)array->getArray() + p->position; Memory::copy (ptr, src, bytesRead); p->position += bytesRead; if (bytesReadOut) *bytesReadOut = bytesRead; exit: return result; }
void TimeStamp::set (LongLong newTime, double newFraction) throw() { plonk_assert (newTime >= 0); plonk_assert (newFraction >= 0.0); plonk_assert (newFraction < 1.0); time = newTime; fraction = newFraction; }
/*PLONK_INLINE_LOW*/ bool TimeStamp::operator>= (TimeStamp const& other) const throw() { plonk_assert (fractionIsValid (this->fraction)); plonk_assert (fractionIsValid (other.fraction)); if (this->isInfinite()) { if (other.isInfinite()) return false; else return true; } else return ((time > other.time) || ((time == other.time) && (fraction >= other.fraction))); }
static PLONK_INLINE_LOW void staticDoFree (void* userData, void* ptr) throw() { #if PLONK_OBJECTMEMORYDEFERFREE_DEBUG plonk_assert (!Threading::currentThreadIsAudioThread()); #endif pl_MemoryDefaultFree (userData, ptr); }
AudioFile::Format AudioFileReaderInternal::getFormat() const throw() { int value; ResultCode result = pl_AudioFileReader_GetFormat (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif const int format = value; switch (format) { case AudioFile::FormatInvalid: return AudioFile::FormatInvalid; case AudioFile::FormatUnknown: return AudioFile::FormatUnknown; case AudioFile::FormatWAV: return AudioFile::FormatWAV; case AudioFile::FormatAIFF: return AudioFile::FormatAIFF; case AudioFile::FormatAIFC: return AudioFile::FormatAIFC; case AudioFile::FormatOggVorbis: return AudioFile::FormatOggVorbis; case AudioFile::FormatOpus: return AudioFile::FormatOpus; case AudioFile::FormatRegion: return AudioFile::FormatRegion; case AudioFile::FormatMulti: return AudioFile::FormatMulti; case AudioFile::FormatArray: return AudioFile::FormatArray; case AudioFile::FormatQueue: return AudioFile::FormatQueue; case AudioFile::FormatCustom: return AudioFile::FormatCustom; default: return AudioFile::FormatInvalid; } }
AudioFile::Encoding AudioFileReaderInternal::getEncoding() const throw() { int value; ResultCode result = pl_AudioFileReader_GetEncoding (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif const int format = value; switch (format) { case AudioFile::EncodingInvalid: return AudioFile::EncodingInvalid; case AudioFile::EncodingUnknown: return AudioFile::EncodingUnknown; case AudioFile::EncodingPCMLittleEndian: return AudioFile::EncodingPCMLittleEndian; case AudioFile::EncodingPCMBigEndian: return AudioFile::EncodingPCMBigEndian; case AudioFile::EncodingFloatLittleEndian: return AudioFile::EncodingFloatLittleEndian; case AudioFile::EncodingFloatBigEndian: return AudioFile::EncodingFloatBigEndian; case AudioFile::EncodingPCMLittleEndianNonInterleaved: return AudioFile::EncodingPCMLittleEndianNonInterleaved; case AudioFile::EncodingPCMBigEndianNonInterleaved: return AudioFile::EncodingPCMBigEndianNonInterleaved; case AudioFile::EncodingFloatLittleEndianNonInterleaved: return AudioFile::EncodingFloatLittleEndianNonInterleaved; case AudioFile::EncodingFloatBigEndianNonInterleaved: return AudioFile::EncodingFloatBigEndianNonInterleaved; default: return AudioFile::EncodingInvalid; } }
int RNG::uniform (const int min, const int max) throw() { // plonk_assert (min >= 0); // plonk_assert (max > 0); plonk_assert (max > min); return pl_RNG_NextInt (this->getInternal()->getRNGRef(), max - min) + min; }
ResultCode ObjectMemoryDeferFree::run() throw() { const double minDuration = 0.000001; const double maxDuration = 0.1; double duration = minDuration; while (! getShouldExit()) { plonk_assert (getMemory().getUserData() == this); Element d = queue->pop(); if (d.ptr != 0) { duration = minDuration; // reset back to high speed staticDoFree (this, d.ptr); } else { // gradually increase the amount of sleep if the queue is empty duration = plonk::min (duration * 2.0, maxDuration); } Threading::sleep (duration); } getMemory().resetFunctions(); queue->clearAll(); return 0; }
bool BinaryFileInternal::setupMulti (PlankFileRef p, FilePathQueue const& fileQueue, const bool bigEndian) throw() { pl_File_Init (p); const bool shouldTakeOwnership = true; ResultCode result; PlankMulitFileReaderRef multi = pl_MultiFileReader_Create(); int mode = PLANKFILE_READ | PLANKFILE_BINARY; if (bigEndian) mode |= PLANKFILE_BIGENDIAN; result = pl_MultiFileReader_InitCustom (multi, mode, new FilePathQueue (fileQueue), shouldTakeOwnership, plonk_BinaryFileInternal_FilePathQueue_NextFuntion, plonk_BinaryFileInternal_FilePathQueue_DestroyCustomFuntion); result = pl_File_OpenMulti (p, multi, mode); plonk_assert (result == PlankResult_OK); return result == PlankResult_OK; }
/*PLONK_INLINE_LOW*/ TimeStamp& TimeStamp::operator+= (const double offset) throw() { if (pl_IsInfD (offset)) { this->time = 0; this->fraction = offset; } else { const double correctedOffset = offset + this->fraction; const LongLong timeOffset = LongLong (correctedOffset); this->time += timeOffset; this->fraction = correctedOffset - timeOffset; // carry the fraction if (this->fraction < 0.0) { this->time--; this->fraction += 1.0; } plonk_assert (fractionIsValid (this->fraction)); } return *this; }
PlankResult BinaryFileInternal::dynamicMemoryCloseCallback (PlankFileRef p) { plonk_assert (p != 0); ByteArray* array = static_cast<ByteArray*> (p->stream); delete array; // deletes the container, which of course holds a ref-counted object return pl_File_Init (p); }
PlankResult BinaryFileInternal::dynamicMemoryClearCallback (PlankFileRef p) { plonk_assert (p != 0); ByteArray* array = static_cast<ByteArray*> (p->stream); array->setSize (0, false); return PlankResult_OK; }
PlankResult BinaryFileInternal::dynamicMemorySetPositionCallback (PlankFileRef p, LongLong offset, int code) { plonk_assert (p != 0); PlankResult result; ByteArray* array = static_cast<ByteArray*> (p->stream); LongLong size = array->length(); LongLong newPosition; result = PlankResult_OK; switch (code) { case PLANKFILE_SETPOSITION_ABSOLUTE: newPosition = offset; break; case PLANKFILE_SETPOSITION_RELATIVE: newPosition = p->position + offset; break; case PLANKFILE_SETPOSITION_RELATIVEEND: newPosition = size + offset; break; default: newPosition = 0; } if (newPosition < 0) { newPosition = 0; result = PlankResult_FileSeekFailed; } else if (newPosition >= size) { newPosition = size; } p->position = newPosition; //exit: return result; }
void AudioFileReaderInternal::resetFramePosition() throw() { ResultCode result = pl_AudioFileReader_ResetFramePosition (getPeerRef()); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void TextFileInternal::writeLine (const char* text) throw() { const ResultCode result = pl_File_WriteLine (getPeerRef(), text); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::write (const double value) throw() { const ResultCode result = pl_File_WriteD (getPeerRef(), value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::read (double& value) throw() { const ResultCode result = pl_File_ReadD (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::write (void* data, const int maximumBytes) throw() { const ResultCode result = pl_File_Write (getPeerRef(), data, maximumBytes); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::setEof() throw() { const ResultCode result = pl_File_SetEOF (getPeerRef()); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
void BinaryFileInternal::setPosition(const LongLong position) throw() { const ResultCode result = pl_File_SetPosition (getPeerRef(), position); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
bool TimeStamp::operator> (TimeStamp const& other) const throw() { plonk_assert (fractionIsValid (this->fraction)); plonk_assert (fractionIsValid (other.fraction)); if (this->isInfinite()) { if (other.isInfinite()) return false; else return true; } else if (time > other.time) return true; else if ((time == other.time) && (fraction > other.fraction)) return true; else return false; }
double AudioFileReaderInternal::getSampleRate() const throw() { double value; ResultCode result = pl_AudioFileReader_GetSampleRate (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return value; }
void BinaryFileInternal::read (Int24& value) throw() { const ResultCode result = pl_File_ReadI24 (getPeerRef(), reinterpret_cast<Int24::Internal*> (&value) ); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif }
LongLong AudioFileReaderInternal::getFramePosition() const throw() { LongLong value; ResultCode result = pl_AudioFileReader_GetFramePosition (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return value; }
int AudioFileReaderInternal::getNumChannels() const throw() { int value; ResultCode result = pl_AudioFileReader_GetNumChannels (getPeerRef(), &value); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return value; }
int BinaryFileInternal::read (void* data, const int maximumBytes) throw() { int bytesRead; const ResultCode result = pl_File_Read (getPeerRef(), data, maximumBytes, &bytesRead); plonk_assert (result == PlankResult_OK || result == PlankResult_FileEOF); #ifndef PLONK_DEBUG (void)result; #endif return bytesRead; }
ResultCode Threading::Thread::setShouldExitAndWait (const double interval) throw() { ResultCode result = PlankResult_OK; result = setShouldExit(); plonk_assert (result == PlankResult_OK); while (isRunning()) Threading::sleep (interval); return result; }
bool BinaryFileInternal::setupBytes (PlankFileRef p, ByteArray const& bytes, const bool writable) throw() { ResultCode result = PlankResult_OK; pl_File_Init (p); if (p->stream != 0) { if ((result = pl_File_Close (p)) != PlankResult_OK) { plonk_assertfalse; return false; } } p->path[0] = '\0'; p->stream = new ByteArray (bytes); p->size = 0; p->mode = PLANKFILE_BINARY | PLANKFILE_NATIVEENDIAN | PLANKFILE_READ; if (writable) p->mode |= PLANKFILE_WRITE; p->type = PLANKFILE_STREAMTYPE_OTHER; result = pl_File_SetFunction (p, dynamicMemoryOpenCallback, dynamicMemoryCloseCallback, dynamicMemoryClearCallback, dynamicMemoryGetStatusCallback, dynamicMemoryReadCallback, dynamicMemoryWriteCallback, dynamicMemorySetPositionCallback, dynamicMemoryGetPositionCallback); plonk_assert (result == PlankResult_OK); result = (p->openFunction) (p); plonk_assert (result == PlankResult_OK); return result == PlankResult_OK; }
LongLong BinaryFileInternal::getPosition() const throw() { LongLong position; const ResultCode result = pl_File_GetPosition (getPeerRef(), &position); plonk_assert (result == PlankResult_OK); #ifndef PLONK_DEBUG (void)result; #endif return position; }