@@ -39,11 +39,6 @@ static unsigned int elastic_average_samples(const output_t *st, const elastic_bu
39
39
return dec -> avg * (st -> radio -> mode == NRSC5_MODE_FM ? RADIO_FRAME_SAMPLES_FM : RADIO_FRAME_SAMPLES_AM );
40
40
}
41
41
42
- static unsigned int elastic_write_available (const elastic_buffer_t * elastic )
43
- {
44
- return elastic -> size - elastic -> write + elastic -> read - 1 ;
45
- }
46
-
47
42
#ifdef USE_FAAD2
48
43
static unsigned int decoder_buffer_write_available (const decoder_t * st )
49
44
{
@@ -208,12 +203,14 @@ void output_align(output_t *st, unsigned int program, unsigned int stream_id, un
208
203
elastic -> ptr [i ].seq = -1 ;
209
204
}
210
205
211
- elastic -> clock = st -> radio -> mode == NRSC5_MODE_FM ? FFT_FM : FFT_AM ;
212
- elastic -> write = seq ;
213
- elastic -> ptr [elastic -> write ].seq = seq ;
206
+ elastic -> clock = elastic_average_samples (st , elastic );
207
+
208
+ unsigned int offset = pdu_seq * avg ;
209
+
210
+ if ((offset + MAX_AUDIO_PACKETS - seq ) % MAX_AUDIO_PACKETS >= 32 )
211
+ offset = (offset + 32 ) % MAX_AUDIO_PACKETS ;
214
212
215
- // TODO: Calculate current delay based on sequence number
216
- elastic -> read = (seq - elastic -> latency ) % elastic -> size ;
213
+ elastic -> read = (offset - elastic -> latency ) % elastic -> size ;
217
214
}
218
215
219
216
#ifdef USE_FAAD2
@@ -272,10 +269,26 @@ void output_advance_elastic(output_t *st, int pos, unsigned int used)
272
269
}
273
270
elastic -> clock -= sample_avg ;
274
271
}
275
-
276
272
}
277
273
}
278
274
275
+ void output_push (output_t * st , uint8_t * pkt , unsigned int len , unsigned int program , unsigned int stream_id , unsigned int seq )
276
+ {
277
+ elastic_buffer_t * elastic = & st -> elastic [program ][stream_id ];
278
+
279
+ if (stream_id != 0 )
280
+ return ; // TODO: Process enhanced stream
281
+
282
+ if (elastic -> ptr [seq ].size != 0 )
283
+ log_warn ("Packet %d already exists in elastic buffer for program %d. Overwriting." , seq , program );
284
+
285
+ memcpy (elastic -> ptr [seq ].data , pkt , len );
286
+ elastic -> ptr [seq ].size = len ;
287
+ elastic -> ptr [seq ].seq = seq ;
288
+
289
+ elastic -> last_write = seq ;
290
+ }
291
+
279
292
void output_advance (output_t * st , unsigned int len , int mode )
280
293
{
281
294
#ifdef USE_FAAD2
@@ -329,23 +342,6 @@ void output_advance(output_t *st, unsigned int len, int mode)
329
342
#endif
330
343
}
331
344
332
- void output_push (output_t * st , uint8_t * pkt , unsigned int len , unsigned int program , unsigned int stream_id , unsigned int seq )
333
- {
334
- elastic_buffer_t * elastic = & st -> elastic [program ][stream_id ];
335
-
336
- if (stream_id != 0 )
337
- return ; // TODO: Process enhanced stream
338
-
339
- if (elastic -> ptr [seq ].size != 0 )
340
- log_warn ("Packet %d already exists in elastic buffer for program %d. Overwriting." , seq , program );
341
-
342
- memcpy (elastic -> ptr [seq ].data , pkt , len );
343
- elastic -> ptr [seq ].size = len ;
344
- elastic -> ptr [seq ].seq = seq ;
345
-
346
- elastic -> write = seq ;
347
- }
348
-
349
345
static void aas_free_lot (aas_file_t * file )
350
346
{
351
347
free (file -> name );
@@ -391,7 +387,6 @@ void output_reset(output_t *st)
391
387
{
392
388
elastic_buffer_t * buffer = & st -> elastic [i ][j ];
393
389
394
- buffer -> write = 0 ;
395
390
buffer -> read = 0 ;
396
391
buffer -> clock = 0 ;
397
392
@@ -428,8 +423,6 @@ void output_init(output_t *st, nrsc5_t *radio)
428
423
memset (st -> services , 0 , sizeof (st -> services ));
429
424
430
425
#ifdef USE_FAAD2
431
- memset (st -> decoder , 0 , sizeof (st -> decoder ));
432
- memset (st -> elastic , 0 , sizeof (st -> elastic ));
433
426
memset (st -> silence , 0 , sizeof (st -> silence ));
434
427
#endif
435
428
0 commit comments