Giter Site home page Giter Site logo

edubart / minivorbis Goto Github PK

View Code? Open in Web Editor NEW
60.0 6.0 7.0 708 KB

Single-file port of libogg and libvorbis for decoding ogg sound files.

License: BSD 3-Clause "New" or "Revised" License

Shell 0.83% C 99.17%
single-file ogg vorbis libogg libvorbis c single-header single-header-lib minivorbis

minivorbis's Introduction

MiniVorbis

This is libogg 1.3.4 + libvorbis 1.3.7 contained in a single header to be bundled in C/C++ applications with ease for decoding OGG sound files. Ogg Vorbis is a open general-purpose compressed audio format for mid to high quality audio and music at fixed and variable bitrates.

Example Usage

#define OGG_IMPL
#define VORBIS_IMPL
#include "minivorbis.h"

int main(int argc, char** argv)
{
    if(argc < 2) {
        printf("No input file.\n");
        return -1;
    }
    /* Open sound file. */
    FILE* fp = fopen(argv[1], "rb");
    if(!fp) {
        printf("Failed to open file '%s'.", argv[1]);
        return -1;
    }
    /* Open sound stream. */
    OggVorbis_File vorbis;
    if(ov_open_callbacks(fp, &vorbis, NULL, 0, OV_CALLBACKS_DEFAULT) != 0) {
        printf("Invalid Ogg file '%s'.", argv[1]);
        return -1;
    }
    /* Print sound information. */
    vorbis_info* info = ov_info(&vorbis, -1);
    printf("Ogg file %d Hz, %d channels, %d kbit/s.\n", info->rate, info->channels, info->bitrate_nominal / 1024);
    /* Read the entire sound stream. */
    unsigned char buf[4096];
    while(1) {
        int section = 0;
        long bytes = ov_read(&vorbis, buf, sizeof(buf), 0, 2, 1, &section);
        if(bytes <= 0) /* end of file or error */
            break;
    }
    /* Close sound file */
    ov_clear(&vorbis);
    return 0;
}

Usage

Copy minivorbis.h into your C/C++ project, include it anywhere you want to use the Vorbis API. Then do the following in one C file to implement Ogg and Vorbis:

#define OGG_IMPL
#define VORBIS_IMPL
#include "minivorbis.h"

Optionally provide the following defines:

  • OV_EXCLUDE_STATIC_CALLBACKS - exclude the default static callbacks

Note that almost no modification was made in the Ogg/Vorbis implementation code, thus there are some C variable names that may collide with your code, therefore it is best to declare the implementation in dedicated C file.

Documentation

For documentation on how to use Ogg and Vorbis read its official documentation.

Extra Miniaudio Vorbis Decoder

You can use miniaudio_vorbis.h to replace Vorbis decoder of the awesome single-header miniaudio library with minivorbis, follow the instructions described on it.

Updates

  • 02-Nov-2020: Library created, using Ogg 1.3.4 and Vorbis 1.3.7.

Notes

The header is generated using the bash script gen.sh all modifications done is there.

License

BSD-like License, same as libogg and libvorbis, see LICENSE.txt for information.

minivorbis's People

Contributors

edubart avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

minivorbis's Issues

playback.c is not actually buildable with MinGW gcc V4.4.1

I'm wondering if this file was ever built, at least under MinGW ...
Things which are not defined at all:

miniaudio.h
ma_result

Here are first few errors:
In file included from playback.c:18:
miniaudio_vorbis.h:22:2: error: #error "include miniaudio.h without implementation first"
In file included from playback.c:18:
miniaudio_vorbis.h:29: error: expected '=', ',', ';', 'asm' or 'attribute' before 'ma_decoder_init_vorbis__internal'
In file included from miniaudio_vorbis.h:38,
from playback.c:18:
minivorbis.h: In function 'vorbis_granule_time':
minivorbis.h:14829: warning: integer constant is too large for 'long' type
In file included from playback.c:18:
miniaudio_vorbis.h: At top level:
miniaudio_vorbis.h:40: error: expected '=', ',', ';', 'asm' or 'attribute' before 'ma_decoder_internal_on_seek_to_pcm_frame__vorbis'
miniaudio_vorbis.h:47: error: expected '=', ',', ';', 'asm' or 'attribute' before 'ma_decoder_internal_on_uninit__vorbis'
miniaudio_vorbis.h:56: error: expected '=', ',', ';', 'asm' or 'attribute' before 'ma_decoder_internal_on_read_pcm_frames__vorbis'
miniaudio_vorbis.h:90: error: expected '=', ',', ';', 'asm' or 'attribute' before 'ma_decoder_internal_on_get_length_in_pcm_frames__vorbis'

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.