Пример #1
0
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);
}
Пример #2
0
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;
}
Пример #3
0
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;
}
Пример #4
0
/*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)));
}
Пример #5
0
static PLONK_INLINE_LOW void staticDoFree (void* userData, void* ptr) throw()
{
#if PLONK_OBJECTMEMORYDEFERFREE_DEBUG
    plonk_assert (!Threading::currentThreadIsAudioThread());
#endif
    pl_MemoryDefaultFree (userData, ptr);
}
Пример #6
0
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;
    }
}
Пример #7
0
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;
    }
}
Пример #8
0
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;
}
Пример #9
0
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;
}
Пример #10
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;
}
Пример #11
0
/*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;
}
Пример #12
0
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);
}
Пример #13
0
PlankResult BinaryFileInternal::dynamicMemoryClearCallback (PlankFileRef p)
{
    plonk_assert (p != 0);
    ByteArray* array = static_cast<ByteArray*> (p->stream);
    array->setSize (0, false);
    return PlankResult_OK;
}
Пример #14
0
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;
}
Пример #15
0
void AudioFileReaderInternal::resetFramePosition() throw()
{
    ResultCode result = pl_AudioFileReader_ResetFramePosition (getPeerRef());
    plonk_assert (result == PlankResult_OK);
#ifndef PLONK_DEBUG
    (void)result;
#endif
}
Пример #16
0
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    
}
Пример #17
0
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
}
Пример #18
0
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                
}
Пример #19
0
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    
}
Пример #20
0
void BinaryFileInternal::setEof() throw()
{
    const ResultCode result = pl_File_SetEOF (getPeerRef());
    plonk_assert (result == PlankResult_OK);
    
#ifndef PLONK_DEBUG
    (void)result;
#endif    
}
Пример #21
0
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
}
Пример #22
0
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;    
}
Пример #23
0
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;
}
Пример #24
0
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                    
}
Пример #25
0
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;
}
Пример #26
0
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;
}
Пример #27
0
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;
}
Пример #28
0
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;
}
Пример #29
0
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;    
}
Пример #30
0
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;
}