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