Bienvenue sur le site de la LibLapin.
Jetez un coup d'oeil en bas de la page pour choisir votre niveau de documentation en fonction de votre niveau avec la LibLapin.
Pour l'instant, c'est réglé sur 'Manuel complet'. Si c'est votre première fois avec la LibLapin, il vaudrait mieux choisir 'Débutant'.
De même, n'oubliez pas de préciser une version de la bibliothèque.

LibLapin's logo

LibLapin

Sound





The sound module header is lapin/sound.h
typedef struct s_bunny_sound
{
     const char _private[sizeof(size_t)];
     const char * const file;
     double volume;
     double pitch;
     bool loop;
     double position[3];
     double attenuation;
     const bool playing;
     const bool pause;

} t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d;

Description

     The sound structure is a partially abstract structure that represents a loaded or a read sound. It is a base structure for t_buny_effects and t‌_‌b‌u‌n‌n‌y‌_‌m‌u‌s‌i‌c.

Any structure that could take a t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d can take any structure based on it.

Attributes

  • const char _private[sizeof(size_t)]:
         Private fields you should edit or your program may crash.
  • const char * const file:
         The field from which the sound or music was extracted. It is set to empty string ("") if the sound was created with b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌e‌f‌f‌e‌c‌t.
  • double volume:
         The volume, between 0 and 100, of the sound.
  • double pitch:
         The pitch, greater than 0 with a normal value that is 1, of the sound. The pitch is the speed of the sound being played.
  • bool loop:
         true if you need to make this sound being repeated.
  • double position[3]:
         The relative 3D position of the sound. Being relative means (0, 0, 0) is "on" the program user. Values to set here may vary a lot depending of the attenuation value. With the default, a distance from the origin of maximum 5 is a good choice.
  • double attenuation:
         The default sound attenuation. In combination with the distance, it will decrease the sound volume. By default, the attenuation is set to 5.
  • const bool playing:
         Is the sound being played?
  • const bool pause:
         Is the sound paused?


INDEX

typedef struct s_bunny_music
{
     t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d sound;
     const double duration;

} t‌_‌b‌u‌n‌n‌y‌_‌m‌u‌s‌i‌c;

Description

     This structure represents a music. It is based on t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d and have an additionnal duration. Music are not loaded into memory but read from disk and load chunk by chunk automatically.

Any function that takes a t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d as parameter can take a t‌_‌b‌u‌n‌n‌y‌_‌m‌u‌s‌i‌c as one.

Attributes



INDEX

typedef struct s_bunny_effect
{
     t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d sound;
     const double duration;

} t‌_‌b‌u‌n‌n‌y‌_‌e‌f‌f‌e‌c‌t;

Description

     This structure describe a sound effect. If not simply generated from b‌u‌n‌n‌y‌_‌l‌o‌a‌d‌_‌e‌f‌f‌e‌c‌t, it may be a little complex: the t‌_‌b‌u‌n‌n‌y‌_‌e‌f‌f‌e‌c‌t is the equivalent of t‌_‌b‌u‌n‌n‌y‌_‌p‌i‌x‌e‌l‌a‌r‌r‌a‌y but for sound: they are a track that will be read, short int after short int, to generate a sound.
Any function that takes a t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d as parameter can take a t‌_‌b‌u‌n‌n‌y‌_‌m‌u‌s‌i‌c as one.

Attributes

  • t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d sound:
         The sound base.
  • const size_t sample_per_second:
         The duration of the music in seconds.
  • const double duration:
         The duration in seconds. Multiplied by sample_per_second will give you the length of sample.
  • int16_t * const sample:
         A constant address to a writable area of *Ssample_per_second * duration short signed int. Each case store a value which compose the wave of the sound effect.

    Modifications inside the sound effect will be computed by calling b‌u‌n‌n‌y‌_‌c‌o‌m‌p‌u‌t‌e‌_‌e‌f‌f‌e‌c‌t. If you do not call it before playing, your modifications will be ignored.


INDEX


Description

     Open a music file and stream it when you play it, from a sound file or a configuration file.

Delete the music file with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌s‌o‌u‌n‌d when you do not need it anymore.

Parameters

  • const char *file:
         The music file to open. Supported files are .wav and .ogg.
    This function also support configuration file input. Configuration file format is described below.

