📄 audiodevice.h
字号:
// Copyright (c) 2004 by Istv醤 V醨adi// This file is part of dxr3Player, a DVD player written specifically // for the DXR3 (aka Hollywood+) decoder card.// This program is free software; you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2 of the License, or// (at your option) any later version.//// This program is distributed in the hope that it will be useful,// but WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with this program; if not, write to the Free Software// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#ifndef DXR3PLAYER_OUTPUT_AUDIODEVICE_H#define DXR3PLAYER_OUTPUT_AUDIODEVICE_H//------------------------------------------------------------------------------#include "util/Util.h"#include "enums.h"#include <cstdlib>//------------------------------------------------------------------------------namespace output {//------------------------------------------------------------------------------/** * Interface for audio devices. */class AudioDevice{private: /** * The size of samples on a single channel. */ static const size_t singleSampleSize = 2;protected: /** * Indicate if the audio device has real-time capabilities. Some * methods may be called only if it has. */ bool realTime; /** * Indicate if the audio device is triggeralbe. Some * methods may be called only if it has. */ bool triggerable; /** * Our current audio mode. */ audioMode_t audioMode; /** * The sample rate. */ unsigned sampleRate; /** * Indicate if stereo playback is enabled. */ bool stereo;public: /** * Default constructor. */ AudioDevice(); /** * Virtual destructor. */ virtual ~AudioDevice(); /** * Get if the audio device has real-time capabilities. */ bool isRealTime() const; /** * Get if the audio device is triggerable. */ bool isTriggerable() const; /** * Setup the audio device. * * @param s the audio mode * @param rate the sampling rate in Hz * @param s indicate if stereo or mono mode */ void setup(audioMode_t mode, unsigned rate, bool s); /** * Get the audio mode. */ audioMode_t getAudioMode() const; /** * Get the sample rate of the sound card. */ unsigned getSampleRate() const; /** * Get the size of a sample. */ size_t getSampleSize() const; /** * Determine if stereo playback is enabled. */ bool isStereo() const; /** * Start playback on the card. * * Can be called only for triggerable sound cards. */ virtual void startPlayback() = 0; /** * Write the given data to the card. It returns when all data has * been written or when the playback has been stopped by a call * to stopPlayback(). */ virtual size_t play(const void* d, size_t length, bool interruptible = true) = 0; /** * Get the number of samples played since starting the playback. * * Can be called only for sound cards with real-time capability */ virtual unsigned long long getNumberOfSamplesPlayed() = 0; /** * Get the amount of sound played since starting the playback in PTS. * * Can be called only for sound cards with real-time capability */ ptsdiff_t getPTSPlayed(); /** * Get the number of samples currently buffered. * * Can be called only for sound cards with real-time capability */ virtual unsigned long long getNumberOfSamplesBuffered() = 0; /** * Get the amount of sound buffered in PTS. * * Can be called only for sound cards with real-time capability */ ptsdiff_t getPTSBuffered(); /** * Stop the playback. */ virtual void stopPlayback() = 0; /** * Stop the audio device. */ virtual void stop() = 0;private: /** * Perform the real setting up of the device. */ virtual void doSetup(audioMode_t& mode, unsigned& rate, bool& s) = 0; /** * Convert the given number of samples to a PTS difference value. */ ptsdiff_t samples2PTS(unsigned long long samples) const;};//------------------------------------------------------------------------------// Inline definitions//------------------------------------------------------------------------------inline AudioDevice::AudioDevice() : realTime(false), triggerable(false), audioMode(AM_ANALOGUE), sampleRate(48000), stereo(true){}//------------------------------------------------------------------------------inline AudioDevice::~AudioDevice(){}//------------------------------------------------------------------------------inline bool AudioDevice::isRealTime() const{ return realTime;}//------------------------------------------------------------------------------inline bool AudioDevice::isTriggerable() const{ return triggerable;}//------------------------------------------------------------------------------inline audioMode_t AudioDevice::getAudioMode() const{ return audioMode;}//------------------------------------------------------------------------------inline unsigned AudioDevice::getSampleRate() const{ return sampleRate;}//------------------------------------------------------------------------------inline size_t AudioDevice::getSampleSize() const{ return singleSampleSize * (stereo ? 2 : 1);}//------------------------------------------------------------------------------inline bool AudioDevice::isStereo() const{ return stereo;}//------------------------------------------------------------------------------inline ptsdiff_t AudioDevice::samples2PTS(unsigned long long samples) const{ ptsdiff_t ptsDiff = samples; ptsDiff *= Util::ptsFrequency; ptsDiff /= sampleRate; return ptsDiff;}//------------------------------------------------------------------------------inline ptsdiff_t AudioDevice::getPTSPlayed(){ return samples2PTS(getNumberOfSamplesPlayed());}//------------------------------------------------------------------------------inline ptsdiff_t AudioDevice::getPTSBuffered(){ return samples2PTS(getNumberOfSamplesBuffered());}//------------------------------------------------------------------------------} /* namespace output *///------------------------------------------------------------------------------#endif // DXR3PLAYER_OUTPUT_AUDIODEVICE_H// Local Variables:// mode: C++// c-basic-offset: 4// indent-tabs-mode: nil// End:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -