YAHAL
Yet Another Hardware Abstraction Library
Loading...
Searching...
No Matches
pcm_audio_interface.h
1// ---------------------------------------------
2// This file is part of
3// _ _ __ _ _ __ __
4// ( \/ ) /__\ ( )_( ) /__\ ( )
5// \ / /(__)\ ) _ ( /(__)\ )(__
6// (__)(__)(__)(_) (_)(__)(__)(____)
7//
8// Yet Another HW Abstraction Library
9// Copyright (C) Andreas Terstegge
10// BSD Licensed (see file LICENSE)
11//
12// ---------------------------------------------
13//
14// This file defines a generic and abstract C++
15// interface for a PCM audio interface.
16
17#ifndef _PCM_AUDIO_INTERFACE_H_
18#define _PCM_AUDIO_INTERFACE_H_
19
20#include <cstdint>
21#include "FIFO.h"
22
23// PCM samples are signed 16 bit integers
24typedef struct {
25 int16_t left;
26 int16_t right;
28
30public:
31 explicit pcm_audio_interface(uint16_t fifo_size)
32 : pcmFIFO(fifo_size) { }
33
34 // Set the PCM outout rate in Hz.
35 // Default is 44.1 kHz
36 virtual void setPcmRate(uint32_t Hz = 44100) = 0;
37
38 // Check how many values can be written to
39 // the PCM FIFO.
40 inline int pcmFifoAvailablePut() {
41 return pcmFIFO.available_put();
42 }
43
44 // Write a PCM sample to the PCM FIFO.
45 // It has to be checked before if the
46 // FIFO has enough space (see method above).
47 inline bool pcmFifoPut(pcm_value_t & v) {
48 return pcmFIFO.put(v);
49 }
50
51 // Read a PCM sample from the PCM FIFO.
52 // Method will return false if no data is
53 // available. Otherwise, v will contain
54 // the PCM sample.
55 inline bool pcmFifoGet(pcm_value_t & v) {
56 return pcmFIFO.get(v);
57 }
58
59protected:
60 // PCM FIFO buffer to store the PCM samples
61 FIFO<pcm_value_t> pcmFIFO;
62
63 ~pcm_audio_interface() = default;
64};
65
66#endif // _PCM_AUDIO_INTERFACE_H_
Definition FIFO.h:9