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