mirror of https://github.com/AxioDL/amuse.git
Minor fixes (#6)
* cmake: require c++14 * correctly clip samples by using numeric_limits rather than C macros * oops, implicit type conversion of template causes overflow * store default sample rate in global constexpr var
This commit is contained in:
parent
3d56d5f0cc
commit
4e7c31849d
|
@ -1,11 +1,16 @@
|
|||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR) # because of CMAKE_CXX_STANDARD
|
||||
|
||||
project(amuse)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
|
||||
endif()
|
||||
|
||||
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/boo AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/athena)
|
||||
message(STATUS "Preparing standalone build")
|
||||
if (NOT MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wno-narrowing")
|
||||
endif()
|
||||
add_subdirectory(boo)
|
||||
add_subdirectory(athena)
|
||||
include_directories(athena/include)
|
||||
|
|
|
@ -99,7 +99,7 @@ int main(int argc, const boo::SystemChar** argv)
|
|||
|
||||
std::vector<boo::SystemString> m_args;
|
||||
m_args.reserve(argc);
|
||||
double rate = 32000.0;
|
||||
double rate = NativeSampleRate;
|
||||
for (int i = 1; i < argc; ++i)
|
||||
{
|
||||
#if _WIN32
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __AMUSE_COMMON_HPP__
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits.h>
|
||||
#include <limits>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
@ -23,6 +23,8 @@
|
|||
#include <Windows.h>
|
||||
#endif
|
||||
|
||||
constexpr float NativeSampleRate = 32000.0f;
|
||||
|
||||
namespace amuse
|
||||
{
|
||||
|
||||
|
@ -74,35 +76,24 @@ static inline T clamp(T a, T val, T b)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
static inline T ClampFull(float in)
|
||||
inline T ClampFull(float in)
|
||||
{
|
||||
return in;
|
||||
}
|
||||
if(std::is_floating_point<T>())
|
||||
{
|
||||
return std::min<T>(std::max<T>(in, -1.0), 1.0);
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr T MAX = std::numeric_limits<T>::max();
|
||||
constexpr T MIN = std::numeric_limits<T>::min();
|
||||
|
||||
template <>
|
||||
inline int16_t ClampFull<int16_t>(float in)
|
||||
{
|
||||
if (in < SHRT_MIN)
|
||||
return SHRT_MIN;
|
||||
else if (in > SHRT_MAX)
|
||||
return SHRT_MAX;
|
||||
return in;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline int32_t ClampFull<int32_t>(float in)
|
||||
{
|
||||
if (in < INT_MIN)
|
||||
return INT_MIN;
|
||||
else if (in > INT_MAX)
|
||||
return INT_MAX;
|
||||
return in;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline float ClampFull<float>(float in)
|
||||
{
|
||||
return in;
|
||||
if(in < MIN)
|
||||
return MIN;
|
||||
else if(in > MAX)
|
||||
return MAX;
|
||||
else
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef M_PIF
|
||||
|
|
|
@ -62,7 +62,7 @@ class Voice : public Entity
|
|||
uint32_t m_lastSamplePos = 0; /**< Last sample position (or last loop sample) */
|
||||
int16_t m_prev1 = 0; /**< DSPADPCM prev sample */
|
||||
int16_t m_prev2 = 0; /**< DSPADPCM prev-prev sample */
|
||||
double m_sampleRate = 32000.0; /**< Current sample rate computed from relative sample key or SETPITCH */
|
||||
double m_sampleRate = NativeSampleRate; /**< Current sample rate computed from relative sample key or SETPITCH */
|
||||
double m_voiceTime = 0.0; /**< Current seconds of voice playback (per-sample resolution) */
|
||||
uint64_t m_voiceSamples = 0; /**< Count of samples processed over voice's lifetime */
|
||||
float m_lastLevel = 0.f; /**< Last computed level ([0,1] mapped to [-10,0] clamped decibels) */
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef __AMUSE_AMUSE_HPP__
|
||||
#define __AMUSE_AMUSE_HPP__
|
||||
|
||||
|
||||
#include "AudioGroup.hpp"
|
||||
#include "AudioGroupData.hpp"
|
||||
#include "AudioGroupPool.hpp"
|
||||
|
|
|
@ -90,7 +90,7 @@ template <typename T>
|
|||
void EffectReverbStdImp<T>::_update()
|
||||
{
|
||||
float timeSamples = x148_x1d0_time * m_sampleRate;
|
||||
double rateRatio = m_sampleRate / 32000.0;
|
||||
double rateRatio = m_sampleRate / NativeSampleRate;
|
||||
for (int c = 0; c < 8; ++c)
|
||||
{
|
||||
for (int t = 0; t < 2; ++t)
|
||||
|
@ -265,7 +265,7 @@ template <typename T>
|
|||
void EffectReverbHiImp<T>::_update()
|
||||
{
|
||||
float timeSamples = x148_x1d0_time * m_sampleRate;
|
||||
double rateRatio = m_sampleRate / 32000.0;
|
||||
double rateRatio = m_sampleRate / NativeSampleRate;
|
||||
for (int c = 0; c < 8; ++c)
|
||||
{
|
||||
for (int t = 0; t < 3; ++t)
|
||||
|
|
|
@ -304,7 +304,7 @@ std::shared_ptr<Voice> Engine::fxStart(int sfxId, float vol, float pan, std::wea
|
|||
return nullptr;
|
||||
|
||||
std::list<std::shared_ptr<Voice>>::iterator ret =
|
||||
_allocateVoice(*grp, std::get<1>(search->second), 32000.0, true, false, smx);
|
||||
_allocateVoice(*grp, std::get<1>(search->second), NativeSampleRate, true, false, smx);
|
||||
|
||||
ObjectId oid = (grp->getDataFormat() == DataFormat::PC) ? entry->objId : SBig(entry->objId);
|
||||
if (!(*ret)->loadSoundObject(oid, 0, 1000.f, entry->defKey, entry->defVel, 0))
|
||||
|
@ -332,7 +332,7 @@ std::shared_ptr<Emitter> Engine::addEmitter(const float* pos, const float* dir,
|
|||
return nullptr;
|
||||
|
||||
std::list<std::shared_ptr<Voice>>::iterator vox =
|
||||
_allocateVoice(*grp, std::get<1>(search->second), 32000.0, true, true, smx);
|
||||
_allocateVoice(*grp, std::get<1>(search->second), NativeSampleRate, true, true, smx);
|
||||
auto emitIt = m_activeEmitters.emplace(m_activeEmitters.end(), new Emitter(*this, *grp, std::move(*vox)));
|
||||
Emitter& ret = *(*emitIt);
|
||||
|
||||
|
|
|
@ -239,7 +239,7 @@ std::shared_ptr<Voice> Sequencer::ChannelState::keyOn(uint8_t note, uint8_t velo
|
|||
}
|
||||
|
||||
std::list<std::shared_ptr<Voice>>::iterator ret = m_parent.m_engine._allocateVoice(
|
||||
m_parent.m_audioGroup, m_parent.m_groupId, 32000.0, true, false, m_parent.m_studio);
|
||||
m_parent.m_audioGroup, m_parent.m_groupId, NativeSampleRate, true, false, m_parent.m_studio);
|
||||
if (*ret)
|
||||
{
|
||||
m_chanVoxs[note] = *ret;
|
||||
|
|
|
@ -101,7 +101,7 @@ SongState::Track::Track(SongState& parent, uint8_t midiChan, const TrackRegion*
|
|||
: m_parent(parent), m_midiChan(midiChan), m_curRegion(nullptr), m_nextRegion(regions)
|
||||
{
|
||||
for (int i = 0; i < 128; ++i)
|
||||
m_remNoteLengths[i] = INT_MIN;
|
||||
m_remNoteLengths[i] = std::numeric_limits<decltype(m_remNoteLengths)::value_type>::min();
|
||||
}
|
||||
|
||||
void SongState::Track::setRegion(Sequencer* seq, const TrackRegion* region)
|
||||
|
@ -381,13 +381,14 @@ bool SongState::Track::advance(Sequencer& seq, int32_t ticks)
|
|||
/* Stop finished notes */
|
||||
for (int i = 0; i < 128; ++i)
|
||||
{
|
||||
if (m_remNoteLengths[i] != INT_MIN)
|
||||
constexpr decltype(m_remNoteLengths)::value_type MIN = std::numeric_limits<decltype(MIN)>::min();
|
||||
if (m_remNoteLengths[i] != MIN)
|
||||
{
|
||||
m_remNoteLengths[i] -= ticks;
|
||||
if (m_remNoteLengths[i] <= 0)
|
||||
{
|
||||
seq.keyOff(m_midiChan, i, 0);
|
||||
m_remNoteLengths[i] = INT_MIN;
|
||||
m_remNoteLengths[i] = MIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -722,7 +722,7 @@ int Voice::maxVid() const
|
|||
std::shared_ptr<Voice> Voice::_startChildMacro(ObjectId macroId, int macroStep, double ticksPerSec, uint8_t midiKey,
|
||||
uint8_t midiVel, uint8_t midiMod, bool pushPc)
|
||||
{
|
||||
std::list<std::shared_ptr<Voice>>::iterator vox = _allocateVoice(32000.0, true);
|
||||
std::list<std::shared_ptr<Voice>>::iterator vox = _allocateVoice(NativeSampleRate, true);
|
||||
if (!(*vox)->loadSoundObject(macroId, macroStep, ticksPerSec, midiKey, midiVel, midiMod, pushPc))
|
||||
{
|
||||
_destroyVoice(vox);
|
||||
|
|
Loading…
Reference in New Issue