diff options
Diffstat (limited to 'intern/audaspace/sndfile')
-rw-r--r-- | intern/audaspace/sndfile/AUD_SndFileFactory.cpp | 52 | ||||
-rw-r--r-- | intern/audaspace/sndfile/AUD_SndFileFactory.h | 76 | ||||
-rw-r--r-- | intern/audaspace/sndfile/AUD_SndFileReader.cpp | 171 | ||||
-rw-r--r-- | intern/audaspace/sndfile/AUD_SndFileReader.h | 128 | ||||
-rw-r--r-- | intern/audaspace/sndfile/AUD_SndFileWriter.cpp | 139 | ||||
-rw-r--r-- | intern/audaspace/sndfile/AUD_SndFileWriter.h | 86 |
6 files changed, 0 insertions, 652 deletions
diff --git a/intern/audaspace/sndfile/AUD_SndFileFactory.cpp b/intern/audaspace/sndfile/AUD_SndFileFactory.cpp deleted file mode 100644 index 106b2937a06..00000000000 --- a/intern/audaspace/sndfile/AUD_SndFileFactory.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * Copyright 2009-2011 Jörg Hermann Müller - * - * This file is part of AudaSpace. - * - * Audaspace is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * AudaSpace is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Audaspace; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file audaspace/sndfile/AUD_SndFileFactory.cpp - * \ingroup audsndfile - */ - - -#include "AUD_SndFileFactory.h" -#include "AUD_SndFileReader.h" - -#include <cstring> - -AUD_SndFileFactory::AUD_SndFileFactory(std::string filename) : - m_filename(filename) -{ -} - -AUD_SndFileFactory::AUD_SndFileFactory(const data_t* buffer, int size) : - m_buffer(new AUD_Buffer(size)) -{ - memcpy(m_buffer->getBuffer(), buffer, size); -} - -boost::shared_ptr<AUD_IReader> AUD_SndFileFactory::createReader() -{ - if(m_buffer.get()) - return boost::shared_ptr<AUD_IReader>(new AUD_SndFileReader(m_buffer)); - else - return boost::shared_ptr<AUD_IReader>(new AUD_SndFileReader(m_filename)); -} diff --git a/intern/audaspace/sndfile/AUD_SndFileFactory.h b/intern/audaspace/sndfile/AUD_SndFileFactory.h deleted file mode 100644 index bc96325d6eb..00000000000 --- a/intern/audaspace/sndfile/AUD_SndFileFactory.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * Copyright 2009-2011 Jörg Hermann Müller - * - * This file is part of AudaSpace. - * - * Audaspace is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * AudaSpace is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Audaspace; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file audaspace/sndfile/AUD_SndFileFactory.h - * \ingroup audsndfile - */ - - -#ifndef __AUD_SNDFILEFACTORY_H__ -#define __AUD_SNDFILEFACTORY_H__ - -#include "AUD_IFactory.h" -#include "AUD_Buffer.h" - -#include <string> -#include <boost/shared_ptr.hpp> - -/** - * This factory reads a sound file via libsndfile. - */ -class AUD_SndFileFactory : public AUD_IFactory -{ -private: - /** - * The filename of the sound source file. - */ - std::string m_filename; - - /** - * The buffer to read from. - */ - boost::shared_ptr<AUD_Buffer> m_buffer; - - // hide copy constructor and operator= - AUD_SndFileFactory(const AUD_SndFileFactory&); - AUD_SndFileFactory& operator=(const AUD_SndFileFactory&); - -public: - /** - * Creates a new factory. - * \param filename The sound file path. - */ - AUD_SndFileFactory(std::string filename); - - /** - * Creates a new factory. - * \param buffer The buffer to read from. - * \param size The size of the buffer. - */ - AUD_SndFileFactory(const data_t* buffer, int size); - - virtual boost::shared_ptr<AUD_IReader> createReader(); -}; - -#endif //__AUD_SNDFILEFACTORY_H__ diff --git a/intern/audaspace/sndfile/AUD_SndFileReader.cpp b/intern/audaspace/sndfile/AUD_SndFileReader.cpp deleted file mode 100644 index aaee814f56b..00000000000 --- a/intern/audaspace/sndfile/AUD_SndFileReader.cpp +++ /dev/null @@ -1,171 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * Copyright 2009-2011 Jörg Hermann Müller - * - * This file is part of AudaSpace. - * - * Audaspace is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * AudaSpace is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Audaspace; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file audaspace/sndfile/AUD_SndFileReader.cpp - * \ingroup audsndfile - */ - - -#include "AUD_SndFileReader.h" - -#include <cstring> - -sf_count_t AUD_SndFileReader::vio_get_filelen(void *user_data) -{ - AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; - return reader->m_membuffer->getSize(); -} - -sf_count_t AUD_SndFileReader::vio_seek(sf_count_t offset, int whence, - void *user_data) -{ - AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; - - switch(whence) - { - case SEEK_SET: - reader->m_memoffset = offset; - break; - case SEEK_CUR: - reader->m_memoffset = reader->m_memoffset + offset; - break; - case SEEK_END: - reader->m_memoffset = reader->m_membuffer->getSize() + offset; - break; - } - - return reader->m_memoffset; -} - -sf_count_t AUD_SndFileReader::vio_read(void *ptr, sf_count_t count, - void *user_data) -{ - AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; - - if(reader->m_memoffset + count > reader->m_membuffer->getSize()) - count = reader->m_membuffer->getSize() - reader->m_memoffset; - - memcpy(ptr, ((data_t*)reader->m_membuffer->getBuffer()) + - reader->m_memoffset, count); - reader->m_memoffset += count; - - return count; -} - -sf_count_t AUD_SndFileReader::vio_tell(void *user_data) -{ - AUD_SndFileReader* reader = (AUD_SndFileReader*)user_data; - - return reader->m_memoffset; -} - -static const char* fileopen_error = "AUD_SndFileReader: File couldn't be " - "read."; - -AUD_SndFileReader::AUD_SndFileReader(std::string filename) : - m_position(0) -{ - SF_INFO sfinfo; - - sfinfo.format = 0; - m_sndfile = sf_open(filename.c_str(), SFM_READ, &sfinfo); - - if(!m_sndfile) - AUD_THROW(AUD_ERROR_FILE, fileopen_error); - - m_specs.channels = (AUD_Channels) sfinfo.channels; - m_specs.rate = (AUD_SampleRate) sfinfo.samplerate; - m_length = sfinfo.frames; - m_seekable = sfinfo.seekable; -} - -AUD_SndFileReader::AUD_SndFileReader(boost::shared_ptr<AUD_Buffer> buffer) : - m_position(0), - m_membuffer(buffer), - m_memoffset(0) -{ - m_vio.get_filelen = vio_get_filelen; - m_vio.read = vio_read; - m_vio.seek = vio_seek; - m_vio.tell = vio_tell; - m_vio.write = NULL; - - SF_INFO sfinfo; - - sfinfo.format = 0; - m_sndfile = sf_open_virtual(&m_vio, SFM_READ, &sfinfo, this); - - if(!m_sndfile) - AUD_THROW(AUD_ERROR_FILE, fileopen_error); - - m_specs.channels = (AUD_Channels) sfinfo.channels; - m_specs.rate = (AUD_SampleRate) sfinfo.samplerate; - m_length = sfinfo.frames; - m_seekable = sfinfo.seekable; -} - -AUD_SndFileReader::~AUD_SndFileReader() -{ - sf_close(m_sndfile); -} - -bool AUD_SndFileReader::isSeekable() const -{ - return m_seekable; -} - -void AUD_SndFileReader::seek(int position) -{ - if(m_seekable) - { - position = sf_seek(m_sndfile, position, SEEK_SET); - m_position = position; - } -} - -int AUD_SndFileReader::getLength() const -{ - return m_length; -} - -int AUD_SndFileReader::getPosition() const -{ - return m_position; -} - -AUD_Specs AUD_SndFileReader::getSpecs() const -{ - return m_specs; -} - -void AUD_SndFileReader::read(int& length, bool& eos, sample_t* buffer) -{ - int olen = length; - - length = sf_readf_float(m_sndfile, buffer, length); - - m_position += length; - - eos = length < olen; -} diff --git a/intern/audaspace/sndfile/AUD_SndFileReader.h b/intern/audaspace/sndfile/AUD_SndFileReader.h deleted file mode 100644 index 5cac5051ee2..00000000000 --- a/intern/audaspace/sndfile/AUD_SndFileReader.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * Copyright 2009-2011 Jörg Hermann Müller - * - * This file is part of AudaSpace. - * - * Audaspace is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * AudaSpace is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Audaspace; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file audaspace/sndfile/AUD_SndFileReader.h - * \ingroup audsndfile - */ - - -#ifndef __AUD_SNDFILEREADER_H__ -#define __AUD_SNDFILEREADER_H__ - -#include "AUD_IReader.h" -#include "AUD_Buffer.h" - -#include <string> -#include <sndfile.h> -#include <boost/shared_ptr.hpp> - -typedef sf_count_t (*sf_read_f)(SNDFILE *sndfile, void *ptr, sf_count_t frames); - -/** - * This class reads a sound file via libsndfile. - */ -class AUD_SndFileReader : public AUD_IReader -{ -private: - /** - * The current position in samples. - */ - int m_position; - - /** - * The sample count in the file. - */ - int m_length; - - /** - * Whether the file is seekable. - */ - bool m_seekable; - - /** - * The specification of the audio data. - */ - AUD_Specs m_specs; - - /** - * The sndfile. - */ - SNDFILE* m_sndfile; - - /** - * The virtual IO structure for memory file reading. - */ - SF_VIRTUAL_IO m_vio; - - /** - * The pointer to the memory file. - */ - boost::shared_ptr<AUD_Buffer> m_membuffer; - - /** - * The current reading pointer of the memory file. - */ - int m_memoffset; - - // Functions for libsndfile virtual IO functionality - static sf_count_t vio_get_filelen(void *user_data); - static sf_count_t vio_seek(sf_count_t offset, int whence, void *user_data); - static sf_count_t vio_read(void *ptr, sf_count_t count, void *user_data); - static sf_count_t vio_tell(void *user_data); - - // hide copy constructor and operator= - AUD_SndFileReader(const AUD_SndFileReader&); - AUD_SndFileReader& operator=(const AUD_SndFileReader&); - -public: - /** - * Creates a new reader. - * \param filename The path to the file to be read. - * \exception AUD_Exception Thrown if the file specified does not exist or - * cannot be read with libsndfile. - */ - AUD_SndFileReader(std::string filename); - - /** - * Creates a new reader. - * \param buffer The buffer to read from. - * \exception AUD_Exception Thrown if the buffer specified cannot be read - * with libsndfile. - */ - AUD_SndFileReader(boost::shared_ptr<AUD_Buffer> buffer); - - /** - * Destroys the reader and closes the file. - */ - virtual ~AUD_SndFileReader(); - - virtual bool isSeekable() const; - virtual void seek(int position); - virtual int getLength() const; - virtual int getPosition() const; - virtual AUD_Specs getSpecs() const; - virtual void read(int& length, bool& eos, sample_t* buffer); -}; - -#endif //__AUD_SNDFILEREADER_H__ diff --git a/intern/audaspace/sndfile/AUD_SndFileWriter.cpp b/intern/audaspace/sndfile/AUD_SndFileWriter.cpp deleted file mode 100644 index da3464751cb..00000000000 --- a/intern/audaspace/sndfile/AUD_SndFileWriter.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * Copyright 2009-2011 Jörg Hermann Müller - * - * This file is part of AudaSpace. - * - * Audaspace is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * AudaSpace is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Audaspace; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file audaspace/sndfile/AUD_SndFileWriter.cpp - * \ingroup audsndfile - */ - - -#include "AUD_SndFileWriter.h" - -#include <cstring> - -static const char* fileopen_error = "AUD_SndFileWriter: File couldn't be written."; -static const char* format_error = "AUD_SndFileWriter: Unsupported format."; - -AUD_SndFileWriter::AUD_SndFileWriter(std::string filename, AUD_DeviceSpecs specs, - AUD_Container format, AUD_Codec codec, unsigned int bitrate) : - m_specs(specs) -{ - SF_INFO sfinfo; - - sfinfo.channels = specs.channels; - sfinfo.samplerate = int(specs.rate); - - switch(format) - { - case AUD_CONTAINER_FLAC: - sfinfo.format = SF_FORMAT_FLAC; - switch(specs.format) - { - case AUD_FORMAT_S16: - sfinfo.format |= SF_FORMAT_PCM_16; - break; - case AUD_FORMAT_S24: - sfinfo.format |= SF_FORMAT_PCM_24; - break; - case AUD_FORMAT_S32: - sfinfo.format |= SF_FORMAT_PCM_32; - break; - case AUD_FORMAT_FLOAT32: - sfinfo.format |= SF_FORMAT_FLOAT; - break; - case AUD_FORMAT_FLOAT64: - sfinfo.format |= SF_FORMAT_DOUBLE; - break; - default: - sfinfo.format = 0; - break; - } - break; - case AUD_CONTAINER_OGG: - if(codec == AUD_CODEC_VORBIS) - sfinfo.format = SF_FORMAT_OGG | SF_FORMAT_VORBIS; - else - sfinfo.format = 0; - break; - case AUD_CONTAINER_WAV: - sfinfo.format = SF_FORMAT_WAV; - switch(specs.format) - { - case AUD_FORMAT_U8: - sfinfo.format |= SF_FORMAT_PCM_U8; - break; - case AUD_FORMAT_S16: - sfinfo.format |= SF_FORMAT_PCM_16; - break; - case AUD_FORMAT_S24: - sfinfo.format |= SF_FORMAT_PCM_24; - break; - case AUD_FORMAT_S32: - sfinfo.format |= SF_FORMAT_PCM_32; - break; - case AUD_FORMAT_FLOAT32: - sfinfo.format |= SF_FORMAT_FLOAT; - break; - case AUD_FORMAT_FLOAT64: - sfinfo.format |= SF_FORMAT_DOUBLE; - break; - default: - sfinfo.format = 0; - break; - } - break; - default: - sfinfo.format = 0; - break; - } - - if(sfinfo.format == 0) - AUD_THROW(AUD_ERROR_SPECS, format_error); - - m_sndfile = sf_open(filename.c_str(), SFM_WRITE, &sfinfo); - - if(!m_sndfile) - AUD_THROW(AUD_ERROR_FILE, fileopen_error); -} - -AUD_SndFileWriter::~AUD_SndFileWriter() -{ - sf_close(m_sndfile); -} - -int AUD_SndFileWriter::getPosition() const -{ - return m_position; -} - -AUD_DeviceSpecs AUD_SndFileWriter::getSpecs() const -{ - return m_specs; -} - -void AUD_SndFileWriter::write(unsigned int length, sample_t* buffer) -{ - length = sf_writef_float(m_sndfile, buffer, length); - - m_position += length; -} diff --git a/intern/audaspace/sndfile/AUD_SndFileWriter.h b/intern/audaspace/sndfile/AUD_SndFileWriter.h deleted file mode 100644 index 0cadbd19a09..00000000000 --- a/intern/audaspace/sndfile/AUD_SndFileWriter.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * ***** BEGIN GPL LICENSE BLOCK ***** - * - * Copyright 2009-2011 Jörg Hermann Müller - * - * This file is part of AudaSpace. - * - * Audaspace is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * AudaSpace is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Audaspace; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file audaspace/sndfile/AUD_SndFileWriter.h - * \ingroup audsndfile - */ - - -#ifndef __AUD_SNDFILEWRITER_H__ -#define __AUD_SNDFILEWRITER_H__ - -#include "AUD_IWriter.h" - -#include <string> -#include <sndfile.h> - -/** - * This class writes a sound file via libsndfile. - */ -class AUD_SndFileWriter : public AUD_IWriter -{ -private: - /** - * The current position in samples. - */ - int m_position; - - /** - * The specification of the audio data. - */ - AUD_DeviceSpecs m_specs; - - /** - * The sndfile. - */ - SNDFILE* m_sndfile; - - // hide copy constructor and operator= - AUD_SndFileWriter(const AUD_SndFileWriter&); - AUD_SndFileWriter& operator=(const AUD_SndFileWriter&); - -public: - /** - * Creates a new writer. - * \param filename The path to the file to be read. - * \param specs The file's audio specification. - * \param format The file's container format. - * \param codec The codec used for encoding the audio data. - * \param bitrate The bitrate for encoding. - * \exception AUD_Exception Thrown if the file specified cannot be written - * with libsndfile. - */ - AUD_SndFileWriter(std::string filename, AUD_DeviceSpecs specs, AUD_Container format, AUD_Codec codec, unsigned int bitrate); - - /** - * Destroys the writer and closes the file. - */ - virtual ~AUD_SndFileWriter(); - - virtual int getPosition() const; - virtual AUD_DeviceSpecs getSpecs() const; - virtual void write(unsigned int length, sample_t* buffer); -}; - -#endif //__AUD_SNDFILEWRITER_H__ |