summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Klotz <uwe_klotz@web.de>2017-10-29 23:10:18 +0100
committerUwe Klotz <uwe_klotz@web.de>2017-11-06 22:27:20 +0100
commita51f666998968eea2c2f9774e8cfc53449e49355 (patch)
treee88ec521f120d479964518f006641033b3d45f00
parent2b1ecda9fbf98b3dfcdfc002b3b4d4e9af6b8f70 (diff)
Split AudioSource into reader interface and abstract base class
-rw-r--r--src/sources/audiosource.h53
-rw-r--r--src/sources/soundsourcecoreaudio.h2
-rw-r--r--src/sources/v1/legacyaudiosourceadapter.h15
3 files changed, 32 insertions, 38 deletions
diff --git a/src/sources/audiosource.h b/src/sources/audiosource.h
index adc2a385d3..b48e057799 100644
--- a/src/sources/audiosource.h
+++ b/src/sources/audiosource.h
@@ -77,6 +77,35 @@ class WritableSampleFrames: public SampleFrames {
};
+class IAudioSourceReader {
+ public:
+ virtual ~IAudioSourceReader() = default;
+
+ protected:
+ // Reads as much of the the requested sample frames and writes
+ // them into the provided buffer. The capacity of the buffer
+ // and the requested range have already been checked and
+ // adjusted (= clamped) before if necessary.
+ //
+ // Returns the number of and decoded sample frames in a readable
+ // buffer. The returned buffer is just a view/slice of the provided
+ // writable buffer if the result is not empty. If the result is
+ // empty the internal memory pointer of the returned buffer might
+ // be null.
+ virtual ReadableSampleFrames readSampleFramesClamped(
+ WritableSampleFrames sampleFrames) = 0;
+
+ // The following function is required for accessing the protected
+ // read function from siblings implementing this interface, e.g.
+ // for proxies and adapters.
+ static ReadableSampleFrames readSampleFramesClampedOn(
+ IAudioSourceReader& that,
+ WritableSampleFrames sampleFrames) {
+ return that.readSampleFramesClamped(sampleFrames);
+ }
+};
+
+
// Common base class for audio sources.
//
// Both the number of channels and the sample rate must
@@ -87,7 +116,7 @@ class WritableSampleFrames: public SampleFrames {
//
// Audio sources are implicitly opened upon creation and
// closed upon destruction.
-class AudioSource: public UrlResource, public AudioSignal {
+class AudioSource: public UrlResource, public AudioSignal, public virtual /*implements*/ IAudioSourceReader {
public:
virtual ~AudioSource() = default;
@@ -289,28 +318,6 @@ class AudioSource: public UrlResource, public AudioSignal {
return that.open(mode, params);
}
- // Reads as much of the the requested sample frames and writes
- // them into the provided buffer. The capacity of the buffer
- // and the requested range have already been checked and
- // adjusted (= clamped) before if necessary.
- //
- // Returns the number of and decoded sample frames in a readable
- // buffer. The returned buffer is just a view/slice of the provided
- // writable buffer if the result is not empty. If the result is
- // empty the internal memory pointer of the returned buffer might
- // be null.
- virtual ReadableSampleFrames readSampleFramesClamped(
- WritableSampleFrames sampleFrames) = 0;
-
- // The following function is required for accessing the protected
- // read function from siblings implementing this interface, e.g.
- // for proxies and adapters.
- static ReadableSampleFrames readSampleFramesClampedOn(
- AudioSource& that,
- WritableSampleFrames sampleFrames) {
- return that.readSampleFramesClamped(sampleFrames);
- }
-
private:
AudioSource(AudioSource&&) = delete;
AudioSource& operator=(const AudioSource&) = delete;
diff --git a/src/sources/soundsourcecoreaudio.h b/src/sources/soundsourcecoreaudio.h
index e00c906006..69c88b3e06 100644
--- a/src/sources/soundsourcecoreaudio.h
+++ b/src/sources/soundsourcecoreaudio.h
@@ -22,7 +22,7 @@
namespace mixxx {
-class SoundSourceCoreAudio: public SoundSource, public virtual LegacyAudioSource, public LegacyAudioSourceAdapter {
+class SoundSourceCoreAudio: public SoundSource, public virtual /*implements*/ LegacyAudioSource, public LegacyAudioSourceAdapter {
public:
explicit SoundSourceCoreAudio(QUrl url);
~SoundSourceCoreAudio() override;
diff --git a/src/sources/v1/legacyaudiosourceadapter.h b/src/sources/v1/legacyaudiosourceadapter.h
index 48c8f8bf69..1d6ae9b00e 100644
--- a/src/sources/v1/legacyaudiosourceadapter.h
+++ b/src/sources/v1/legacyaudiosourceadapter.h
@@ -9,27 +9,14 @@
namespace mixxx {
-// forward declaration(s)
-class AudioSource;
-
// Only required for SoundSourceCoreAudio.
-class LegacyAudioSourceAdapter: public AudioSource {
+class LegacyAudioSourceAdapter: public virtual /*implements*/ IAudioSourceReader {
public:
LegacyAudioSourceAdapter(
AudioSource* pOwner,
LegacyAudioSource* pImpl);
- void close() override {
- m_pOwner->close();
- }
-
protected:
- OpenResult tryOpen(
- OpenMode mode,
- const OpenParams& params) override {
- return tryOpenOn(*m_pOwner, mode, params);
- }
-
ReadableSampleFrames readSampleFramesClamped(
WritableSampleFrames sampleFrames) override;