1
Audio / Multiscope sound access
« on: May 19, 2015, 01:44:15 pm »
I would like to know if there is a way to access an instance of sf::sound or sf::music in a scope different than where it is declared and/or loaded? Eg declare a sound in main() but play() it in another function or vice versa?
The code below gives me errors on sm.play() ("undeclared identifier" and "left of '.play' must have class/struct/union")
Also, I imagine it's not possible but correct me if I'm wrong: I can't use a variable when setting up audio to play, eg when calling sf::Sound x, can I?
The code below gives me errors on sm.play() ("undeclared identifier" and "left of '.play' must have class/struct/union")
void playwilhelm(int i=1000)
{
sm.play();
cout << "\nScream should be played now\n";
Sleep(i);
cout << "\nEnd Scream\n";
}
int main()
{
sf::SoundBuffer wilhelm;
wilhelm.loadFromFile("music\\wilhelm scream.wav");
sf::Sound sm;
sm.setBuffer(wilhelm);
sm.setVolume(50);
playwilhelm (2000);
{
sm.play();
cout << "\nScream should be played now\n";
Sleep(i);
cout << "\nEnd Scream\n";
}
int main()
{
sf::SoundBuffer wilhelm;
wilhelm.loadFromFile("music\\wilhelm scream.wav");
sf::Sound sm;
sm.setBuffer(wilhelm);
sm.setVolume(50);
playwilhelm (2000);
Also, I imagine it's not possible but correct me if I'm wrong: I can't use a variable when setting up audio to play, eg when calling sf::Sound x, can I?