|
34 | 34 |
|
35 | 35 | #include <cstdint> |
36 | 36 |
|
37 | | -/* -------------------------------------------------------------------------- |
38 | | - * Local static helpers/tables |
39 | | - * |
40 | | - * -------------------------------------------------------------------------- */ |
41 | | - |
42 | | -static FLUID_INLINE unsigned int fluid_synth_get_ticks(fluid_synth_t *synth) |
43 | | -{ |
44 | | - return fluid_atomic_int_get(&synth->ticks_since_start); |
45 | | -} |
46 | | - |
47 | | -static FLUID_INLINE void fluid_synth_add_ticks(fluid_synth_t *synth, int val) |
48 | | -{ |
49 | | - fluid_atomic_int_add(&synth->ticks_since_start, val); |
50 | | -} |
51 | | - |
52 | | - |
53 | | -/*************************************************************** |
54 | | - * FLUID SAMPLE TIMERS |
55 | | - * Timers that use written audio data as timing reference |
56 | | - */ |
57 | | -struct _fluid_sample_timer_t |
58 | | -{ |
59 | | - fluid_sample_timer_t *next; /* Single linked list of timers */ |
60 | | - unsigned long starttick; |
61 | | - fluid_timer_callback_t callback; |
62 | | - void *data; |
63 | | - int isfinished; |
64 | | -}; |
65 | | - |
66 | | -/* |
67 | | - * fluid_sample_timer_process - called when synth->ticks is updated |
68 | | - */ |
69 | | -static void fluid_sample_timer_process(fluid_synth_t *synth) |
70 | | -{ |
71 | | - fluid_sample_timer_t *st; |
72 | | - long msec; |
73 | | - int cont; |
74 | | - unsigned int ticks = fluid_synth_get_ticks(synth); |
75 | | - |
76 | | - for (st = synth->sample_timers; st; st = st->next) |
77 | | - { |
78 | | - if (st->isfinished) |
79 | | - { |
80 | | - continue; |
81 | | - } |
82 | | - |
83 | | - msec = (long)(1000.0 * ((double)(ticks - st->starttick)) / synth->sample_rate); |
84 | | - cont = (*st->callback)(st->data, msec); |
85 | | - |
86 | | - if (cont == 0) |
87 | | - { |
88 | | - st->isfinished = 1; |
89 | | - } |
90 | | - } |
91 | | -} |
92 | | - |
93 | | -/* |
94 | | - * Process blocks (FLUID_BUFSIZE) of audio. |
95 | | - * Must be called from renderer thread only! |
96 | | - * @return number of blocks rendered. Might (often) return less than requested |
97 | | - */ |
98 | | -static int fluid_synth_render_blocks(fluid_synth_t *synth, int blockcount) |
99 | | -{ |
100 | | - int i, maxblocks; |
101 | | - fluid_profile_ref_var(prof_ref); |
102 | | - |
103 | | - /* Assign ID of synthesis thread */ |
104 | | - // synth->synth_thread_id = fluid_thread_get_id (); |
105 | | - |
106 | | - fluid_check_fpe("??? Just starting up ???"); |
107 | | - |
108 | | - fluid_rvoice_eventhandler_dispatch_all(synth->eventhandler); |
109 | | - |
110 | | - /* do not render more blocks than we can store internally */ |
111 | | - maxblocks = fluid_rvoice_mixer_get_bufcount(synth->eventhandler->mixer); |
112 | | - |
113 | | - if (blockcount > maxblocks) |
114 | | - { |
115 | | - blockcount = maxblocks; |
116 | | - } |
117 | | - |
118 | | - for (i = 0; i < blockcount; i++) |
119 | | - { |
120 | | - fluid_sample_timer_process(synth); |
121 | | - fluid_synth_add_ticks(synth, FLUID_BUFSIZE); |
122 | | - |
123 | | - /* If events have been queued waiting for fluid_rvoice_eventhandler_dispatch_all() |
124 | | - * (should only happen with parallel render) stop processing and go for rendering |
125 | | - */ |
126 | | - if (fluid_rvoice_eventhandler_dispatch_count(synth->eventhandler)) |
127 | | - { |
128 | | - // Something has happened, we can't process more |
129 | | - blockcount = i + 1; |
130 | | - break; |
131 | | - } |
132 | | - } |
133 | | - |
134 | | - fluid_check_fpe("fluid_sample_timer_process"); |
135 | | - |
136 | | - blockcount = fluid_rvoice_mixer_render(synth->eventhandler->mixer, blockcount); |
137 | | - |
138 | | - /* Testcase, that provokes a denormal floating point error */ |
139 | | -#if 0 |
140 | | - { |
141 | | - float num = 1; |
142 | | - |
143 | | - while(num != 0) |
144 | | - { |
145 | | - num *= 0.5; |
146 | | - }; |
147 | | - }; |
148 | | -#endif |
149 | | - fluid_check_fpe("??? Remainder of synth_one_block ???"); |
150 | | - fluid_profile(FLUID_PROF_ONE_BLOCK, |
151 | | - prof_ref, |
152 | | - fluid_rvoice_mixer_get_active_voices(synth->eventhandler->mixer), |
153 | | - blockcount * FLUID_BUFSIZE); |
154 | | - return blockcount; |
155 | | -} |
156 | | - |
157 | 37 | /* -------------------------------------------------------------------------- |
158 | 38 | * Integer write core: tag dispatch + traits (C++11) |
159 | 39 | * -------------------------------------------------------------------------- */ |
|
0 commit comments