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:
- Download Audiere for windows.
- Extract the downloaded file.
- Create a New Folder.
- Place audiere.dll and some music files lets say .mp3 files in it.
- Open DevCPP and Start a Console Project in the directory.
- Open the main.CPP file of the project.
- 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:
- play(): It is used to play the audio file.
- stop(): It is used to stop the audio file.
- isPlaying(): It is used to check if any file is playing or not.
- reset(): It is used to reset the audio file while playing any audio file.
- setVolume(float volume): It is used to set the volume of the audio file.
- setRepeat(bool repeat): It is used to set the count of repeat any audio file is played.
- 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.
- 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
- getLength(): It gives the length of your music file
- 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
- 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; } |
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!