SFML community forums
Help => Audio => Topic started by: cheeseboy on September 17, 2011, 12:49:00 pm
-
In SoundStream.hpp
Shoudn't virtual bool OnGetData(Chunk& data) = 0; be virtual bool OnGetData(Chunk& data) {return 0;} and virtual void OnSeek(Uint32 timeOffset) = 0; be virtual void OnSeek(Uint32 timeOffset) {} ?
-
No, they are pure virtual, they must be implemented in derived classes. There's no default behaviour.
-
// A modified SFML SoundStream class
#include <SFML/Audio.hpp>
#include <iostream>
#include "emuStream.h"
emuStream::emuStream()
{
emu = NULL;
gme_err_t err = gme_open_file("testing.nsf",&emu,44100);
number_of_tracks = gme_track_count(emu);
c_track = 0;
gme_start_track(emu,c_track);
Initialize(2,44100);
}
emuStream::emuStream(std::string fname)
{
emu = NULL;
gme_err_t err = gme_open_file(fname.c_str(),&emu,44100);
std::cout << err;
// You may want to add exception handling for the returned error.
number_of_tracks = gme_track_count(emu);
c_track = 0;
gme_start_track(emu,c_track);
Initialize(2,44100);
}
bool emuStream::OnOpen()
{
return true;
}
int emuStream::GetTracks()
{
return gme_track_count(emu);
}
void emuStream::SetTrack(int track)
{
if(track <= number_of_tracks-1)
{
gme_start_track(emu,track);
c_track = track;
}
}
void emuStream::NextTrack()
{
if(c_track < number_of_tracks - 1)
{
c_track += 1;
}
gme_start_track(emu,c_track);
}
bool emuStream::OnGetData(Chunk& Data)
{
short int *sndsample = NULL;
sndsample = (short int*)malloc(sizeof(short int*)*buffer_size);
if(!sndsample)
{
return false;
}
if(gme_track_ended(emu))
{
if(c_track < number_of_tracks - 1)
{
c_track += 1;
}
gme_start_track(emu,c_track);
}
gme_err_t err = gme_play(emu,buffer_size,&sndsample[0]);
Data.Samples = sndsample;
Data.NbSamples = buffer_size;
return true;
}
emuStream::~emuStream()
{
gme_delete(emu);
}
errors with
SFML.cpp: In function ‘double gmeInit(const char*)’:
SFML.cpp:83:35: error: cannot allocate an object of abstract type ‘emuStream’
emuStream.h:10:7: note: because the following virtual functions are pure within ‘emuStream’:
/usr/include/SFML/Audio/SoundStream.hpp:238:18: note: virtual void sf::SoundStream::OnSeek(sf::Uint32)
SFML.cpp: In function ‘double gmeLoad(const char*)’:
SFML.cpp:99:35: error: cannot allocate an object of abstract type ‘emuStream’
emuStream.h:10:7: note: since type ‘emuStream’ has pure virtual functions
make[2]: *** [.eobjs/Linux/Linux/Run/SFML.o] Error 1
make[2]: Leaving directory `/home/greg/Dropbox/Public/GM Stuff/enigma-dev/ENIGMAsystem/SHELL/Audio_Systems/SFML'
make[1]: *** [build] Error 2
make[1]: Leaving directory `/home/greg/Dropbox/Public/GM Stuff/enigma-dev/ENIGMAsystem/SHELL'
make: *** [Game] Error 2
How do I fix it?
-
error: cannot allocate an object of abstract type ‘emuStream’ because the following virtual functions are pure within ‘emuStream’: virtual void sf::SoundStream::OnSeek(sf::Uint32)
This means you have to define OnSeek in your custom SoundStream class.