1 /*
2 Copyright (C) 2010 The Exult team
3 
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18 #ifndef OggAudioSample_H
19 #define OggAudioSample_H
20 
21 #include "AudioSample.h"
22 #include <vorbis/vorbisfile.h>
23 #include <memory>
24 
25 namespace Pentagram {
26 
27 // FIXME - OggAudioSample doesn't support playing the same sample on more than
28 // one channel at the same time. Its really intended only for music playing
29 // support
30 
31 class OggAudioSample : public AudioSample
32 {
33 public:
34 	OggAudioSample(std::unique_ptr<IDataSource> oggdata);
35 	OggAudioSample(std::unique_ptr<uint8[]> buffer, uint32 size);
36 
37 	void initDecompressor(void *DecompData) const override;
38 	uint32 decompressFrame(void *DecompData, void *samples) const override;
39 	void freeDecompressor(void *DecompData) const override;
40 
41 	static ov_callbacks callbacks;
42 
43 	static size_t read_func  (void *ptr, size_t size, size_t nmemb, void *datasource);
44 	static int    seek_func  (void *datasource, ogg_int64_t offset, int whence);
45     static long   tell_func  (void *datasource);
46 
47 	static bool   isThis(IDataSource *oggdata);
48 
49 protected:
50 
51 	struct OggDecompData {
52 		OggVorbis_File	ov;
53 		int bitstream;
54 		int last_rate;
55 		bool last_stereo;
56 		IDataSource *datasource;
57 		bool freed;
58 	};
59 
60 	std::unique_ptr<IDataSource> oggdata;
61 	mutable bool locked;
62 };
63 
64 }
65 
66 #endif
67