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

Author Topic: [C++] (1.5) Using loop points in sf::Music  (Read 4555 times)

0 Members and 1 Guest are viewing this topic.

__fastcall

  • Newbie
  • *
  • Posts: 8
    • View Profile
[C++] (1.5) Using loop points in sf::Music
« on: October 08, 2009, 01:36:40 am »
This is what I came up with:

Code: [Select]

#include <SFML/Audio.hpp>
#include <iostream>
#include <string>

void LoopedMusicDelegate( void* ptr );

class LoopedMusic : public sf::Thread {
private:
sf::Music mBeginningMusic;
sf::Music mLoopingMusic;

public:
LoopedMusic( const std::string& beginFilename, const std::string& loopFilename )
: sf::Thread( LoopedMusicDelegate, this )
{
// Ignore errors for now
mBeginningMusic.OpenFromFile( beginFilename );
mLoopingMusic.OpenFromFile( loopFilename );

mLoopingMusic.SetLoop( true );
}


void Play() {
mBeginningMusic.Play();
Launch();  // Run thread
}

// TODO:
// Add Stop() 'n' stuff...

private:
friend void LoopedMusicDelegate( void* );

void Run() {
while ( mBeginningMusic.GetStatus() != sf::Music::Stopped )
;
mLoopingMusic.Play();
}
};

void LoopedMusicDelegate( void* ptr ) {
reinterpret_cast<LoopedMusic*>( ptr )->Run();
}



int main() {
LoopedMusic m( "SampleMusicIntro.wav", "SampleMusicLoop.wav" );

m.Play();

// Wait for user input:
std::cin.get();
}


Basically it waits until the introduction music finishes playing and then plays the looping music.  Sometimes the introductions of some of the sample music can be anywhere from one second to six seconds.  This works for a handful of the musics I have separated, unfortunately for a few, there's a distinct pause between the end of the intro music and the beginning of the looping music.  I have double checked the SampleMusic*.wav files and there are no pauses and they transfer smoothly in a media player.

Any ideas?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[C++] (1.5) Using loop points in sf::Music
« Reply #1 on: October 08, 2009, 08:49:34 am »
Hi

First, you're doing a wrong usage of sf::Thread. You inherit from it but then you use it with a non-member function. Read the tutorial again ;)

Regarding your solution, it clearly wastes CPU. But unfortunately this problem would be solved efficiently only if I add direct support for it in SFML.
Laurent Gomila - SFML developer

 

anything