Chris@39: #include "portaudiocpp/DirectionSpecificStreamParameters.hxx" Chris@39: Chris@39: #include "portaudiocpp/Device.hxx" Chris@39: Chris@39: namespace portaudio Chris@39: { Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: ////// Chris@39: /// Returns a `nil' DirectionSpecificStreamParameters object. This can be used to Chris@39: /// specify that one direction of a Stream is not required (i.e. when creating Chris@39: /// a half-duplex Stream). All fields of the null DirectionSpecificStreamParameters Chris@39: /// object are invalid except for the device and the number of channel, which are set Chris@39: /// to paNoDevice and 0 respectively. Chris@39: ////// Chris@39: DirectionSpecificStreamParameters DirectionSpecificStreamParameters::null() Chris@39: { Chris@39: DirectionSpecificStreamParameters tmp; Chris@39: tmp.paStreamParameters_.device = paNoDevice; Chris@39: tmp.paStreamParameters_.channelCount = 0; Chris@39: return tmp; Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: ////// Chris@39: /// Default constructor -- all parameters will be uninitialized. Chris@39: ////// Chris@39: DirectionSpecificStreamParameters::DirectionSpecificStreamParameters() Chris@39: { Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Constructor which sets all required fields. Chris@39: ////// Chris@39: DirectionSpecificStreamParameters::DirectionSpecificStreamParameters(const Device &device, int numChannels, Chris@39: SampleDataFormat format, bool interleaved, PaTime suggestedLatency, void *hostApiSpecificStreamInfo) Chris@39: { Chris@39: setDevice(device); Chris@39: setNumChannels(numChannels); Chris@39: setSampleFormat(format, interleaved); Chris@39: setSuggestedLatency(suggestedLatency); Chris@39: setHostApiSpecificStreamInfo(hostApiSpecificStreamInfo); Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: void DirectionSpecificStreamParameters::setDevice(const Device &device) Chris@39: { Chris@39: paStreamParameters_.device = device.index(); Chris@39: } Chris@39: Chris@39: void DirectionSpecificStreamParameters::setNumChannels(int numChannels) Chris@39: { Chris@39: paStreamParameters_.channelCount = numChannels; Chris@39: } Chris@39: Chris@39: void DirectionSpecificStreamParameters::setSampleFormat(SampleDataFormat format, bool interleaved) Chris@39: { Chris@39: paStreamParameters_.sampleFormat = static_cast(format); Chris@39: Chris@39: if (!interleaved) Chris@39: paStreamParameters_.sampleFormat |= paNonInterleaved; Chris@39: } Chris@39: Chris@39: void DirectionSpecificStreamParameters::setHostApiSpecificSampleFormat(PaSampleFormat format, bool interleaved) Chris@39: { Chris@39: paStreamParameters_.sampleFormat = format; Chris@39: Chris@39: paStreamParameters_.sampleFormat |= paCustomFormat; Chris@39: Chris@39: if (!interleaved) Chris@39: paStreamParameters_.sampleFormat |= paNonInterleaved; Chris@39: } Chris@39: Chris@39: void DirectionSpecificStreamParameters::setSuggestedLatency(PaTime latency) Chris@39: { Chris@39: paStreamParameters_.suggestedLatency = latency; Chris@39: } Chris@39: Chris@39: void DirectionSpecificStreamParameters::setHostApiSpecificStreamInfo(void *streamInfo) Chris@39: { Chris@39: paStreamParameters_.hostApiSpecificStreamInfo = streamInfo; Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters() Chris@39: { Chris@39: if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice) Chris@39: return &paStreamParameters_; Chris@39: else Chris@39: return NULL; Chris@39: } Chris@39: Chris@39: const PaStreamParameters *DirectionSpecificStreamParameters::paStreamParameters() const Chris@39: { Chris@39: if (paStreamParameters_.channelCount > 0 && paStreamParameters_.device != paNoDevice) Chris@39: return &paStreamParameters_; Chris@39: else Chris@39: return NULL; Chris@39: } Chris@39: Chris@39: Device &DirectionSpecificStreamParameters::device() const Chris@39: { Chris@39: return System::instance().deviceByIndex(paStreamParameters_.device); Chris@39: } Chris@39: Chris@39: int DirectionSpecificStreamParameters::numChannels() const Chris@39: { Chris@39: return paStreamParameters_.channelCount; Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Returns the (non host api-specific) sample format, without including Chris@39: /// the paNonInterleaved flag. If the sample format is host api-spefific, Chris@39: /// INVALID_FORMAT (0) will be returned. Chris@39: ////// Chris@39: SampleDataFormat DirectionSpecificStreamParameters::sampleFormat() const Chris@39: { Chris@39: if (isSampleFormatHostApiSpecific()) Chris@39: return INVALID_FORMAT; Chris@39: else Chris@39: return static_cast(paStreamParameters_.sampleFormat & ~paNonInterleaved); Chris@39: } Chris@39: Chris@39: bool DirectionSpecificStreamParameters::isSampleFormatInterleaved() const Chris@39: { Chris@39: return ((paStreamParameters_.sampleFormat & paNonInterleaved) == 0); Chris@39: } Chris@39: Chris@39: bool DirectionSpecificStreamParameters::isSampleFormatHostApiSpecific() const Chris@39: { Chris@39: return ((paStreamParameters_.sampleFormat & paCustomFormat) == 0); Chris@39: } Chris@39: Chris@39: ////// Chris@39: /// Returns the host api-specific sample format, without including any Chris@39: /// paCustomFormat or paNonInterleaved flags. Will return 0 if the sample format is Chris@39: /// not host api-specific. Chris@39: ////// Chris@39: PaSampleFormat DirectionSpecificStreamParameters::hostApiSpecificSampleFormat() const Chris@39: { Chris@39: if (isSampleFormatHostApiSpecific()) Chris@39: return paStreamParameters_.sampleFormat & ~paCustomFormat & ~paNonInterleaved; Chris@39: else Chris@39: return 0; Chris@39: } Chris@39: Chris@39: PaTime DirectionSpecificStreamParameters::suggestedLatency() const Chris@39: { Chris@39: return paStreamParameters_.suggestedLatency; Chris@39: } Chris@39: Chris@39: void *DirectionSpecificStreamParameters::hostApiSpecificStreamInfo() const Chris@39: { Chris@39: return paStreamParameters_.hostApiSpecificStreamInfo; Chris@39: } Chris@39: Chris@39: // ----------------------------------------------------------------------------------- Chris@39: Chris@39: } // namespace portaudio