- close();
-}
-
-void SoundDecoder::open_file(const string &fn)
-{
- if(ovfile.datasource)
- throw logic_error("Sound has already been opened");
-
- IO::BufferedFile *file = new IO::BufferedFile(fn);
- if(ov_open_callbacks(file, &ovfile, 0, 0, io_callbacks)<0)
- {
- delete file;
- throw runtime_error("Could not open ogg vorbis file "+fn);
- }
- source = file;
-
- open_common();
-}
-
-void SoundDecoder::open_io(Msp::IO::Seekable &io)
-{
- if(ovfile.datasource)
- throw logic_error("Sound has already been opened");
-
- if(ov_open_callbacks(&io, &ovfile, 0, 0, io_callbacks)<0)
- throw runtime_error("Could not open ogg vorbis resource");
-
- open_common();
-}
-
-void SoundDecoder::open_common()
-{
- vorbis_info *info = ov_info(&ovfile, -1);
- freq = info->rate;
-
- size = ov_pcm_total(&ovfile, 0)*info->channels*2;
-
- switch(info->channels)
- {
- case 1: format = MONO16; break;
- case 2: format = STEREO16; break;
- default: throw runtime_error("Unsupported number of channels");
- }
-}
-
-void SoundDecoder::close()
-{
- if(ovfile.datasource)
- ov_clear(&ovfile);