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 / bindings / cpp / source / portaudiocpp / DirectionSpecificStreamParameters.cxx @ 164:9fa11135915a

History | View | Annotate | Download (5.02 KB)

1
#include "portaudiocpp/DirectionSpecificStreamParameters.hxx"
2

    
3
#include "portaudiocpp/Device.hxx"
4

    
5
namespace portaudio
6
{
7

    
8
        // -----------------------------------------------------------------------------------
9

    
10
        //////
11
        /// Returns a `nil' DirectionSpecificStreamParameters object. This can be used to 
12
        /// specify that one direction of a Stream is not required (i.e. when creating 
13
        /// a half-duplex Stream). All fields of the null DirectionSpecificStreamParameters 
14
        /// object are invalid except for the device and the number of channel, which are set 
15
        /// to paNoDevice and 0 respectively.
16
        //////
17
        DirectionSpecificStreamParameters DirectionSpecificStreamParameters::null()
18
        {
19
                DirectionSpecificStreamParameters tmp;
20
                tmp.paStreamParameters_.device = paNoDevice;
21
                tmp.paStreamParameters_.channelCount = 0;
22
                return tmp;
23
        }
24

    
25
        // -----------------------------------------------------------------------------------
26

    
27
        //////
28
        /// Default constructor -- all parameters will be uninitialized.
29
        //////
30
        DirectionSpecificStreamParameters::DirectionSpecificStreamParameters()
31
        {
32
        }
33

    
34
        //////
35
        /// Constructor which sets all required fields.
36
        //////
37
        DirectionSpecificStreamParameters::DirectionSpecificStreamParameters(const Device &device, int numChannels, 
38
                SampleDataFormat format, bool interleaved, PaTime suggestedLatency, void *hostApiSpecificStreamInfo)
39
        {
40
                setDevice(device);
41
                setNumChannels(numChannels);
42
                setSampleFormat(format, interleaved);
43
                setSuggestedLatency(suggestedLatency);
44
                setHostApiSpecificStreamInfo(hostApiSpecificStreamInfo);
45
        }
46

    
47
        // -----------------------------------------------------------------------------------
48

    
49
        void DirectionSpecificStreamParameters::setDevice(const Device &device)
50
        {
51
                paStreamParameters_.device = device.index();
52
        }
53

    
54
        void DirectionSpecificStreamParameters::setNumChannels(int numChannels)
55
        {
56
                paStreamParameters_.channelCount = numChannels;
57
        }
58

    
59
        void DirectionSpecificStreamParameters::setSampleFormat(SampleDataFormat format, bool interleaved)
60
        {
61
                paStreamParameters_.sampleFormat = static_cast<PaSampleFormat>(format);
62

    
63
                if (!interleaved)
64
                        paStreamParameters_.sampleFormat |= paNonInterleaved;
65
        }
66

    
67
        void DirectionSpecificStreamParameters::setHostApiSpecificSampleFormat(PaSampleFormat format, bool interleaved)
68
        {
69
                paStreamParameters_.sampleFormat = format;
70

    
71
                paStreamParameters_.sampleFormat |= paCustomFormat;
72

    
73
                if (!interleaved)
74
                        paStreamParameters_.sampleFormat |= paNonInterleaved;
75
        }
76

    
77
        void DirectionSpecificStreamParameters::setSuggestedLatency(PaTime latency)
78
        {
79
                paStreamParameters_.suggestedLatency = latency;
80
        }
81

    
82
        void DirectionSpecificStreamParameters::setHostApiSpecificStreamInfo(void *streamInfo)
83
        {
84
                paStreamParameters_.hostApiSpecificStreamInfo = streamInfo;
85
        }
86

    
87
        // -----------------------------------------------------------------------------------
88

    
89
        PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters()
90
        {
91
                if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice)
92
                        return &paStreamParameters_;
93
                else
94
                        return NULL;
95
        }
96

    
97
        const PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters() const
98
        {
99
                if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice)
100
                        return &paStreamParameters_;
101
                else
102
                        return NULL;
103
        }
104

    
105
        Device &DirectionSpecificStreamParameters::device() const
106
        {
107
                return System::instance().deviceByIndex(paStreamParameters_.device);
108
        }
109

    
110
        int DirectionSpecificStreamParameters::numChannels() const
111
        {
112
                return paStreamParameters_.channelCount;
113
        }
114

    
115
        //////
116
        /// Returns the (non host api-specific) sample format, without including 
117
        /// the paNonInterleaved flag. If the sample format is host api-spefific, 
118
        /// INVALID_FORMAT (0) will be returned.
119
        //////
120
        SampleDataFormat DirectionSpecificStreamParameters::sampleFormat() const
121
        {
122
                if (isSampleFormatHostApiSpecific())
123
                        return INVALID_FORMAT;
124
                else
125
                        return static_cast<SampleDataFormat>(paStreamParameters_.sampleFormat & ~paNonInterleaved);
126
        }
127

    
128
        bool DirectionSpecificStreamParameters::isSampleFormatInterleaved() const
129
        {
130
                return ((paStreamParameters_.sampleFormat & paNonInterleaved) == 0);
131
        }
132

    
133
        bool DirectionSpecificStreamParameters::isSampleFormatHostApiSpecific() const
134
        {
135
                return ((paStreamParameters_.sampleFormat & paCustomFormat) == 0);
136
        }
137

    
138
        //////
139
        /// Returns the host api-specific sample format, without including any 
140
        /// paCustomFormat or paNonInterleaved flags. Will return 0 if the sample format is 
141
        /// not host api-specific.
142
        //////
143
        PaSampleFormat DirectionSpecificStreamParameters::hostApiSpecificSampleFormat() const
144
        {
145
                if (isSampleFormatHostApiSpecific())
146
                        return paStreamParameters_.sampleFormat & ~paCustomFormat & ~paNonInterleaved;
147
                else
148
                        return 0;
149
        }
150

    
151
        PaTime DirectionSpecificStreamParameters::suggestedLatency() const
152
        {
153
                return paStreamParameters_.suggestedLatency;
154
        }
155

    
156
        void *DirectionSpecificStreamParameters::hostApiSpecificStreamInfo() const
157
        {
158
                return paStreamParameters_.hostApiSpecificStreamInfo;
159
        }
160

    
161
        // -----------------------------------------------------------------------------------
162

    
163
} // namespace portaudio