Thursday, July 4, 2024

Audiere Library

Audiere is a high-level Audio API developed by Chad Austin and Matthew Campbell. It was released on 6 August 2001. It supports direct sound in Windows as well as in Linux. It can play sounds in formats like WAV, MP3, as well as any formats. It can be used in many languages like C, C++, Java, etc.

Installing Audiere:

  • For Linux/Windows: For setting up the environment you can download the Audiere package from this website.
  • For MinGW: Build all the dependencies for Audiere, including libogg, libvorbis from xiph.org, libspeex, libdumb and FLAC from the below command:
    ./configure --prefix=/mingw && make && make install
    

Setting the Environment:

  1. Download Audiere for windows.
  2. Extract the downloaded file.
  3. Create a New Folder.
  4. Place audiere.dll and some music files lets say .mp3 files in it.
  5. Open DevCPP and Start a Console Project in the directory.
  6. Open the main.CPP file of the project.
  7. Go to Project Options and in Directories state the include path of the audiere.h file and in parameters add to the linker path <strong\lib\audiere.lib.

Header File:

#include <audiere.h>

Below are some of the function used in this library:

  1. play(): It is used to play the audio file.
  2. stop(): It is used to stop the audio file.
  3. isPlaying(): It is used to check if any file is playing or not.
  4. reset(): It is used to reset the audio file while playing any audio file.
  5. setVolume(float volume): It is used to set the volume of the audio file.
  6. setRepeat(bool repeat): It is used to set the count of repeat any audio file is played.
  7. setPan(float pan): It controls the speakers balance. -0.1 gives sound output only through the left Channel (or Speaker) and +0.1 gives the output through right channel (Speaker) only.
  8. isSeekable(): It tells us if your music file supports the setting of the position of your sound.setPosition method can be used to set to the desired position. Current position can always be known by calling the getPosition function
  9. getLength(): It gives the length of your music file
  10. setPitchShift(float shift): It controls the tone. Value varies between 0.5 and 2.0, 1.0 is the default value. Volume range is between 0.0 to 1.0
  11. getPitchShift(): It is used to get the tone value.

Below is the implementation of playing music using functions in audiere.h library:




// C++ program to play music using
// audiere file function
#include "audiere.h"
#include <stdio>
#include <string>
  
// Using Audiere File
using namespace audiere;
using namespace std;
  
// Driver Code
int main(void)
{
    // Name of the file
    string name = "file1.mp3";
  
    // Create Object to open device
    AudioDevicePtr device(OpenDevice());
  
    // Create Object to open the music file
    OutputStreamPtr sound(OpenSound(device,
                                    name.c_str(),
                                    false));
  
    // Play music using play() function
    sound->play();
  
    // Repeat music using setRepeat() function
    sound->setRepeat(true);
  
    // Change volume using setVolume() function
    sound->setVolume(2.0f);
  
    getchar();
    return 0;
}


Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments