To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

The primary repository for this project is hosted at https://github.com/sonic-visualiser/sv-dependency-builds .
This repository is a read-only copy which is updated automatically every hour.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / src / portaudio_20161030_catalina_patch / src / hostapi / coreaudio / pa_mac_core_internal.h @ 164:9fa11135915a

History | View | Annotate | Download (7.19 KB)

1
/*
2
 * Internal interfaces for PortAudio Apple AUHAL implementation
3
 *
4
 * PortAudio Portable Real-Time Audio Library
5
 * Latest Version at: http://www.portaudio.com
6
 *
7
 * Written by Bjorn Roche of XO Audio LLC, from PA skeleton code.
8
 * Portions copied from code by Dominic Mazzoni (who wrote a HAL implementation)
9
 *
10
 * Dominic's code was based on code by Phil Burk, Darren Gibbs,
11
 * Gord Peters, Stephane Letz, and Greg Pfiel.
12
 *
13
 * The following people also deserve acknowledgements:
14
 *
15
 * Olivier Tristan for feedback and testing
16
 * Glenn Zelniker and Z-Systems engineering for sponsoring the Blocking I/O
17
 * interface.
18
 * 
19
 *
20
 * Based on the Open Source API proposed by Ross Bencina
21
 * Copyright (c) 1999-2002 Ross Bencina, Phil Burk
22
 *
23
 * Permission is hereby granted, free of charge, to any person obtaining
24
 * a copy of this software and associated documentation files
25
 * (the "Software"), to deal in the Software without restriction,
26
 * including without limitation the rights to use, copy, modify, merge,
27
 * publish, distribute, sublicense, and/or sell copies of the Software,
28
 * and to permit persons to whom the Software is furnished to do so,
29
 * subject to the following conditions:
30
 *
31
 * The above copyright notice and this permission notice shall be
32
 * included in all copies or substantial portions of the Software.
33
 *
34
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
38
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
39
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
 */
42

    
43
/*
44
 * The text above constitutes the entire PortAudio license; however, 
45
 * the PortAudio community also makes the following non-binding requests:
46
 *
47
 * Any person wishing to distribute modifications to the Software is
48
 * requested to send the modifications to the original developer so that
49
 * they can be incorporated into the canonical version. It is also 
50
 * requested that these non-binding requests be included along with the 
51
 * license above.
52
 */
