annotate audioio/AudioPulseAudioTarget.h @ 181:b35c7af2e1d0

* Add start frame get/set to EditableDenseThreeDimensionalModel and use it when importing grids from CSV with timings attached
author Chris Cannam
date Fri, 11 Sep 2009 15:42:32 +0000
parents 2aa263b384f8
children 0876ea394902
rev   line source
Chris@117 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@117 2
Chris@117 3 /*
Chris@117 4 Sonic Visualiser
Chris@117 5 An audio file viewer and annotation editor.
Chris@117 6 Centre for Digital Music, Queen Mary, University of London.
Chris@117 7 This file copyright 2008 QMUL.
Chris@117 8
Chris@117 9 This program is free software; you can redistribute it and/or
Chris@117 10 modify it under the terms of the GNU General Public License as
Chris@117 11 published by the Free Software Foundation; either version 2 of the
Chris@117 12 License, or (at your option) any later version. See the file
Chris@117 13 COPYING included with this distribution for more information.
Chris@117 14 */
Chris@117 15
Chris@117 16 #ifndef _AUDIO_PULSE_AUDIO_TARGET_H_
Chris@117 17 #define _AUDIO_PULSE_AUDIO_TARGET_H_
Chris@117 18
Chris@117 19 #ifdef HAVE_LIBPULSE
Chris@117 20
Chris@117 21 #include <pulse/pulseaudio.h>
Chris@117 22
Chris@117 23 #include <QObject>
Chris@117 24 #include <QMutex>
Chris@118 25 #include "base/Thread.h"
Chris@117 26
Chris@117 27 #include "AudioCallbackPlayTarget.h"
Chris@117 28
Chris@117 29 class AudioCallbackPlaySource;
Chris@117 30
Chris@117 31 class AudioPulseAudioTarget : public AudioCallbackPlayTarget
Chris@117 32 {
Chris@117 33 Q_OBJECT
Chris@117 34
Chris@117 35 public:
Chris@117 36 AudioPulseAudioTarget(AudioCallbackPlaySource *source);
Chris@117 37 virtual ~AudioPulseAudioTarget();
Chris@117 38
Chris@117 39 virtual void shutdown();
Chris@117 40
Chris@117 41 virtual bool isOK() const;
Chris@117 42
Chris@117 43 virtual double getCurrentTime() const;
Chris@117 44
Chris@117 45 public slots:
Chris@117 46 virtual void sourceModelReplaced();
Chris@117 47
Chris@117 48 protected:
Chris@117 49 void streamWrite(size_t);
Chris@117 50 void streamStateChanged();
Chris@117 51 void contextStateChanged();
Chris@117 52
Chris@117 53 static void streamWriteStatic(pa_stream *, size_t, void *);
Chris@117 54 static void streamStateChangedStatic(pa_stream *, void *);
Chris@120 55 static void streamOverflowStatic(pa_stream *, void *);
Chris@120 56 static void streamUnderflowStatic(pa_stream *, void *);
Chris@117 57 static void contextStateChangedStatic(pa_context *, void *);
Chris@117 58
Chris@117 59 QMutex m_mutex;
Chris@117 60
Chris@118 61 class MainLoopThread : public Thread
Chris@117 62 {
Chris@117 63 public:
Chris@119 64 MainLoopThread(pa_mainloop *loop) : Thread(NonRTThread), m_loop(loop) { } //!!! or RTThread
Chris@117 65 virtual void run() {
Chris@117 66 int rv = 0;
Chris@117 67 pa_mainloop_run(m_loop, &rv); //!!! check return value from this, and rv
Chris@117 68 }
Chris@117 69
Chris@117 70 private:
Chris@117 71 pa_mainloop *m_loop;
Chris@117 72 };
Chris@117 73
Chris@117 74 pa_mainloop *m_loop;
Chris@117 75 pa_mainloop_api *m_api;
Chris@117 76 pa_context *m_context;
Chris@117 77 pa_stream *m_stream;
Chris@117 78 pa_sample_spec m_spec;
Chris@117 79
Chris@117 80 MainLoopThread *m_loopThread;
Chris@117 81
Chris@117 82 int m_bufferSize;
Chris@117 83 int m_sampleRate;
Chris@117 84 int m_latency;
Chris@117 85 bool m_done;
Chris@117 86 };
Chris@117 87
Chris@117 88 #endif /* HAVE_PULSEAUDIO */
Chris@117 89
Chris@117 90 #endif
Chris@117 91