GithubHelp home page GithubHelp logo

cmixer's Introduction

cmixer

A lightweight, portable ANSI C audio mixer for games.

Features

  • Easy to use
  • Tiny: two files, around 600sloc
  • No dependencies (stb_vorbis is optional)
  • Support for wav and ogg files if stb_vorbis is used
  • Simple API for adding custom formats
  • Resampling and seamless looping
  • Per-source gain, pan and pitch control
  • Fast, fixed-point internal processing

Getting Started

The library's .c and .h files can be dropped into a project and compiled along with it. If ogg vorbis support is desired stb_vorbis.c should also be added to the project and the -DCM_USE_STB_VORBIS flag passed to the compiler.

Before use, the library should be initialized with the desired samplerate:

cm_init(44100);

A sound can be played by first creating a source, then calling cm_play() on that source.

cm_Source *src = cm_new_source_from_file("sound.wav");
cm_play(src);

When the cm_process() function is called, all the currently playing streams will be processed and mixed, the master output will be written to the provided 16bit buffer. This output is always stereo interlaced, thus the buffer length must always be an even number:

cm_Int16 buffer[512];
cm_process(buffer, 512);

cm_process() can safely be called from a separate thread; if more than one thread is used a lock event handler must be set:

static void lock_handler(cm_Event *e) {
  if (e->type == CM_EVENT_LOCK) {
    printf("acquired lock\n");
  }
  if (e->type == CM_EVENT_UNLOCK) {
    printf("released lock\n");
  }
}

cm_set_lock(lock_handler);

See doc/api.md for an overview of the API or demo for usage demos.

License

This library is free software; you can redistribute it and/or modify it under the terms of the MIT license. See LICENSE for details.

cmixer's People

Contributors

rxi avatar

Watchers

 avatar

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.