annotate src/portaudio/bindings/cpp/source/portaudiocpp/StreamParameters.cxx @ 107:71c914cf6201

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