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