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

Author Topic: write an audio file in small chunks  (Read 5191 times)

0 Members and 1 Guest are viewing this topic.

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
write an audio file in small chunks
« on: October 17, 2010, 03:11:38 am »
Is it possible to write audio file in small chunks? For example, if I want to record an audio stream into a file. But when I just want to write in an existing file, it seems SFML overwrites it. Thanks in advance :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
write an audio file in small chunks
« Reply #1 on: October 17, 2010, 10:45:52 am »
This is not possible. Can't you store the file content in a buffer, and write it when you have received everything?
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
write an audio file in small chunks
« Reply #2 on: October 17, 2010, 02:11:32 pm »
Das ist very strange... now it magically started to work. This is what I hate about programming... sometimes the constellation of stars is the only explanation to how the programs are working... >.<

But still, I think that would be a good idea. Let's assume I want to save an audio data so huge that it cannot fit into memory. As in my program it could happen easily. I think it would be a good idea to support this, but I don't know how hard would it be, or how much design change would it need. What is you opinion?

[EDIT] I have an additional question: I created a music. When I play it in the program, with SFML (just by producing samples for SoundStream), it sounds very clear. Then I export the samples in a .wav file, or in an .ogg file, and play it with a eternal music player, the sound becomes noisy. Good to know: my program works with samples in the range -1.0f to 1.0f, and then before playing or rendering it, multiplies them with 32768.0f, then casts to sf::Int16. So It is near the border to be clipped down. I think that causes the crispy sounding in the files. But why does than SFML plays it nicely? Any tips?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
write an audio file in small chunks
« Reply #3 on: October 17, 2010, 06:25:56 pm »
I don't think it can be implemented easily, and it would require major API modifications anyway. Sorry ;)
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
write an audio file in small chunks
« Reply #4 on: October 17, 2010, 07:52:06 pm »
If I think about it.... that isn't a thing a game programming library should be able to do :D Well, since this thing works without it (at the moment, the stars are in align :D), it's no problem. (As I'm browsing the source, it looks like you are already saving to the file in chunks, though :P It doesn't seem to be a very hard thing to hack such function on my own, if I need one :))

Thanks all the help, and keep up the good work, Laurent ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
write an audio file in small chunks
« Reply #5 on: October 17, 2010, 08:57:34 pm »
Quote
As I'm browsing the source, it looks like you are already saving to the file in chunks, though

True, in fact it would be very easy to implement. Sorry my last answer was totally wrong :lol:

But it would still require major design modifications. Maybe this will be possible in SFML 2, I'm thinking about making the sf::SoundFile class public.
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
write an audio file in small chunks
« Reply #6 on: October 17, 2010, 10:00:11 pm »
Quote from: "Laurent"
True, in fact it would be very easy to implement. Sorry my last answer was totally wrong :lol: But it would still require major design modifications.

So in fact you were half right :D

Quote from: "Laurent"
Maybe this will be possible in SFML 2, I'm thinking about making the sf::SoundFile class public.

As people used to say: hope dies last. Anyway, you made me curious about what you will do to the audio core :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
write an audio file in small chunks
« Reply #7 on: October 17, 2010, 11:02:24 pm »
Quote
As people used to say: hope dies last. Anyway, you made me curious about what you will do to the audio core

Basically the audio API won't change much, I'm just thinking about a solution for giving more flexibility, especially regarding sf::Music usage. So either with more options built-in, or by making the sf::SoundFile public so that users can implement their own custom sf::SoundStream to replace sf::Music.
Laurent Gomila - SFML developer

nulloid

  • Full Member
  • ***
  • Posts: 134
    • View Profile
write an audio file in small chunks
« Reply #8 on: October 17, 2010, 11:31:35 pm »
*humbly votes for the second solution... isn't a big fan of built-in things... :)*

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
write an audio file in small chunks
« Reply #9 on: October 17, 2010, 11:37:47 pm »
Yep, I also prefer providing enough building blocks so that users can do whatever they need, rather than implementing more specific options directly into SFML. But sometimes this is not possible.
Laurent Gomila - SFML developer