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

Author Topic: SFML and 8/16-Bit Music?  (Read 11287 times)

0 Members and 1 Guest are viewing this topic.

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
SFML and 8/16-Bit Music?
« on: September 21, 2010, 09:59:01 pm »
Hello, everybody :]

Now that I've gotten SFML's audio abilities to work, I'm somewhat at a loss as to how I can get started making and using my own 8-bit and 16-bit music for games I will make in the future. Is it possible to use that style of music in SFML? I'm assuming I would need midi or some other format. I can imagine how to get it working with .wav and other types of standard audio formats, but those aren't going for the space-saving and programmability that I would like to be using. Essentially, I suppose you could say I'd like to have a programmable sort of music in my games, perhaps using just plain source code, which I've read is how it used to be done, since there was only so much space on game media formats in the past.

Any links, advice, tips, or help of any kind would be greatly appreciated. :] Thank you in advance.

Colton
Whether you think you can or you can't, you're right.

Maxamor

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML and 8/16-Bit Music?
« Reply #1 on: November 21, 2010, 02:23:27 am »
I'm looking to do the same thing myself. I'm drawn to the idea of making some glue between blargg's NES audio library and SFML. I haven't worked on it yet, but if I figure it out I'll post it :).

Edit: My thoughts are that it may be possible using sf::SoundStream.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML and 8/16-Bit Music?
« Reply #2 on: November 21, 2010, 10:38:53 am »
Can you explain me what "8-bit and 16-bit music" is exactly? What does it look like?
Laurent Gomila - SFML developer

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
SFML and 8/16-Bit Music?
« Reply #3 on: November 21, 2010, 01:58:42 pm »
I assume he means music in the style of 8 and 16 bit video game consoles.

The easiest solution is probably just to render your songs to an audio file (like ogg vorbis). You should be able to get away with some pretty low bitrates (to save space) with 8 bit style music.

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
SFML and 8/16-Bit Music?
« Reply #4 on: December 15, 2010, 07:57:34 am »
8-bit music and 16-bit music were just references to the 8-bit and 16-bit platforms that used those types of music. I don't really know what technology the music itself was referred to beneath... probably had more to do with a sampling rate than that. But from what I know and what I've learned, the sound effects were pretty much just digital, primitive sound waves with some effects or contortions applied to them (sine, sawtooth, square, etc.). I'm not familiar with the SoundBuffer class from the SFML library to know whether it can do that or not... I'm sure Laurent or someone of much more expertise than me could say so :] But I read something about creating a custom SoundBuffer object just with an array of samples. I don't know if this would achieve the desired effect, and I haven't the slightest clue how to go about trying to use that feature.

But I have found an easy alternative to use in the meantime, and it's a program called sfxr that generates 8-bit sound effects for you with various parameters that you can manipulate and randomize and then export in a .wav format. I believe they make a port for both Mac and Windows, and I use the Mac port. If anyone wants a clearer idea of what I'm referring to, including Laurent if you wish to consider implementing something like this within the next release of SFML (but in a programmable sense), then here's the link that will take you to the site, and it's a free application:

http://www.drpetter.se/project_sfxr.html

I don't know whether simply using the .wav-exported versions of these sound effects or actually programmed sound effects would be faster at runtime. I don't know enough about that to make a judgment. Perhaps y'all might know? :]
Whether you think you can or you can't, you're right.

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
SFML and 8/16-Bit Music?
« Reply #5 on: December 26, 2010, 04:25:35 am »
No, you can't do that with SFML. Not directly, anyway.

You see, old systems, like the C64, had a built-in synthesizer, which modern systems do not.

It made sense back then, since developers could be sure everyone would have the exact same hardware, and thus get the same experience.
Besides, the older systems simply didn't have the resources to play audio the way they do today. Just 1 minute of 16 bit 44.1 KHz mono music is about 5.05 MB data, which would be an enormous amount on a system such as the C64, which had only 64 KB RAM, or an Amiga 500, which had 512 KB.

To achieve what you are asking for, I would advise you to create the music with one or more software synthesizers in a sequencer program, such as Reaper (http://www.reaper.fm/), or look into tracker programs.

Noegddgeon

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
    • Soundcloud
SFML and 8/16-Bit Music?
« Reply #6 on: December 26, 2010, 05:00:19 am »
I see. I have a bunch of tools to make music.... I have Ableton Live, Aria Maestosa, Audacity... so making .wavs isn't a problem at all. And Aria Maestosa exports from its native MIDI format to .wav, and the files are quite small. So this suits my needs for now, I suppose, though it would be nice to have a MIDI extension to read them and play them.... seems like it would help take memory management to the hole nubba level. ;]

Thank you for the information :] I hope MIDI functionality gets added to SFML in the future.
Whether you think you can or you can't, you're right.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
SFML and 8/16-Bit Music?
« Reply #7 on: December 26, 2010, 06:36:34 am »
If you dig through the forums you'll find a guy that got libmodplug (library for playing common tracker formats) working alongside/with/through normal sfml-audio. MIDI should be just as easy (hard?), provided the right lib for it.

