summaryrefslogtreecommitdiff
path: root/src/audio/buf.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/audio/buf.h')
-rw-r--r--src/audio/buf.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/audio/buf.h b/src/audio/buf.h
new file mode 100644
index 00000000..de123481
--- /dev/null
+++ b/src/audio/buf.h
@@ -0,0 +1,74 @@
1/* Copyright 2020 Jaakko Keränen <jaakko.keranen@iki.fi>
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are met:
5
61. Redistributions of source code must retain the above copyright notice, this
7 list of conditions and the following disclaimer.
82. Redistributions in binary form must reproduce the above copyright notice,
9 this list of conditions and the following disclaimer in the documentation
10 and/or other materials provided with the distribution.
11
12THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
13ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
14WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
15DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
16ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
17(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
19ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
22
23#pragma once
24
25#include "the_Foundation/block.h"
26#include "the_Foundation/mutex.h"
27
28#include <SDL_audio.h>
29
30iDeclareType(InputBuf)
31iDeclareType(SampleBuf)
32
33#if !defined (AUDIO_S24LSB)
34# define AUDIO_S24LSB 0x8018 /* 24-bit integer samples */
35#endif
36#if !defined (AUDIO_F64LSB)
37# define AUDIO_F64LSB 0x8140 /* 64-bit floating point samples */
38#endif
39
40struct Impl_InputBuf {
41 iMutex mtx;
42 iCondition changed;
43 iBlock data;
44 iBool isComplete;
45};
46
47iDeclareTypeConstruction(InputBuf)
48
49size_t size_InputBuf (const iInputBuf *);
50
51/*----------------------------------------------------------------------------------------------*/
52
53struct Impl_SampleBuf {
54 SDL_AudioFormat format;
55 uint8_t numChannels;
56 uint8_t sampleSize; /* as bytes; one sample includes values for all channels */
57 void * data;
58 size_t count;
59 size_t head, tail;
60 iCondition moreNeeded;
61};
62
63iDeclareTypeConstructionArgs(SampleBuf, SDL_AudioFormat format, size_t numChannels, size_t count)
64
65size_t size_SampleBuf (const iSampleBuf *);
66iBool isFull_SampleBuf (const iSampleBuf *);
67size_t vacancy_SampleBuf (const iSampleBuf *);
68
69iLocalDef void *ptr_SampleBuf_(iSampleBuf *d, size_t pos) {
70 return ((char *) d->data) + (d->sampleSize * pos);
71}
72
73void write_SampleBuf (iSampleBuf *, const void *samples, const size_t n);
74void read_SampleBuf (iSampleBuf *, const size_t n, void *samples_out);