Skip to content

Commit e4a2368

Browse files
committed
Use total_frames in ringbuffer play/record
1 parent 9931c13 commit e4a2368

File tree

3 files changed

+26
-22
lines changed

3 files changed

+26
-22
lines changed

rtmixer_build.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
ring_buffer_size_t PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer* rbuf, ring_buffer_size_t elementCount);
4141
ring_buffer_size_t PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer* rbuf, ring_buffer_size_t elementCount, void** dataPtr1, ring_buffer_size_t* sizePtr1, void** dataPtr2, ring_buffer_size_t* sizePtr2);
4242
ring_buffer_size_t PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer* rbuf, ring_buffer_size_t elementCount);
43+
44+
/* From limits.h: */
45+
46+
#define ULONG_MAX ...
4347
""" % locals())
4448
ffibuilder.cdef(open('src/rtmixer.h').read())
4549
ffibuilder.set_source(

src/rtmixer.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,20 @@ int callback(const void* input, void* output, frame_t frameCount
140140
device_data = (float*)input + offset * state->input_channels;
141141
}
142142

143-
frame_t frames = 0;
143+
frame_t frames = action->total_frames - action->done_frames;
144144

145-
if (using_buffer)
145+
if (frameCount < frames)
146146
{
147-
frames = action->total_frames - action->done_frames;
148-
if (frameCount < frames)
149-
{
150-
frames = frameCount;
151-
}
152-
if (frames + offset > frameCount)
153-
{
154-
assert(frameCount > offset);
155-
frames = frameCount - offset;
156-
}
147+
frames = frameCount;
148+
}
149+
if (frames + offset > frameCount)
150+
{
151+
assert(frameCount > offset);
152+
frames = frameCount - offset;
153+
}
157154

155+
if (using_buffer)
156+
{
158157
float* buffer = action->buffer + action->done_frames * action->channels;
159158
action->done_frames += frames;
160159
if (playing)
@@ -179,16 +178,9 @@ int callback(const void* input, void* output, frame_t frameCount
179178
device_data += state->input_channels;
180179
}
181180
}
182-
if (action->done_frames == action->total_frames)
183-
{
184-
remove_action(actionaddr, state);
185-
continue;
186-
}
187181
}
188182
else if (using_ringbuffer)
189183
{
190-
// TODO: continue to ignore action->total_frames?
191-
192184
float* block1 = NULL;
193185
float* block2 = NULL;
194186
ring_buffer_size_t size1 = 0;
@@ -198,7 +190,7 @@ int callback(const void* input, void* output, frame_t frameCount
198190
if (playing)
199191
{
200192
totalsize = PaUtil_GetRingBufferReadRegions(action->ringbuffer
201-
, (ring_buffer_size_t)(frameCount - offset)
193+
, (ring_buffer_size_t)frames
202194
, (void**)&block1, &size1, (void**)&block2, &size2);
203195

204196
while (size1--)
@@ -223,7 +215,7 @@ int callback(const void* input, void* output, frame_t frameCount
223215
else if (recording)
224216
{
225217
totalsize = PaUtil_GetRingBufferWriteRegions(action->ringbuffer
226-
, (ring_buffer_size_t)(frameCount - offset)
218+
, (ring_buffer_size_t)frames
227219
, (void**)&block1, &size1, (void**)&block2, &size2);
228220

229221
while (size1--)
@@ -246,7 +238,7 @@ int callback(const void* input, void* output, frame_t frameCount
246238
PaUtil_AdvanceRingBufferWriteIndex(action->ringbuffer, totalsize);
247239
}
248240

249-
if (totalsize < frameCount - offset)
241+
if (totalsize < frames)
250242
{
251243
// Ring buffer is empty or full
252244

@@ -256,6 +248,12 @@ int callback(const void* input, void* output, frame_t frameCount
256248
continue;
257249
}
258250
}
251+
252+
if (action->done_frames == action->total_frames)
253+
{
254+
remove_action(actionaddr, state);
255+
continue;
256+
}
259257
actionaddr = &(action->next);
260258
}
261259
return paContinue;

src/rtmixer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ def play_ringbuffer(self, ringbuffer, channels=None, start=0,
148148
allow_belated=allow_belated,
149149
requested_time=start,
150150
ringbuffer=ringbuffer._ptr,
151+
total_frames=_lib.ULONG_MAX,
151152
channels=channels,
152153
mapping=mapping,
153154
))
@@ -208,6 +209,7 @@ def record_ringbuffer(self, ringbuffer, channels=None, start=0,
208209
allow_belated=allow_belated,
209210
requested_time=start,
210211
ringbuffer=ringbuffer._ptr,
212+
total_frames=_lib.ULONG_MAX,
211213
channels=channels,
212214
mapping=mapping,
213215
))

0 commit comments

Comments
 (0)