Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'extern/audaspace/src/generator')
-rw-r--r--extern/audaspace/src/generator/Sawtooth.cpp38
-rw-r--r--extern/audaspace/src/generator/SawtoothReader.cpp83
-rw-r--r--extern/audaspace/src/generator/Silence.cpp31
-rw-r--r--extern/audaspace/src/generator/SilenceReader.cpp63
-rw-r--r--extern/audaspace/src/generator/Sine.cpp38
-rw-r--r--extern/audaspace/src/generator/SineReader.cpp75
-rw-r--r--extern/audaspace/src/generator/Square.cpp38
-rw-r--r--extern/audaspace/src/generator/SquareReader.cpp83
-rw-r--r--extern/audaspace/src/generator/Triangle.cpp38
-rw-r--r--extern/audaspace/src/generator/TriangleReader.cpp83
10 files changed, 570 insertions, 0 deletions
diff --git a/extern/audaspace/src/generator/Sawtooth.cpp b/extern/audaspace/src/generator/Sawtooth.cpp
new file mode 100644
index 00000000000..f5acad44839
--- /dev/null
+++ b/extern/audaspace/src/generator/Sawtooth.cpp
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/Sawtooth.h"
+#include "generator/SawtoothReader.h"
+
+AUD_NAMESPACE_BEGIN
+
+Sawtooth::Sawtooth(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_sampleRate(sampleRate)
+{
+}
+
+float Sawtooth::getFrequency() const
+{
+ return m_frequency;
+}
+
+std::shared_ptr<IReader> Sawtooth::createReader()
+{
+ return std::shared_ptr<IReader>(new SawtoothReader(m_frequency, m_sampleRate));
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/SawtoothReader.cpp b/extern/audaspace/src/generator/SawtoothReader.cpp
new file mode 100644
index 00000000000..3664b8d3b61
--- /dev/null
+++ b/extern/audaspace/src/generator/SawtoothReader.cpp
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/SawtoothReader.h"
+
+#include <cmath>
+
+AUD_NAMESPACE_BEGIN
+
+SawtoothReader::SawtoothReader(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_position(0),
+ m_sample(0),
+ m_sampleRate(sampleRate)
+{
+}
+
+void SawtoothReader::setFrequency(float frequency)
+{
+ m_frequency = frequency;
+}
+
+bool SawtoothReader::isSeekable() const
+{
+ return true;
+}
+
+void SawtoothReader::seek(int position)
+{
+ m_position = position;
+ m_sample = std::fmod(m_position * m_frequency / (float)m_sampleRate + 1.0f, 2.0f) - 1.0f;
+}
+
+int SawtoothReader::getLength() const
+{
+ return -1;
+}
+
+int SawtoothReader::getPosition() const
+{
+ return m_position;
+}
+
+Specs SawtoothReader::getSpecs() const
+{
+ Specs specs;
+ specs.rate = m_sampleRate;
+ specs.channels = CHANNELS_MONO;
+ return specs;
+}
+
+void SawtoothReader::read(int& length, bool& eos, sample_t* buffer)
+{
+ float k = 2.0 * m_frequency / m_sampleRate;
+
+ for(int i = 0; i < length; i++)
+ {
+ m_sample += k;
+
+ if(m_sample >= 1.0f)
+ m_sample -= std::floor(m_sample) + 1.0f;
+
+ buffer[i] = m_sample;
+ }
+
+ m_position += length;
+ eos = false;
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/Silence.cpp b/extern/audaspace/src/generator/Silence.cpp
new file mode 100644
index 00000000000..a173a1bc5f6
--- /dev/null
+++ b/extern/audaspace/src/generator/Silence.cpp
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/Silence.h"
+#include "generator/SilenceReader.h"
+
+AUD_NAMESPACE_BEGIN
+
+Silence::Silence()
+{
+}
+
+std::shared_ptr<IReader> Silence::createReader()
+{
+ return std::shared_ptr<IReader>(new SilenceReader());
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/SilenceReader.cpp b/extern/audaspace/src/generator/SilenceReader.cpp
new file mode 100644
index 00000000000..39358cc087a
--- /dev/null
+++ b/extern/audaspace/src/generator/SilenceReader.cpp
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/SilenceReader.h"
+
+#include <cstring>
+
+AUD_NAMESPACE_BEGIN
+
+SilenceReader::SilenceReader() :
+ m_position(0)
+{
+}
+
+bool SilenceReader::isSeekable() const
+{
+ return true;
+}
+
+void SilenceReader::seek(int position)
+{
+ m_position = position;
+}
+
+int SilenceReader::getLength() const
+{
+ return -1;
+}
+
+int SilenceReader::getPosition() const
+{
+ return m_position;
+}
+
+Specs SilenceReader::getSpecs() const
+{
+ Specs specs;
+ specs.rate = RATE_48000;
+ specs.channels = CHANNELS_MONO;
+ return specs;
+}
+
+void SilenceReader::read(int& length, bool& eos, sample_t* buffer)
+{
+ std::memset(buffer, 0, length * sizeof(sample_t));
+ m_position += length;
+ eos = false;
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/Sine.cpp b/extern/audaspace/src/generator/Sine.cpp
new file mode 100644
index 00000000000..b7cdc132df6
--- /dev/null
+++ b/extern/audaspace/src/generator/Sine.cpp
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/Sine.h"
+#include "generator/SineReader.h"
+
+AUD_NAMESPACE_BEGIN
+
+Sine::Sine(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_sampleRate(sampleRate)
+{
+}
+
+float Sine::getFrequency() const
+{
+ return m_frequency;
+}
+
+std::shared_ptr<IReader> Sine::createReader()
+{
+ return std::shared_ptr<IReader>(new SineReader(m_frequency, m_sampleRate));
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/SineReader.cpp b/extern/audaspace/src/generator/SineReader.cpp
new file mode 100644
index 00000000000..49b7cc3114b
--- /dev/null
+++ b/extern/audaspace/src/generator/SineReader.cpp
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/SineReader.h"
+
+#include <cmath>
+
+AUD_NAMESPACE_BEGIN
+
+SineReader::SineReader(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_position(0),
+ m_sampleRate(sampleRate)
+{
+}
+
+void SineReader::setFrequency(float frequency)
+{
+ m_frequency = frequency;
+}
+
+bool SineReader::isSeekable() const
+{
+ return true;
+}
+
+void SineReader::seek(int position)
+{
+ m_position = position;
+}
+
+int SineReader::getLength() const
+{
+ return -1;
+}
+
+int SineReader::getPosition() const
+{
+ return m_position;
+}
+
+Specs SineReader::getSpecs() const
+{
+ Specs specs;
+ specs.rate = m_sampleRate;
+ specs.channels = CHANNELS_MONO;
+ return specs;
+}
+
+void SineReader::read(int& length, bool& eos, sample_t* buffer)
+{
+ // fill with sine data
+ for(int i = 0; i < length; i++)
+ {
+ buffer[i] = std::sin((m_position + i) * 2 * M_PI * m_frequency / m_sampleRate);
+ }
+
+ m_position += length;
+ eos = false;
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/Square.cpp b/extern/audaspace/src/generator/Square.cpp
new file mode 100644
index 00000000000..361c243c549
--- /dev/null
+++ b/extern/audaspace/src/generator/Square.cpp
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/Square.h"
+#include "generator/SquareReader.h"
+
+AUD_NAMESPACE_BEGIN
+
+Square::Square(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_sampleRate(sampleRate)
+{
+}
+
+float Square::getFrequency() const
+{
+ return m_frequency;
+}
+
+std::shared_ptr<IReader> Square::createReader()
+{
+ return std::shared_ptr<IReader>(new SquareReader(m_frequency, m_sampleRate));
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/SquareReader.cpp b/extern/audaspace/src/generator/SquareReader.cpp
new file mode 100644
index 00000000000..8f49b097487
--- /dev/null
+++ b/extern/audaspace/src/generator/SquareReader.cpp
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/SquareReader.h"
+
+#include <cmath>
+
+AUD_NAMESPACE_BEGIN
+
+SquareReader::SquareReader(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_position(0),
+ m_sample(0),
+ m_sampleRate(sampleRate)
+{
+}
+
+void SquareReader::setFrequency(float frequency)
+{
+ m_frequency = frequency;
+}
+
+bool SquareReader::isSeekable() const
+{
+ return true;
+}
+
+void SquareReader::seek(int position)
+{
+ m_position = position;
+ m_sample = std::fmod(m_position * m_frequency / (float)m_sampleRate, 2.0f);
+}
+
+int SquareReader::getLength() const
+{
+ return -1;
+}
+
+int SquareReader::getPosition() const
+{
+ return m_position;
+}
+
+Specs SquareReader::getSpecs() const
+{
+ Specs specs;
+ specs.rate = m_sampleRate;
+ specs.channels = CHANNELS_MONO;
+ return specs;
+}
+
+void SquareReader::read(int& length, bool& eos, sample_t* buffer)
+{
+ float k = 2.0 * m_frequency / m_sampleRate;
+
+ for(int i = 0; i < length; i++)
+ {
+ m_sample += k;
+
+ if(m_sample >= 2.0f)
+ m_sample = std::fmod(m_sample, 2.0f);
+
+ buffer[i] = (m_sample < 1.0f) * 2.0f - 1.0f;
+ }
+
+ m_position += length;
+ eos = false;
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/Triangle.cpp b/extern/audaspace/src/generator/Triangle.cpp
new file mode 100644
index 00000000000..ca8f1b63fb9
--- /dev/null
+++ b/extern/audaspace/src/generator/Triangle.cpp
@@ -0,0 +1,38 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/Triangle.h"
+#include "generator/TriangleReader.h"
+
+AUD_NAMESPACE_BEGIN
+
+Triangle::Triangle(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_sampleRate(sampleRate)
+{
+}
+
+float Triangle::getFrequency() const
+{
+ return m_frequency;
+}
+
+std::shared_ptr<IReader> Triangle::createReader()
+{
+ return std::shared_ptr<IReader>(new TriangleReader(m_frequency, m_sampleRate));
+}
+
+AUD_NAMESPACE_END
diff --git a/extern/audaspace/src/generator/TriangleReader.cpp b/extern/audaspace/src/generator/TriangleReader.cpp
new file mode 100644
index 00000000000..c363d3850ca
--- /dev/null
+++ b/extern/audaspace/src/generator/TriangleReader.cpp
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright 2009-2016 Jörg Müller
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+
+#include "generator/TriangleReader.h"
+
+#include <cmath>
+
+AUD_NAMESPACE_BEGIN
+
+TriangleReader::TriangleReader(float frequency, SampleRate sampleRate) :
+ m_frequency(frequency),
+ m_position(0),
+ m_sample(0.5f),
+ m_sampleRate(sampleRate)
+{
+}
+
+void TriangleReader::setFrequency(float frequency)
+{
+ m_frequency = frequency;
+}
+
+bool TriangleReader::isSeekable() const
+{
+ return true;
+}
+
+void TriangleReader::seek(int position)
+{
+ m_position = position;
+ m_sample = std::fmod(m_position * m_frequency / (float)m_sampleRate + 1.5f, 2.0f) - 1.0f;
+}
+
+int TriangleReader::getLength() const
+{
+ return -1;
+}
+
+int TriangleReader::getPosition() const
+{
+ return m_position;
+}
+
+Specs TriangleReader::getSpecs() const
+{
+ Specs specs;
+ specs.rate = m_sampleRate;
+ specs.channels = CHANNELS_MONO;
+ return specs;
+}
+
+void TriangleReader::read(int& length, bool& eos, sample_t* buffer)
+{
+ float k = 2.0 * m_frequency / m_sampleRate;
+
+ for(int i = 0; i < length; i++)
+ {
+ m_sample += k;
+
+ if(m_sample >= 1.0f)
+ m_sample -= std::floor(m_sample) + 1.0f;
+
+ buffer[i] = std::fabs(m_sample) * 2.0f - 1.0f;
+ }
+
+ m_position += length;
+ eos = false;
+}
+
+AUD_NAMESPACE_END