annotate src/portaudio/bindings/cpp/source/portaudiocpp/StreamParameters.cxx @ 19:891f60ab2af1

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