Async 1.8.0
AsyncAudioContainerWav.h
Go to the documentation of this file.
1
31#ifndef ASYNC_AUDIO_CONTAINER_WAV_INCLUDED
32#define ASYNC_AUDIO_CONTAINER_WAV_INCLUDED
33
34
35/****************************************************************************
36 *
37 * System Includes
38 *
39 ****************************************************************************/
40
41#include <sigc++/sigc++.h>
42#include <cstring>
43#include <cstdint>
44
45
46/****************************************************************************
47 *
48 * Project Includes
49 *
50 ****************************************************************************/
51
52#include <AsyncAudioContainer.h>
53
54
55/****************************************************************************
56 *
57 * Local Includes
58 *
59 ****************************************************************************/
60
61
62
63/****************************************************************************
64 *
65 * Forward declarations
66 *
67 ****************************************************************************/
68
69
70
71/****************************************************************************
72 *
73 * Namespace
74 *
75 ****************************************************************************/
76
77namespace Async
78{
79
80
81/****************************************************************************
82 *
83 * Forward declarations of classes inside of the declared namespace
84 *
85 ****************************************************************************/
86
87
88
89/****************************************************************************
90 *
91 * Defines & typedefs
92 *
93 ****************************************************************************/
94
95
96
97/****************************************************************************
98 *
99 * Exported Global Variables
100 *
101 ****************************************************************************/
102
103
104
105/****************************************************************************
106 *
107 * Class definitions
108 *
109 ****************************************************************************/
110
125{
126 public:
128 static constexpr const char *OBJNAME = "wav";
129
130 //struct Factory : public AudioContainerSpecificFactory<AudioContainerWav>
131 //{
132 // Factory(void) : AudioContainerSpecificFactory<AudioContainerWav>("wav") {}
133 //};
134
139
143 virtual ~AudioContainerWav(void);
144
149 virtual const char* mediaType(void) const { return "audio/wav"; }
150
155 virtual const char* filenameExtension(void) const { return "wav"; }
156
167 virtual int writeSamples(const float *samples, int count);
168
176 virtual void flushSamples(void);
177
186 virtual void setRealtime(void) { m_realtime = true; }
187
196 virtual size_t headerSize(void) const { return WAVE_HEADER_SIZE; }
197
207 virtual const char* header(void);
208
209 private:
210 static const size_t WAVE_HEADER_SIZE = 44;
211 static const size_t NUM_CHANNELS = 1;
212
213 char m_wave_header[WAVE_HEADER_SIZE];
214 int m_sample_rate = INTERNAL_SAMPLE_RATE;
215 size_t m_samples_written = 0;
216 size_t m_block_size = sizeof(int16_t)*INTERNAL_SAMPLE_RATE / 10;
217 char* m_block = nullptr;
218 char* m_block_ptr = nullptr;
219 bool m_realtime = false;
220
222 AudioContainerWav& operator=(const AudioContainerWav&);
223
224 size_t storeBuf(char *ptr, const char* buf, size_t len)
225 {
226 std::memcpy(ptr, buf, len);
227 return len;
228 }
229
230 size_t store32bitValue(char *ptr, uint32_t val)
231 {
232 *ptr++ = val & 0xff;
233 val >>= 8;
234 *ptr++ = val & 0xff;
235 val >>= 8;
236 *ptr++ = val & 0xff;
237 val >>= 8;
238 *ptr++ = val & 0xff;
239 return 4;
240 }
241
242 size_t store16bitValue(char *ptr, uint16_t val)
243 {
244 *ptr++ = val & 0xff;
245 val >>= 8;
246 *ptr++ = val & 0xff;
247 return 2;
248 }
249}; /* class AudioContainerWav */
250
251
252} /* namespace */
253
254#endif /* ASYNC_AUDIO_CONTAINER_WAV_INCLUDED */
255
256/*
257 * This file has not been truncated
258 */
Base class for audio container handlers.
virtual const char * mediaType(void) const
Retrieve the media type for the audio container.
static constexpr const char * OBJNAME
The name of this class when used by the object factory.
virtual void setRealtime(void)
Indicate to the container that realtime operation is desired.
virtual int writeSamples(const float *samples, int count)
Write samples into this audio sink.
virtual ~AudioContainerWav(void)
Destructor.
virtual const char * filenameExtension(void) const
Get the standard filename extension for the audio container.
virtual void flushSamples(void)
Tell the sink to flush the previously written samples.
virtual const char * header(void)
Get the header data.
virtual size_t headerSize(void) const
Get the size of the header for this container.
AudioContainerWav(void)
Default constructor.
Namespace for the asynchronous programming classes.