annotate audio/AudioCallbackRecordTarget.h @ 775:56a81812c131 smoother-recording

Use ModelId for recording model; add mix-to-mono option
author Chris Cannam
date Tue, 16 Jun 2020 15:17:50 +0100
parents bfa9604714c9
children
rev   line source
Chris@476 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@476 2
Chris@476 3 /*
Chris@476 4 Sonic Visualiser
Chris@476 5 An audio file viewer and annotation editor.
Chris@476 6 Centre for Digital Music, Queen Mary, University of London.
Chris@476 7
Chris@476 8 This program is free software; you can redistribute it and/or
Chris@476 9 modify it under the terms of the GNU General Public License as
Chris@476 10 published by the Free Software Foundation; either version 2 of the
Chris@476 11 License, or (at your option) any later version. See the file
Chris@476 12 COPYING included with this distribution for more information.
Chris@476 13 */
Chris@476 14
Chris@574 15 #ifndef SV_AUDIO_CALLBACK_RECORD_TARGET_H
Chris@574 16 #define SV_AUDIO_CALLBACK_RECORD_TARGET_H
Chris@574 17
Chris@574 18 #include "base/AudioRecordTarget.h"
Chris@775 19 #include "data/model/Model.h"
Chris@476 20
Chris@476 21 #include <bqaudioio/ApplicationRecordTarget.h>
Chris@476 22
Chris@476 23 #include <string>
Chris@575 24 #include <atomic>
Chris@476 25
Chris@476 26 #include <QObject>
Chris@476 27 #include <QMutex>
Chris@476 28
Chris@476 29 #include "base/BaseTypes.h"
Chris@575 30 #include "base/RingBuffer.h"
Chris@476 31
Chris@476 32 class ViewManagerBase;
Chris@477 33 class WritableWaveFileModel;
Chris@476 34
Chris@574 35 class AudioCallbackRecordTarget : public QObject,
Chris@574 36 public AudioRecordTarget,
Chris@574 37 public breakfastquay::ApplicationRecordTarget
Chris@476 38 {
Chris@476 39 Q_OBJECT
Chris@476 40
Chris@476 41 public:
Chris@574 42 AudioCallbackRecordTarget(ViewManagerBase *, QString clientName);
Chris@574 43 virtual ~AudioCallbackRecordTarget();
Chris@476 44
Chris@559 45 virtual std::string getClientName() const override { return m_clientName; }
Chris@476 46
Chris@559 47 virtual int getApplicationSampleRate() const override;
Chris@559 48 virtual int getApplicationChannelCount() const override;
Chris@476 49
Chris@559 50 virtual void setSystemRecordBlockSize(int) override;
Chris@559 51 virtual void setSystemRecordSampleRate(int) override;
Chris@559 52 virtual void setSystemRecordLatency(int) override;
Chris@559 53 virtual void setSystemRecordChannelCount(int) override;
Chris@476 54
Chris@559 55 virtual void putSamples(const float *const *samples, int nchannels, int nframes) override;
Chris@476 56
Chris@559 57 virtual void setInputLevels(float peakLeft, float peakRight) override;
Chris@476 58
Chris@559 59 virtual void audioProcessingOverload() override { }
Chris@483 60
Chris@574 61 virtual bool isRecording() const override { return m_recording; }
Chris@574 62 virtual sv_frame_t getRecordDuration() const override { return m_frameCount; }
Chris@574 63
Chris@580 64 /**
Chris@580 65 * Return the current input levels in the range 0.0 -> 1.0, for
Chris@580 66 * metering purposes. The values returned are the peak values
Chris@580 67 * since the last time this function was called (after which they
Chris@580 68 * are reset to zero until setInputLevels is called again by the
Chris@580 69 * driver).
Chris@580 70 *
Chris@580 71 * Return true if the values have been set since this function was
Chris@580 72 * last called (i.e. if they are meaningful). Return false if they
Chris@580 73 * have not been set (in which case both will be zero).
Chris@580 74 */
Chris@775 75 virtual bool getInputLevels(float &left, float &right) override;
Chris@574 76
Chris@775 77 ModelId startRecording(); // a WritableWaveFileModel; has not been
Chris@775 78 // added to document yet
Chris@476 79 void stopRecording();
Chris@477 80
Chris@477 81 signals:
Chris@477 82 void recordStatusChanged(bool recording);
Chris@485 83 void recordDurationChanged(sv_frame_t, sv_samplerate_t); // emitted occasionally
Chris@497 84 void recordCompleted();
Chris@477 85
Chris@477 86 protected slots:
Chris@575 87 void updateModel();
Chris@476 88
Chris@476 89 private:
Chris@476 90 ViewManagerBase *m_viewManager;
Chris@476 91 std::string m_clientName;
Chris@575 92 std::atomic_bool m_recording;
Chris@476 93 sv_samplerate_t m_recordSampleRate;
Chris@775 94 int m_systemRecordChannelCount;
Chris@775 95 bool m_recordMono;
Chris@485 96 sv_frame_t m_frameCount;
Chris@476 97 QString m_audioFileName;
Chris@775 98 ModelId m_modelId; // a WritableWaveFileModel
Chris@575 99 RingBuffer<float> **m_buffers;
Chris@575 100 QMutex m_bufPtrMutex;
Chris@575 101 int m_bufferCount;
Chris@574 102 float m_inputLeft;
Chris@574 103 float m_inputRight;
Chris@580 104 bool m_levelsSet;
Chris@575 105
Chris@575 106 void recreateBuffers();
Chris@476 107 };
Chris@476 108
Chris@476 109 #endif