You should probably be able to use libmodplug with sfml sound buffer sample thingy, otherwise you may be able to use openAL yourself (not sure if this is allowed, while something else is also using it). I believe the LOVE engine uses libmodplug so there would be some working code there also.

This is actually a feature I have wanted for a while - I'm off to play around myself!

Anyway, if you use rendered audio - at least compress your wavs with FLAC (I'm pretty sure FLAC is supported) to get the size down considerably with no loss or hi hats that sound like 6 slightly out of phase flangers battling each other.

model76

  • Full Member
  • ***
  • Posts: 231
    • View Profile
SFML and 8/16-Bit Music?
« Reply #8 on: December 26, 2010, 10:13:21 pm »
I see SFML MIDI file support as a major problem.

As MIDI doesn't contain any sound information, what sounds should SFML play? The OS's default wavetable? What if it doesn't have one? If it does, what standard does it adhere to? GM? Or maybe GS? What happens if the user has non-standard settings?

Even if Laurent manages to find a solution, it still leaves the developer with the problem that the end-user experience is entirely dependent on the system setup, and can't even be approximated.

I my opinion, if SFML was to support MIDI, it should do so on a much deeper level. A way that would allow developers to use the MIDI signals any way they like, for playing samples or otherwise.
I believe this kind of midi support would be a major selling point for SFML, where the other kind would mostly just work to confuse people.

For simpler music support, I too think some tracker format support would work a lot better, because those actually contain the audio data, along with a set of MIDI-like commands. At least that is how I understand tracker files. I haven't worked with them that much, though.

As for compressed audio formats, FLAC is great, FLAC is loss-less, but you really should try working with OGG as well. While it isn't loss-less, it does sound a whole lot better than MP3, and is even slightly smaller in size. For a good compressor, search the net for "OggDropXPD".

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
SFML and 8/16-Bit Music?
« Reply #9 on: December 27, 2010, 04:13:50 am »
Yeah I guess MIDI does have a lot of issues actually although your solution seems quite viable.

Yes, module/tracker files can be considered similar to MIDI but they do carry their own samples. This doesn't remove any possibility of trouble though - some mods can use effects that are applied by the player - different players may sound different to each other. This shouldn't be an issue if SFML were to support mods though as you would be making music for the same player that you end up distributing to the end user.

Maxamor

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML and 8/16-Bit Music?
« Reply #10 on: January 04, 2011, 04:16:47 am »
I wanted to follow up about emulating NSF files. I was able to implement my own sf::SoundStream which plays NSF files by emulating the NES APU using blargg's audio library. I didn't implement all of the methods found in SoundStream, but my implementation is complete enough to load files and play the audio tracks.

If you're interested maybe this is something I could post in the wiki?

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
SFML and 8/16-Bit Music?
« Reply #11 on: January 06, 2011, 10:08:11 am »
I'd certainly be interested in seeing how you did it. :)

Maxamor

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML and 8/16-Bit Music?
« Reply #12 on: January 07, 2011, 08:31:58 am »
Here are the source and header:

NSFSoundStream.hpp
NSFSoundStream.cpp

It uses some header-only things from boost, namely scoped_array and scoped_ptr. You'll need them to compile it without modification.

It also relies on the source files from blargg's Game_Music_Emu.

There really isn't a lot to it -- you use the emulator to fill the audio buffer in OnGetData, and then point to the chunk to the freshly-filled buffer. This class is essentially an adaptation of the "cpp_basics.cpp" file that comes with Game_Music_Emu into an sf::SoundStream. I never finished implementing everything, but there are enough things implemented to play the music tracks and get the voice names from an NSF file.

Zcool31

  • Newbie
  • *
  • Posts: 13
    • View Profile
SFML and 8/16-Bit Music?
« Reply #13 on: January 08, 2011, 04:20:39 pm »
I have a question that is not completely unrelated. What I am trying to accomplish is to create a FM Synthesizer using SFML's SoundStream. I had assumed that I could simply implement the SoundStream's OnGetData function to simply generate the next some number of samples in the sound. Knowing that internally, SoundStream keeps three chunks ahead, I assumed that I could keep the chunk size small to counteract the latency. I know that if I use chunks of 300-700 in VSTHost, I can get low latency with no stuttering. However, when I tried this in SoundStream, I got massive stuttering with about 1/4 second delay between chunks.

The smallest chunk size I could get to work on my machine was about 4000 samples, or 1/10 of a second.

I find this difficult to believe as I know that my system can generate the signal much faster than this. Most of the delay comes from the SFML component.

Is there a good way for me to eliminate this delay? Would it be possible for me to use SFML's OpenAL to this effect? Any help would be appreciated.

Maxamor

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML and 8/16-Bit Music?
« Reply #14 on: January 10, 2011, 05:54:24 pm »
When using my NSFSoundStream I use a buffer size of 4096. This is the only time I've ever dealt with SFML audio/SoundStream so I couldn't tell you much more than that. :(

 

anything