[Solved] Using BGameSound's SetGain()

Hi there!

Can anybody help me with the usage of BGameSound (and its derived BFileGameSound)? I’d like to mute a sound and think that’s done by using SetGain(0). But for some reason, the played back sound is always the same volume, no matter what’s the gain set to.

I tried with a little test app:

#include <FileGameSound.h>
#include <stdio.h>

	BFileGameSound* player = new BFileGameSound("/boot/home/_test.wav", false);

	if (player->InitCheck() != B_OK)
		return 1;


		printf("0) Gain() = %f\n", player->Gain());

	snooze(1000000 * 3); // wait 3 sec

		printf("1.1) Gain set to 0.0 (Gain() = %f)\n", player->Gain());
		printf("1.2) Gain() = %f\n", player->Gain());

	snooze(1000000 * 3); // wait 3 sec

		printf("2.1) Gain set to 1 (Gain() = %f)\n", player->Gain());
		printf("2.2) Gain() = %f\n", player->Gain());

	snooze(1000000 * 3); // wait 3 sec

	return 0;

The output is:

0) Gain() = 1.000000
1.1) Gain set to 0.0 (Gain() = 0.000000)
1.2) Gain() = 0.000000
2.1) Gain set to 1 (Gain() = 1.000000)
2.2) Gain() = 1.000000

So the gain get set alright, but the playback volume is unaffected. Any ideas what goes wrong?

The gain is implemented only for 2-channel (stereo) files and ignored for mono, see this FIXME in the code: GameSoundBuffer.cpp « game « kits « src - haiku - Haiku's main repository

So, did you try with a stereo file?

1 Like

Thanks, I indeed used mono files. Tried with a stereo music file and that did work (though a crash when doing StartPlaying() the second time). No matter, can’t use it anyway if it’s only doing stereo.

You can convert the mono files to (pseudo) stereo with our wonderful ffmpegGUI, or like I did (as I’m ashamed to say) by using ffmpeg on the commandline :wink:

I could. But I don’t want to limit my little app to stereo files. :slight_smile:

GameKit’s audio capabilities are too limiting anyway, and if I continue developing it, I may have to open that scary can of worms I fear the MediaKit will turn out to be for this dabbler…

I see. I was assuming that it was for a game. May I ask what kind of app it is?

The app will be called “Samedi”, a little app to load audio samples into up to 8 pads and assign them to MIDI notes. The samples can then be played back by pressing the set key on your MIDI keyboard.

The above is from the ReadMe included with the app, which I wrote in less time than I have been bumbling around Icon-O-Matic failing yet to make an icon… :slight_smile:

1 Like




I wonder what can be done as an icon for it…



Travolta, nice… :grin:

I chose the name “Samedi” as a tortured wordplay of “sample” and “MIDI”. I tried to have 4 pads of my totally underused AKAI MPK mini MIDI controller and maybe a sort of sound wave above it as icon. But I can’t make it work…

This is the AKAI btw:


@Handmaus : completely different association with samedi here. Baron Samedi from James Bond: Live and let die :slight_smile:

1 Like

If you need some help just let me know. I´m always interested in combining programming and music. Though not very experienced in audio programming, so far I only wrote a simple tone generator on top of libao.

1 Like

Oh, didn’t knew this one, never seen the movie. Did a quick image search, very powerful looks for a villain.
But I don’t see how it can relate to a musical app, I still think Tony Manero represents better the concept.
Anyway, too late, the icon is already done.

@humdinger where’s the repository to do a pull request?


Thanks, it’s very probable I’ll have to take you up on that… :slight_smile:
But first I’ll release this first simple version, after a quick round of translations at Polyglot. Will announce that in that other thread momentarily.

Brilliant! :joy:
Unfortunately a bit too large for an icon… :slight_smile:

Thanks! :smiley:
Was tempted to include also a mirrors ball.
THAT would have been brilliant! :stuck_out_tongue_winking_eye:

Ahhh… boredom while working to pay the bills has unexpected effects on the mind… :melting_face:

Also tried to iterate a bit more seriously on your idea, with the soundwave and a “condensed” edition of the Akai. It still has way too much detail though, needs work.
What elements would you take off?

Samedi icon 256px 01
Samedi icon 64px 01

1 Like

To start, I’d drop brand and buttons labels, replace glowing buttons by coloured buttons and make the big red button shape simpler.

1 Like

You are obviously so much better than me at creating graphics and icons!
I made the MidiSynth icon, which could be a starting point:


That icon, too, could probably be much improved, esp. being less sloppy at large sizes. DiskProbe reveals the amateurish details of my crimes…

The soundwave may be better visible when more compressed. Here a bad example:


1 Like

Just to add: I first envisioned not having the whole keyboard for the icon, but only 4 of the 8 pads, because those would be the main input for the app. Should also be easier to design just those 4 pads on a simple chassis.

1 Like

Great, in the meantime I’ve started porting my tone generator to Haiku to learn about the Media Kit. Steep learning curve but not impossible :wink:


No way! :sweat_smile:
All this previous sketches are just fast’n’loose photoshop trickery with photos from the web, I do things like this on a daily basis at work, don’t get fooled by it

To everyone that may be reading this,That’s a genuinely good Haiku icon, with all the hard work to synthesize forms that work at the small sizes needed, that has real merit. I think that not much people know the hours and hours of trial and error that every one of this little f*{+rs can take.
Simplicity is hard!

By the way, thanks for that, if going this route, that’s a lot of hours that I don’t have to spend doing keys

I said “if going this route” because you mention later that this app will only make use of the pads. But not the keys?
What’s the potential future of this app, will it evolve as something more featureful, or will it be kept just for padboards?
A family of this little modular apps working in conjunction will be a thing worth seeing. It will be very familiar to the ways of working i have seen that musicians have, with all the pedals, filters, pads and the like.
With Cortex as an interconnection hub.
Stack’n’Tile could act as a sort of pedalboard to hold it all toghether, but then we need to resurrect that project that was floating around sometime ago to save and retrieve Stack’n’Tile configurations.
That, or make everything replicatable and do a sort of “boards” system feature that lets you span empty windows in wich to embed replicants, that could be saved and retrieved.
Whatever makes more sense, any of the two strategies will also be a useful feature for the rest of the system.

Aaaaaaand another component for the nascent Haiku DAW! Great!


And no mistake! I most often give up after a while…
I had a feeling that you were a bit too fast for the results… :wink:

Samedi just accepts any MIDI note coming in, no matter if comes from separate hardware pads, a full synth, my little MIDI controller or other software running on the system, like Sequitur or some other MIDI sequencer.
With Samedi you just assign some MIDI note to trigger an audio sample playback.

The idea to just use 4 pads plus a wave as icon is just because it more resembles Samedi’s simple nature and it makes the icon easier to create.

Your vision with components plugging into each other is already kinda there (in theory) with MIDI. You have MIDI producers and consumers that react to certain MIDI events.

I’m even less a musician than a coder or graphics artist, so I have trouble using Sequitur as MIDI sequencer. I probably also forgot how many things work there…
But years ago, I had Sequitur running and controlling SyncModular, the unfortunately closed source “analog synth” for BeOS and therefore 32bit only. Back then I wanted to make crazy sounds on the Synth and have a percussion of audio samples controlled by a MIDI track playing alongside it.

Now finally I created Samedi to do the sample-playing, but using 64bit Haiku normally, miss my SyncModular synth. :joy:

1 Like