53

    
54
/**
55
 @file pa_mac_core
56
 @ingroup hostapi_src
57
 @author Bjorn Roche
58
 @brief AUHAL implementation of PortAudio
59
*/
60

    
61
#ifndef PA_MAC_CORE_INTERNAL_H__
62
#define PA_MAC_CORE_INTERNAL_H__
63

    
64
#include <CoreAudio/CoreAudio.h>
65
#include <CoreServices/CoreServices.h>
66
#ifdef AUDIO_COMPONENT_FIX
67
#include <AudioUnit/AudioComponent.h>
68
#endif
69
#include <AudioUnit/AudioUnit.h>
70
#include <AudioToolbox/AudioToolbox.h>
71

    
72
#include "portaudio.h"
73
#include "pa_util.h"
74
#include "pa_hostapi.h"
75
#include "pa_stream.h"
76
#include "pa_allocation.h"
77
#include "pa_cpuload.h"
78
#include "pa_process.h"
79
#include "pa_ringbuffer.h"
80

    
81
#include "pa_mac_core_blocking.h"
82

    
83
/* function prototypes */
84

    
85
#ifdef __cplusplus
86
extern "C"
87
{
88
#endif /* __cplusplus */
89

    
90
PaError PaMacCore_Initialize( PaUtilHostApiRepresentation **hostApi, PaHostApiIndex index );
91

    
92
#ifdef __cplusplus
93
}
94
#endif /* __cplusplus */
95

    
96
#define RING_BUFFER_ADVANCE_DENOMINATOR (4)
97

    
98
PaError ReadStream( PaStream* stream, void *buffer, unsigned long frames );
99
PaError WriteStream( PaStream* stream, const void *buffer, unsigned long frames );
100
signed long GetStreamReadAvailable( PaStream* stream );
101
signed long GetStreamWriteAvailable( PaStream* stream );
102
/* PaMacAUHAL - host api datastructure specific to this implementation */
103
typedef struct
104
{
105
    PaUtilHostApiRepresentation inheritedHostApiRep;
106
    PaUtilStreamInterface callbackStreamInterface;
107
    PaUtilStreamInterface blockingStreamInterface;
108

    
109
    PaUtilAllocationGroup *allocations;
110

    
111
    /* implementation specific data goes here */
112
    long devCount;
113
    AudioDeviceID *devIds; /*array of all audio devices*/
114
    AudioDeviceID defaultIn;
115
    AudioDeviceID defaultOut;
116
}
117
PaMacAUHAL;
118

    
119
typedef struct PaMacCoreDeviceProperties
120
{
121
    /* Values in Frames from property queries. */
122
    UInt32 safetyOffset;
123
    UInt32 bufferFrameSize;
124
    // UInt32 streamLatency; // Seems to be the same as deviceLatency!?
125
    UInt32 deviceLatency;
126
    /* Current device sample rate. May change! 
127
       These are initialized to the nominal device sample rate, 
128
       and updated with the actual sample rate, when/where available. 
129
       Note that these are the *device* sample rates, prior to any required 
130
       SR conversion. */
131
    Float64 sampleRate;
132
    Float64 samplePeriod; // reciprocal
133
}
134
PaMacCoreDeviceProperties;
135

    
136
/* stream data structure specifically for this implementation */
137
typedef struct PaMacCoreStream
138
{
139
    PaUtilStreamRepresentation streamRepresentation;
140
    PaUtilCpuLoadMeasurer cpuLoadMeasurer;
141
    PaUtilBufferProcessor bufferProcessor;
142

    
143
    /* implementation specific data goes here */
144
    bool bufferProcessorIsInitialized;
145
#ifndef AUDIO_COMPONENT_FIX
146
    AudioUnit inputUnit;
147
    AudioUnit outputUnit;
148
#else
149
    AudioComponentInstance inputUnit;
150
    AudioComponentInstance outputUnit;
151
#endif
152
    AudioDeviceID inputDevice;
153
    AudioDeviceID outputDevice;
154
    size_t userInChan;
155
    size_t userOutChan;
156
    size_t inputFramesPerBuffer;
157
    size_t outputFramesPerBuffer;
158
    PaMacBlio blio;
159
    /* We use this ring buffer when input and out devs are different. */
160
    PaUtilRingBuffer inputRingBuffer;
161
    /* We may need to do SR conversion on input. */
162
    AudioConverterRef inputSRConverter;
163
    /* We need to preallocate an inputBuffer for reading data. */
164
    AudioBufferList inputAudioBufferList;
165
    AudioTimeStamp startTime;
166
    /* FIXME: instead of volatile, these should be properly memory barriered */
167
    volatile uint32_t xrunFlags; /*PaStreamCallbackFlags*/
168
    volatile enum {
169
       STOPPED          = 0, /* playback is completely stopped,
170
                                and the user has called StopStream(). */
171
       CALLBACK_STOPPED = 1, /* callback has requested stop,
172
                                but user has not yet called StopStream(). */
173
       STOPPING         = 2, /* The stream is in the process of closing
174
                                because the user has called StopStream.
175
                                This state is just used internally;
176
                                externally it is indistinguishable from
177
                                ACTIVE.*/
178
       ACTIVE           = 3  /* The stream is active and running. */
179
    } state;
180
    double sampleRate;
181
    PaMacCoreDeviceProperties  inputProperties;
182
    PaMacCoreDeviceProperties  outputProperties;
183
    
184
        /* data updated by main thread and notifications, protected by timingInformationMutex */
185
        int timingInformationMutexIsInitialized;
186
        pthread_mutex_t timingInformationMutex;
187

    
188
    /* These are written by the PA thread or from CoreAudio callbacks. Protected by the mutex. */
189
    Float64 timestampOffsetCombined;
190
    Float64 timestampOffsetInputDevice;
191
    Float64 timestampOffsetOutputDevice;
192
        
193
        /* Offsets in seconds to be applied to Apple timestamps to convert them to PA timestamps.
194
     * While the io proc is active, the following values are only accessed and manipulated by the ioproc */
195
    Float64 timestampOffsetCombined_ioProcCopy;
196
    Float64 timestampOffsetInputDevice_ioProcCopy;
197
    Float64 timestampOffsetOutputDevice_ioProcCopy;
198
    
199
}
200
PaMacCoreStream;
201

    
202
#endif /* PA_MAC_CORE_INTERNAL_H__ */