annotate src/portaudio_20140130/bindings/cpp/source/portaudiocpp/StreamParameters.cxx @ 39:7ddb4fc30dac

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