annotate src/portaudio_20161030/bindings/cpp/source/portaudiocpp/StreamParameters.cxx @ 169:223a55898ab9 tip default

Add null config files
author Chris Cannam <cannam@all-day-breakfast.com>
date Mon, 02 Mar 2020 14:03:47 +0000
parents 59a8758c56b1
children
rev   line source
cannam@140 1 #include "portaudiocpp/StreamParameters.hxx"
cannam@140 2
cannam@140 3 #include <cstddef>
cannam@140 4
cannam@140 5 #include "portaudiocpp/Device.hxx"
cannam@140 6
cannam@140 7 namespace portaudio
cannam@140 8 {
cannam@140 9 // -----------------------------------------------------------------------------------
cannam@140 10
cannam@140 11 //////
cannam@140 12 /// Default constructor; does nothing.
cannam@140 13 //////
cannam@140 14 StreamParameters::StreamParameters()
cannam@140 15 {
cannam@140 16 }
cannam@140 17
cannam@140 18 //////
cannam@140 19 /// Sets up the all parameters needed to open either a half-duplex or full-duplex Stream.
cannam@140 20 ///
cannam@140 21 /// @param inputParameters The parameters for the input direction of the to-be opened
cannam@140 22 /// Stream or DirectionSpecificStreamParameters::null() for an output-only Stream.
cannam@140 23 /// @param outputParameters The parameters for the output direction of the to-be opened
cannam@140 24 /// Stream or DirectionSpecificStreamParameters::null() for an input-only Stream.
cannam@140 25 /// @param sampleRate The to-be opened Stream's sample rate in Hz.
cannam@140 26 /// @param framesPerBuffer The number of frames per buffer for a CallbackStream, or
cannam@140 27 /// the preferred buffer granularity for a BlockingStream.
cannam@140 28 /// @param flags The flags for the to-be opened Stream; default paNoFlag.
cannam@140 29 //////
cannam@140 30 StreamParameters::StreamParameters(const DirectionSpecificStreamParameters &inputParameters,
cannam@140 31 const DirectionSpecificStreamParameters &outputParameters, double sampleRate, unsigned long framesPerBuffer,
cannam@140 32 PaStreamFlags flags) : inputParameters_(inputParameters), outputParameters_(outputParameters),
cannam@140 33 sampleRate_(sampleRate), framesPerBuffer_(framesPerBuffer), flags_(flags)
cannam@140 34 {
cannam@140 35 }
cannam@140 36
cannam@140 37 // -----------------------------------------------------------------------------------
cannam@140 38
cannam@140 39 //////
cannam@140 40 /// Sets the requested sample rate. If this sample rate isn't supported by the hardware, the
cannam@140 41 /// Stream will fail to open. The real-life sample rate used might differ slightly due to
cannam@140 42 /// imperfections in the sound card hardware; use Stream::sampleRate() to retreive the
cannam@140 43 /// best known estimate for this value.
cannam@140 44 //////
cannam@140 45 void StreamParameters::setSampleRate(double sampleRate)
cannam@140 46 {
cannam@140 47 sampleRate_ = sampleRate;
cannam@140 48 }
cannam@140 49
cannam@140 50 //////
cannam@140 51 /// Either the number of frames per buffer for a CallbackStream, or
cannam@140 52 /// the preferred buffer granularity for a BlockingStream. See PortAudio
cannam@140 53 /// documentation.
cannam@140 54 //////
cannam@140 55 void StreamParameters::setFramesPerBuffer(unsigned long framesPerBuffer)
cannam@140 56 {
cannam@140 57 framesPerBuffer_ = framesPerBuffer;
cannam@140 58 }
cannam@140 59
cannam@140 60 //////
cannam@140 61 /// Sets the specified flag or does nothing when the flag is already set. Doesn't
cannam@140 62 /// `unset' any previously existing flags (use clearFlags() for that).
cannam@140 63 //////
cannam@140 64 void StreamParameters::setFlag(PaStreamFlags flag)
cannam@140 65 {
cannam@140 66 flags_ |= flag;
cannam@140 67 }
cannam@140 68
cannam@140 69 //////
cannam@140 70 /// Unsets the specified flag or does nothing if the flag isn't set. Doesn't affect
cannam@140 71 /// any other flags.
cannam@140 72 //////
cannam@140 73 void StreamParameters::unsetFlag(PaStreamFlags flag)
cannam@140 74 {
cannam@140 75 flags_ &= ~flag;
cannam@140 76 }
cannam@140 77
cannam@140 78 //////
cannam@140 79 /// Clears or `unsets' all set flags.
cannam@140 80 //////
cannam@140 81 void StreamParameters::clearFlags()
cannam@140 82 {
cannam@140 83 flags_ = paNoFlag;
cannam@140 84 }
cannam@140 85
cannam@140 86 // -----------------------------------------------------------------------------------
cannam@140 87
cannam@140 88 void StreamParameters::setInputParameters(const DirectionSpecificStreamParameters &parameters)
cannam@140 89 {
cannam@140 90 inputParameters_ = parameters;
cannam@140 91 }
cannam@140 92
cannam@140 93 void StreamParameters::setOutputParameters(const DirectionSpecificStreamParameters &parameters)
cannam@140 94 {
cannam@140 95 outputParameters_ = parameters;
cannam@140 96 }
cannam@140 97
cannam@140 98 // -----------------------------------------------------------------------------------
cannam@140 99
cannam@140 100 bool StreamParameters::isSupported() const
cannam@140 101 {
cannam@140 102 return (Pa_IsFormatSupported(inputParameters_.paStreamParameters(),
cannam@140 103 outputParameters_.paStreamParameters(), sampleRate_) == paFormatIsSupported);
cannam@140 104 }
cannam@140 105
cannam@140 106 // -----------------------------------------------------------------------------------
cannam@140 107
cannam@140 108 double StreamParameters::sampleRate() const
cannam@140 109 {
cannam@140 110 return sampleRate_;
cannam@140 111 }
cannam@140 112
cannam@140 113 unsigned long StreamParameters::framesPerBuffer() const
cannam@140 114 {
cannam@140 115 return framesPerBuffer_;
cannam@140 116 }
cannam@140 117
cannam@140 118 //////
cannam@140 119 /// Returns all currently set flags as a binary combined
cannam@140 120 /// integer value (PaStreamFlags). Use isFlagSet() to
cannam@140 121 /// avoid dealing with the bitmasks.
cannam@140 122 //////
cannam@140 123 PaStreamFlags StreamParameters::flags() const
cannam@140 124 {
cannam@140 125 return flags_;
cannam@140 126 }
cannam@140 127
cannam@140 128 //////
cannam@140 129 /// Returns true if the specified flag is currently set
cannam@140 130 /// or false if it isn't.
cannam@140 131 //////
cannam@140 132 bool StreamParameters::isFlagSet(PaStreamFlags flag) const
cannam@140 133 {
cannam@140 134 return ((flags_ & flag) != 0);
cannam@140 135 }
cannam@140 136
cannam@140 137 // -----------------------------------------------------------------------------------
cannam@140 138
cannam@140 139 DirectionSpecificStreamParameters &StreamParameters::inputParameters()
cannam@140 140 {
cannam@140 141 return inputParameters_;
cannam@140 142 }
cannam@140 143
cannam@140 144 const DirectionSpecificStreamParameters &StreamParameters::inputParameters() const
cannam@140 145 {
cannam@140 146 return inputParameters_;
cannam@140 147 }
cannam@140 148
cannam@140 149 DirectionSpecificStreamParameters &StreamParameters::outputParameters()
cannam@140 150 {
cannam@140 151 return outputParameters_;
cannam@140 152 }
cannam@140 153
cannam@140 154 const DirectionSpecificStreamParameters &StreamParameters::outputParameters() const
cannam@140 155 {
cannam@140 156 return outputParameters_;
cannam@140 157 }
cannam@140 158
cannam@140 159 // -----------------------------------------------------------------------------------
cannam@140 160 } // namespace portaudio
cannam@140 161
cannam@140 162
cannam@140 163
cannam@140 164
cannam@140 165