Git Product home page Git Product logo

sfbaudioengine's Introduction

SFBAudioEngine is a set of C++ classes enabling applications to easily play audio in the following formats:

  • WAVE
  • AIFF
  • Apple Lossless
  • AAC
  • FLAC
  • MP3
  • Musepack
  • WavePack
  • Ogg Vorbis
  • Monkey's Audio
  • Ogg Speex
  • True Audio
  • All other formats supported natively by Core Audio

In addition to playback, SFBAudioEngine supports reading and writing of metadata for most supported formats.

SFBAudioEngine uses C++11 language features (such as delegated constructors and range-based for), but not C++11 STL features (such as std::shared_ptr). This means that clang must be used to compile SFBAudioEngine and any application using it, but either GNU's libstdc++ or clang's libc++ may be used provided that SFBAudioEngine's dependencies are compiled using the same library.

A command line audio player using SFBAudioEngine is as simple as:

#include <CoreFoundation/CoreFoundation.h>

#include "SFBAudioEngine/AudioDecoder.h"
#include "SFBAudioEngine/AudioPlayer.h"

#include <unistd.h>

int main(int argc, char *argv [])
{
	if(1 == argc) {
		printf("Usage: %s file [file ...]\n", argv[0]);
		return EXIT_FAILURE;
	}
	
	AudioPlayer player;
	
	while(0 < --argc) {
		const char *path = *++argv;
		CFURLRef fileURL = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, 
																   reinterpret_cast<const UInt8 *>(path), 
																   strlen(path), 
																   FALSE);

		AudioDecoder *decoder = AudioDecoder::CreateDecoderForURL(fileURL);

		CFRelease(fileURL), fileURL = NULL;
		
		if(NULL == decoder) {
			puts("Couldn't create decoder");
			continue;
		}

		if(!player.Enqueue(decoder)) {
			puts("Couldn't enqueue decoder");
			delete decoder, decoder = NULL;
		}
	}

	player.Play();

	// Display progress every 2 seconds
	while(player.IsPlaying()) {
		CFRunLoopRunInMode(kCFRunLoopDefaultMode, 2, true);
		printf("%.2f / %.2f [%.2f]\n", player.GetCurrentTime(), player.GetTotalTime(), player.GetRemainingTime());
	}

	player.Stop();

	return EXIT_SUCCESS;
}

sfbaudioengine's People

Contributors

sbooth avatar

Watchers

James Cloos avatar githow 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.