hi,
I'm trying to load & play ogg and flac files. I wrote a class that uses sf::Music to load & play the files.
Although it seems to load them & even play them, I can't hear anything... Yes I have the volume turned up, and the device turned on
I have two different audio devices: my video card's hdmi output, and the internal sound card, which I use. I can play sounds with sf::Sound & sf::SoundBuffer, but not music. I'm on kUbuntu 11.10 64 bit, and using the latest SFML snapshot.
here's the code:
#ifndef sound_stream_h
#define sound_stream_h
#include "common.h"
class sound_stream
{
private:
sf::Music samples;
bool loaded;
protected:
public:
void load(std::string filename);
void play();
void pause();
void stop();
int get_duration();
void set_loop(bool loop);
void set_pitch(float pitch);
void set_volume(float volume);
sound_stream() : loaded(false) {}
};
#endif
#include "sound_stream.h"
#include "objs.h"
void sound_stream::load(std::string filename)
{
std::cout << "-Loading: " << filename << "\n";
timer sound_timer;
sound_timer.set_timerbegin();
std::string full_path = objs::get()->conf.app_path + filename;
if (objs::get()->file_exists(full_path))
{
if (samples.OpenFromFile(full_path))
{
loaded = true;
std::cout << " Loaded in: " << sound_timer.get_time_passed() / 1000.0f << " seconds\n";
}
else
{
loaded = false;
std::cerr << "Error loading sound stream file: " << filename << "\n";
}
}
else
{
loaded = false;
std::cerr << "Error loading sound stream file: " << filename << "\n";
}
}
void sound_stream::play()
{
if (!loaded)
{
return;
}
samples.Play();
}
void sound_stream::pause()
{
if (!loaded)
{
return;
}
samples.Pause();
}
void sound_stream::stop()
{
if (!loaded)
{
return;
}
samples.Stop();
}
int sound_stream::get_duration()
{
if (!loaded)
{
return -1;
}
return samples.GetDuration();
}
void sound_stream::set_loop(bool loop)
{
if (!loaded)
{
return;
}
samples.SetLoop(loop);
}
void sound_stream::set_pitch(float pitch)
{
if (!loaded)
{
return;
}
samples.SetPitch(pitch);
}
void sound_stream::set_volume(float volume)
{
if (!loaded)
{
return;
}
if (volume >= 0.0f && volume <= 100.0f)
{
samples.SetVolume(volume);
}
}
and I use it like this:
sound_stream test;
test.load("resources/test.flac");
test.play();
any idea what might be going wrong?
Best regards,
Yours3!f