Chris@39: #include "portaudiocpp/StreamParameters.hxx" Chris@39: Chris@39: #include Chris@39: Chris@39: #include "portaudiocpp/Device.hxx" Chris@39: Chris@39: namespace portaudio Chris@39: { Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: ////// Chris@39: /// Default constructor; does nothing. Chris@39: ////// Chris@39: StreamParameters::StreamParameters() Chris@39: { Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Sets up the all parameters needed to open either a half-duplex or full-duplex Stream. Chris@39: /// Chris@39: /// @param inputParameters The parameters for the input direction of the to-be opened Chris@39: /// Stream or DirectionSpecificStreamParameters::null() for an output-only Stream. Chris@39: /// @param outputParameters The parameters for the output direction of the to-be opened Chris@39: /// Stream or DirectionSpecificStreamParameters::null() for an input-only Stream. Chris@39: /// @param sampleRate The to-be opened Stream's sample rate in Hz. Chris@39: /// @param framesPerBuffer The number of frames per buffer for a CallbackStream, or Chris@39: /// the preferred buffer granularity for a BlockingStream. Chris@39: /// @param flags The flags for the to-be opened Stream; default paNoFlag. Chris@39: ////// Chris@39: StreamParameters::StreamParameters(const DirectionSpecificStreamParameters &inputParameters, Chris@39: const DirectionSpecificStreamParameters &outputParameters, double sampleRate, unsigned long framesPerBuffer, Chris@39: PaStreamFlags flags) : inputParameters_(inputParameters), outputParameters_(outputParameters), Chris@39: sampleRate_(sampleRate), framesPerBuffer_(framesPerBuffer), flags_(flags) Chris@39: { Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: ////// Chris@39: /// Sets the requested sample rate. If this sample rate isn't supported by the hardware, the Chris@39: /// Stream will fail to open. The real-life sample rate used might differ slightly due to Chris@39: /// imperfections in the sound card hardware; use Stream::sampleRate() to retreive the Chris@39: /// best known estimate for this value. Chris@39: ////// Chris@39: void StreamParameters::setSampleRate(double sampleRate) Chris@39: { Chris@39: sampleRate_ = sampleRate; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Either the number of frames per buffer for a CallbackStream, or Chris@39: /// the preferred buffer granularity for a BlockingStream. See PortAudio Chris@39: /// documentation. Chris@39: ////// Chris@39: void StreamParameters::setFramesPerBuffer(unsigned long framesPerBuffer) Chris@39: { Chris@39: framesPerBuffer_ = framesPerBuffer; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Sets the specified flag or does nothing when the flag is already set. Doesn't Chris@39: /// `unset' any previously existing flags (use clearFlags() for that). Chris@39: ////// Chris@39: void StreamParameters::setFlag(PaStreamFlags flag) Chris@39: { Chris@39: flags_ |= flag; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Unsets the specified flag or does nothing if the flag isn't set. Doesn't affect Chris@39: /// any other flags. Chris@39: ////// Chris@39: void StreamParameters::unsetFlag(PaStreamFlags flag) Chris@39: { Chris@39: flags_ &= ~flag; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Clears or `unsets' all set flags. Chris@39: ////// Chris@39: void StreamParameters::clearFlags() Chris@39: { Chris@39: flags_ = paNoFlag; Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: void StreamParameters::setInputParameters(const DirectionSpecificStreamParameters ¶meters) Chris@39: { Chris@39: inputParameters_ = parameters; Chris@39: } Chris@39: Chris@39: void StreamParameters::setOutputParameters(const DirectionSpecificStreamParameters ¶meters) Chris@39: { Chris@39: outputParameters_ = parameters; Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: bool StreamParameters::isSupported() const Chris@39: { Chris@39: return (Pa_IsFormatSupported(inputParameters_.paStreamParameters(), Chris@39: outputParameters_.paStreamParameters(), sampleRate_) == paFormatIsSupported); Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: double StreamParameters::sampleRate() const Chris@39: { Chris@39: return sampleRate_; Chris@39: } Chris@39: Chris@39: unsigned long StreamParameters::framesPerBuffer() const Chris@39: { Chris@39: return framesPerBuffer_; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Returns all currently set flags as a binary combined Chris@39: /// integer value (PaStreamFlags). Use isFlagSet() to Chris@39: /// avoid dealing with the bitmasks. Chris@39: ////// Chris@39: PaStreamFlags StreamParameters::flags() const Chris@39: { Chris@39: return flags_; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Returns true if the specified flag is currently set Chris@39: /// or false if it isn't. Chris@39: ////// Chris@39: bool StreamParameters::isFlagSet(PaStreamFlags flag) const Chris@39: { Chris@39: return ((flags_ & flag) != 0); Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: DirectionSpecificStreamParameters &StreamParameters::inputParameters() Chris@39: { Chris@39: return inputParameters_; Chris@39: } Chris@39: Chris@39: const DirectionSpecificStreamParameters &StreamParameters::inputParameters() const Chris@39: { Chris@39: return inputParameters_; Chris@39: } Chris@39: Chris@39: DirectionSpecificStreamParameters &StreamParameters::outputParameters() Chris@39: { Chris@39: return outputParameters_; Chris@39: } Chris@39: Chris@39: const DirectionSpecificStreamParameters &StreamParameters::outputParameters() const Chris@39: { Chris@39: return outputParameters_; Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: } // namespace portaudio Chris@39: Chris@39: Chris@39: Chris@39: Chris@39: