Blender V2.61 - r43446

AUD_SndFileReader.h

Go to the documentation of this file.
00001 /*
00002  * ***** BEGIN GPL LICENSE BLOCK *****
00003  *
00004  * Copyright 2009-2011 Jörg Hermann Müller
00005  *
00006  * This file is part of AudaSpace.
00007  *
00008  * Audaspace is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version.
00012  *
00013  * AudaSpace is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  * GNU General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with Audaspace; if not, write to the Free Software Foundation,
00020  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00021  *
00022  * ***** END GPL LICENSE BLOCK *****
00023  */
00024 
00030 #ifndef AUD_SNDFILEREADER
00031 #define AUD_SNDFILEREADER
00032 
00033 #include "AUD_IReader.h"
00034 #include "AUD_Reference.h"
00035 #include "AUD_Buffer.h"
00036 
00037 #include <string>
00038 #include <sndfile.h>
00039 
00040 typedef sf_count_t (*sf_read_f)(SNDFILE *sndfile, void *ptr, sf_count_t frames);
00041 
00045 class AUD_SndFileReader : public AUD_IReader
00046 {
00047 private:
00051     int m_position;
00052 
00056     int m_length;
00057 
00061     bool m_seekable;
00062 
00066     AUD_Specs m_specs;
00067 
00071     SNDFILE* m_sndfile;
00072 
00076     SF_VIRTUAL_IO m_vio;
00077 
00081     AUD_Reference<AUD_Buffer> m_membuffer;
00082 
00086     int m_memoffset;
00087 
00088     // Functions for libsndfile virtual IO functionality
00089     static sf_count_t vio_get_filelen(void *user_data);
00090     static sf_count_t vio_seek(sf_count_t offset, int whence, void *user_data);
00091     static sf_count_t vio_read(void *ptr, sf_count_t count, void *user_data);
00092     static sf_count_t vio_tell(void *user_data);
00093 
00094     // hide copy constructor and operator=
00095     AUD_SndFileReader(const AUD_SndFileReader&);
00096     AUD_SndFileReader& operator=(const AUD_SndFileReader&);
00097 
00098 public:
00105     AUD_SndFileReader(std::string filename);
00106 
00113     AUD_SndFileReader(AUD_Reference<AUD_Buffer> buffer);
00114 
00118     virtual ~AUD_SndFileReader();
00119 
00120     virtual bool isSeekable() const;
00121     virtual void seek(int position);
00122     virtual int getLength() const;
00123     virtual int getPosition() const;
00124     virtual AUD_Specs getSpecs() const;
00125     virtual void read(int& length, bool& eos, sample_t* buffer);
00126 };
00127 
00128 #endif //AUD_SNDFILEREADER