Sound performance in Haiku. Which library to use?

Hello! Tried this, but as a result I get no sound, but a
Suggested buffer duration 10000, size 3528

#include <stdio.h>
#include <MediaDefs.h>
#include <Sound.h>
#include <SoundPlayer.h>
#include <Entry.h>
#include <Path.h>

void playsound(char *path) {
  BSound *sound;
  BSoundPlayer player;
  entry_ref ref;
  BEntry entry(path, true);
  BSoundPlayer::play_id id;


  if (entry.InitCheck() == B_OK) {
    if (entry.GetRef(&ref) == B_OK) {
      sound = new BSound(&ref);
      if (sound->InitCheck() == B_OK) {
        printf("InitCheck() == OK\n");
        player.Start();
        player.SetVolume(1.0);
        id = player.StartPlaying(sound);
        sound->ReleaseRef();
        player.WaitForSound(id);
      }
    }
  }
}

int main() {
  printf("play\n");
  playsound("/boot/home/simple.mp3");
}
2 Likes

Can someone help me please to get a sound output here? Opening the file works with MediaPlayer.
Here is all I get the console output line.

Look: Sound and Haiku

https://www.haiku-os.org/docs/userguide/en/preferences/media.html

From what the BeBook says on BSoundPlayer, using it seems to be more complicated. For example:

You need to implement a hook function that will be called for each audio buffer passed through the BSoundPlayer’s playback node.

For Samedi, I chose to use the GameKit’s very simply BFileGameSound. It doesn’t allow much control (e.g. Gain() only works on stereo files), but is extremely easy to use:

	BFileGameSound* player = new BFileGameSound("/boot/home/simple.mp3", false);

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

	player->StartPlaying();

Maybe that’s an option for you, too.

2 Likes