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

Author Topic: sf::Music loop point implementation problem  (Read 2881 times)

0 Members and 1 Guest are viewing this topic.

greenshoe

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
sf::Music loop point implementation problem
« on: August 31, 2013, 03:29:35 pm »
Hi,

I've been trying to implement loop points by overriding onGetData and onSeek virtual functions of sf::Music. Long story short, something is wrong.

It seems, whenever I can hear the loop fail the following has been printed in my console window (2ish seconds earlier):

Quote
An internal OpenAL call failed in SoundStream.cpp (327) : AL_INVALID_VALUE, a numeric argument is out of range

I've tried my best to compose a minimal and complete example. I'm hoping one of you guys can help me point out what I'm doing wrong here. I'm using Visual Studio 2012 32-bit on Windows 7.

In my code, begin by scrolling down to the main() function (last function in the main.cpp file). I've written a few comments there on tests I've tried out. Here are the files:

http://www.greenshoe-magic.net/main.cpp
http://www.greenshoe-magic.net/smartguy.wav

« Last Edit: August 31, 2013, 03:35:29 pm by greenshoe »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: sf::Music loop point implementation problem
« Reply #1 on: August 31, 2013, 08:21:04 pm »
You might want to explain what your code is actually for, so people don't have to crunch through it to understand what it does. ;)

Also void main() is not valid and std::exception(const char*) seems to not exist on my end...
You should also avoid the C-prefix for classes (just Google quickly for the reasons).

As for the issue, I see it as well, but I haven't tried to understand what to code does (no much time). :-\
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

greenshoe

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Music loop point implementation problem
« Reply #2 on: August 31, 2013, 09:33:03 pm »
As mentioned in my first post, I'm trying to override sf::Music to support music loop points. The term loop points are usually used in music composing software (eg. Propellerhead Reason). A lot of games also have this feature. Say for instance that you have a song that has an intro and a main theme. In some cases, to create a little extra dynamic flow, you only want to play the intro once, then repeat the main theme over and over (eg. until either you or the boss dies). There are a lot of songs that start out weak and fragile, but picks up and turns into a steady rock and roll beat;D It would certainly be a mood killer if, in the midst of battle, when all the rage is built up and the song simply restarted playing the fragile beginning. Loop points solves this problem since you can have the part with intensity repeated and the intro only played once. Back in 2010, a user requested this be added to the sf::Music class:

http://en.sfml-dev.org/forums/index.php?topic=2957.0

As far as I can see, this feature hasn't been added yet. However, Laurent suggested it could be implemented using the code in this post:

http://en.sfml-dev.org/forums/index.php?topic=2957.msg19539#msg19539

As you can see, that's nearly the same code as what I currently have. I pretty much copy-pasted the whole of that code, but changed the variable names.

greenshoe

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: sf::Music loop point implementation problem
« Reply #3 on: August 31, 2013, 10:18:02 pm »
I think I've found the reason why it's not working.

In onGetData, when i change data.sampleCount, I do not take into consideration that onGetData expects a sample count that is in accordance with the channel count of the song. I made a dirty quick fix and it worked like a charm:

Code: [Select]
while (data.sampleCount % this->getChannelCount() != 0)
{
    data.sampleCount++;
}

I'll need to get back to fixing the underlying problem though lol. Thanks for the help eXpl0it3r.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: sf::Music loop point implementation problem
« Reply #4 on: August 31, 2013, 11:27:39 pm »
Thanks for the help eXpl0it3r.
Didn't really do anything, but you're welcome! :P
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything