Code Monkey home page Code Monkey logo

console-player's Introduction

Console Player

Lei Mao

Introduction

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.

Dependencies

Files

.
├── 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

Installation

Build Docker Image

$ docker build -f docker/clayer.Dockerfile --no-cache --tag=clayer:0.0.1 .

Run Docker Container

$ docker run -it --rm --device /dev/snd -v $(pwd):/mnt clayer:0.0.1

Install CMake

Check out the installation guide from Kitware.

Install Dependencies

$ apt-get install libsndfile-dev libasound2-dev

Install to Custom Directory (Recommended)

$ mkdir -p build
$ cd build
$ cmake -DCMAKE_INSTALL_PREFIX=[custom_dir] ..
$ make
$ make install

Install to Default Directory

$ mkdir -p build
$ cd build
$ cmake ..
$ make
$ # This requires writing permissions to `usr` directory
$ sudo make install

Usages

Play Audio in Console

./console_player audio_file [loop]

Add optional argument loop if you want to repeatedly playing the audio file.

Use CPlayer Library

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.

Demo

Run CPlayer in Console

$ 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

Run BGM Demo

$ ./bgm ../../demo/spring-village.ogg

The 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.

References

console-player's People

Contributors

leimao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

tin6150

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.