4 * ***** BEGIN LGPL LICENSE BLOCK *****
6 * Copyright 2009 Jörg Hermann Müller
8 * This file is part of AudaSpace.
10 * AudaSpace is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * AudaSpace is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with AudaSpace. If not, see <http://www.gnu.org/licenses/>.
23 * ***** END LGPL LICENSE BLOCK *****
26 #ifndef AUD_SNDFILEREADER
27 #define AUD_SNDFILEREADER
29 #include "AUD_IReader.h"
30 #include "AUD_Reference.h"
35 typedef sf_count_t (*sf_read_f)(SNDFILE *sndfile, void *ptr, sf_count_t frames);
38 * This class reads a sound file via libsndfile.
40 class AUD_SndFileReader : public AUD_IReader
44 * The current position in samples.
49 * The sample count in the file.
54 * Whether the file is seekable.
59 * The specification of the audio data.
64 * The playback buffer.
74 * The reading function.
79 * The virtual IO structure for memory file reading.
84 * The pointer to the memory file.
86 AUD_Reference<AUD_Buffer> m_membuffer;
89 * The current reading pointer of the memory file.
93 // Functions for libsndfile virtual IO functionality
94 static sf_count_t vio_get_filelen(void *user_data);
95 static sf_count_t vio_seek(sf_count_t offset, int whence, void *user_data);
96 static sf_count_t vio_read(void *ptr, sf_count_t count, void *user_data);
97 static sf_count_t vio_tell(void *user_data);
101 * Creates a new reader.
102 * \param filename The path to the file to be read.
103 * \exception AUD_Exception Thrown if the file specified does not exist or
104 * cannot be read with libsndfile.
106 AUD_SndFileReader(const char* filename);
109 * Creates a new reader.
110 * \param buffer The buffer to read from.
111 * \exception AUD_Exception Thrown if the buffer specified cannot be read
114 AUD_SndFileReader(AUD_Reference<AUD_Buffer> buffer);
117 * Destroys the reader and closes the file.
119 virtual ~AUD_SndFileReader();
121 virtual bool isSeekable();
122 virtual void seek(int position);
123 virtual int getLength();
124 virtual int getPosition();
125 virtual AUD_Specs getSpecs();
126 virtual AUD_ReaderType getType();
127 virtual bool notify(AUD_Message &message);
128 virtual void read(int & length, sample_t* & buffer);
131 #endif //AUD_SNDFILEREADER