Return value


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.

  • EINVAL:

    An invalid file format was sent.

  • ENOENT:

    The file was not found.

  • BE_SYNTAX_ERROR:

    The sent configuration file contains syntax error.


Logs written by this function or subfunctions may be tagged with "ressource", "configuration", "syntax" or "sound" labels.


Configuration file format

You can set properties of a t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d thanks to a file at runtime. This allow you to get rid of a lot of configuration and to create space for any outside editor.

INI format and complete field description

Mandatory field
  • RessourceFile is a single string that contains the address of a sound.
    Usage:

    RessourceFile="Sound file that will be loaded"
Optionnal fields
  • Volume is the volume of the sound. It should be an integer between 0 and 100.

    Volume=42
  • Pitch is the accelleration of the sound. A pitch of 2 will shorter the sound, but also make it more acute. A pitch of 0.5 will make it longer and also more low. A single double is neccessary.

    Pitch=3
  • Loop indicates if the sound must be play continuously or a single time. A single integer is required, like 1, true, 0 or false.

    Loop=true
  • Position indicates the position of the sound in space. It is three double.

    Position=X,Y,Y
  • Attenuation is how fast the sound decrease when going far away. It is a single double. that should be between 0 and 10.

    Attenuation=10

CSV format

The CSV format does not follow the same architecture as the INI one. Here is its architecture:

"ressourcefile";"path_to_ressource_file"
"volume";volume
"pitch";pitch
"loop";loop
"position";x;y;z
"attenuation";attenuation

DABSIC format

The DABSIC format follow the same architecture as the INI one. Here is its architecture:

RessourceFile="Sound file that will be loaded"
Volume=42
Pitch=3
Loop=true
{Position X, Y, Y }
Attenuation=10

XML format

Not documented yet.

LUA format

Not documented yet.

JSON format

Not documented yet.

LISP format

Not documented yet.

YAML format

There is no support for YAML yet.




INDEX

Description

This macro contains the number of sample per seconds in a t‌_‌b‌u‌n‌n‌y‌_‌e‌f‌f‌e‌c‌t created by b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌e‌f‌f‌e‌c‌t. Its value is 44100.


INDEX


Description

     Create a sound effect of the sent duration in seconds. It means in practice that its t‌_‌b‌u‌n‌n‌y‌_‌e‌f‌f‌e‌c‌t sample buffer will have duration * S‌A‌M‌P‌L‌E‌_‌P‌E‌R‌_‌S‌E‌C‌O‌N‌D‌S signed short ints to describe the sound.

Delete the sound file with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌s‌o‌u‌n‌d when you do not need it anymore.

Parameters

  • double duration:
         The duration of the generated sound in seconds.

Return value


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function or subfunctions may be tagged with "ressource" or "sound" labels.




INDEX


Description

     Open a sound file and load it. The sent file can be a configuration file.

Delete the sound file with b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌s‌o‌u‌n‌d when you do not need it anymore.

Note that the t‌_‌b‌u‌n‌n‌y‌_‌e‌f‌f‌e‌c‌t field sample_per_second can be different from S‌A‌M‌P‌L‌E‌_‌P‌E‌R‌_‌S‌E‌C‌O‌N‌D‌S as it was not created by b‌u‌n‌n‌y‌_‌n‌e‌w‌_‌e‌f‌f‌e‌c‌t and is fully based on the loaded file.

Parameters

  • const char *file:
         The sound file to open. Supported files are .wav and .ogg.
    This function also support configuration file input. Configuration file format is described below.

Return value


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.

  • EINVAL:

    An invalid file format was sent.

  • ENOENT:

    The file was not found.

  • BE_SYNTAX_ERROR:

    The sent configuration file contains syntax error.


Logs written by this function or subfunctions may be tagged with "ressource", "configuration", "syntax" or "sound" labels.


Configuration file format

You can set properties of a t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d thanks to a file at runtime. This allow you to get rid of a lot of configuration and to create space for any outside editor.

INI format and complete field description

Mandatory field
  • RessourceFile is a single string that contains the address of a sound.
    Usage:

    RessourceFile="Sound file that will be loaded"
