A powerful C++ audio playback engine for Mac OS X and iOS
C++ Objective-C C
Pull request Compare This branch is 2 commits ahead, 395 commits behind sbooth:master.
Latest commit 9ad7e03 Sep 16, 2012 @indragiek indragiek Updated .gitignore
Permalink
Failed to load latest commit information.
Configs Use GNU++11 as the C++ standard Jun 8, 2012
Converter Handle 64-bit float input correctly Mar 11, 2012
Decoders Don't set kAudioFormatFlagIsAlignedHigh for 32-bit integer WavPack files Jul 25, 2012
Input Fix some issues discovered by the clang analyzer Mar 31, 2012
Metadata Don't fail if CFNumberGetValue returns false Aug 10, 2012
Player Correctly free memory if an error occurs Aug 10, 2012
SFBAudioEngine.xcodeproj Changed base SDK to latest Sep 16, 2012
SimplePlayer-iOS More copyright updates and NULL -> nullptr replacement Feb 24, 2012
SimplePlayer More copyright updates and NULL -> nullptr replacement Feb 24, 2012
ThirdParty/PublicUtility Don't crash if an out-of-bounds read would occur Jul 31, 2011
.gitignore Updated .gitignore Sep 16, 2012
ACKNOWLEDGMENTS Removed log4cxx and added libtta++ Mar 1, 2012
AllocateABL.cpp Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
AllocateABL.h Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CFErrorUtilities.cpp Added CreateError() and CreateErrorForURL() Feb 26, 2012
CFErrorUtilities.h Added CreateError() and CreateErrorForURL() Feb 26, 2012
COPYING Added 2012 to copyright Jun 8, 2012
ChannelLayoutsAreEqual.cpp Fix some issues discovered by the clang analyzer Mar 31, 2012
ChannelLayoutsAreEqual.h Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CreateChannelLayout.cpp Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CreateChannelLayout.h Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CreateDisplayNameForURL.cpp Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CreateDisplayNameForURL.h Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CreateStringForOSType.cpp Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
CreateStringForOSType.h Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
DeallocateABL.cpp Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
DeallocateABL.h Massive C++11 update. Changed all instances of NULL to nullptr, and u… Feb 24, 2012
Guard.cpp Deleted operator= and copy ctor Feb 29, 2012
Guard.h Deleted operator= and copy ctor Feb 29, 2012
Info.plist Added project files Oct 24, 2009
Logger+NSOverloads.mm Updated copyright Feb 26, 2012
Logger.cpp Added operator<< overload for CFUUIDBytes May 4, 2012
Logger.h Added operator<< overload for CFUUIDBytes May 4, 2012
Mutex.cpp Deleted operator= and copy ctor Feb 29, 2012
Mutex.h Deleted operator= and copy ctor Feb 29, 2012
README.md Updated README Feb 29, 2012
Semaphore.cpp Deleted operator= and copy ctor Feb 29, 2012
Semaphore.h Deleted operator= and copy ctor Feb 29, 2012

README.md

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;
}