jackaudio.c (bae31bfa48b9caecee25da3d5333901a126a06b4) | jackaudio.c (d73415a315471ac0b127ed3fad45c8ec5d711de1) |
---|---|
1/* 2 * QEMU JACK Audio Connection Kit Client 3 * 4 * Copyright (c) 2020 Geoffrey McRae (gnif) 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 90 unchanged lines hidden (view full) --- 99 for (int i = 0; i < channels; ++i) { 100 buffer->data[i] = g_malloc(frames * sizeof(float)); 101 } 102} 103 104static void qjack_buffer_clear(QJackBuffer *buffer) 105{ 106 assert(buffer->data); | 1/* 2 * QEMU JACK Audio Connection Kit Client 3 * 4 * Copyright (c) 2020 Geoffrey McRae (gnif) 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights --- 90 unchanged lines hidden (view full) --- 99 for (int i = 0; i < channels; ++i) { 100 buffer->data[i] = g_malloc(frames * sizeof(float)); 101 } 102} 103 104static void qjack_buffer_clear(QJackBuffer *buffer) 105{ 106 assert(buffer->data); |
107 atomic_store_release(&buffer->used, 0); | 107 qatomic_store_release(&buffer->used, 0); |
108 buffer->rptr = 0; 109 buffer->wptr = 0; 110} 111 112static void qjack_buffer_free(QJackBuffer *buffer) 113{ 114 if (!buffer->data) { 115 return; --- 8 unchanged lines hidden (view full) --- 124} 125 126/* write PCM interleaved */ 127static int qjack_buffer_write(QJackBuffer *buffer, float *data, int size) 128{ 129 assert(buffer->data); 130 const int samples = size / sizeof(float); 131 int frames = samples / buffer->channels; | 108 buffer->rptr = 0; 109 buffer->wptr = 0; 110} 111 112static void qjack_buffer_free(QJackBuffer *buffer) 113{ 114 if (!buffer->data) { 115 return; --- 8 unchanged lines hidden (view full) --- 124} 125 126/* write PCM interleaved */ 127static int qjack_buffer_write(QJackBuffer *buffer, float *data, int size) 128{ 129 assert(buffer->data); 130 const int samples = size / sizeof(float); 131 int frames = samples / buffer->channels; |
132 const int avail = buffer->frames - atomic_load_acquire(&buffer->used); | 132 const int avail = buffer->frames - qatomic_load_acquire(&buffer->used); |
133 134 if (frames > avail) { 135 frames = avail; 136 } 137 138 int copy = frames; 139 int wptr = buffer->wptr; 140 --- 7 unchanged lines hidden (view full) --- 148 wptr = 0; 149 } 150 151 --copy; 152 } 153 154 buffer->wptr = wptr; 155 | 133 134 if (frames > avail) { 135 frames = avail; 136 } 137 138 int copy = frames; 139 int wptr = buffer->wptr; 140 --- 7 unchanged lines hidden (view full) --- 148 wptr = 0; 149 } 150 151 --copy; 152 } 153 154 buffer->wptr = wptr; 155 |
156 atomic_add(&buffer->used, frames); | 156 qatomic_add(&buffer->used, frames); |
157 return frames * buffer->channels * sizeof(float); 158}; 159 160/* write PCM linear */ 161static int qjack_buffer_write_l(QJackBuffer *buffer, float **dest, int frames) 162{ 163 assert(buffer->data); | 157 return frames * buffer->channels * sizeof(float); 158}; 159 160/* write PCM linear */ 161static int qjack_buffer_write_l(QJackBuffer *buffer, float **dest, int frames) 162{ 163 assert(buffer->data); |
164 const int avail = buffer->frames - atomic_load_acquire(&buffer->used); | 164 const int avail = buffer->frames - qatomic_load_acquire(&buffer->used); |
165 int wptr = buffer->wptr; 166 167 if (frames > avail) { 168 frames = avail; 169 } 170 171 int right = buffer->frames - wptr; 172 if (right > frames) { --- 7 unchanged lines hidden (view full) --- 180 } 181 182 wptr += frames; 183 if (wptr >= buffer->frames) { 184 wptr -= buffer->frames; 185 } 186 buffer->wptr = wptr; 187 | 165 int wptr = buffer->wptr; 166 167 if (frames > avail) { 168 frames = avail; 169 } 170 171 int right = buffer->frames - wptr; 172 if (right > frames) { --- 7 unchanged lines hidden (view full) --- 180 } 181 182 wptr += frames; 183 if (wptr >= buffer->frames) { 184 wptr -= buffer->frames; 185 } 186 buffer->wptr = wptr; 187 |
188 atomic_add(&buffer->used, frames); | 188 qatomic_add(&buffer->used, frames); |
189 return frames; 190} 191 192/* read PCM interleaved */ 193static int qjack_buffer_read(QJackBuffer *buffer, float *dest, int size) 194{ 195 assert(buffer->data); 196 const int samples = size / sizeof(float); 197 int frames = samples / buffer->channels; | 189 return frames; 190} 191 192/* read PCM interleaved */ 193static int qjack_buffer_read(QJackBuffer *buffer, float *dest, int size) 194{ 195 assert(buffer->data); 196 const int samples = size / sizeof(float); 197 int frames = samples / buffer->channels; |
198 const int avail = atomic_load_acquire(&buffer->used); | 198 const int avail = qatomic_load_acquire(&buffer->used); |
199 200 if (frames > avail) { 201 frames = avail; 202 } 203 204 int copy = frames; 205 int rptr = buffer->rptr; 206 --- 7 unchanged lines hidden (view full) --- 214 rptr = 0; 215 } 216 217 --copy; 218 } 219 220 buffer->rptr = rptr; 221 | 199 200 if (frames > avail) { 201 frames = avail; 202 } 203 204 int copy = frames; 205 int rptr = buffer->rptr; 206 --- 7 unchanged lines hidden (view full) --- 214 rptr = 0; 215 } 216 217 --copy; 218 } 219 220 buffer->rptr = rptr; 221 |
222 atomic_sub(&buffer->used, frames); | 222 qatomic_sub(&buffer->used, frames); |
223 return frames * buffer->channels * sizeof(float); 224} 225 226/* read PCM linear */ 227static int qjack_buffer_read_l(QJackBuffer *buffer, float **dest, int frames) 228{ 229 assert(buffer->data); 230 int copy = frames; | 223 return frames * buffer->channels * sizeof(float); 224} 225 226/* read PCM linear */ 227static int qjack_buffer_read_l(QJackBuffer *buffer, float **dest, int frames) 228{ 229 assert(buffer->data); 230 int copy = frames; |
231 const int used = atomic_load_acquire(&buffer->used); | 231 const int used = qatomic_load_acquire(&buffer->used); |
232 int rptr = buffer->rptr; 233 234 if (copy > used) { 235 copy = used; 236 } 237 238 int right = buffer->frames - rptr; 239 if (right > copy) { --- 7 unchanged lines hidden (view full) --- 247 } 248 249 rptr += copy; 250 if (rptr >= buffer->frames) { 251 rptr -= buffer->frames; 252 } 253 buffer->rptr = rptr; 254 | 232 int rptr = buffer->rptr; 233 234 if (copy > used) { 235 copy = used; 236 } 237 238 int right = buffer->frames - rptr; 239 if (right > copy) { --- 7 unchanged lines hidden (view full) --- 247 } 248 249 rptr += copy; 250 if (rptr >= buffer->frames) { 251 rptr -= buffer->frames; 252 } 253 buffer->rptr = rptr; 254 |
255 atomic_sub(&buffer->used, copy); | 255 qatomic_sub(&buffer->used, copy); |
256 return copy; 257} 258 259static int qjack_process(jack_nframes_t nframes, void *arg) 260{ 261 QJackClient *c = (QJackClient *)arg; 262 263 if (c->state != QJACK_STATE_RUNNING) { --- 407 unchanged lines hidden --- | 256 return copy; 257} 258 259static int qjack_process(jack_nframes_t nframes, void *arg) 260{ 261 QJackClient *c = (QJackClient *)arg; 262 263 if (c->state != QJACK_STATE_RUNNING) { --- 407 unchanged lines hidden --- |