Skip to content

Commit

Permalink
Made linux getMillisecondCounter() run monotonically. Added a new cla…
Browse files Browse the repository at this point in the history
…ss Decibels, with some decibel conversion methods. Minor updates to AudioThumbnail and FileInputSource.
  • Loading branch information
Julian Storer committed Dec 8, 2010
1 parent c4029bc commit 897c3e1
Show file tree
Hide file tree
Showing 28 changed files with 396 additions and 178 deletions.
2 changes: 2 additions & 0 deletions Builds/MacOSX/Juce.xcodeproj/project.pbxproj
Expand Up @@ -413,6 +413,7 @@
EBA6B46F7B3C11CA3744A4D0 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_AudioDataConverters.h; path = ../../src/audio/dsp/juce_AudioDataConverters.h; sourceTree = SOURCE_ROOT; };
A1D687AE613A8B61EB63923D = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_AudioSampleBuffer.cpp; path = ../../src/audio/dsp/juce_AudioSampleBuffer.cpp; sourceTree = SOURCE_ROOT; };
812620B53BE820D26A63B65D = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_AudioSampleBuffer.h; path = ../../src/audio/dsp/juce_AudioSampleBuffer.h; sourceTree = SOURCE_ROOT; };
11C1A96A35A2F03F8C34BD43 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_Decibels.h; path = ../../src/audio/dsp/juce_Decibels.h; sourceTree = SOURCE_ROOT; };
E68EB4BC75216B5B56E3F937 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_IIRFilter.cpp; path = ../../src/audio/dsp/juce_IIRFilter.cpp; sourceTree = SOURCE_ROOT; };
EE2259D9768027C2C001EEAD = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_IIRFilter.h; path = ../../src/audio/dsp/juce_IIRFilter.h; sourceTree = SOURCE_ROOT; };
B457515938E7141D5E79B671 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_MidiBuffer.cpp; path = ../../src/audio/midi/juce_MidiBuffer.cpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -1111,6 +1112,7 @@
EBA6B46F7B3C11CA3744A4D0,
A1D687AE613A8B61EB63923D,
812620B53BE820D26A63B65D,
11C1A96A35A2F03F8C34BD43,
E68EB4BC75216B5B56E3F937,
EE2259D9768027C2C001EEAD ); name = dsp; sourceTree = "<group>"; };
99B60B012D5CCF0BD861011D = { isa = PBXGroup; children = (
Expand Down
1 change: 1 addition & 0 deletions Builds/VisualStudio2005/Juce.vcproj
Expand Up @@ -181,6 +181,7 @@
<File RelativePath="..\..\src\audio\dsp\juce_AudioDataConverters.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_AudioSampleBuffer.cpp"/>
<File RelativePath="..\..\src\audio\dsp\juce_AudioSampleBuffer.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_Decibels.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_IIRFilter.cpp"/>
<File RelativePath="..\..\src\audio\dsp\juce_IIRFilter.h"/>
</Filter>
Expand Down
1 change: 1 addition & 0 deletions Builds/VisualStudio2008/Juce.vcproj
Expand Up @@ -181,6 +181,7 @@
<File RelativePath="..\..\src\audio\dsp\juce_AudioDataConverters.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_AudioSampleBuffer.cpp"/>
<File RelativePath="..\..\src\audio\dsp\juce_AudioSampleBuffer.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_Decibels.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_IIRFilter.cpp"/>
<File RelativePath="..\..\src\audio\dsp\juce_IIRFilter.h"/>
</Filter>
Expand Down
1 change: 1 addition & 0 deletions Builds/VisualStudio2008_DLL/Juce.vcproj
Expand Up @@ -183,6 +183,7 @@
<File RelativePath="..\..\src\audio\dsp\juce_AudioDataConverters.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_AudioSampleBuffer.cpp"/>
<File RelativePath="..\..\src\audio\dsp\juce_AudioSampleBuffer.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_Decibels.h"/>
<File RelativePath="..\..\src\audio\dsp\juce_IIRFilter.cpp"/>
<File RelativePath="..\..\src\audio\dsp\juce_IIRFilter.h"/>
</Filter>
Expand Down
1 change: 1 addition & 0 deletions Builds/VisualStudio2010/Juce.vcxproj
Expand Up @@ -469,6 +469,7 @@
<ClInclude Include="..\..\src\audio\devices\juce_MidiOutput.h"/>
<ClInclude Include="..\..\src\audio\dsp\juce_AudioDataConverters.h"/>
<ClInclude Include="..\..\src\audio\dsp\juce_AudioSampleBuffer.h"/>
<ClInclude Include="..\..\src\audio\dsp\juce_Decibels.h"/>
<ClInclude Include="..\..\src\audio\dsp\juce_IIRFilter.h"/>
<ClInclude Include="..\..\src\audio\midi\juce_MidiBuffer.h"/>
<ClInclude Include="..\..\src\audio\midi\juce_MidiFile.h"/>
Expand Down
3 changes: 3 additions & 0 deletions Builds/VisualStudio2010/Juce.vcxproj.filters
Expand Up @@ -1329,6 +1329,9 @@
<ClInclude Include="..\..\src\audio\dsp\juce_AudioSampleBuffer.h">
<Filter>Juce\Source\audio\dsp</Filter>
</ClInclude>
<ClInclude Include="..\..\src\audio\dsp\juce_Decibels.h">
<Filter>Juce\Source\audio\dsp</Filter>
</ClInclude>
<ClInclude Include="..\..\src\audio\dsp\juce_IIRFilter.h">
<Filter>Juce\Source\audio\dsp</Filter>
</ClInclude>
Expand Down
2 changes: 2 additions & 0 deletions Builds/iPhone/Juce.xcodeproj/project.pbxproj
Expand Up @@ -413,6 +413,7 @@
EBA6B46F7B3C11CA3744A4D0 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_AudioDataConverters.h; path = ../../src/audio/dsp/juce_AudioDataConverters.h; sourceTree = SOURCE_ROOT; };
A1D687AE613A8B61EB63923D = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_AudioSampleBuffer.cpp; path = ../../src/audio/dsp/juce_AudioSampleBuffer.cpp; sourceTree = SOURCE_ROOT; };
812620B53BE820D26A63B65D = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_AudioSampleBuffer.h; path = ../../src/audio/dsp/juce_AudioSampleBuffer.h; sourceTree = SOURCE_ROOT; };
11C1A96A35A2F03F8C34BD43 = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_Decibels.h; path = ../../src/audio/dsp/juce_Decibels.h; sourceTree = SOURCE_ROOT; };
E68EB4BC75216B5B56E3F937 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_IIRFilter.cpp; path = ../../src/audio/dsp/juce_IIRFilter.cpp; sourceTree = SOURCE_ROOT; };
EE2259D9768027C2C001EEAD = { isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = juce_IIRFilter.h; path = ../../src/audio/dsp/juce_IIRFilter.h; sourceTree = SOURCE_ROOT; };
B457515938E7141D5E79B671 = { isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = juce_MidiBuffer.cpp; path = ../../src/audio/midi/juce_MidiBuffer.cpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -1111,6 +1112,7 @@
EBA6B46F7B3C11CA3744A4D0,
A1D687AE613A8B61EB63923D,
812620B53BE820D26A63B65D,
11C1A96A35A2F03F8C34BD43,
E68EB4BC75216B5B56E3F937,
EE2259D9768027C2C001EEAD ); name = dsp; sourceTree = "<group>"; };
99B60B012D5CCF0BD861011D = { isa = PBXGroup; children = (
Expand Down
2 changes: 2 additions & 0 deletions Juce.jucer
Expand Up @@ -189,6 +189,8 @@
resource="0" file="src/audio/dsp/juce_AudioSampleBuffer.cpp"/>
<FILE id="ALRRctFtO" name="juce_AudioSampleBuffer.h" compile="0" resource="0"
file="src/audio/dsp/juce_AudioSampleBuffer.h"/>
<FILE id="vERxbEd" name="juce_Decibels.h" compile="0" resource="0"
file="src/audio/dsp/juce_Decibels.h"/>
<FILE id="GlESUU1V" name="juce_IIRFilter.cpp" compile="1" resource="0"
file="src/audio/dsp/juce_IIRFilter.cpp"/>
<FILE id="Vu9xVqUfN" name="juce_IIRFilter.h" compile="0" resource="0"
Expand Down
Binary file modified extras/juce demo/Builds/MacOSX/Icon.icns
Binary file not shown.
Binary file modified extras/juce demo/Builds/VisualStudio2005/icon.ico
Binary file not shown.
Binary file modified extras/juce demo/Builds/VisualStudio2008/icon.ico
Binary file not shown.
Binary file modified extras/juce demo/Builds/VisualStudio2010/icon.ico
Binary file not shown.
Binary file modified extras/juce demo/Builds/iPhone/Icon.icns
Binary file not shown.
94 changes: 42 additions & 52 deletions juce_amalgamated.cpp
Expand Up @@ -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_)
{
}

Expand All @@ -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
Expand Down Expand Up @@ -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))
{
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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 (;;)
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 897c3e1

Please sign in to comment.