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

Author Topic: [SOLVED]Trouble loading audio from memory.  (Read 4557 times)

0 Members and 1 Guest are viewing this topic.

EFDos

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
[SOLVED]Trouble loading audio from memory.
« on: March 05, 2014, 09:31:28 am »
Hello all, I've been using sfml for the development of a game, and I've been loving it so far (API Design, Documentation, ease of use, everything).

But now I've ran into the first big problem which I really can't find out how to solve, and I really hope somebody can help me with this. So let me start explaining:

On this point of the development we've decide to design our own binary file format to store resources - sounds and images used to just lay around - and make the game read and load resources from our files.

It works perfectly with images, but with sounds - music specifically - I get this error:

Quote
Failed to open sound file from memory (Supported file format but file is malformed.)

What I do is, I find the ogg music inside the file, load it to a buffer - as I understand, a soundstream needs it's source to be kept in memory for access - and tell sf::Music to load it with openFromMemory(), and that's where I get the error.

Important notes:
- The original ogg music files did play inside the game, when we were using openFromFile()
- I do not believe the music data can be messed up inside our file. I use the same process for Images - which works inside the game - and I even extracted a music file back -by the same means I use to load it into the game- to test. I can load and play this extracted file inside the game with openFromFile(), just like the original file. I even did a checksum on it with the original file, and they did match. So I really don't get why openFromMemory() can't load and play it.
-I haven't tested with non-stream sounds yet, don't know if I'd get a different result. I'll update this when I test.

I'm really sorry if my english is monstrously bad, and thanks in advance  :)
« Last Edit: March 06, 2014, 05:00:20 am by EFDos »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Trouble loading audio from memory.
« Reply #1 on: March 05, 2014, 10:10:30 am »
So this is clearly about how you access the music data in your binary file. You should show us the corresponding code.
Laurent Gomila - SFML developer

kimci86

  • Full Member
  • ***
  • Posts: 128
    • View Profile
Re: Trouble loading audio from memory.
« Reply #2 on: March 05, 2014, 07:50:55 pm »
Hello,

In your getMusic function,
Quote
if(musicBuffer[i])
{
    /* initialize */
}

Didn't you mean this ?
if(!musicBuffer[i])
(notice the negation '!')

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Trouble loading audio from memory.
« Reply #3 on: March 05, 2014, 09:18:28 pm »
size_t getMusicSize(short int id)
   {
      int i;
      for(i=0 ; i<n_files_music ; i++)
      {
         if(musicIndexes.ID == id)
            break;
      }
      return (size_t)musicIndexes.length;
   }
So if I pass in an invalid 'id' I have no way to detect that and I just get the size of the last music - doesn't seem very robust to me...

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: [SOLVED]Trouble loading audio from memory.
« Reply #4 on: March 07, 2014, 10:41:31 am »
In general, your code is very error-prone, because low-level.

Why don't you use proper abstraction mechanisms such as STL containers and strings? That would also avoid your memory leaks. Furthermore, in the places where you really need raw byte interpretation, use reinterpret_cast to make that clear -- not C casts.
« Last Edit: March 07, 2014, 10:43:33 am by Nexus »
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything