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

Author Topic: Enhanced Music Control  (Read 20597 times)

0 Members and 1 Guest are viewing this topic.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: Enhanced Music Control
« Reply #30 on: October 30, 2014, 02:29:36 pm »
still no loop points available?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Enhanced Music Control
« Reply #31 on: October 30, 2014, 05:43:48 pm »
No.
Laurent Gomila - SFML developer

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Enhanced Music Control
« Reply #32 on: November 22, 2014, 07:24:21 pm »
This has been a long-time issue for me with SFML and I always seem to have to create my own workaround for it.

As Ryan Bram previously mentioned, this problem can be resolved with zero interface changes merely by pulling the loop information out of the audio file metadata.

libsndfile already provides the ability to extract some metadata.  While I was unable to extract the exact "LOOPSTART" and "LOOPLENGTH" metadata fields that he mentioned using libsndfile, I was able to extract similar strings by putting them in the "comments" field of the audio file.

Personally, I think a LOOPLENGTH identifier is pointless, since it just adds more complication when you can just use EOF.  All we really need is a LOOPSTART.

The key for the change is in the SoundFile class.  All this class has to do is:

1)  In SoundFile::initialize:  Extract a loop start point from the sound file metadata (start point should be a sample offset for maximum precision and not a time offset)
2)  In SoundFile::read: Once EOF is reached, merely seek the file back to the loop point (if specified)


Both of these steps require minimal code changes (maybe 10-15 lines), do not really impact larger design issues, and do not require any interface changes.  The only externally visible change you'd need is to the documentation to make note of the feature.


I've made a similar change in my local copy of SFML 2.0 and it works great.  I'd be okay with applying the change (after cleaning it up) to the latest SFML bulid... but only if it's going to be welcome.



So what do you guys think?



EDIT:

Laurent mentioned this on the first page:

Quote
Using specific metadata is not an option, since SFML supports many standard audio formats.

This is why I suggest extracting text from the 'comments' field.  This is generic enough to be common across all audio formats.  And the functionality for reading this metadata is already in libsndfile.
« Last Edit: November 22, 2014, 07:26:39 pm by Disch »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Enhanced Music Control
« Reply #33 on: November 22, 2014, 08:29:57 pm »
I think you should base any suggestion and/or local change on the feature/no_libsndfile branch. With this branch I think you can do what you want without modifying SFML (until we integrate something directly to the public API).
Laurent Gomila - SFML developer

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Enhanced Music Control
« Reply #34 on: November 22, 2014, 09:46:45 pm »
Hrm... without libsndfile this becomes a lot trickier... since metadata now has to be read from each file type individually.  Which means creating a private interface for reading metadata.

Still no way to do this without modifying SFML that I can see.  To ensure music can be looped properly without breaks in the audio, the change has to be made where the audio data is supplied.

In this branch the most logical place for the change seems to be in Music::onGetData, with a pure virtual addition to SoundFileReader to obtain metadata.  How that metadata function would look is a mystery to me, though.  I'm not familiar enough with the specifics of each individual file format to build a common interface.

Guess I'll stick with my custom 2.0 build for now, and possibly will look into this in the future.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Enhanced Music Control
« Reply #35 on: November 22, 2014, 11:13:51 pm »
I thought that the most important thing was to implement loops. If your concern is to read metadata, then yes, you'll still have to modify SFML (but since we don't rely on libsndfile anymore, we now have total control on what we do with metadata).

Wouldn't implementing loops with manual definition be an acceptable solution for you?
Laurent Gomila - SFML developer

Disch

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Enhanced Music Control
« Reply #36 on: November 23, 2014, 12:20:16 am »
Quote
Wouldn't implementing loops with manual definition be an acceptable solution for you?

Grah, yeah that would work just fine.  I guess I just had a one-track mind where I was trying to get my previous solution to work in the new setup.

Can this be done with the no_libsndfile branch as it is now?  It doesn't look like it to me.  I see a looping option in SoundStream, but it always loops from the start of the file.  I guess we could add a new 'setLoopPoint' function or something to SoundStream.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Enhanced Music Control
« Reply #37 on: November 23, 2014, 11:24:53 am »
You'd have to write your own class, similar to sf::Music. Since sf::InputSoundFile is now public, you can easily implement loop points there.
Laurent Gomila - SFML developer