GithubHelp home page GithubHelp logo

cnfa_win2000's Introduction

cnfa

CN's foundational audio drivers

See CNFA.h for more help and use info.

This toolset is 100% based around sound callbacks.

You get three functions:

struct CNFADriver* CNFAInit(const char* driver_name,
                            const char* your_name,
                            CNFACBType cb,
                            int reqSPSPlay,
                            int reqSPSRec,
                            int reqChannelsPlay,
                            int reqChannelsRec,
                            int sugBufferSize,
                            const char* outputSelect,
                            const char* inputSelect,
                            void* opaque)

// Returns bitmask: 1 if mic recording, 2 if playback running, 3 if both running.
int CNFAState(struct CNFADriver* cnfaobject)

void CNFAClose(struct CNFADriver* cnfaobject)

Then it goes and calls a callback function, the CNFACBType cb parameter. This can feed you new frames, or you can pass frames back in. framesp is the size of one channel of the output buffer in samples. If there are multiple channels they should be interleaved i.e. L:R:L:R... framerp is the size of one channel of the input buffer in samples. Works the same way as the output buffer. You can obtain the number of input/output channels from sd->channelsRec and sd->channelsPlay respectively.

void Callback(struct CNFADriver* sd, short* out, short* in, int framesp, int framesr)
{
  int i;
  for( i = 0; i < framesr * sd->channelsRec; i++ ) 
    short value = in[i];
  for( i = 0; i < framesp * sd->channelsPlay; i++ )
    out[i] = 0; //Send output frames.
}

There are two examples in this repository, example.c and wave_player.c. Both of these show examples of using CNFA to output sound. For use of CNFA for input see colorchord

Building .DLL and .SO files

If you would like to use CNFA in a project where using a DLL or SO file is more practical, you can easily build those files. The below steps are for the Clang & GGC compilers, but others like TCC should work fine as well, just have not been tested.

NOTE: In order for functions to be exported, you'll need to make sure -DBUILD_DLL is specified!

Parts of CNFA rely on rawdraw, so make sure to clone this repo somewhere and insert the path to it in the [RAWDRAW PATH] space below:

Don't forget to install all libraries' headers! For Linux, at least these packages: libasound2-dev, libpulse-dev

Windows build:

& "C:\Program Files\LLVM\bin\clang.exe" CNFA.c -shared -o CNFA.dll -DWINDOWS -DCNFA_IMPLEMENTATION -DBUILD_DLL -D_CRT_SECURE_NO_WARNINGS -I"[RAWDRAW PATH]" -lmmdevapi -lavrt -lole32

Linux build:

make shared-example

This will build the shared library as libCNFA.so and will build the example project to link against it. You can run the example project with ./example. The makefile will try and copy the os_generic.h header from rawdraw automatically using wget.

The command to build simply build the shared library is:

gcc CNFA.c -shared -fpic -o CNFA.so -DCNFA_IMPLEMENTATION -DBUILD_DLL -I"[RAWDRAW PATH]" -lasound -lpulse -lpthread

cnfa_win2000's People

Contributors

cnlohr avatar sellicott avatar caib avatar undeadherbs avatar overlisting avatar alarixnia 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.