HARDT - The Ham Radio DSP Toolkit
hsoundcardwriter.h
1 #ifndef __HSOUNDCARDWRITER_H
2 #define __HSOUNDCARDWRITER_H
3 
4 #include <mutex>
5 #include <condition_variable>
6 
7 #include "hardt.h"
8 
9 #define NUMBER_OF_BUFFERS 4
10 
14 template <class T>
15 class HSoundcardWriter : public HWriter<T>
16 {
17  private:
18 
19  struct CallbackData
20  {
21  int channels;
22  int framesize;
23  int wrloc;
24  int rdloc;
25  T* buffer;
26  std::mutex mtx;
27  std::condition_variable lock;
28  } _cbd;
29 
30  PaStream *_stream;
31  bool _isStarted;
32 
33  bool _isInitialized;
34 
35  bool Start();
36  bool Stop();
37 
38  void Init(int device, H_SAMPLE_RATE rate, int channels, H_SAMPLE_FORMAT format, int framesPerBuffer);
39 
40  public:
41 
43  HSoundcardWriter(int device, H_SAMPLE_RATE rate, int channels, H_SAMPLE_FORMAT format, int framesPerBuffer);
44 
46  HSoundcardWriter(int device, H_SAMPLE_RATE rate, int channels, H_SAMPLE_FORMAT format, int framesPerBuffer, HWriterConsumer<T>* consumer);
47 
50 
52  int Write(T* src, size_t blocksize);
53 
55  static int callback( const void *inputBuffer, void *outputBuffer,
56  unsigned long framesPerBuffer,
57  const PaStreamCallbackTimeInfo* timeInfo,
58  PaStreamCallbackFlags statusFlags,
59  void *userData );
60 
62  bool Command(HCommand* command) {
63  // No further propagation of commands
64  return true;
65  }
66 };
67 
68 #endif
HSoundcardWriter
Definition: hsoundcardwriter.h:15
HSoundcardWriter::~HSoundcardWriter
~HSoundcardWriter()
Definition: hsoundcardwriter.cpp:93
HWriter
Definition: hwriter.h:10
HSoundcardWriter::HSoundcardWriter
HSoundcardWriter(int device, H_SAMPLE_RATE rate, int channels, H_SAMPLE_FORMAT format, int framesPerBuffer)
Definition: hsoundcardwriter.cpp:17
HSoundcardWriter::Write
int Write(T *src, size_t blocksize)
Definition: hsoundcardwriter.cpp:121
HCommand
Definition: hcommand.h:81
HSoundcardWriter::callback
static int callback(const void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer, const PaStreamCallbackTimeInfo *timeInfo, PaStreamCallbackFlags statusFlags, void *userData)
Definition: hsoundcardwriter.cpp:164
HSoundcardWriter::Command
bool Command(HCommand *command)
Definition: hsoundcardwriter.h:62
HWriterConsumer
Definition: hwriterconsumer.h:8