| #pragma once |
| |
| #ifndef TSOUND_INCLUDED |
| #define TSOUND_INCLUDED |
| |
| #include <memory> |
| |
| #include "tsmartpointer.h" |
| #include "texception.h" |
| #include "tthreadmessage.h" |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TSOUND_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| |
| namespace TSound { |
| typedef UCHAR Channel; |
| |
| const int MONO = 0; |
| const int LEFT = 0; |
| const int RIGHT = LEFT + 1; |
| } |
| |
| |
| |
| |
| |
| class TSoundTrack; |
| class TSoundTransform; |
| |
| #ifdef _WIN32 |
| template class DVAPI TSmartPointerT<TSoundTrack>; |
| #endif |
| |
| typedef TSmartPointerT<TSoundTrack> TSoundTrackP; |
| |
| |
| |
| |
| |
| |
| class DVAPI TSoundTrackFormat { |
| public: |
| TUINT32 m_sampleRate; |
| int m_bitPerSample; |
| int m_channelCount; |
| bool m_signedSample; |
| |
| TSoundTrackFormat(TUINT32 sampleRate = 0, int bitPerSample = 0, |
| int channelCount = 0, bool signedSample = true) |
| : m_sampleRate(sampleRate) |
| , m_bitPerSample(bitPerSample) |
| , m_channelCount(channelCount) |
| , m_signedSample(signedSample) {} |
| |
| ~TSoundTrackFormat() {} |
| |
| bool operator==(const TSoundTrackFormat &rhs); |
| |
| bool operator!=(const TSoundTrackFormat &rhs); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TSoundTrack : public TSmartObject { |
| DECLARE_CLASS_CODE |
| |
| protected: |
| TUINT32 m_sampleRate; |
| int m_sampleSize; |
| int m_bitPerSample; |
| TINT32 m_sampleCount; |
| int m_channelCount; |
| |
| TSoundTrack *m_parent; |
| |
| UCHAR *m_buffer; |
| bool m_bufferOwner; |
| |
| TSoundTrack(); |
| |
| TSoundTrack(TUINT32 sampleRate, int bitPerSample, int channelCount, |
| int sampleSize, TINT32 sampleCount, bool isSampleSigned); |
| |
| TSoundTrack(TUINT32 sampleRate, int bitPerSample, int channelCount, |
| int sampleSize, TINT32 sampleCount, UCHAR *buffer, |
| TSoundTrack *parent); |
| |
| public: |
| |
| |
| |
| |
| |
| static TSoundTrackP create(TUINT32 sampleRate, int bitPerSample, |
| int channelCount, TINT32 sampleCount, |
| bool signedSample = true); |
| |
| static TSoundTrackP create(TUINT32 sampleRate, int bitPerSample, |
| int channelCount, TINT32 sampleCount, void *buffer, |
| bool signedSample = true); |
| |
| |
| |
| |
| |
| static TSoundTrackP create(const TSoundTrackFormat &format, |
| TINT32 sampleCount); |
| |
| static TSoundTrackP create(const TSoundTrackFormat &format, |
| TINT32 sampleCount, void *buffer); |
| |
| ~TSoundTrack(); |
| |
| |
| TINT32 secondsToSamples(double sec) const; |
| |
| |
| double samplesToSeconds(TINT32 smp) const; |
| |
| TUINT32 getSampleRate() const { return m_sampleRate; } |
| int getSampleSize() const { return m_sampleSize; } |
| int getChannelCount() const { return m_channelCount; } |
| int getBitPerSample() const { return m_bitPerSample; } |
| TINT32 getSampleCount() const { return m_sampleCount; } |
| |
| |
| double getDuration() const; |
| |
| |
| virtual bool isSampleSigned() const = 0; |
| |
| |
| TSoundTrackFormat getFormat() const; |
| |
| |
| const UCHAR *getRawData() const { return m_buffer; }; |
| |
| void setSampleRate(TUINT32 sampleRate) { m_sampleRate = sampleRate; } |
| |
| |
| virtual TSoundTrackP clone() const = 0; |
| |
| |
| virtual TSoundTrackP clone(TSound::Channel chan) const = 0; |
| |
| |
| virtual TSoundTrackP extract(TINT32 s0, TINT32 s1) = 0; |
| |
| |
| TSoundTrackP extract(double t0, double t1); |
| |
| |
| |
| |
| |
| |
| virtual void copy(const TSoundTrackP &src, TINT32 dst_s0) = 0; |
| |
| |
| |
| |
| |
| |
| void copy(const TSoundTrackP &src, double dst_t0); |
| |
| |
| virtual void blank(TINT32 s0, TINT32 s1) = 0; |
| |
| |
| |
| |
| void blank(double t0, double t1); |
| |
| |
| |
| |
| |
| virtual TSoundTrackP apply(TSoundTransform *) = 0; |
| |
| |
| |
| virtual double getPressure(TINT32 sample, TSound::Channel chan) const = 0; |
| |
| |
| double getPressure(double second, TSound::Channel chan) const; |
| |
| |
| |
| virtual void getMinMaxPressure(TINT32 s0, TINT32 s1, TSound::Channel chan, |
| double &min, double &max) const = 0; |
| |
| |
| |
| |
| |
| |
| void getMinMaxPressure(double t0, double t1, TSound::Channel chan, |
| double &min, double &max) const; |
| |
| |
| void getMinMaxPressure(TSound::Channel chan, double &min, double &max) const; |
| |
| |
| |
| virtual double getMaxPressure(TINT32 s0, TINT32 s1, |
| TSound::Channel chan) const = 0; |
| |
| |
| |
| |
| |
| double getMaxPressure(double t0, double t1, TSound::Channel chan) const; |
| |
| |
| double getMaxPressure(TSound::Channel chan) const; |
| |
| |
| |
| virtual double getMinPressure(TINT32 s0, TINT32 s1, |
| TSound::Channel chan) const = 0; |
| |
| |
| |
| |
| |
| double getMinPressure(double t0, double t1, TSound::Channel chan) const; |
| |
| |
| double getMinPressure(TSound::Channel chan) const; |
| }; |
| |
| |
| |
| class TSoundDeviceException final : public TException { |
| public: |
| enum Type { |
| FailedInit, |
| UnableOpenDevice, |
| UnableCloseDevice, |
| UnablePrepare, |
| UnsupportedFormat, |
| UnableSetDevice, |
| UnableVolume, |
| NoMixer, |
| Busy |
| |
| }; |
| |
| TSoundDeviceException(Type type, const std::string &msg) |
| : TException(msg), m_type(type) {} |
| TSoundDeviceException(Type type, const std::wstring &msg) |
| : TException(msg), m_type(type) {} |
| |
| Type getType() { return m_type; } |
| |
| private: |
| Type m_type; |
| }; |
| |
| |
| |
| |
| class TSoundInputDeviceImp; |
| |
| |
| |
| |
| |
| class DVAPI TSoundInputDevice { |
| std::shared_ptr<TSoundInputDeviceImp> m_imp; |
| |
| public: |
| enum Source { Mic = 0, LineIn, DigitalIn, CdAudio }; |
| |
| TSoundInputDevice(); |
| ~TSoundInputDevice(); |
| |
| |
| |
| |
| static bool installed(); |
| |
| |
| TSoundTrackFormat getPreferredFormat(TUINT32 sampleRate, int channelCount, |
| int bitPerSample); |
| |
| |
| TSoundTrackFormat getPreferredFormat(const TSoundTrackFormat &); |
| |
| |
| |
| bool supportsVolume(); |
| |
| |
| |
| void record(const TSoundTrackFormat &format, Source devtype = Mic); |
| |
| |
| |
| |
| |
| |
| void record(const TSoundTrackP &st, Source src = Mic); |
| |
| |
| TSoundTrackP stop(); |
| |
| |
| double getVolume(); |
| |
| |
| bool setVolume(double value); |
| |
| |
| bool isRecording(); |
| }; |
| |
| |
| |
| |
| |
| |
| |
| |
| class DVAPI TSoundOutputDeviceListener { |
| public: |
| virtual ~TSoundOutputDeviceListener(){}; |
| |
| virtual void onPlayCompleted() = 0; |
| }; |
| |
| |
| |
| class TSoundOutputDeviceImp; |
| |
| |
| |
| |
| |
| class DVAPI TSoundOutputDevice { |
| std::shared_ptr<TSoundOutputDeviceImp> m_imp; |
| |
| public: |
| TSoundOutputDevice(); |
| ~TSoundOutputDevice(); |
| |
| |
| |
| |
| static bool installed(); |
| |
| |
| TSoundTrackFormat getPreferredFormat(TUINT32 sampleRate, int channelCount, |
| int bitPerSample); |
| |
| |
| TSoundTrackFormat getPreferredFormat(const TSoundTrackFormat &); |
| |
| bool isFormatSupported(const TSoundTrackFormat &); |
| |
| #ifndef _WIN32 |
| |
| |
| bool supportsVolume(); |
| |
| |
| double getVolume(); |
| |
| |
| bool setVolume(double value); |
| void prepareVolume(double volume); |
| #endif |
| |
| |
| bool open(const TSoundTrackP &st); |
| |
| |
| void play(const TSoundTrackP &st, TINT32 s0, TINT32 s1, bool loop = false, |
| bool scrubbing = false); |
| |
| |
| bool close(); |
| |
| |
| |
| |
| |
| |
| void play(const TSoundTrackP &st, double t0, double t1, bool loop = false, |
| bool scrubbing = false) { |
| play(st, st->secondsToSamples(t0), st->secondsToSamples(t1), loop, |
| scrubbing); |
| } |
| |
| |
| void stop(); |
| |
| |
| bool isPlaying() const; |
| |
| #ifdef _WIN32 |
| |
| bool isAllQueuedItemsPlayed(); |
| #endif |
| |
| |
| bool isLooping(); |
| |
| |
| void setLooping(bool loop); |
| |
| void attach(TSoundOutputDeviceListener *listener); |
| void detach(TSoundOutputDeviceListener *listener); |
| }; |
| |
| #endif |