annotate src/portaudio_20161030/bindings/cpp/source/portaudiocpp/StreamParameters.cxx @ 55:284acf908dcd

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