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