Coder Social home page Coder Social logo

wave's Introduction

wave

  • Wave is a lightweight 3D sound wrapper for OpenAL. Written in C++11.
  • Wave decodes both OGG (.ogg) and MusePack (.mpc) file formats.
  • All dependencies included: OpenAL Soft, MusePack, STB_Vorbis.
  • Cross-platform. Builds on Windows/Linux. Compiles on g++/msvc.
  • Tiny. One header and one source file.
  • zlib/libpng licensed.

sample

#include <iostream>
#include "wave.hpp"

int main( int argc, char **argv ) {
    if( argc != 2 )
        return std::cerr << "Usage: " << argv[0] << " file" << std::endl, -1;

    // enumerate audio devices
    for( auto &it : wave::enumerate() )
        std::cout << "Audio device: " << it << std::endl;

    // create as many audio contexts as you want. use music one for now.
    wave::device sfx, music, voice, ambient, video, ui, &env = music;

    // our context uses system device #0
    if( !env.init(0) )
        return std::cerr << "Cant open audio device." << std::endl, -1;
    else
        std::cout << "Using audio device: " << env.devname << std::endl;

    // create sound and speaker on this context
    unsigned snd_idx = env.insert_sound( wave::sound() );
    unsigned spk_idx = env.insert_speaker( wave::speaker() );

    if( snd_idx == ~0 )
        return std::cerr << "Invalid sound index" << std::endl, -1;
    if( spk_idx == ~0 )
        return std::cerr << "Invalid speaker index" << std::endl, -1;

    wave::speaker &spk = env.speakers[ spk_idx ];
    wave::sound &snd = env.sounds[ snd_idx ];

    // load audio into buffer sound
    if( !snd.load( argv[1] ) )
        return std::cerr << "Cant open file: " << argv[1] << std::endl, -1;
    else
        std::cout << "Playing '" << snd.path << "' " << snd.seconds << " secs." << std::endl;

    // play sound until finish
    spk.play( snd );
    for( ;spk.is_playing(); );

    return 0;
}

external links

wave's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

wave's Issues

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.