Optionnal fields
  • Volume is the volume of the sound. It should be an integer between 0 and 100.

    Volume=42
  • Pitch is the accelleration of the sound. A pitch of 2 will shorter the sound, but also make it more acute. A pitch of 0.5 will make it longer and also more low. A single double is neccessary.

    Pitch=3
  • Loop indicates if the sound must be play continuously or a single time. A single integer is required, like 1, true, 0 or false.

    Loop=true
  • Position indicates the position of the sound in space. It is three double.

    Position=X,Y,Y
  • Attenuation is how fast the sound decrease when going far away. It is a single double. that should be between 0 and 10.

    Attenuation=10

CSV format

The CSV format does not follow the same architecture as the INI one. Here is its architecture:

"ressourcefile";"path_to_ressource_file"
"volume";volume
"pitch";pitch
"loop";loop
"position";x;y;z
"attenuation";attenuation

DABSIC format

The DABSIC format follow the same architecture as the INI one. Here is its architecture:

RessourceFile="Sound file that will be loaded"
Volume=42
Pitch=3
Loop=true
{Position X, Y, Y }
Attenuation=10

XML format

Not documented yet.

LUA format

Not documented yet.

JSON format

Not documented yet.

LISP format

Not documented yet.

YAML format

There is no support for YAML yet.




INDEX


Description

     Generate the sent sound effect in your sound card after what you have written into its buffer.

Parameters


Return value

Returns true on success.


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function or subfunctions may be tagged with "sound" labels.




INDEX


Description

     Set the sent volume to the sent sound. Do not use this function if the sound is inside a t_bunny_manager. Use b‌u‌n‌n‌y‌_‌m‌a‌n‌a‌g‌e‌d‌_‌s‌o‌u‌n‌d‌_‌v‌o‌l‌u‌m‌e instead.

Parameters




INDEX


Description

     Set the sent pitch to the sent sound. Do not use this function if the sound is inside a t_bunny_manager. Use b‌u‌n‌n‌y‌_‌m‌a‌n‌a‌g‌e‌d‌_‌s‌o‌u‌n‌d‌_‌p‌i‌t‌c‌h instead.

Parameters




INDEX


Description

     Set if the sound loop or not.

Parameters




INDEX


Description

     Set the sent position to the sent sound.

Parameters




INDEX


Description

     Set the sent position to the sent sound.

Parameters




INDEX


Description

     Play the sent sound.

Parameters




INDEX


Description

     Pause the sent sound.

Parameters




INDEX


Description

     Stop the sent sound.

Parameters




INDEX


Description

     Set the read cursor at the sent position in sound.

Parameters




INDEX


Description

     Get the current read position of the sent sound.

Parameters


Return value

Returns the position in seconds in the sound that match the currently being read part.




INDEX


Description

     Get the duration of the sent sound.

Parameters


Return value

Returns the length in seconds of the sound.




INDEX


Description

     Return true if the sent sound is being played right now.

Parameters


Return value

Returns if the sound is being played right now or not.



INDEX


Description

     Delete the sent sound.

Parameters


Additional informations

This macro wraps a call to a real function, which is:

void _b‌u‌n‌n‌y‌_‌d‌e‌l‌e‌t‌e‌_‌s‌o‌u‌n‌d( t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d *sound );




INDEX

k

Description

     In the bunny library, some bottom level ressources are shared. This means that when you load several times the same sound effect, the sound effect itself is only loaded once and then it is given to multiples holders.

Sometimes, you only base your work on a sound effect but plan to edit it to create a new one... And editing it would edit all sounds played by all other holders, so before doing it, you will need to call b‌u‌n‌n‌y‌_‌m‌a‌k‌e‌_‌e‌f‌f‌e‌c‌t‌_‌u‌n‌i‌q‌u‌e so your sound effect got duplicated and pulled out the ressource manager.

In t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d_effect, shared parts are the private side of the mother structure t‌_‌b‌u‌n‌n‌y‌_‌s‌o‌u‌n‌d and the buffer field.

Parameters


Return value

Return true if everything went well. false if instead it went wrong.


Error values and logs

On error, $Vb‌u‌n‌n‌y‌_‌e‌r‌r‌n‌o is set to:


  • ENOMEM:

    Out of memory.


Logs written by this function or subfunctions may be tagged with "sound" labels.




INDEX