Lei Mao
The Console Player (CPlayer) was implemented using C++, and the library libsndfile and libasound. libsndfile was used to decode audio files and libasound was used to play audio in the hardware.
The commonly supported audio formats in CPlayer includes wav, ogg, and flac. More effort of supporting mp3 in libsndfile is coming from the community. Additionally, the CPlayer library libcplayer could be used for other C++ projects, such as games, to play audio in the background asynchronously.
- CMake 3.13.0+
libsndfilelibasound
.
├── bgm
│ ├── bgm.cpp
│ └── CMakeLists.txt
├── CMakeLists.txt
├── demo
│ ├── BIS1536-001-flac-16.flac
│ ├── punch-deck-elegance-in-simplicity.wav
│ └── spring-village.ogg
├── LICENSE.md
├── README.md
└── src
├── CMakeLists.txt
├── cplayer.cpp
├── cplayer.h
└── main.cpp
$ docker build -f docker/clayer.Dockerfile --no-cache --tag=clayer:0.0.1 .$ docker run -it --rm --device /dev/snd -v $(pwd):/mnt clayer:0.0.1Check out the installation guide from Kitware.
$ apt-get install libsndfile-dev libasound2-dev$ mkdir -p build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=[custom_dir] ..
$ make
$ make install$ mkdir -p build
$ cd build
$ cmake ..
$ make
$ # This requires writing permissions to `usr` directory
$ sudo make install./console_player audio_file [loop]Add optional argument loop if you want to repeatedly playing the audio file.
The libcplayer library supports playing the audio in the background asynchronously. Please check the header file cplayer.h and the demo code bgm.cpp for details.
$ mkdir -p build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=. ..
$ make
$ make install
$ cd bin/
$ # Play the audio file once.
$ ./console_player ../../demo/punch-deck-elegance-in-simplicity.wav
$ # Loop playing the audio file.
$ ./console_player ../../demo/spring-village.ogg loop$ ./bgm ../../demo/spring-village.oggThe music would be played 6 times. In the first 3 times, the full audio file would be played. In the last 3 times, the player would receive kill signal from the program, and the audio play would be terminated before its end.