diff options
author | Jörg Müller <nexyon@gmail.com> | 2017-08-18 09:24:12 +0300 |
---|---|---|
committer | Jörg Müller <nexyon@gmail.com> | 2017-08-18 09:24:12 +0300 |
commit | 986267300ba42a5c99d2802cd701803dd558e389 (patch) | |
tree | 9bf6a84f8e3ebb8d01e5617b1cccfd2693cc1345 /extern/audaspace/src/file | |
parent | d0dad0260434c4420fa9756264c1cc5e745e5ec9 (diff) |
Audaspace: Moving audaspace 1.3 into extern.
Deleting the old internal audaspace.
Major changes from there are:
- The whole library was refactored to use C++11.
- Many stability and performance improvements.
- Major Python API refactor:
- Most requested: Play self generated sounds using numpy arrays.
- For games: Sound list, random sounds and dynamic music.
- Writing sounds to files.
- Sequencing API.
- Opening sound devices, eg. Jack.
- Ability to choose different OpenAL devices in the user settings.
Diffstat (limited to 'extern/audaspace/src/file')
-rw-r--r-- | extern/audaspace/src/file/File.cpp | 45 | ||||
-rw-r--r-- | extern/audaspace/src/file/FileManager.cpp | 88 | ||||
-rw-r--r-- | extern/audaspace/src/file/FileWriter.cpp | 95 |
3 files changed, 228 insertions, 0 deletions
diff --git a/extern/audaspace/src/file/File.cpp b/extern/audaspace/src/file/File.cpp new file mode 100644 index 00000000000..0cdecb03657 --- /dev/null +++ b/extern/audaspace/src/file/File.cpp @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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 "file/File.h" +#include "file/FileManager.h" +#include "util/Buffer.h" +#include "Exception.h" + +#include <cstring> + +AUD_NAMESPACE_BEGIN + +File::File(std::string filename) : + m_filename(filename) +{ +} + +File::File(const data_t* buffer, int size) : + m_buffer(new Buffer(size)) +{ + std::memcpy(m_buffer->getBuffer(), buffer, size); +} + +std::shared_ptr<IReader> File::createReader() +{ + if(m_buffer.get()) + return FileManager::createReader(m_buffer); + else + return FileManager::createReader(m_filename); +} + +AUD_NAMESPACE_END diff --git a/extern/audaspace/src/file/FileManager.cpp b/extern/audaspace/src/file/FileManager.cpp new file mode 100644 index 00000000000..f8ef8deb409 --- /dev/null +++ b/extern/audaspace/src/file/FileManager.cpp @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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 "file/FileManager.h" +#include "file/IFileInput.h" +#include "file/IFileOutput.h" +#include "Exception.h" + +AUD_NAMESPACE_BEGIN + +std::list<std::shared_ptr<IFileInput>>& FileManager::inputs() +{ + static std::list<std::shared_ptr<IFileInput>> inputs; + return inputs; +} + +std::list<std::shared_ptr<IFileOutput>>& FileManager::outputs() +{ + static std::list<std::shared_ptr<IFileOutput>> outputs; + return outputs; +} + +void FileManager::registerInput(std::shared_ptr<IFileInput> input) +{ + inputs().push_back(input); +} + +void FileManager::registerOutput(std::shared_ptr<aud::IFileOutput> output) +{ + outputs().push_back(output); +} + +std::shared_ptr<IReader> FileManager::createReader(std::string filename) +{ + for(std::shared_ptr<IFileInput> input : inputs()) + { + try + { + return input->createReader(filename); + } + catch(Exception&) {} + } + + AUD_THROW(FileException, "The file couldn't be read with any installed file reader."); +} + +std::shared_ptr<IReader> FileManager::createReader(std::shared_ptr<Buffer> buffer) +{ + for(std::shared_ptr<IFileInput> input : inputs()) + { + try + { + return input->createReader(buffer); + } + catch(Exception&) {} + } + + AUD_THROW(FileException, "The file couldn't be read with any installed file reader."); +} + +std::shared_ptr<IWriter> FileManager::createWriter(std::string filename, DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate) +{ + for(std::shared_ptr<IFileOutput> output : outputs()) + { + try + { + return output->createWriter(filename, specs, format, codec, bitrate); + } + catch(Exception&) {} + } + + AUD_THROW(FileException, "The file couldn't be written with any installed writer."); +} + +AUD_NAMESPACE_END diff --git a/extern/audaspace/src/file/FileWriter.cpp b/extern/audaspace/src/file/FileWriter.cpp new file mode 100644 index 00000000000..a6bb0f0049a --- /dev/null +++ b/extern/audaspace/src/file/FileWriter.cpp @@ -0,0 +1,95 @@ +/******************************************************************************* + * 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 "file/FileWriter.h" +#include "file/FileManager.h" +#include "util/Buffer.h" +#include "IReader.h" +#include "Exception.h" + +AUD_NAMESPACE_BEGIN + +std::shared_ptr<IWriter> FileWriter::createWriter(std::string filename,DeviceSpecs specs, Container format, Codec codec, unsigned int bitrate) +{ + return FileManager::createWriter(filename, specs, format, codec, bitrate); +} + +void FileWriter::writeReader(std::shared_ptr<IReader> reader, std::shared_ptr<IWriter> writer, unsigned int length, unsigned int buffersize) +{ + Buffer buffer(buffersize * AUD_SAMPLE_SIZE(writer->getSpecs())); + sample_t* buf = buffer.getBuffer(); + + int len; + bool eos = false; + int channels = writer->getSpecs().channels; + + for(unsigned int pos = 0; ((pos < length) || (length <= 0)) && !eos; pos += len) + { + len = buffersize; + if((len > length - pos) && (length > 0)) + len = length - pos; + reader->read(len, eos, buf); + + for(int i = 0; i < len * channels; i++) + { + // clamping! + if(buf[i] > 1) + buf[i] = 1; + else if(buf[i] < -1) + buf[i] = -1; + } + + writer->write(len, buf); + } +} + +void FileWriter::writeReader(std::shared_ptr<IReader> reader, std::vector<std::shared_ptr<IWriter> >& writers, unsigned int length, unsigned int buffersize) +{ + Buffer buffer(buffersize * AUD_SAMPLE_SIZE(reader->getSpecs())); + Buffer buffer2(buffersize * sizeof(sample_t)); + sample_t* buf = buffer.getBuffer(); + sample_t* buf2 = buffer2.getBuffer(); + + int len; + bool eos = false; + int channels = reader->getSpecs().channels; + + for(unsigned int pos = 0; ((pos < length) || (length <= 0)) && !eos; pos += len) + { + len = buffersize; + if((len > length - pos) && (length > 0)) + len = length - pos; + reader->read(len, eos, buf); + + for(int channel = 0; channel < channels; channel++) + { + for(int i = 0; i < len; i++) + { + // clamping! + if(buf[i * channels + channel] > 1) + buf2[i] = 1; + else if(buf[i * channels + channel] < -1) + buf2[i] = -1; + else + buf2[i] = buf[i * channels + channel]; + } + + writers[channel]->write(len, buf2); + } + } +} + +AUD_NAMESPACE_END |