VgaGames4

VgaGames4 - audio man-pages

[.. upper level ..]

# Audio functions

Playing audio-files.

- Enumerations and Structures
- VG_AUDIO_FREQS
- VG_AUDIO_VOLUMES
- Audio system
- vg4->audio->open()
  Open audio system.
- vg4->audio->close()
  Close audio system.
- vg4->audio->suspend()
  Suspend or continue audio output.
- vg4->audio->is_open()
  Return whether audio system has been opened.
- (Un)Loading audio files
- vg4->audio->load()
  Load an audio file.
- vg4->audio->unload()
  Unload an audio file.
- vg4->audio->unload_group()
  Unload audio files of a volume-group.
- vg4->audio->getname()
  Get filename of a loaded audio.
- Playing audio files
- vg4->audio->play()
  Play a loaded audio.
- vg4->audio->play_after()
  Play a loaded audio, after another one has been ended.
- vg4->audio->pause()
  Pause or continue playing an audio.
- vg4->audio->pause_group()
  Pause or continue playing audio files of a volume-group.
- vg4->audio->stop()
  Stop playing an audio.
- vg4->audio->stop_group()
  Stop playing audio files of a volume-group.
- vg4->audio->is_playing()
  Return whether a loaded audio is playing.
- Volume
- vg4->audio->volume()
  Set volume of main volume or of a volume-group.
- vg4->audio->mute()
  Set to mute or unset from mute.
- vg4->audio->is_mute()
  Return whether audio is set to mute.

## Example

    /* load an audio file, play it and wait for its end */

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <errno.h>
    #include <vgagames4.h>

    int main(int argc, char **argv) {
      int audc;

      (void)argc; (void)argv;

      /* initialize, but we don't need a window */
      if (!VG_init("test")) { exit(1); }

      /* open audio system */
      if (!vg4->audio->open(VG_AUDIO_FREQ_MEDIUM, VG_TRUE)) { VG_dest(); exit(1); }

      /* load audio file */
      audc = vg4->audio->load("audio.wav", 100, VG_AUDIO_VOLUME_MUSIC);
      if (audc == 0) { VG_dest(); exit(1); }
      printf("%s loaded\n", vg4->audio->getname(audc));

      /* play audio */
      vg4->audio->play(audc, VG_FALSE, VG_FALSE);

      /* wait until audio playing has been ended */
      for (;;) {
        if (!vg4->audio->is_playing(audc, NULL)) { break; }
        sleep(1);
      }

      /* unload audio */
      vg4->audio->unload(audc);

      /* destroy and exit */
      VG_dest();
      exit(0);
    }