Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Is your source correct?  (Read 2694 times)

0 Members and 1 Guest are viewing this topic.

cheeseboy

  • Guest
Is your source correct?
« 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) {} ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Is your source correct?
« Reply #1 on: September 17, 2011, 02:08:20 pm »
No, they are pure virtual, they must be implemented in derived classes. There's no default behaviour.
Laurent Gomila - SFML developer

cheeseboy

  • Guest
Is your source correct?
« Reply #2 on: September 17, 2011, 02:26:01 pm »
Code: [Select]
// 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

Quote
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?

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Is your source correct?
« Reply #3 on: September 17, 2011, 04:15:52 pm »
Quote from: "the error"
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.
SFML / OS X developer