mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-04 03:40:07 +00:00
Made linux getMillisecondCounter() run monotonically. Added a new class Decibels, with some decibel conversion methods. Minor updates to AudioThumbnail and FileInputSource.
This commit is contained in:
parent
c4029bc86d
commit
897c3e1fa7
28 changed files with 396 additions and 178 deletions
|
|
@ -9946,8 +9946,8 @@ END_JUCE_NAMESPACE
|
|||
/*** Start of inlined file: juce_FileInputSource.cpp ***/
|
||||
BEGIN_JUCE_NAMESPACE
|
||||
|
||||
FileInputSource::FileInputSource (const File& file_)
|
||||
: file (file_)
|
||||
FileInputSource::FileInputSource (const File& file_, bool useFileTimeInHashGeneration_)
|
||||
: file (file_), useFileTimeInHashGeneration (useFileTimeInHashGeneration_)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -9967,7 +9967,12 @@ InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPat
|
|||
|
||||
int64 FileInputSource::hashCode() const
|
||||
{
|
||||
return file.hashCode();
|
||||
int64 h = file.hashCode();
|
||||
|
||||
if (useFileTimeInHashGeneration)
|
||||
h ^= file.getLastModificationTime().toMilliseconds();
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
END_JUCE_NAMESPACE
|
||||
|
|
@ -11932,12 +11937,14 @@ String& String::operator= (const String& other) throw()
|
|||
{
|
||||
juce_wchar* const newText = other.text;
|
||||
StringHolder::retain (newText);
|
||||
StringHolder::release (reinterpret_cast <Atomic<juce_wchar*>*> (&text)->exchange (newText));
|
||||
StringHolder::release (reinterpret_cast <Atomic<juce_wchar*>&> (text).exchange (newText));
|
||||
return *this;
|
||||
}
|
||||
|
||||
String::String (const size_t numChars, const int /*dummyVariable*/)
|
||||
: text (StringHolder::createUninitialised (numChars))
|
||||
inline String::Preallocation::Preallocation (const size_t numChars_) : numChars (numChars_) {}
|
||||
|
||||
String::String (const Preallocation& preallocationSize)
|
||||
: text (StringHolder::createUninitialised (preallocationSize.numChars))
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -11992,7 +11999,7 @@ String::String (const juce_wchar* const t, const size_t maxChars)
|
|||
|
||||
const String String::charToString (const juce_wchar character)
|
||||
{
|
||||
String result ((size_t) 1, (int) 0);
|
||||
String result (Preallocation (1));
|
||||
result.text[0] = character;
|
||||
result.text[1] = 0;
|
||||
return result;
|
||||
|
|
@ -12815,7 +12822,7 @@ bool String::matchesWildcard (const String& wildcard, const bool ignoreCase) con
|
|||
const String String::repeatedString (const String& stringToRepeat, int numberOfTimesToRepeat)
|
||||
{
|
||||
const int len = stringToRepeat.length();
|
||||
String result ((size_t) (len * numberOfTimesToRepeat + 1), (int) 0);
|
||||
String result (Preallocation (len * numberOfTimesToRepeat + 1));
|
||||
juce_wchar* n = result.text;
|
||||
*n = 0;
|
||||
|
||||
|
|
@ -12836,7 +12843,7 @@ const String String::paddedLeft (const juce_wchar padCharacter, int minimumLengt
|
|||
if (len >= minimumLength || padCharacter == 0)
|
||||
return *this;
|
||||
|
||||
String result ((size_t) minimumLength + 1, (int) 0);
|
||||
String result (Preallocation (minimumLength + 1));
|
||||
juce_wchar* n = result.text;
|
||||
|
||||
minimumLength -= len;
|
||||
|
|
@ -12902,7 +12909,7 @@ const String String::replaceSection (int index, int numCharsToReplace, const Str
|
|||
if (newTotalLen <= 0)
|
||||
return String::empty;
|
||||
|
||||
String result ((size_t) newTotalLen, (int) 0);
|
||||
String result (Preallocation ((size_t) newTotalLen));
|
||||
|
||||
StringHolder::copyChars (result.text, text, index);
|
||||
|
||||
|
|
@ -13271,7 +13278,7 @@ const String String::retainCharacters (const String& charactersToRetain) const
|
|||
if (isEmpty())
|
||||
return empty;
|
||||
|
||||
String result (StringHolder::getAllocatedNumChars (text), (int) 0);
|
||||
String result (Preallocation (StringHolder::getAllocatedNumChars (text)));
|
||||
juce_wchar* dst = result.text;
|
||||
const juce_wchar* src = text;
|
||||
|
||||
|
|
@ -13292,7 +13299,7 @@ const String String::removeCharacters (const String& charactersToRemove) const
|
|||
if (isEmpty())
|
||||
return empty;
|
||||
|
||||
String result (StringHolder::getAllocatedNumChars (text), (int) 0);
|
||||
String result (Preallocation (StringHolder::getAllocatedNumChars (text)));
|
||||
juce_wchar* dst = result.text;
|
||||
const juce_wchar* src = text;
|
||||
|
||||
|
|
@ -13380,7 +13387,7 @@ const String String::formatted (const juce_wchar* const pf, ... )
|
|||
va_start (args, pf);
|
||||
|
||||
size_t bufferSize = 256;
|
||||
String result (bufferSize, (int) 0);
|
||||
String result (Preallocation ((size_t) bufferSize));
|
||||
result.text[0] = 0;
|
||||
|
||||
for (;;)
|
||||
|
|
@ -13505,9 +13512,7 @@ const String String::toHexString (const short number)
|
|||
return toHexString ((int) (unsigned short) number);
|
||||
}
|
||||
|
||||
const String String::toHexString (const unsigned char* data,
|
||||
const int size,
|
||||
const int groupSize)
|
||||
const String String::toHexString (const unsigned char* data, const int size, const int groupSize)
|
||||
{
|
||||
if (size <= 0)
|
||||
return empty;
|
||||
|
|
@ -13516,7 +13521,7 @@ const String String::toHexString (const unsigned char* data,
|
|||
if (groupSize > 0)
|
||||
numChars += size / groupSize;
|
||||
|
||||
String s ((size_t) numChars, (int) 0);
|
||||
String s (Preallocation ((size_t) numChars));
|
||||
|
||||
juce_wchar* d = s.text;
|
||||
|
||||
|
|
@ -13769,7 +13774,7 @@ const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
|
|||
if (buffer [numBytes] == 0)
|
||||
break;
|
||||
|
||||
String result ((size_t) numBytes + 1, (int) 0);
|
||||
String result (Preallocation (numBytes + 1));
|
||||
juce_wchar* dest = result.text;
|
||||
|
||||
size_t i = 0;
|
||||
|
|
@ -22625,8 +22630,10 @@ void AudioThumbnail::saveTo (OutputStream& output) const
|
|||
channels.getUnchecked(chan)->getData(i)->write (output);
|
||||
}
|
||||
|
||||
void AudioThumbnail::setDataSource (LevelDataSource* newSource)
|
||||
bool AudioThumbnail::setDataSource (LevelDataSource* newSource)
|
||||
{
|
||||
jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
|
||||
|
||||
numSamplesFinished = 0;
|
||||
|
||||
if (cache.loadThumb (*this, newSource->hashCode) && isFullyLoaded())
|
||||
|
|
@ -22651,14 +22658,15 @@ void AudioThumbnail::setDataSource (LevelDataSource* newSource)
|
|||
|
||||
createChannels (1 + (int) (totalSamples / samplesPerThumbSample));
|
||||
}
|
||||
|
||||
return sampleRate > 0 && totalSamples > 0;
|
||||
}
|
||||
|
||||
void AudioThumbnail::setSource (InputSource* const newSource)
|
||||
bool AudioThumbnail::setSource (InputSource* const newSource)
|
||||
{
|
||||
clear();
|
||||
|
||||
if (newSource != 0)
|
||||
setDataSource (new LevelDataSource (*this, newSource));
|
||||
return newSource != 0 && setDataSource (new LevelDataSource (*this, newSource));
|
||||
}
|
||||
|
||||
void AudioThumbnail::setReader (AudioFormatReader* newReader, int64 hash)
|
||||
|
|
@ -22669,6 +22677,11 @@ void AudioThumbnail::setReader (AudioFormatReader* newReader, int64 hash)
|
|||
setDataSource (new LevelDataSource (*this, newReader, hash));
|
||||
}
|
||||
|
||||
int64 AudioThumbnail::getHashCode() const
|
||||
{
|
||||
return source == 0 ? 0 : source->hashCode;
|
||||
}
|
||||
|
||||
void AudioThumbnail::addBlock (const int64 startSample, const AudioSampleBuffer& incoming,
|
||||
int startOffsetInBuffer, int numSamples)
|
||||
{
|
||||
|
|
@ -237848,7 +237861,7 @@ int64 Time::getHighResolutionTicks() throw()
|
|||
LARGE_INTEGER ticks;
|
||||
QueryPerformanceCounter (&ticks);
|
||||
|
||||
const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
|
||||
const int64 mainCounterAsHiResTicks = (juce_millisecondsSinceStartup() * hiResTicksPerSecond) / 1000;
|
||||
const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
|
||||
|
||||
// fix for a very obscure PCI hardware bug that can make the counter
|
||||
|
|
@ -255339,27 +255352,6 @@ namespace LinuxStatsHelpers
|
|||
|
||||
return String::empty;
|
||||
}
|
||||
|
||||
bool getTimeSinceStartup (timeval* const t) throw()
|
||||
{
|
||||
if (gettimeofday (t, 0) != 0)
|
||||
return false;
|
||||
|
||||
static unsigned int calibrate = 0;
|
||||
static bool calibrated = false;
|
||||
|
||||
if (! calibrated)
|
||||
{
|
||||
calibrated = true;
|
||||
|
||||
struct sysinfo sysi;
|
||||
if (sysinfo (&sysi) == 0)
|
||||
calibrate = t->tv_sec - sysi.uptime; // Safe to assume system was not brought up earlier than 1970!
|
||||
}
|
||||
|
||||
t->tv_sec -= calibrate;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const String SystemStats::getCpuVendor()
|
||||
|
|
@ -255423,20 +255415,18 @@ void PlatformUtilities::fpuReset()
|
|||
|
||||
uint32 juce_millisecondsSinceStartup() throw()
|
||||
{
|
||||
timeval t;
|
||||
if (LinuxStatsHelpers::getTimeSinceStartup (&t))
|
||||
return (uint32) (t.tv_sec * 1000 + (t.tv_usec / 1000));
|
||||
timespec t;
|
||||
clock_gettime (CLOCK_MONOTONIC, &t);
|
||||
|
||||
return 0;
|
||||
return t.tv_sec * 1000 + t.tv_nsec / 1000000;
|
||||
}
|
||||
|
||||
int64 Time::getHighResolutionTicks() throw()
|
||||
{
|
||||
timeval t;
|
||||
if (LinuxStatsHelpers::getTimeSinceStartup (&t))
|
||||
return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
|
||||
timespec t;
|
||||
clock_gettime (CLOCK_MONOTONIC, &t);
|
||||
|
||||
return 0;
|
||||
return (t.tv_sec * (int64) 1000000) + (t.tv_nsec / (int64) 1000);
|
||||
}
|
||||
|
||||
int64 Time::getHighResolutionTicksPerSecond() throw()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue