forked from bartvdbraak/blender
Audaspace: porting changes from upstream.
- Silence now has an optional sample rate parameter. - Fix: wrong length reported by modulator and superpose. - Minor formatting, include and documentation fixes.
This commit is contained in:
parent
243fbf1c4b
commit
8096f36796
4
extern/audaspace/bindings/C/AUD_Sound.cpp
vendored
4
extern/audaspace/bindings/C/AUD_Sound.cpp
vendored
@ -277,9 +277,9 @@ AUD_API AUD_Sound* AUD_Sound_sawtooth(float frequency, AUD_SampleRate rate)
|
|||||||
return new AUD_Sound(new Sawtooth(frequency, rate));
|
return new AUD_Sound(new Sawtooth(frequency, rate));
|
||||||
}
|
}
|
||||||
|
|
||||||
AUD_API AUD_Sound*AUD_Sound_silence()
|
AUD_API AUD_Sound* AUD_Sound_silence(AUD_SampleRate rate)
|
||||||
{
|
{
|
||||||
return new AUD_Sound(new Silence());
|
return new AUD_Sound(new Silence(rate));
|
||||||
}
|
}
|
||||||
|
|
||||||
AUD_API AUD_Sound* AUD_Sound_sine(float frequency, AUD_SampleRate rate)
|
AUD_API AUD_Sound* AUD_Sound_sine(float frequency, AUD_SampleRate rate)
|
||||||
|
3
extern/audaspace/bindings/C/AUD_Sound.h
vendored
3
extern/audaspace/bindings/C/AUD_Sound.h
vendored
@ -113,9 +113,10 @@ extern AUD_API AUD_Sound* AUD_Sound_sawtooth(float frequency, AUD_SampleRate rat
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a quiet sound.
|
* Creates a quiet sound.
|
||||||
|
* \param rate The sample rate of the silence sound.
|
||||||
* \return A handle of the sound.
|
* \return A handle of the sound.
|
||||||
*/
|
*/
|
||||||
extern AUD_API AUD_Sound* AUD_Sound_silence();
|
extern AUD_API AUD_Sound* AUD_Sound_silence(AUD_SampleRate rate);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a sine sound.
|
* Creates a sine sound.
|
||||||
|
6
extern/audaspace/bindings/C/AUD_Special.cpp
vendored
6
extern/audaspace/bindings/C/AUD_Special.cpp
vendored
@ -177,11 +177,11 @@ static void pauseSound(AUD_Handle* handle)
|
|||||||
|
|
||||||
AUD_API AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds)
|
AUD_API AUD_Handle* AUD_pauseAfter(AUD_Handle* handle, float seconds)
|
||||||
{
|
{
|
||||||
std::shared_ptr<ISound> silence = std::shared_ptr<ISound>(new Silence);
|
|
||||||
std::shared_ptr<ISound> limiter = std::shared_ptr<ISound>(new Limiter(silence, 0, seconds));
|
|
||||||
|
|
||||||
auto device = DeviceManager::getDevice();
|
auto device = DeviceManager::getDevice();
|
||||||
|
|
||||||
|
std::shared_ptr<ISound> silence = std::shared_ptr<ISound>(new Silence(device->getSpecs().rate));
|
||||||
|
std::shared_ptr<ISound> limiter = std::shared_ptr<ISound>(new Limiter(silence, 0, seconds));
|
||||||
|
|
||||||
std::lock_guard<ILockable> lock(*device);
|
std::lock_guard<ILockable> lock(*device);
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -100,7 +100,7 @@ Sequence_new(PyTypeObject* type, PyObject* args, PyObject* kwds)
|
|||||||
|
|
||||||
PyDoc_STRVAR(M_aud_Sequence_add_doc,
|
PyDoc_STRVAR(M_aud_Sequence_add_doc,
|
||||||
"add()\n\n"
|
"add()\n\n"
|
||||||
"Adds a new entry to the scene.\n"
|
"Adds a new entry to the sequence.\n\n"
|
||||||
":arg sound: The sound this entry should play.\n"
|
":arg sound: The sound this entry should play.\n"
|
||||||
":type sound: :class:`Sound`\n"
|
":type sound: :class:`Sound`\n"
|
||||||
":arg begin: The start time.\n"
|
":arg begin: The start time.\n"
|
||||||
@ -151,8 +151,8 @@ Sequence_add(Sequence* self, PyObject* args, PyObject* kwds)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(M_aud_Sequence_remove_doc,
|
PyDoc_STRVAR(M_aud_Sequence_remove_doc,
|
||||||
"reomve()\n\n"
|
"remove()\n\n"
|
||||||
"Adds a new entry to the scene.\n"
|
"Removes an entry from the sequence.\n\n"
|
||||||
":arg entry: The entry to remove.\n"
|
":arg entry: The entry to remove.\n"
|
||||||
":type entry: :class:`SequenceEntry`\n");
|
":type entry: :class:`SequenceEntry`\n");
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ static PyGetSetDef Sequence_properties[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyDoc_STRVAR(M_aud_Sequence_doc,
|
PyDoc_STRVAR(M_aud_Sequence_doc,
|
||||||
"This sound represents sequenced entries to play a sound scene.");
|
"This sound represents sequenced entries to play a sound sequence.");
|
||||||
|
|
||||||
extern PyTypeObject SoundType;
|
extern PyTypeObject SoundType;
|
||||||
|
|
||||||
|
16
extern/audaspace/bindings/python/PySound.cpp
vendored
16
extern/audaspace/bindings/python/PySound.cpp
vendored
@ -470,14 +470,22 @@ Sound_sawtooth(PyTypeObject* type, PyObject* args)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(M_aud_Sound_silence_doc,
|
PyDoc_STRVAR(M_aud_Sound_silence_doc,
|
||||||
"silence()\n\n"
|
"silence(rate=48000)\n\n"
|
||||||
"Creates a silence sound which plays simple silence.\n\n"
|
"Creates a silence sound which plays simple silence.\n\n"
|
||||||
|
":arg rate: The sampling rate in Hz. It's recommended to set this "
|
||||||
|
"value to the playback device's samling rate to avoid resamping.\n"
|
||||||
|
":type rate: int\n"
|
||||||
":return: The created :class:`Sound` object.\n"
|
":return: The created :class:`Sound` object.\n"
|
||||||
":rtype: :class:`Sound`");
|
":rtype: :class:`Sound`");
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
Sound_silence(PyTypeObject* type)
|
Sound_silence(PyTypeObject* type, PyObject* args)
|
||||||
{
|
{
|
||||||
|
double rate = 48000;
|
||||||
|
|
||||||
|
if(!PyArg_ParseTuple(args, "|d:sawtooth", &rate))
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
Sound* self;
|
Sound* self;
|
||||||
|
|
||||||
self = (Sound*)type->tp_alloc(type, 0);
|
self = (Sound*)type->tp_alloc(type, 0);
|
||||||
@ -485,7 +493,7 @@ Sound_silence(PyTypeObject* type)
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
self->sound = new std::shared_ptr<ISound>(new Silence());
|
self->sound = new std::shared_ptr<ISound>(new Silence((SampleRate)rate));
|
||||||
}
|
}
|
||||||
catch(Exception& e)
|
catch(Exception& e)
|
||||||
{
|
{
|
||||||
@ -1788,7 +1796,7 @@ static PyMethodDef Sound_methods[] = {
|
|||||||
{"sawtooth", (PyCFunction)Sound_sawtooth, METH_VARARGS | METH_CLASS,
|
{"sawtooth", (PyCFunction)Sound_sawtooth, METH_VARARGS | METH_CLASS,
|
||||||
M_aud_Sound_sawtooth_doc
|
M_aud_Sound_sawtooth_doc
|
||||||
},
|
},
|
||||||
{"silence", (PyCFunction)Sound_silence, METH_NOARGS | METH_CLASS,
|
{"silence", (PyCFunction)Sound_silence, METH_VARARGS | METH_CLASS,
|
||||||
M_aud_Sound_silence_doc
|
M_aud_Sound_silence_doc
|
||||||
},
|
},
|
||||||
{"sine", (PyCFunction)Sound_sine, METH_VARARGS | METH_CLASS,
|
{"sine", (PyCFunction)Sound_sine, METH_VARARGS | METH_CLASS,
|
||||||
|
9
extern/audaspace/include/generator/Silence.h
vendored
9
extern/audaspace/include/generator/Silence.h
vendored
@ -23,6 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "ISound.h"
|
#include "ISound.h"
|
||||||
|
#include "respec/Specification.h"
|
||||||
|
|
||||||
AUD_NAMESPACE_BEGIN
|
AUD_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -32,6 +33,11 @@ AUD_NAMESPACE_BEGIN
|
|||||||
class AUD_API Silence : public ISound
|
class AUD_API Silence : public ISound
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* The target sample rate for output.
|
||||||
|
*/
|
||||||
|
const SampleRate m_sampleRate;
|
||||||
|
|
||||||
// delete copy constructor and operator=
|
// delete copy constructor and operator=
|
||||||
Silence(const Silence&) = delete;
|
Silence(const Silence&) = delete;
|
||||||
Silence& operator=(const Silence&) = delete;
|
Silence& operator=(const Silence&) = delete;
|
||||||
@ -39,8 +45,9 @@ private:
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Creates a new silence sound.
|
* Creates a new silence sound.
|
||||||
|
* \param sampleRate The target sample rate for playback.
|
||||||
*/
|
*/
|
||||||
Silence();
|
Silence(SampleRate sampleRate = RATE_48000);
|
||||||
|
|
||||||
virtual std::shared_ptr<IReader> createReader();
|
virtual std::shared_ptr<IReader> createReader();
|
||||||
};
|
};
|
||||||
|
@ -38,6 +38,11 @@ private:
|
|||||||
*/
|
*/
|
||||||
int m_position;
|
int m_position;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The sample rate for the output.
|
||||||
|
*/
|
||||||
|
const SampleRate m_sampleRate;
|
||||||
|
|
||||||
// delete copy constructor and operator=
|
// delete copy constructor and operator=
|
||||||
SilenceReader(const SilenceReader&) = delete;
|
SilenceReader(const SilenceReader&) = delete;
|
||||||
SilenceReader& operator=(const SilenceReader&) = delete;
|
SilenceReader& operator=(const SilenceReader&) = delete;
|
||||||
@ -45,8 +50,9 @@ private:
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* Creates a new reader.
|
* Creates a new reader.
|
||||||
|
* \param sampleRate The output sample rate.
|
||||||
*/
|
*/
|
||||||
SilenceReader();
|
SilenceReader(SampleRate sampleRate);
|
||||||
|
|
||||||
virtual bool isSeekable() const;
|
virtual bool isSeekable() const;
|
||||||
virtual void seek(int position);
|
virtual void seek(int position);
|
||||||
|
3
extern/audaspace/include/generator/Sine.h
vendored
3
extern/audaspace/include/generator/Sine.h
vendored
@ -53,8 +53,7 @@ public:
|
|||||||
* \param frequency The desired frequency.
|
* \param frequency The desired frequency.
|
||||||
* \param sampleRate The target sample rate for playback.
|
* \param sampleRate The target sample rate for playback.
|
||||||
*/
|
*/
|
||||||
Sine(float frequency,
|
Sine(float frequency, SampleRate sampleRate = RATE_48000);
|
||||||
SampleRate sampleRate = RATE_48000);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the frequency of the sine wave.
|
* Returns the frequency of the sine wave.
|
||||||
|
3
extern/audaspace/src/fx/DynamicMusic.cpp
vendored
3
extern/audaspace/src/fx/DynamicMusic.cpp
vendored
@ -15,9 +15,6 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
#include "fx/DynamicMusic.h"
|
#include "fx/DynamicMusic.h"
|
||||||
#include "generator/Silence.h"
|
|
||||||
#include "fx/Fader.h"
|
|
||||||
#include "fx/Limiter.h"
|
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
2
extern/audaspace/src/fx/ModulatorReader.cpp
vendored
2
extern/audaspace/src/fx/ModulatorReader.cpp
vendored
@ -48,7 +48,7 @@ int ModulatorReader::getLength() const
|
|||||||
int len2 = m_reader2->getLength();
|
int len2 = m_reader2->getLength();
|
||||||
if((len1 < 0) || (len2 < 0))
|
if((len1 < 0) || (len2 < 0))
|
||||||
return -1;
|
return -1;
|
||||||
return std::min(len1, len2);
|
return std::max(len1, len2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ModulatorReader::getPosition() const
|
int ModulatorReader::getPosition() const
|
||||||
|
5
extern/audaspace/src/generator/Silence.cpp
vendored
5
extern/audaspace/src/generator/Silence.cpp
vendored
@ -19,13 +19,14 @@
|
|||||||
|
|
||||||
AUD_NAMESPACE_BEGIN
|
AUD_NAMESPACE_BEGIN
|
||||||
|
|
||||||
Silence::Silence()
|
Silence::Silence(SampleRate sampleRate) :
|
||||||
|
m_sampleRate(sampleRate)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IReader> Silence::createReader()
|
std::shared_ptr<IReader> Silence::createReader()
|
||||||
{
|
{
|
||||||
return std::shared_ptr<IReader>(new SilenceReader());
|
return std::shared_ptr<IReader>(new SilenceReader(m_sampleRate));
|
||||||
}
|
}
|
||||||
|
|
||||||
AUD_NAMESPACE_END
|
AUD_NAMESPACE_END
|
||||||
|
@ -20,8 +20,9 @@
|
|||||||
|
|
||||||
AUD_NAMESPACE_BEGIN
|
AUD_NAMESPACE_BEGIN
|
||||||
|
|
||||||
SilenceReader::SilenceReader() :
|
SilenceReader::SilenceReader(SampleRate sampleRate) :
|
||||||
m_position(0)
|
m_position(0),
|
||||||
|
m_sampleRate(sampleRate)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +49,7 @@ int SilenceReader::getPosition() const
|
|||||||
Specs SilenceReader::getSpecs() const
|
Specs SilenceReader::getSpecs() const
|
||||||
{
|
{
|
||||||
Specs specs;
|
Specs specs;
|
||||||
specs.rate = RATE_48000;
|
specs.rate = m_sampleRate;
|
||||||
specs.channels = CHANNELS_MONO;
|
specs.channels = CHANNELS_MONO;
|
||||||
return specs;
|
return specs;
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ int SuperposeReader::getLength() const
|
|||||||
int len2 = m_reader2->getLength();
|
int len2 = m_reader2->getLength();
|
||||||
if((len1 < 0) || (len2 < 0))
|
if((len1 < 0) || (len2 < 0))
|
||||||
return -1;
|
return -1;
|
||||||
return std::min(len1, len2);
|
return std::max(len1, len2);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SuperposeReader::getPosition() const
|
int SuperposeReader::getPosition() const
|
||||||
|
Loading…
Reference in New Issue
Block a user