1/*
2 * Copyright (c) 1998-2010 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8															   * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23#include "IOAudioDebug.h"
24#include "IOAudioEngine.h"
25#include "IOAudioStream.h"
26#include "IOAudioTypes.h"
27
28//#include <AppleDSP/OSvKernDSPLib.h>
29
30extern "C" void vDSP_vadd( const float input1[], __darwin_ptrdiff_t stride1, const float input2[], __darwin_ptrdiff_t stride2, float res[], __darwin_ptrdiff_t strideres, __darwin_size_t size);
31
32IOReturn IOAudioEngine::mixOutputSamples(const void *sourceBuf, void *mixBuf, UInt32 firstSampleFrame, UInt32 numSampleFrames, const IOAudioStreamFormat *streamFormat, IOAudioStream *audioStream)
33{
34	IOReturn result = kIOReturnBadArgument;
35
36    if (sourceBuf && mixBuf)
37	{
38		const float * floatSource1Buf;
39		const float * floatSource2Buf;
40		float * floatMixBuf;
41
42        UInt32 numSamplesLeft = numSampleFrames * streamFormat->fNumChannels;
43
44		__darwin_size_t numSamps = numSamplesLeft;
45
46		floatMixBuf = &(((float *)mixBuf)[firstSampleFrame * streamFormat->fNumChannels]);
47		floatSource2Buf = floatMixBuf;
48		floatSource1Buf = (const float *)sourceBuf;
49
50		__darwin_ptrdiff_t strideOne=1, strideTwo=1, resultStride=1;
51
52		vDSP_vadd(floatSource1Buf, strideOne, floatSource2Buf, strideTwo, floatMixBuf, resultStride, numSamps);
53
54        result = kIOReturnSuccess;
55    }
56
57    return result;
58}
59