Rev 2097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1528 | jag | 1 | /* |
2 | * audio.h |
||
2097 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2024 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1528 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
6 | */ |
||
7 | |||
8 | |||
9 | #ifndef __AUDIO |
||
10 | #define __AUDIO |
||
11 | |||
12 | #include "RtAudio.h" |
||
13 | |||
14 | #include <vector> |
||
15 | #include <string> |
||
16 | |||
17 | typedef float sample_t; |
||
18 | |||
2297 | jag | 19 | |
1528 | jag | 20 | struct audio_out { |
21 | |||
22 | enum {INVALID=-1}; |
||
23 | |||
24 | // audio devices |
||
25 | RtAudio dac; |
||
26 | std::vector<RtAudio::DeviceInfo> infos; |
||
27 | std::vector<std::string> names; // use @ settings screen |
||
28 | int num_devices, default_device, current_device, next_device, last_device; |
||
29 | |||
30 | // sample rate vars |
||
31 | int sample_rate; |
||
32 | int samples_per_buffer; // buffer has all channels |
||
33 | int samples_channel_size, samples_buffer_size; // in bytes |
||
34 | void set_sample_rate (int s); |
||
35 | void set_samples_per_channel (int spc); |
||
36 | |||
37 | // for settings ui |
||
38 | int i_sample_rate; |
||
39 | void find_sample_rate_id (unsigned int sr); |
||
40 | int goto_next_device (int i); |
||
41 | int goto_next_sample_rate_id (int i); |
||
42 | |||
43 | std::string prefs_name; |
||
44 | void load_prefs (); |
||
45 | void save_prefs (); |
||
46 | void defaults (); |
||
47 | |||
48 | audio_out (); |
||
49 | ~audio_out (); |
||
50 | |||
51 | void alloc (); |
||
52 | void probe (); |
||
53 | int open (); |
||
54 | int open (int id, unsigned int sr, unsigned int spc); |
||
55 | int start (); |
||
56 | int close (); |
||
57 | void list (); |
||
58 | |||
59 | |||
60 | // written by the main thread |
||
61 | // |
||
62 | // a multi buffer scheme |
||
63 | // |
||
64 | // main thread writes a buffer, while audio thread streams another to audio card |
||
65 | // |
||
66 | |||
67 | int num_samples_buffers; |
||
68 | sample_t * samples_buffers; // a bunch of sample buffers |
||
69 | int* available; // buffer available for streaming? |
||
70 | |||
71 | sample_t *readp, *writep; |
||
72 | int readi, writei; |
||
73 | inline int can_write () {return !available [writei];} |
||
74 | |||
75 | // reuseable buffers |
||
76 | // result, AM, FM, gater, volume, mix, mix alpha, buffer L,R , fader 1,2 |
||
77 | sample_t *result, *ams, *fms, *gatr, *vol, *mix, *mixa, *bufL, *bufR, *fdr1, *fdr2; |
||
78 | |||
79 | int num_channels; |
||
80 | int samples_per_channel; |
||
81 | int last_sample; |
||
82 | |||
83 | static int audio_wanted (void *ob, void *ib, unsigned int spc, double t, RtAudioStreamStatus status, void *data); |
||
84 | |||
85 | |||
86 | }; |
||
87 | |||
88 | extern audio_out aout; |
||
89 | extern int SAMPLE_RATE; |
||
90 | extern float SAMPLE_DURATION; |
||
91 | |||
2297 | jag | 92 | struct console; |
93 | console& operator<< (console& c, const audio_out& ao); |
||
94 | |||
1528 | jag | 95 | #endif |