diff options
Diffstat (limited to 'src/audio/buf.h')
-rw-r--r-- | src/audio/buf.h | 74 |
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 | |||
3 | Redistribution and use in source and binary forms, with or without | ||
4 | modification, are permitted provided that the following conditions are met: | ||
5 | |||
6 | 1. Redistributions of source code must retain the above copyright notice, this | ||
7 | list of conditions and the following disclaimer. | ||
8 | 2. 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 | |||
12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
14 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
15 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR | ||
16 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
17 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
18 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
19 | ANY 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 | ||
21 | SOFTWARE, 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 | |||
30 | iDeclareType(InputBuf) | ||
31 | iDeclareType(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 | |||
40 | struct Impl_InputBuf { | ||
41 | iMutex mtx; | ||
42 | iCondition changed; | ||
43 | iBlock data; | ||
44 | iBool isComplete; | ||
45 | }; | ||
46 | |||
47 | iDeclareTypeConstruction(InputBuf) | ||
48 | |||
49 | size_t size_InputBuf (const iInputBuf *); | ||
50 | |||
51 | /*----------------------------------------------------------------------------------------------*/ | ||
52 | |||
53 | struct 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 | |||
63 | iDeclareTypeConstructionArgs(SampleBuf, SDL_AudioFormat format, size_t numChannels, size_t count) | ||
64 | |||
65 | size_t size_SampleBuf (const iSampleBuf *); | ||
66 | iBool isFull_SampleBuf (const iSampleBuf *); | ||
67 | size_t vacancy_SampleBuf (const iSampleBuf *); | ||
68 | |||
69 | iLocalDef void *ptr_SampleBuf_(iSampleBuf *d, size_t pos) { | ||
70 | return ((char *) d->data) + (d->sampleSize * pos); | ||
71 | } | ||
72 | |||
73 | void write_SampleBuf (iSampleBuf *, const void *samples, const size_t n); | ||
74 | void read_SampleBuf (iSampleBuf *, const size_t n, void *samples_out); | ||