3 This file is part of libmspal
4 Copyright © 2008 Mikko Rasa, Mikkosoft Productions
5 Diestributed under the LGPL
8 #include <msp/core/except.h>
28 void Sound::open(const string &fn)
30 if(ov_fopen(const_cast<char *>(fn.c_str()), &ovfile)<0)
31 throw Exception("Could not open ogg vorbis file "+fn);
33 vorbis_info *info=ov_info(&ovfile, -1);
35 switch(info->channels)
37 case 1: format=MONO16; break;
38 case 2: format=STEREO16; break;
39 default: throw Exception("Unsupported number of channels");
43 void Sound::load_data()
46 throw InvalidState("Data has already been loaded");
48 size=ov_pcm_total(&ovfile, 0)*4;
51 while(unsigned len=read(data+pos, size-pos))
56 void Sound::load(const string &fn)
62 const char *Sound::get_data() const
65 throw InvalidState("Data has not been loaded");
69 unsigned Sound::read(char *buf, unsigned len)
72 int res=ov_read(&ovfile, buf, len, 0, 2, 1, §ion);
74 throw Exception("Error reading ogg vorbis file");