mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 03:04:00 +00:00
Implement sound out to file
This commit is contained in:
parent
df858d805c
commit
5359a95757
81
Sources/CoreAudioSDK/CAConditionalMacros.h
Normal file
81
Sources/CoreAudioSDK/CAConditionalMacros.h
Normal file
|
@ -0,0 +1,81 @@
|
|||
/* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
|
||||
("Apple") in consideration of your agreement to the following terms, and your
|
||||
use, installation, modification or redistribution of this Apple software
|
||||
constitutes acceptance of these terms. If you do not agree with these terms,
|
||||
please do not use, install, modify or redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and subject
|
||||
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
|
||||
copyrights in this original Apple software (the "Apple Software"), to use,
|
||||
reproduce, modify and redistribute the Apple Software, with or without
|
||||
modifications, in source and/or binary forms; provided that if you redistribute
|
||||
the Apple Software in its entirety and without modifications, you must retain
|
||||
this notice and the following text and disclaimers in all such redistributions of
|
||||
the Apple Software. Neither the name, trademarks, service marks or logos of
|
||||
Apple Computer, Inc. may be used to endorse or promote products derived from the
|
||||
Apple Software without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or implied,
|
||||
are granted by Apple herein, including but not limited to any patent rights that
|
||||
may be infringed by your derivative works or by other works in which the Apple
|
||||
Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
|
||||
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
|
||||
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
|
||||
COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
|
||||
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
|
||||
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*=============================================================================
|
||||
CAConditionalMacros.h
|
||||
|
||||
=============================================================================*/
|
||||
#if !defined(__CAConditionalMacros_h__)
|
||||
#define __CAConditionalMacros_h__
|
||||
|
||||
//=============================================================================
|
||||
// This file exists to make figuring out how to include system headers
|
||||
// easier in a cross platform world. We throw in an include of the standard
|
||||
// ConditionalMacros too.
|
||||
//=============================================================================
|
||||
|
||||
// ########## THIS FILE SHOULD GO AWAY SOON, replaced by __COREAUDIO_USE_FLAT_INCLUDES__
|
||||
// but for now, use this as a way to define __COREAUDIO_USE_FLAT_INCLUDES__ programmatically
|
||||
|
||||
// TargetConditionals.h defines the bare minimum we need
|
||||
#include "TargetConditionals.h"
|
||||
|
||||
// Determine whether or not to use framework style includes for system headers
|
||||
#if !defined(CoreAudio_Use_Framework_Includes) && !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
|
||||
#if TARGET_RT_MAC_MACHO
|
||||
#define CoreAudio_Use_Framework_Includes 1
|
||||
#else
|
||||
#define CoreAudio_Use_Framework_Includes 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Include the regular ConditionalMacros.h too, since it has useful stuff that
|
||||
// TargetConditionals.h lacks for some reason.
|
||||
#if CoreAudio_Use_Framework_Includes
|
||||
#include <CoreServices/../Frameworks/CarbonCore.framework/Headers/ConditionalMacros.h>
|
||||
#else
|
||||
#include "ConditionalMacros.h"
|
||||
#endif
|
||||
|
||||
#ifndef TARGET_CPU_PPC_ANY
|
||||
#define TARGET_CPU_PPC_ANY (TARGET_CPU_PPC || TARGET_CPU_PPC64)
|
||||
#endif
|
||||
#ifndef TARGET_CPU_X86_ANY
|
||||
#define TARGET_CPU_X86_ANY (TARGET_CPU_X86 || TARGET_CPU_X86_64)
|
||||
#endif
|
||||
|
||||
#endif
|
84
Sources/CoreAudioSDK/CADebugMacros.cpp
Normal file
84
Sources/CoreAudioSDK/CADebugMacros.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
/* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
|
||||
("Apple") in consideration of your agreement to the following terms, and your
|
||||
use, installation, modification or redistribution of this Apple software
|
||||
constitutes acceptance of these terms. If you do not agree with these terms,
|
||||
please do not use, install, modify or redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and subject
|
||||
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
|
||||
copyrights in this original Apple software (the "Apple Software"), to use,
|
||||
reproduce, modify and redistribute the Apple Software, with or without
|
||||
modifications, in source and/or binary forms; provided that if you redistribute
|
||||
the Apple Software in its entirety and without modifications, you must retain
|
||||
this notice and the following text and disclaimers in all such redistributions of
|
||||
the Apple Software. Neither the name, trademarks, service marks or logos of
|
||||
Apple Computer, Inc. may be used to endorse or promote products derived from the
|
||||
Apple Software without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or implied,
|
||||
are granted by Apple herein, including but not limited to any patent rights that
|
||||
may be infringed by your derivative works or by other works in which the Apple
|
||||
Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
|
||||
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
|
||||
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
|
||||
COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
|
||||
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
|
||||
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*=============================================================================
|
||||
CADebugMacros.cp
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#include "CADebugMacros.h"
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#if TARGET_API_MAC_OSX
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#if DEBUG
|
||||
#include <stdio.h>
|
||||
|
||||
void DebugPrint(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vprintf(fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
#endif // DEBUG
|
||||
|
||||
#if TARGET_API_MAC_OSX
|
||||
void LogError(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#if DEBUG
|
||||
vprintf(fmt, args);
|
||||
#endif
|
||||
vsyslog(LOG_ERR, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void LogWarning(const char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
#if DEBUG
|
||||
vprintf(fmt, args);
|
||||
#endif
|
||||
vsyslog(LOG_WARNING, fmt, args);
|
||||
va_end(args);
|
||||
}
|
||||
#endif
|
492
Sources/CoreAudioSDK/CADebugMacros.h
Normal file
492
Sources/CoreAudioSDK/CADebugMacros.h
Normal file
|
@ -0,0 +1,492 @@
|
|||
/* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
|
||||
("Apple") in consideration of your agreement to the following terms, and your
|
||||
use, installation, modification or redistribution of this Apple software
|
||||
constitutes acceptance of these terms. If you do not agree with these terms,
|
||||
please do not use, install, modify or redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and subject
|
||||
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
|
||||
copyrights in this original Apple software (the "Apple Software"), to use,
|
||||
reproduce, modify and redistribute the Apple Software, with or without
|
||||
modifications, in source and/or binary forms; provided that if you redistribute
|
||||
the Apple Software in its entirety and without modifications, you must retain
|
||||
this notice and the following text and disclaimers in all such redistributions of
|
||||
the Apple Software. Neither the name, trademarks, service marks or logos of
|
||||
Apple Computer, Inc. may be used to endorse or promote products derived from the
|
||||
Apple Software without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or implied,
|
||||
are granted by Apple herein, including but not limited to any patent rights that
|
||||
may be infringed by your derivative works or by other works in which the Apple
|
||||
Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
|
||||
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
|
||||
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
|
||||
COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
|
||||
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
|
||||
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*=============================================================================
|
||||
CADebugMacros.h
|
||||
|
||||
|
||||
Revision 1.22 2006/01/17 22:13:07 dwyatt
|
||||
__LP64__ warnings
|
||||
|
||||
Revision 1.21 2005/03/15 22:50:28 jcm10
|
||||
use DebugPrintfLineEnding so that syslog doesn't get filled with empty lines
|
||||
|
||||
Revision 1.20 2004/10/27 01:28:08 jcm10
|
||||
add more FailIf macros
|
||||
|
||||
Revision 1.19 2004/09/09 09:14:26 jcm10
|
||||
add a ThrowIf for Windows errors
|
||||
|
||||
Revision 1.18 2004/08/25 02:26:26 jcm10
|
||||
always flush when using the side file
|
||||
|
||||
Revision 1.17 2004/08/02 18:45:35 dwyatt
|
||||
add LogWarning
|
||||
|
||||
Revision 1.16 2004/04/13 21:00:55 jcm10
|
||||
get rid of ThrowError
|
||||
|
||||
Revision 1.15 2004/04/12 22:58:29 jcm10
|
||||
fix the macros that used 4CC's to not generate warnings in release builds
|
||||
|
||||
Revision 1.14 2004/04/01 20:00:36 jcm10
|
||||
add Throw and clean up the ThrowIf macros
|
||||
|
||||
Revision 1.13 2004/02/27 01:45:19 jcm10
|
||||
add ThrowError()
|
||||
|
||||
Revision 1.12 2004/01/29 22:50:09 jcm10
|
||||
have AssertNoError print the error number as a 4 char code
|
||||
|
||||
Revision 1.11 2003/08/29 04:13:55 jcm10
|
||||
show the time in milliseconds
|
||||
|
||||
Revision 1.10 2003/07/04 23:56:26 jcm10
|
||||
add a few more DebugMessages
|
||||
|
||||
Revision 1.9 2003/06/06 01:51:32 jcm10
|
||||
clean up some whitespace
|
||||
|
||||
Revision 1.8 2002/12/14 23:59:58 jcm10
|
||||
CADebugger is now C compatible so it can be included in pre-compiled headers
|
||||
|
||||
Revision 1.7 2002/10/02 21:01:40 jcm10
|
||||
add ThrowIfNULL
|
||||
|
||||
Revision 1.6 2002/09/11 19:17:55 jcm10
|
||||
in ThrowIfError, print the error number as a four char code too
|
||||
|
||||
Revision 1.5 2002/07/20 01:46:45 jcm10
|
||||
turn off thread stamping
|
||||
|
||||
Revision 1.4 2002/07/17 21:53:08 jcm10
|
||||
make the thread stamping and time stamping work right
|
||||
|
||||
Revision 1.3 2002/07/03 23:49:55 jcm10
|
||||
add AssertNoKernelError
|
||||
|
||||
Revision 1.2 2002/05/02 22:31:57 jcm10
|
||||
display kernel errors in hex
|
||||
|
||||
Revision 1.1 2002/03/01 01:52:40 jcm10
|
||||
moved here from ../Utility
|
||||
|
||||
Revision 1.1 2002/02/28 23:18:54 jcm10
|
||||
added the CA prefix to the files for more consistency
|
||||
|
||||
Revision 0.0 Thu Feb 28 2002 14:46:56 US/Pacific moorf
|
||||
Created
|
||||
|
||||
$NoKeywords: $
|
||||
=============================================================================*/
|
||||
#if !defined(__CADebugMacros_h__)
|
||||
#define __CADebugMacros_h__
|
||||
|
||||
//=============================================================================
|
||||
// CADebugMacros
|
||||
//=============================================================================
|
||||
|
||||
//#define CoreAudio_StopOnFailure 1
|
||||
//#define CoreAudio_TimeStampMessages 1
|
||||
//#define CoreAudio_ThreadStampMessages 1
|
||||
//#define CoreAudio_FlushDebugMessages 1
|
||||
|
||||
#if __BIG_ENDIAN__
|
||||
#define CA4CCToCString(the4CC) { ((char*)&the4CC)[0], ((char*)&the4CC)[1], ((char*)&the4CC)[2], ((char*)&the4CC)[3], 0 }
|
||||
#else
|
||||
#define CA4CCToCString(the4CC) { ((char*)&the4CC)[3], ((char*)&the4CC)[2], ((char*)&the4CC)[1], ((char*)&the4CC)[0], 0 }
|
||||
#endif
|
||||
|
||||
#pragma mark Basic Definitions
|
||||
|
||||
#if DEBUG || CoreAudio_Debug
|
||||
|
||||
// can be used to break into debugger immediately, also see CADebugger
|
||||
#define BusError() (*(long *)0 = 0)
|
||||
|
||||
// basic debugging print routines
|
||||
#if TARGET_OS_MAC && !TARGET_API_MAC_CARBON
|
||||
extern pascal void DebugStr(const unsigned char* debuggerMsg);
|
||||
#define DebugMessage(msg) DebugStr("\p"msg)
|
||||
#define DebugMessageN1(msg, N1)
|
||||
#define DebugMessageN2(msg, N1, N2)
|
||||
#define DebugMessageN3(msg, N1, N2, N3)
|
||||
#else
|
||||
#include "CADebugPrintf.h"
|
||||
|
||||
#if (CoreAudio_FlushDebugMessages && !CoreAudio_UseSysLog) || defined(CoreAudio_UseSideFile)
|
||||
#define FlushRtn ;fflush(DebugPrintfFile)
|
||||
#else
|
||||
#define FlushRtn
|
||||
#endif
|
||||
|
||||
#if CoreAudio_ThreadStampMessages
|
||||
#include <pthread.h>
|
||||
#include "CAHostTimeBase.h"
|
||||
#define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: %s"DebugPrintfLineEnding, pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
|
||||
#define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
|
||||
#define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
|
||||
#define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
|
||||
#define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
|
||||
#define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
|
||||
#define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
|
||||
#define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
|
||||
#define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
|
||||
#define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, "%p %.4f: "msg"\n", pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
|
||||
#elif CoreAudio_TimeStampMessages
|
||||
#include "CAHostTimeBase.h"
|
||||
#define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFile, "%.4f: %s"DebugPrintfLineEnding, pthread_self(), ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), msg) FlushRtn
|
||||
#define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1) FlushRtn
|
||||
#define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2) FlushRtn
|
||||
#define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3) FlushRtn
|
||||
#define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4) FlushRtn
|
||||
#define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5) FlushRtn
|
||||
#define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6) FlushRtn
|
||||
#define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7) FlushRtn
|
||||
#define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
|
||||
#define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, "%.4f: "msg DebugPrintfLineEnding, ((Float64)(CAHostTimeBase::GetCurrentTimeInNanos()) / 1000000.0), N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
|
||||
#else
|
||||
#define DebugMessage(msg) DebugPrintfRtn(DebugPrintfFile, "%s"DebugPrintfLineEnding, msg) FlushRtn
|
||||
#define DebugMessageN1(msg, N1) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1) FlushRtn
|
||||
#define DebugMessageN2(msg, N1, N2) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2) FlushRtn
|
||||
#define DebugMessageN3(msg, N1, N2, N3) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3) FlushRtn
|
||||
#define DebugMessageN4(msg, N1, N2, N3, N4) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4) FlushRtn
|
||||
#define DebugMessageN5(msg, N1, N2, N3, N4, N5) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5) FlushRtn
|
||||
#define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6) FlushRtn
|
||||
#define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7) FlushRtn
|
||||
#define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7, N8) FlushRtn
|
||||
#define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9) DebugPrintfRtn(DebugPrintfFile, msg DebugPrintfLineEnding, N1, N2, N3, N4, N5, N6, N7, N8, N9) FlushRtn
|
||||
#endif
|
||||
#endif
|
||||
void DebugPrint(const char *fmt, ...); // can be used like printf
|
||||
#define DEBUGPRINT(msg) DebugPrint msg // have to double-parenthesize arglist (see Debugging.h)
|
||||
#if VERBOSE
|
||||
#define vprint(msg) DEBUGPRINT(msg)
|
||||
#else
|
||||
#define vprint(msg)
|
||||
#endif
|
||||
|
||||
#if CoreAudio_StopOnFailure
|
||||
#include "CADebugger.h"
|
||||
#define STOP CADebuggerStop()
|
||||
#else
|
||||
#define STOP
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define DebugMessage(msg)
|
||||
#define DebugMessageN1(msg, N1)
|
||||
#define DebugMessageN2(msg, N1, N2)
|
||||
#define DebugMessageN3(msg, N1, N2, N3)
|
||||
#define DebugMessageN4(msg, N1, N2, N3, N4)
|
||||
#define DebugMessageN5(msg, N1, N2, N3, N4, N5)
|
||||
#define DebugMessageN6(msg, N1, N2, N3, N4, N5, N6)
|
||||
#define DebugMessageN7(msg, N1, N2, N3, N4, N5, N6, N7)
|
||||
#define DebugMessageN8(msg, N1, N2, N3, N4, N5, N6, N7, N8)
|
||||
#define DebugMessageN9(msg, N1, N2, N3, N4, N5, N6, N7, N8, N9)
|
||||
#define DEBUGPRINT(msg)
|
||||
#define vprint(msg)
|
||||
#define STOP
|
||||
#endif
|
||||
|
||||
void LogError(const char *fmt, ...); // writes to syslog (and stderr if debugging)
|
||||
void LogWarning(const char *fmt, ...); // writes to syslog (and stderr if debugging)
|
||||
|
||||
#if DEBUG || CoreAudio_Debug
|
||||
|
||||
#pragma mark Debug Macros
|
||||
|
||||
#define Assert(inCondition, inMessage) \
|
||||
if(!(inCondition)) \
|
||||
{ \
|
||||
DebugMessage(inMessage); \
|
||||
STOP; \
|
||||
}
|
||||
|
||||
#define AssertNoError(inError, inMessage) \
|
||||
{ \
|
||||
SInt32 __Err = (inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
char __4CC[5] = CA4CCToCString(__Err); \
|
||||
DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
|
||||
STOP; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define AssertNoKernelError(inError, inMessage) \
|
||||
{ \
|
||||
unsigned int __Err = (unsigned int)(inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
|
||||
STOP; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define FailIf(inCondition, inHandler, inMessage) \
|
||||
if(inCondition) \
|
||||
{ \
|
||||
DebugMessage(inMessage); \
|
||||
STOP; \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
|
||||
if(inCondition) \
|
||||
{ \
|
||||
DebugMessage(inMessage); \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
|
||||
if((inPointer) == NULL) \
|
||||
{ \
|
||||
DebugMessage(inMessage); \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailIfKernelError(inKernelError, inException, inMessage) \
|
||||
{ \
|
||||
kern_return_t __Err = (inKernelError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define FailIfError(inError, inException, inMessage) \
|
||||
{ \
|
||||
SInt32 __Err = (inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
char __4CC[5] = CA4CCToCString(__Err); \
|
||||
DebugMessageN2(inMessage ", Error: %ld (%s)", __Err, __4CC); \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
} \
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
#define Throw(inException) STOP; throw (inException)
|
||||
|
||||
#define ThrowIf(inCondition, inException, inMessage) \
|
||||
if(inCondition) \
|
||||
{ \
|
||||
DebugMessage(inMessage); \
|
||||
Throw(inException); \
|
||||
}
|
||||
|
||||
#define ThrowIfNULL(inPointer, inException, inMessage) \
|
||||
if((inPointer) == NULL) \
|
||||
{ \
|
||||
DebugMessage(inMessage); \
|
||||
Throw(inException); \
|
||||
}
|
||||
|
||||
#define ThrowIfKernelError(inKernelError, inException, inMessage) \
|
||||
{ \
|
||||
kern_return_t __Err = (inKernelError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
|
||||
Throw(inException); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ThrowIfError(inError, inException, inMessage) \
|
||||
{ \
|
||||
SInt32 __Err = (inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
char __4CC[5] = CA4CCToCString(__Err); \
|
||||
DebugMessageN2(inMessage ", Error: %d (%s)", (int)__Err, __4CC); \
|
||||
Throw(inException); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if TARGET_OS_WIN32
|
||||
#define ThrowIfWinError(inError, inException, inMessage) \
|
||||
{ \
|
||||
HRESULT __Err = (inError); \
|
||||
if(FAILED(__Err)) \
|
||||
{ \
|
||||
DebugMessageN1(inMessage ", Error: 0x%X", __Err); \
|
||||
Throw(inException); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SubclassResponsibility(inMethodName, inException) \
|
||||
{ \
|
||||
DebugMessage(inMethodName": Subclasses must implement this method"); \
|
||||
Throw(inException); \
|
||||
}
|
||||
|
||||
#endif // defined(__cplusplus)
|
||||
|
||||
#else
|
||||
|
||||
#pragma mark Release Macros
|
||||
|
||||
#define Assert(inCondition, inMessage) \
|
||||
if(!(inCondition)) \
|
||||
{ \
|
||||
STOP; \
|
||||
}
|
||||
|
||||
#define AssertNoError(inError, inMessage) \
|
||||
{ \
|
||||
SInt32 __Err = (inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
STOP; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define AssertNoKernelError(inError, inMessage) \
|
||||
{ \
|
||||
unsigned int __Err = (unsigned int)(inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
STOP; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define FailIf(inCondition, inHandler, inMessage) \
|
||||
if(inCondition) \
|
||||
{ \
|
||||
STOP; \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailWithAction(inCondition, inAction, inHandler, inMessage) \
|
||||
if(inCondition) \
|
||||
{ \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailIfNULL(inPointer, inAction, inHandler, inMessage) \
|
||||
if((inPointer) == NULL) \
|
||||
{ \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailIfKernelError(inKernelError, inException, inMessage) \
|
||||
if((inKernelError) != 0) \
|
||||
{ \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#define FailIfError(inError, inException, inMessage) \
|
||||
if((inError) != 0) \
|
||||
{ \
|
||||
STOP; \
|
||||
{ inAction; } \
|
||||
goto inHandler; \
|
||||
}
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
#define Throw(inException) STOP; throw (inException)
|
||||
|
||||
#define ThrowIf(inCondition, inException, inMessage) \
|
||||
if(inCondition) \
|
||||
{ \
|
||||
Throw(inException); \
|
||||
}
|
||||
|
||||
#define ThrowIfNULL(inPointer, inException, inMessage) \
|
||||
if((inPointer) == NULL) \
|
||||
{ \
|
||||
Throw(inException); \
|
||||
}
|
||||
|
||||
#define ThrowIfKernelError(inKernelError, inException, inMessage) \
|
||||
{ \
|
||||
kern_return_t __Err = (inKernelError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
Throw(inException); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define ThrowIfError(inError, inException, inMessage) \
|
||||
{ \
|
||||
SInt32 __Err = (inError); \
|
||||
if(__Err != 0) \
|
||||
{ \
|
||||
Throw(inException); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if TARGET_OS_WIN32
|
||||
#define ThrowIfWinError(inError, inException, inMessage) \
|
||||
{ \
|
||||
HRESULT __Err = (inError); \
|
||||
if(FAILED(__Err)) \
|
||||
{ \
|
||||
Throw(inException); \
|
||||
} \
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SubclassResponsibility(inMethodName, inException) \
|
||||
{ \
|
||||
Throw(inException); \
|
||||
}
|
||||
|
||||
#endif // defined(__cplusplus)
|
||||
|
||||
#endif // DEBUG || CoreAudio_Debug
|
||||
|
||||
#endif
|
64
Sources/CoreAudioSDK/CAMath.h
Normal file
64
Sources/CoreAudioSDK/CAMath.h
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* Copyright: © Copyright 2005 Apple Computer, Inc. All rights reserved.
|
||||
|
||||
Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc.
|
||||
("Apple") in consideration of your agreement to the following terms, and your
|
||||
use, installation, modification or redistribution of this Apple software
|
||||
constitutes acceptance of these terms. If you do not agree with these terms,
|
||||
please do not use, install, modify or redistribute this Apple software.
|
||||
|
||||
In consideration of your agreement to abide by the following terms, and subject
|
||||
to these terms, Apple grants you a personal, non-exclusive license, under AppleÕs
|
||||
copyrights in this original Apple software (the "Apple Software"), to use,
|
||||
reproduce, modify and redistribute the Apple Software, with or without
|
||||
modifications, in source and/or binary forms; provided that if you redistribute
|
||||
the Apple Software in its entirety and without modifications, you must retain
|
||||
this notice and the following text and disclaimers in all such redistributions of
|
||||
the Apple Software. Neither the name, trademarks, service marks or logos of
|
||||
Apple Computer, Inc. may be used to endorse or promote products derived from the
|
||||
Apple Software without specific prior written permission from Apple. Except as
|
||||
expressly stated in this notice, no other rights or licenses, express or implied,
|
||||
are granted by Apple herein, including but not limited to any patent rights that
|
||||
may be infringed by your derivative works or by other works in which the Apple
|
||||
Software may be incorporated.
|
||||
|
||||
The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO
|
||||
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
|
||||
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
|
||||
COMBINATION WITH YOUR PRODUCTS.
|
||||
|
||||
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
|
||||
OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
|
||||
(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
|
||||
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/*=============================================================================
|
||||
CAMath.h
|
||||
|
||||
=============================================================================*/
|
||||
|
||||
#ifndef __CAMath_h__
|
||||
#define __CAMath_h__
|
||||
|
||||
#if !defined(__COREAUDIO_USE_FLAT_INCLUDES__)
|
||||
#include <CoreAudio/CoreAudioTypes.h>
|
||||
#else
|
||||
#include <CoreAudioTypes.h>
|
||||
#endif
|
||||
|
||||
inline bool fiszero(Float64 f) { return (f == 0.); }
|
||||
inline bool fiszero(Float32 f) { return (f == 0.f); }
|
||||
|
||||
inline bool fnonzero(Float64 f) { return !fiszero(f); }
|
||||
inline bool fnonzero(Float32 f) { return !fiszero(f); }
|
||||
|
||||
inline bool fequal(const Float64 &a, const Float64 &b) { return a == b; }
|
||||
inline bool fequal(const Float32 &a, const Float32 &b) { return a == b; }
|
||||
|
||||
inline bool fnotequal(const Float64 &a, const Float64 &b) { return !fequal(a, b); }
|
||||
inline bool fnotequal(const Float32 &a, const Float32 &b) { return !fequal(a, b); }
|
||||
|
||||
#endif // __CAMath_h__
|
|
@ -12,9 +12,14 @@
|
|||
#include <AudioUnit/AudioUnit.h>
|
||||
#include <AudioToolbox/AudioToolbox.h>
|
||||
|
||||
#include "CAAudioFileFormats.h"
|
||||
#include "AUOutputBL.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#define R(x) if (OSStatus r = (x)) fprintf(stderr, "%s -> %ld\n", #x, r);
|
||||
|
||||
class VLAUSoundOut : public VLSoundOut {
|
||||
public:
|
||||
VLAUSoundOut();
|
||||
|
@ -29,14 +34,14 @@ public:
|
|||
protected:
|
||||
VLAUSoundOut(bool fileOutput);
|
||||
|
||||
void InitSoundOut(bool fileOutput);
|
||||
void InitSoundOutput(bool fileOutput);
|
||||
virtual void SetupOutput(AUNode outputNode);
|
||||
virtual void PlaySequence(MusicSequence music);
|
||||
MusicTimeStamp SequenceLength(MusicSequence music);
|
||||
|
||||
AUGraph fGraph;
|
||||
private:
|
||||
MusicPlayer fPlayer;
|
||||
private:
|
||||
MusicSequence fMusic;
|
||||
bool fRunning;
|
||||
|
||||
|
@ -45,7 +50,7 @@ private:
|
|||
|
||||
class VLAUFileSoundOut : public VLAUSoundOut {
|
||||
public:
|
||||
VLAUFileSoundOut(CFURLRef file);
|
||||
VLAUFileSoundOut(CFURLRef file, OSType dataFormat);
|
||||
~VLAUFileSoundOut();
|
||||
protected:
|
||||
virtual void SetupOutput(AUNode outputNode);
|
||||
|
@ -53,6 +58,7 @@ protected:
|
|||
private:
|
||||
AudioUnit fOutput;
|
||||
CFURLRef fFile;
|
||||
OSType fDataFormat;
|
||||
};
|
||||
|
||||
VLSoundEvent::~VLSoundEvent()
|
||||
|
@ -83,9 +89,9 @@ void VLSoundOut::SetScheduler(VLSoundScheduler * scheduler)
|
|||
sSoundScheduler.reset(scheduler);
|
||||
}
|
||||
|
||||
VLSoundOut * VLSoundOut::FileWriter(CFURLRef file)
|
||||
VLSoundOut * VLSoundOut::FileWriter(CFURLRef file, OSType dataFormat)
|
||||
{
|
||||
return new VLAUFileSoundOut(file);
|
||||
return new VLAUFileSoundOut(file, dataFormat);
|
||||
}
|
||||
|
||||
VLSoundOut::~VLSoundOut()
|
||||
|
@ -98,10 +104,9 @@ VLAUSoundOut::VLAUSoundOut()
|
|||
InitSoundOutput(false);
|
||||
}
|
||||
|
||||
VLAUSoundOut::VLAUSoundOut(bool fileOutput)
|
||||
VLAUSoundOut::VLAUSoundOut(bool)
|
||||
: fRunning(false), fMusic(0)
|
||||
{
|
||||
InitSoundOutput(fileOutput);
|
||||
}
|
||||
|
||||
VLAUSoundOut::~VLAUSoundOut()
|
||||
|
@ -140,22 +145,27 @@ void VLAUSoundOut::InitSoundOutput(bool fileOutput)
|
|||
|
||||
AUGraphNewNode(fGraph, &cd, 0, NULL, &outNode);
|
||||
|
||||
AUGraphOpen(fGraph);
|
||||
R(AUGraphOpen(fGraph));
|
||||
AUGraphConnectNodeInput(fGraph, synthNode, 0, limiterNode, 0);
|
||||
AUGraphConnectNodeInput(fGraph, limiterNode, 0, outNode, 0);
|
||||
|
||||
if (fileOutput) {
|
||||
UInt32 value = 1;
|
||||
AudioUnit synth;
|
||||
AUGraphGetNodeInfo(fGraph, synthNode, 0, 0, 0, &synth)
|
||||
AudioUnitSetProperty(synth,
|
||||
kAudioUnitProperty_OfflineRender,
|
||||
kAudioUnitScope_Global, 0,
|
||||
&value, sizeof(value));
|
||||
R(AUGraphGetNodeInfo(fGraph, synthNode, 0, 0, 0, &synth));
|
||||
R(AudioUnitSetProperty(synth,
|
||||
kAudioUnitProperty_OfflineRender,
|
||||
kAudioUnitScope_Global, 0,
|
||||
&value, sizeof(value)));
|
||||
value = 512;
|
||||
R(AudioUnitSetProperty(synth,
|
||||
kAudioUnitProperty_OfflineRender,
|
||||
kAudioUnitScope_Global, 0,
|
||||
&value, sizeof(value)));
|
||||
}
|
||||
SetupOutput(outNode);
|
||||
|
||||
AUGraphInitialize(fGraph);
|
||||
R(AUGraphInitialize(fGraph));
|
||||
|
||||
NewMusicPlayer(&fPlayer);
|
||||
}
|
||||
|
@ -170,9 +180,9 @@ void VLAUSoundOut::PlaySequence(MusicSequence music)
|
|||
|
||||
fMusic = music;
|
||||
|
||||
MusicSequenceSetAUGraph(fMusic, fGraph);
|
||||
MusicPlayerSetSequence(fPlayer, fMusic);
|
||||
MusicPlayerStart(fPlayer);
|
||||
R(MusicSequenceSetAUGraph(fMusic, fGraph));
|
||||
R(MusicPlayerSetSequence(fPlayer, fMusic));
|
||||
R(MusicPlayerStart(fPlayer));
|
||||
|
||||
fRunning = true;
|
||||
}
|
||||
|
@ -227,10 +237,8 @@ void VLAUSoundOut::Play(const int8_t * note, size_t numNotes)
|
|||
void VLAUSoundOut::PlayFile(CFDataRef file)
|
||||
{
|
||||
MusicSequence music;
|
||||
MusicTrack track;
|
||||
|
||||
NewMusicSequence(&music);
|
||||
MusicSequenceNewTrack(music, &track);
|
||||
MusicSequenceLoadSMFDataWithFlags(music, file,
|
||||
kMusicSequenceLoadSMF_ChannelsToTracks);
|
||||
PlaySequence(music);
|
||||
|
@ -239,13 +247,13 @@ void VLAUSoundOut::PlayFile(CFDataRef file)
|
|||
MusicTimeStamp VLAUSoundOut::SequenceLength(MusicSequence music)
|
||||
{
|
||||
UInt32 ntracks;
|
||||
MusicSequenceGetTrackCount(sequence, &ntracks);
|
||||
MusicSequenceGetTrackCount(music, &ntracks);
|
||||
MusicTimeStamp sequenceLength = 0;
|
||||
for (UInt32 i = 0; i < ntracks; ++i) {
|
||||
MusicTrack track;
|
||||
MusicTimeStamp trackLength;
|
||||
UInt32 propsize = sizeof(MusicTimeStamp);
|
||||
MusicSequenceGetIndTrack(sequence, i, &track);
|
||||
MusicSequenceGetIndTrack(music, i, &track);
|
||||
MusicTrackGetProperty(track, kSequenceTrackProperty_TrackLength,
|
||||
&trackLength, &propsize);
|
||||
sequenceLength = std::max(sequenceLength, trackLength);
|
||||
|
@ -253,9 +261,11 @@ MusicTimeStamp VLAUSoundOut::SequenceLength(MusicSequence music)
|
|||
return sequenceLength;
|
||||
}
|
||||
|
||||
VLAUFileSoundOut::VLAUFileSoundOut(CFURLRef file)
|
||||
: VLAUSoundOut(true), fFile(file)
|
||||
VLAUFileSoundOut::VLAUFileSoundOut(CFURLRef file, OSType dataFormat)
|
||||
: VLAUSoundOut(true), fFile(file), fDataFormat(dataFormat)
|
||||
{
|
||||
InitSoundOutput(true);
|
||||
|
||||
CFRetain(fFile);
|
||||
}
|
||||
|
||||
|
@ -266,33 +276,43 @@ VLAUFileSoundOut::~VLAUFileSoundOut()
|
|||
|
||||
void VLAUFileSoundOut::SetupOutput(AUNode outputNode)
|
||||
{
|
||||
AUGraphGetNodeInfo(fGraph, outputNode, 0, 0, 0, &fOutput);
|
||||
R(AUGraphGetNodeInfo(fGraph, outputNode, 0, 0, 0, &fOutput));
|
||||
Float64 sampleRate = 22050.0;
|
||||
AudioUnitSetProperty(fOutput,
|
||||
kAudioUnitProperty_SampleRate,
|
||||
kAudioUnitScope_Output, 0,
|
||||
&sampleRate, sizeof(sampleRate));
|
||||
}
|
||||
R(AudioUnitSetProperty(fOutput,
|
||||
kAudioUnitProperty_SampleRate,
|
||||
kAudioUnitScope_Output, 0,
|
||||
&sampleRate, sizeof(sampleRate)));
|
||||
}
|
||||
|
||||
void VLAUFileSoundOut::PlaySequence(MusicSequence music)
|
||||
{
|
||||
SInt32 urlErr;
|
||||
CFURLDestroyResource(fFile, &urlErr);
|
||||
|
||||
OSStatus result = 0;
|
||||
UInt32 size;
|
||||
UInt32 numFrames = 512;
|
||||
MusicTimeStamp musicLen = SequenceLength(music)+8;
|
||||
CFStringRef name =
|
||||
CFURLCopyLastPathComponent(fFile);
|
||||
CAAudioFileFormats formats = CAAudioFileFormats::Instance();
|
||||
CAAudioFileFormats * formats = CAAudioFileFormats::Instance();
|
||||
|
||||
AudioFileTypeID fileType;
|
||||
formats->InferFileFormatFromFilename(name, fileType);
|
||||
|
||||
CAStreamBasicDescription outputFormat;
|
||||
formats->InferDataFormatFromFileFormat(fileType, outputFormat);
|
||||
if (fDataFormat)
|
||||
outputFormat.mFormatID = fDataFormat;
|
||||
else if (!formats->InferDataFormatFromFileFormat(fileType, outputFormat))
|
||||
switch (fileType) {
|
||||
case kAudioFileM4AType:
|
||||
outputFormat.mFormatID = kAudioFormatMPEG4AAC;
|
||||
break;
|
||||
default:
|
||||
outputFormat.mFormatID = kAudioFormatLinearPCM;
|
||||
break;
|
||||
}
|
||||
outputFormat.mChannelsPerFrame = 2;
|
||||
|
||||
outputFormat.mSampleRate = 22050.0;
|
||||
if (outputFormat.mFormatID == kAudioFormatLinearPCM) {
|
||||
outputFormat.mBytesPerPacket = outputFormat.mChannelsPerFrame * 2;
|
||||
outputFormat.mFramesPerPacket = 1;
|
||||
|
@ -309,8 +329,8 @@ void VLAUFileSoundOut::PlaySequence(MusicSequence music)
|
|||
} else {
|
||||
// use AudioFormat API to fill out the rest.
|
||||
size = sizeof(outputFormat);
|
||||
AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL,
|
||||
&size, &outputFormat);
|
||||
R(AudioFormatGetProperty(kAudioFormatProperty_FormatInfo, 0, NULL,
|
||||
&size, &outputFormat));
|
||||
}
|
||||
|
||||
CFURLRef dir =
|
||||
|
@ -320,52 +340,39 @@ void VLAUFileSoundOut::PlaySequence(MusicSequence music)
|
|||
CFRelease(dir);
|
||||
|
||||
ExtAudioFileRef outfile;
|
||||
ExtAudioFileCreateNew(&parentDir, name,
|
||||
fileType, &outputFormat, NULL, &outfile);
|
||||
R(ExtAudioFileCreateNew(&parentDir, name,
|
||||
fileType, &outputFormat, NULL, &outfile));
|
||||
CFRelease(name);
|
||||
|
||||
{
|
||||
CAStreamBasicDescription clientFormat;
|
||||
size = sizeof(clientFormat);
|
||||
require_noerr (result = AudioUnitGetProperty (outputUnit,
|
||||
kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Output, 0,
|
||||
&clientFormat, &size), fail);
|
||||
size = sizeof(clientFormat);
|
||||
require_noerr (result = ExtAudioFileSetProperty(outfile, kExtAudioFileProperty_ClientDataFormat, size, &clientFormat), fail);
|
||||
|
||||
{
|
||||
MusicTimeStamp currentTime;
|
||||
AUOutputBL outputBuffer (clientFormat, numFrames);
|
||||
AudioTimeStamp tStamp;
|
||||
memset (&tStamp, 0, sizeof(AudioTimeStamp));
|
||||
tStamp.mFlags = kAudioTimeStampSampleTimeValid;
|
||||
int i = 0;
|
||||
int numTimesFor10Secs = (int)(10. / (numFrames / srate));
|
||||
do {
|
||||
outputBuffer.Prepare();
|
||||
AudioUnitRenderActionFlags actionFlags = 0;
|
||||
require_noerr (result = AudioUnitRender (outputUnit, &actionFlags, &tStamp, 0, numFrames, outputBuffer.ABL()), fail);
|
||||
CAStreamBasicDescription clientFormat;
|
||||
size = sizeof(clientFormat);
|
||||
R(AudioUnitGetProperty(fOutput, kAudioUnitProperty_StreamFormat,
|
||||
kAudioUnitScope_Output, 0, &clientFormat, &size));
|
||||
clientFormat.Print(stderr);
|
||||
R(ExtAudioFileSetProperty(outfile, kExtAudioFileProperty_ClientDataFormat,
|
||||
size, &clientFormat));
|
||||
|
||||
tStamp.mSampleTime += numFrames;
|
||||
VLAUSoundOut::PlaySequence(music);
|
||||
|
||||
MusicTimeStamp currentTime;
|
||||
AUOutputBL outputBuffer (clientFormat, numFrames);
|
||||
AudioTimeStamp tStamp;
|
||||
memset (&tStamp, 0, sizeof(AudioTimeStamp));
|
||||
tStamp.mFlags = kAudioTimeStampSampleTimeValid;
|
||||
do {
|
||||
outputBuffer.Prepare();
|
||||
AudioUnitRenderActionFlags actionFlags = 0;
|
||||
R(AudioUnitRender(fOutput, &actionFlags, &tStamp, 0, numFrames,
|
||||
outputBuffer.ABL()));
|
||||
|
||||
tStamp.mSampleTime += numFrames;
|
||||
|
||||
require_noerr (result = ExtAudioFileWrite(outfile, numFrames, outputBuffer.ABL()), fail);
|
||||
R(ExtAudioFileWrite(outfile, numFrames, outputBuffer.ABL()));
|
||||
|
||||
require_noerr (result = MusicPlayerGetTime (player, ¤tTime), fail);
|
||||
if (shouldPrint && (++i % numTimesFor10Secs == 0))
|
||||
printf ("current time: %6.2f beats\n", currentTime);
|
||||
} while (currentTime < sequenceLength);
|
||||
}
|
||||
}
|
||||
MusicPlayerGetTime (fPlayer, ¤tTime);
|
||||
} while (currentTime < musicLen);
|
||||
|
||||
// close
|
||||
ExtAudioFileDispose(outfile);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
printf ("Problem: %ld\n", result);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ public:
|
|||
class VLSoundOut {
|
||||
public:
|
||||
static VLSoundOut * Instance();
|
||||
static VLSoundOut * FileWriter(CFURLRef file);
|
||||
static VLSoundOut * FileWriter(CFURLRef file, OSType dataFormat);
|
||||
|
||||
static void SetScheduler(VLSoundScheduler * scheduler);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user