summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-09-30 15:55:34 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-09-30 15:55:34 +0000
commit5be5674b066b63ac8994db86f34c83c2c7f956ed (patch)
tree4e21895a290c19757c70de842dbb1aec74c8e105
parent41541c5c31c5cd4f1a6dbbd7354046cfd5cfa13f (diff)
downloadrockbox-5be5674b066b63ac8994db86f34c83c2c7f956ed.tar.gz
rockbox-5be5674b066b63ac8994db86f34c83c2c7f956ed.zip
Remove the PCMREC_PARANOID support since the issues have been identified and fixed however detecting an encoder writing too many samples to a chunk will remain and be enabled in a DEBUG build as an aid for adding encoders. Do some cleanup on the filename queue. Loosen up the control interface where synchronous thread blocking isn't required for pause/stop/resume.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14918 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/export/enc_base.h4
-rw-r--r--firmware/export/pcm_record.h18
-rw-r--r--firmware/pcm_record.c207
3 files changed, 49 insertions, 180 deletions
diff --git a/firmware/export/enc_base.h b/firmware/export/enc_base.h
index a9eff523ce..c7c30d66c0 100644
--- a/firmware/export/enc_base.h
+++ b/firmware/export/enc_base.h
@@ -157,12 +157,12 @@ struct encoder_config
157#define CHUNKF_ALLFLAGS (0x0033ul | CHUNKF_ERROR) 157#define CHUNKF_ALLFLAGS (0x0033ul | CHUNKF_ERROR)
158 158
159/* Header at the beginning of every encoder chunk */ 159/* Header at the beginning of every encoder chunk */
160#ifdef PCMREC_PARANOID 160#ifdef DEBUG
161#define ENC_CHUNK_MAGIC H_TO_BE32(('P' << 24) | ('T' << 16) | ('Y' << 8) | 'R') 161#define ENC_CHUNK_MAGIC H_TO_BE32(('P' << 24) | ('T' << 16) | ('Y' << 8) | 'R')
162#endif 162#endif
163struct enc_chunk_hdr 163struct enc_chunk_hdr
164{ 164{
165#ifdef PCMREC_PARANOID 165#ifdef DEBUG
166 unsigned long id; /* overflow detection - 'PTYR' - acronym for 166 unsigned long id; /* overflow detection - 'PTYR' - acronym for
167 "PTYR Tells You Right" ;) */ 167 "PTYR Tells You Right" ;) */
168#endif 168#endif
diff --git a/firmware/export/pcm_record.h b/firmware/export/pcm_record.h
index dcc473c3f3..19c10cb228 100644
--- a/firmware/export/pcm_record.h
+++ b/firmware/export/pcm_record.h
@@ -30,14 +30,6 @@
30#define PCMREC_W_PCM_BUFFER_OVF 0x00000001 30#define PCMREC_W_PCM_BUFFER_OVF 0x00000001
31/* encoder output buffer has overflowed */ 31/* encoder output buffer has overflowed */
32#define PCMREC_W_ENC_BUFFER_OVF 0x00000002 32#define PCMREC_W_ENC_BUFFER_OVF 0x00000002
33#ifdef PCMREC_PARANOID
34/* dma write position alignment incorrect */
35#define PCMREC_W_DMA_WR_POS_ALIGN 0x00000004
36/* pcm read position changed at some point not under control of recording */
37#define PCMREC_W_PCM_RD_POS_TRASHED 0x00000008
38/* dma write position changed at some point not under control of recording */
39#define PCMREC_W_DMA_WR_POS_TRASHED 0x00000010
40#endif /* PCMREC_PARANOID */
41/** Errors **/ 33/** Errors **/
42/* failed to load encoder */ 34/* failed to load encoder */
43#define PCMREC_E_LOAD_ENCODER 0x80001000 35#define PCMREC_E_LOAD_ENCODER 0x80001000
@@ -47,16 +39,10 @@
47#define PCMREC_E_FNQ_DESYNC 0x80004000 39#define PCMREC_E_FNQ_DESYNC 0x80004000
48/* I/O error has occurred */ 40/* I/O error has occurred */
49#define PCMREC_E_IO 0x80008000 41#define PCMREC_E_IO 0x80008000
50#ifdef PCMREC_PARANOID 42#ifdef DEBUG
51/* encoder has written past end of allotted space */ 43/* encoder has written past end of allotted space */
52#define PCMREC_E_CHUNK_OVF 0x80010000 44#define PCMREC_E_CHUNK_OVF 0x80010000
53/* chunk header incorrect */ 45#endif /* DEBUG */
54#define PCMREC_E_BAD_CHUNK 0x80020000
55/* encoder read position changed outside of recording control */
56#define PCMREC_E_ENC_RD_INDEX_TRASHED 0x80040000
57/* encoder write position changed outside of recording control */
58#define PCMREC_E_ENC_WR_INDEX_TRASHED 0x80080000
59#endif /* PCMREC_PARANOID */
60 46
61/** 47/**
62 * RAW pcm data recording 48 * RAW pcm data recording
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c
index 8a6b08ef62..f3cb21e491 100644
--- a/firmware/pcm_record.c
+++ b/firmware/pcm_record.c
@@ -147,58 +147,19 @@ static unsigned long pre_record_ticks; /* pre-record time in ticks */
147 147
148#define GET_PCM_CHUNK(offset) ((long *)(pcm_buffer + (offset))) 148#define GET_PCM_CHUNK(offset) ((long *)(pcm_buffer + (offset)))
149#define GET_ENC_CHUNK(index) ENC_CHUNK_HDR(enc_buffer + enc_chunk_size*(index)) 149#define GET_ENC_CHUNK(index) ENC_CHUNK_HDR(enc_buffer + enc_chunk_size*(index))
150
151#ifdef PCMREC_PARANOID
152static void paranoid_set_code(unsigned long code, int line)
153{
154 logf("%08X at %d", code, line);
155 if ((long)code < 0)
156 errors |= code;
157 else
158 warnings |= code;
159}
160
161#define PARANOID_ENC_INDEX_CHECK(index) \
162 { if (index != index##_last) \
163 paranoid_set_code((&index == &enc_rd_index) ? \
164 PCMREC_E_ENC_RD_INDEX_TRASHED : PCMREC_E_ENC_WR_INDEX_TRASHED, \
165 __LINE__); }
166#define PARANOID_PCM_POS_CHECK(pos) \
167 { if (pos != pos##_last) \
168 paranoid_set_code((&pos == &pcm_rd_pos) ? \
169 PCMREC_W_PCM_RD_POS_TRASHED : PCMREC_W_DMA_WR_POS_TRASHED, \
170 __LINE__); }
171#define PARANOID_SET_LAST(var) \
172 ; var##_last = var
173#define PARANOID_CHUNK_CHECK(chunk) \
174 paranoid_chunk_check(chunk)
175#else
176#define PARANOID_ENC_INDEX_CHECK(index)
177#define PARANOID_PCM_POS_CHECK(pos)
178#define PARANOID_SET_LAST(var)
179#define PARANOID_CHUNK_CHECK(chunk)
180#endif
181
182#define INC_ENC_INDEX(index) \ 150#define INC_ENC_INDEX(index) \
183 PARANOID_ENC_INDEX_CHECK(index) \ 151 { if (++index >= enc_num_chunks) index = 0; }
184 { if (++index >= enc_num_chunks) index = 0; } \
185 PARANOID_SET_LAST(index)
186#define DEC_ENC_INDEX(index) \ 152#define DEC_ENC_INDEX(index) \
187 PARANOID_ENC_INDEX_CHECK(index) \ 153 { if (--index < 0) index = enc_num_chunks - 1; }
188 { if (--index < 0) index = enc_num_chunks - 1; } \
189 PARANOID_SET_LAST(index)
190#define SET_ENC_INDEX(index, value) \
191 PARANOID_ENC_INDEX_CHECK(index) \
192 index = value \
193 PARANOID_SET_LAST(index)
194#define SET_PCM_POS(pos, value) \
195 PARANOID_PCM_POS_CHECK(pos) \
196 pos = value \
197 PARANOID_SET_LAST(pos)
198 154
199static size_t rec_buffer_size; /* size of available buffer */ 155static size_t rec_buffer_size; /* size of available buffer */
200static unsigned char *pcm_buffer; /* circular recording buffer */ 156static unsigned char *pcm_buffer; /* circular recording buffer */
201static unsigned char *enc_buffer; /* circular encoding buffer */ 157static unsigned char *enc_buffer; /* circular encoding buffer */
158#ifdef DEBUG
159static unsigned long *wrap_id_p; /* magic at wrap position - a debugging
160 aid to check if the encoder data
161 spilled out of its chunk */
162#endif /* DEBUG */
202static volatile int dma_wr_pos; /* current DMA write pos */ 163static volatile int dma_wr_pos; /* current DMA write pos */
203static int pcm_rd_pos; /* current PCM read pos */ 164static int pcm_rd_pos; /* current PCM read pos */
204static int pcm_enc_pos; /* position encoder is processing */ 165static int pcm_enc_pos; /* position encoder is processing */
@@ -244,6 +205,16 @@ static unsigned char *fn_queue; /* pointer to first filename */
244static ssize_t fnq_size; /* capacity of queue in bytes */ 205static ssize_t fnq_size; /* capacity of queue in bytes */
245static int fnq_rd_pos; /* current read position */ 206static int fnq_rd_pos; /* current read position */
246static int fnq_wr_pos; /* current write position */ 207static int fnq_wr_pos; /* current write position */
208#define FNQ_NEXT(pos) \
209 ({ int p = (pos) + MAX_PATH; \
210 if (p >= fnq_size) \
211 p = 0; \
212 p; })
213#define FNQ_PREV(pos) \
214 ({ int p = (pos) - MAX_PATH; \
215 if (p < 0) \
216 p = fnq_size - MAX_PATH; \
217 p; })
247 218
248enum 219enum
249{ 220{
@@ -257,16 +228,6 @@ enum
257 reached */ 228 reached */
258}; 229};
259 230
260/** extra debugging info positioned away from other vars **/
261#ifdef PCMREC_PARANOID
262static unsigned long *wrap_id_p; /* magic at end of encoding buffer */
263static volatile int dma_wr_pos_last; /* previous dma write position */
264static int pcm_rd_pos_last; /* previous pcm read position */
265static int enc_rd_index_last; /* previsou encoder read position */
266static int enc_wr_index_last; /* previsou encoder read position */
267#endif
268
269
270/***************************************************************************/ 231/***************************************************************************/
271 232
272static struct event_queue pcmrec_queue; 233static struct event_queue pcmrec_queue;
@@ -320,17 +281,7 @@ static int pcm_rec_have_more(int status)
320 if ((unsigned)(pcm_enc_pos - next_pos) < PCM_CHUNK_SIZE) 281 if ((unsigned)(pcm_enc_pos - next_pos) < PCM_CHUNK_SIZE)
321 warnings |= PCMREC_W_PCM_BUFFER_OVF; 282 warnings |= PCMREC_W_PCM_BUFFER_OVF;
322 283
323#ifdef PCMREC_PARANOID 284 dma_wr_pos = next_pos;
324 /* write position must always be on PCM_CHUNK_SIZE boundary -
325 anything else is corruption */
326 if (next_pos & (PCM_CHUNK_SIZE-1))
327 {
328 logf("dma_wr_pos unalgn: %d", next_pos);
329 warnings |= PCMREC_W_DMA_WR_POS_ALIGN;
330 next_pos &= ~PCM_CHUNK_SIZE; /* re-align */
331 }
332#endif
333 SET_PCM_POS(dma_wr_pos, next_pos);
334 } 285 }
335 286
336 pcm_record_more(GET_PCM_CHUNK(dma_wr_pos), PCM_CHUNK_SIZE); 287 pcm_record_more(GET_PCM_CHUNK(dma_wr_pos), PCM_CHUNK_SIZE);
@@ -494,7 +445,7 @@ void audio_stop_recording(void)
494{ 445{
495 logf("audio_stop_recording"); 446 logf("audio_stop_recording");
496 flush_interrupt(); 447 flush_interrupt();
497 queue_send(&pcmrec_queue, PCMREC_STOP, 0); 448 queue_post(&pcmrec_queue, PCMREC_STOP, 0);
498 logf("audio_stop_recording done"); 449 logf("audio_stop_recording done");
499} /* audio_stop_recording */ 450} /* audio_stop_recording */
500 451
@@ -505,7 +456,7 @@ void audio_pause_recording(void)
505{ 456{
506 logf("audio_pause_recording"); 457 logf("audio_pause_recording");
507 flush_interrupt(); 458 flush_interrupt();
508 queue_send(&pcmrec_queue, PCMREC_PAUSE, 0); 459 queue_post(&pcmrec_queue, PCMREC_PAUSE, 0);
509 logf("audio_pause_recording done"); 460 logf("audio_pause_recording done");
510} /* audio_pause_recording */ 461} /* audio_pause_recording */
511 462
@@ -515,7 +466,7 @@ void audio_pause_recording(void)
515void audio_resume_recording(void) 466void audio_resume_recording(void)
516{ 467{
517 logf("audio_resume_recording"); 468 logf("audio_resume_recording");
518 queue_send(&pcmrec_queue, PCMREC_RESUME, 0); 469 queue_post(&pcmrec_queue, PCMREC_RESUME, 0);
519 logf("audio_resume_recording done"); 470 logf("audio_resume_recording done");
520} /* audio_resume_recording */ 471} /* audio_resume_recording */
521 472
@@ -587,22 +538,18 @@ static bool pcmrec_fnq_is_full(void)
587 538
588 return size >= fnq_size - MAX_PATH; 539 return size >= fnq_size - MAX_PATH;
589} /* pcmrec_fnq_is_full */ 540} /* pcmrec_fnq_is_full */
590 541
591/* queue another filename - will overwrite oldest one if full */ 542/* queue another filename - will overwrite oldest one if full */
592static bool pcmrec_fnq_add_filename(const char *filename) 543static bool pcmrec_fnq_add_filename(const char *filename)
593{ 544{
594 strncpy(fn_queue + fnq_wr_pos, filename, MAX_PATH); 545 strncpy(fn_queue + fnq_wr_pos, filename, MAX_PATH);
595 546 fnq_wr_pos = FNQ_NEXT(fnq_wr_pos);
596 if ((fnq_wr_pos += MAX_PATH) >= fnq_size)
597 fnq_wr_pos = 0;
598 547
599 if (fnq_rd_pos != fnq_wr_pos) 548 if (fnq_rd_pos != fnq_wr_pos)
600 return true; 549 return true;
601 550
602 /* queue full */ 551 /* queue full */
603 if ((fnq_rd_pos += MAX_PATH) >= fnq_size) 552 fnq_rd_pos = FNQ_NEXT(fnq_rd_pos);
604 fnq_rd_pos = 0;
605
606 return true; 553 return true;
607} /* pcmrec_fnq_add_filename */ 554} /* pcmrec_fnq_add_filename */
608 555
@@ -614,9 +561,7 @@ static bool pcmrec_fnq_replace_tail(const char *filename)
614 if (pcmrec_fnq_is_empty()) 561 if (pcmrec_fnq_is_empty())
615 return false; 562 return false;
616 563
617 pos = fnq_wr_pos - MAX_PATH; 564 pos = FNQ_PREV(fnq_wr_pos);
618 if (pos < 0)
619 pos = fnq_size - MAX_PATH;
620 565
621 strncpy(fn_queue + pos, filename, MAX_PATH); 566 strncpy(fn_queue + pos, filename, MAX_PATH);
622 567
@@ -632,9 +577,7 @@ static bool pcmrec_fnq_get_filename(char *filename)
632 if (filename) 577 if (filename)
633 strncpy(filename, fn_queue + fnq_rd_pos, MAX_PATH); 578 strncpy(filename, fn_queue + fnq_rd_pos, MAX_PATH);
634 579
635 if ((fnq_rd_pos += MAX_PATH) >= fnq_size) 580 fnq_rd_pos = FNQ_NEXT(fnq_rd_pos);
636 fnq_rd_pos = 0;
637
638 return true; 581 return true;
639} /* pcmrec_fnq_get_filename */ 582} /* pcmrec_fnq_get_filename */
640 583
@@ -650,51 +593,6 @@ static void pcmrec_close_file(int *fd_p)
650 *fd_p = -1; 593 *fd_p = -1;
651} /* pcmrec_close_file */ 594} /* pcmrec_close_file */
652 595
653#ifdef PCMREC_PARANOID
654static void paranoid_chunk_check(const struct enc_chunk_hdr *chunk)
655{
656 /* check integrity of things that must be ok - data or not */
657
658 /* check magic in header */
659 if (chunk->id != ENC_CHUNK_MAGIC)
660 {
661 errors |= PCMREC_E_BAD_CHUNK | PCMREC_E_CHUNK_OVF;
662 logf("bad chunk: %d", chunk - (struct enc_chunk_hdr *)enc_buffer);
663 }
664
665 /* check magic wrap id */
666 if (*wrap_id_p != ENC_CHUNK_MAGIC)
667 {
668 errors |= PCMREC_E_BAD_CHUNK | PCMREC_E_CHUNK_OVF;
669 logf("bad magic at wrap pos");
670 }
671
672 if (chunk->enc_data == NULL) /* has data? */
673 return;
674
675 /* check that data points to something after header */
676 if (chunk->enc_data < ENC_CHUNK_SKIP_HDR(chunk->enc_data, chunk))
677 {
678 errors |= PCMREC_E_BAD_CHUNK;
679 logf("chk ptr < hdr end");
680 }
681
682 /* check if data end is within chunk */
683 if (chunk->enc_data + chunk->enc_size >
684 (unsigned char *)chunk + enc_chunk_size)
685 {
686 errors |= PCMREC_E_BAD_CHUNK;
687 logf("chk data > chk end");
688 }
689
690 if ((chunk->flags & ~CHUNKF_ALLFLAGS) != 0)
691 {
692 errors |= PCMREC_E_BAD_CHUNK;
693 logf("chk bad flags %08X", chunk->flags);
694 }
695} /* paranoid_chunk_check */
696#endif /* PCMREC_PARANOID */
697
698/** Data Flushing **/ 596/** Data Flushing **/
699 597
700/** 598/**
@@ -1004,8 +902,6 @@ static void pcmrec_flush(unsigned flush_num)
1004 rec_fdata.new_enc_size = rec_fdata.chunk->enc_size; 902 rec_fdata.new_enc_size = rec_fdata.chunk->enc_size;
1005 rec_fdata.new_num_pcm = rec_fdata.chunk->num_pcm; 903 rec_fdata.new_num_pcm = rec_fdata.chunk->num_pcm;
1006 904
1007 PARANOID_CHUNK_CHECK(rec_fdata.chunk);
1008
1009 if (rec_fdata.chunk->flags & CHUNKF_START_FILE) 905 if (rec_fdata.chunk->flags & CHUNKF_START_FILE)
1010 { 906 {
1011 pcmrec_start_file(); 907 pcmrec_start_file();
@@ -1071,9 +967,6 @@ static int pcmrec_get_chunk_index(struct enc_chunk_hdr *chunk)
1071 967
1072static struct enc_chunk_hdr * pcmrec_get_prev_chunk(int index) 968static struct enc_chunk_hdr * pcmrec_get_prev_chunk(int index)
1073{ 969{
1074#ifdef PCMREC_PARANOID
1075 int index_last = index;
1076#endif
1077 DEC_ENC_INDEX(index); 970 DEC_ENC_INDEX(index);
1078 return GET_ENC_CHUNK(index); 971 return GET_ENC_CHUNK(index);
1079} /* pcmrec_get_prev_chunk */ 972} /* pcmrec_get_prev_chunk */
@@ -1185,9 +1078,6 @@ static void pcmrec_new_stream(const char *filename, /* next file name */
1185 /* get stats on data added to start - sort of a prerecord 1078 /* get stats on data added to start - sort of a prerecord
1186 operation */ 1079 operation */
1187 int i = pcmrec_get_chunk_index(data.chunk); 1080 int i = pcmrec_get_chunk_index(data.chunk);
1188#ifdef PCMREC_PARANOID
1189 int i_last = i;
1190#endif
1191 struct enc_chunk_hdr *chunk = data.chunk; 1081 struct enc_chunk_hdr *chunk = data.chunk;
1192 1082
1193 logf("start data: %d %d", i, enc_wr_index); 1083 logf("start data: %d %d", i, enc_wr_index);
@@ -1241,13 +1131,13 @@ static void pcmrec_init(void)
1241 1131
1242 /* pcm FIFO */ 1132 /* pcm FIFO */
1243 dma_lock = true; 1133 dma_lock = true;
1244 SET_PCM_POS(pcm_rd_pos, 0); 1134 pcm_rd_pos = 0;
1245 SET_PCM_POS(dma_wr_pos, 0); 1135 dma_wr_pos = 0;
1246 pcm_enc_pos = 0; 1136 pcm_enc_pos = 0;
1247 1137
1248 /* encoder FIFO */ 1138 /* encoder FIFO */
1249 SET_ENC_INDEX(enc_wr_index, 0); 1139 enc_wr_index = 0;
1250 SET_ENC_INDEX(enc_rd_index, 0); 1140 enc_rd_index = 0;
1251 1141
1252 /* filename queue */ 1142 /* filename queue */
1253 fnq_rd_pos = 0; 1143 fnq_rd_pos = 0;
@@ -1380,9 +1270,6 @@ static void pcmrec_record(const char *filename)
1380 if (pre_record_ticks) 1270 if (pre_record_ticks)
1381 { 1271 {
1382 int i = rd_start; 1272 int i = rd_start;
1383#ifdef PCMREC_PARANOID
1384 int i_last = i;
1385#endif
1386 /* calculate number of available chunks */ 1273 /* calculate number of available chunks */
1387 unsigned long avail_pre_chunks = (enc_wr_index - enc_rd_index + 1274 unsigned long avail_pre_chunks = (enc_wr_index - enc_rd_index +
1388 enc_num_chunks) % enc_num_chunks; 1275 enc_num_chunks) % enc_num_chunks;
@@ -1432,7 +1319,7 @@ static void pcmrec_record(const char *filename)
1432#endif 1319#endif
1433 } 1320 }
1434 1321
1435 SET_ENC_INDEX(enc_rd_index, rd_start); 1322 enc_rd_index = rd_start;
1436 1323
1437 /* filename queue should be empty */ 1324 /* filename queue should be empty */
1438 if (!pcmrec_fnq_is_empty()) 1325 if (!pcmrec_fnq_is_empty())
@@ -1632,7 +1519,6 @@ static void pcmrec_thread(void)
1632 if (is_recording) 1519 if (is_recording)
1633 break; 1520 break;
1634 pcmrec_close(); 1521 pcmrec_close();
1635 reset_hardware();
1636 /* Be sure other threads are released if waiting */ 1522 /* Be sure other threads are released if waiting */
1637 queue_clear(&pcmrec_queue); 1523 queue_clear(&pcmrec_queue);
1638 flush_interrupts = 0; 1524 flush_interrupts = 0;
@@ -1680,7 +1566,7 @@ void enc_set_parameters(struct enc_parameters *params)
1680 enc_sample_rate = params->enc_sample_rate; 1566 enc_sample_rate = params->enc_sample_rate;
1681 logf("enc sampr:%lu", enc_sample_rate); 1567 logf("enc sampr:%lu", enc_sample_rate);
1682 1568
1683 SET_PCM_POS(pcm_rd_pos, dma_wr_pos); 1569 pcm_rd_pos = dma_wr_pos;
1684 pcm_enc_pos = pcm_rd_pos; 1570 pcm_enc_pos = pcm_rd_pos;
1685 1571
1686 enc_config.afmt = params->afmt; 1572 enc_config.afmt = params->afmt;
@@ -1704,7 +1590,7 @@ void enc_set_parameters(struct enc_parameters *params)
1704 1590
1705 bufsize = rec_buffer_size - (enc_buffer - pcm_buffer) - 1591 bufsize = rec_buffer_size - (enc_buffer - pcm_buffer) -
1706 resbytes - FNQ_MIN_NUM_PATHS*MAX_PATH 1592 resbytes - FNQ_MIN_NUM_PATHS*MAX_PATH
1707#ifdef PCMREC_PARANOID 1593#ifdef DEBUG
1708 - sizeof (*wrap_id_p) 1594 - sizeof (*wrap_id_p)
1709#endif 1595#endif
1710 ; 1596 ;
@@ -1716,12 +1602,12 @@ void enc_set_parameters(struct enc_parameters *params)
1716 bufsize = enc_num_chunks*enc_chunk_size; 1602 bufsize = enc_num_chunks*enc_chunk_size;
1717 logf("enc size:%lu", bufsize); 1603 logf("enc size:%lu", bufsize);
1718 1604
1719#ifdef PCMREC_PARANOID 1605#ifdef DEBUG
1720 /* add magic at wraparound */ 1606 /* add magic at wraparound for spillover checks */
1721 wrap_id_p = SKIPBYTES((unsigned long *)enc_buffer, bufsize); 1607 wrap_id_p = SKIPBYTES((unsigned long *)enc_buffer, bufsize);
1722 bufsize += sizeof (*wrap_id_p); 1608 bufsize += sizeof (*wrap_id_p);
1723 *wrap_id_p = ENC_CHUNK_MAGIC; 1609 *wrap_id_p = ENC_CHUNK_MAGIC;
1724#endif /* PCMREC_PARANOID */ 1610#endif
1725 1611
1726 /** set OUT parameters **/ 1612 /** set OUT parameters **/
1727 params->enc_buffer = enc_buffer; 1613 params->enc_buffer = enc_buffer;
@@ -1747,26 +1633,24 @@ void enc_set_parameters(struct enc_parameters *params)
1747 fnq_size *= MAX_PATH; 1633 fnq_size *= MAX_PATH;
1748 logf("fnq files:%ld", fnq_size / MAX_PATH); 1634 logf("fnq files:%ld", fnq_size / MAX_PATH);
1749 1635
1750#if 0 1636#if defined(DEBUG)
1751 logf("ab :%08lX", (uintptr_t)audiobuf); 1637 logf("ab :%08lX", (uintptr_t)audiobuf);
1752 logf("pcm:%08lX", (uintptr_t)pcm_buffer); 1638 logf("pcm:%08lX", (uintptr_t)pcm_buffer);
1753 logf("enc:%08lX", (uintptr_t)enc_buffer); 1639 logf("enc:%08lX", (uintptr_t)enc_buffer);
1754 logf("res:%08lX", (uintptr_t)params->reserve_buffer); 1640 logf("res:%08lX", (uintptr_t)params->reserve_buffer);
1755#ifdef PCMREC_PARANOID
1756 logf("wip:%08lX", (uintptr_t)wrap_id_p); 1641 logf("wip:%08lX", (uintptr_t)wrap_id_p);
1757#endif
1758 logf("fnq:%08lX", (uintptr_t)fn_queue); 1642 logf("fnq:%08lX", (uintptr_t)fn_queue);
1759 logf("end:%08lX", (uintptr_t)fn_queue + fnq_size); 1643 logf("end:%08lX", (uintptr_t)fn_queue + fnq_size);
1760 logf("abe:%08lX", (uintptr_t)audiobufend); 1644 logf("abe:%08lX", (uintptr_t)audiobufend);
1761#endif 1645#endif
1762 1646
1763 /* init all chunk headers and reset indexes */ 1647 /* init all chunk headers and reset indexes */
1764 SET_ENC_INDEX(enc_rd_index, 0); 1648 enc_rd_index = 0;
1765 for (enc_wr_index = enc_num_chunks; enc_wr_index > 0; ) 1649 for (enc_wr_index = enc_num_chunks; enc_wr_index > 0; )
1766 { 1650 {
1767 struct enc_chunk_hdr *chunk = GET_ENC_CHUNK(--enc_wr_index); 1651 struct enc_chunk_hdr *chunk = GET_ENC_CHUNK(--enc_wr_index);
1768#ifdef PCMREC_PARANOID 1652#ifdef DEBUG
1769 chunk->id = ENC_CHUNK_MAGIC; 1653 chunk->id = ENC_CHUNK_MAGIC;
1770#endif 1654#endif
1771 chunk->flags = 0; 1655 chunk->flags = 0;
1772 } 1656 }
@@ -1780,7 +1664,7 @@ struct enc_chunk_hdr * enc_get_chunk(void)
1780{ 1664{
1781 struct enc_chunk_hdr *chunk = GET_ENC_CHUNK(enc_wr_index); 1665 struct enc_chunk_hdr *chunk = GET_ENC_CHUNK(enc_wr_index);
1782 1666
1783#ifdef PCMREC_PARANOID 1667#ifdef DEBUG
1784 if (chunk->id != ENC_CHUNK_MAGIC || *wrap_id_p != ENC_CHUNK_MAGIC) 1668 if (chunk->id != ENC_CHUNK_MAGIC || *wrap_id_p != ENC_CHUNK_MAGIC)
1785 { 1669 {
1786 errors |= PCMREC_E_CHUNK_OVF; 1670 errors |= PCMREC_E_CHUNK_OVF;
@@ -1809,8 +1693,6 @@ void enc_finish_chunk(void)
1809 logf("finish chk enc error"); 1693 logf("finish chk enc error");
1810 } 1694 }
1811 1695
1812 PARANOID_CHUNK_CHECK(chunk);
1813
1814 /* advance enc_wr_index to the next encoder chunk */ 1696 /* advance enc_wr_index to the next encoder chunk */
1815 INC_ENC_INDEX(enc_wr_index); 1697 INC_ENC_INDEX(enc_wr_index);
1816 1698
@@ -1872,13 +1754,14 @@ unsigned char * enc_get_pcm_data(size_t size)
1872 int next_pos = (pcm_rd_pos + size) & PCM_CHUNK_MASK; 1754 int next_pos = (pcm_rd_pos + size) & PCM_CHUNK_MASK;
1873 1755
1874 pcm_enc_pos = pcm_rd_pos; 1756 pcm_enc_pos = pcm_rd_pos;
1875 1757 pcm_rd_pos = next_pos;
1876 SET_PCM_POS(pcm_rd_pos, next_pos);
1877 1758
1878 /* ptr must point to continous data at wraparound position */ 1759 /* ptr must point to continous data at wraparound position */
1879 if ((size_t)pcm_rd_pos < size) 1760 if ((size_t)pcm_rd_pos < size)
1761 {
1880 memcpy(pcm_buffer + PCM_NUM_CHUNKS*PCM_CHUNK_SIZE, 1762 memcpy(pcm_buffer + PCM_NUM_CHUNKS*PCM_CHUNK_SIZE,
1881 pcm_buffer, pcm_rd_pos); 1763 pcm_buffer, pcm_rd_pos);
1764 }
1882 1765
1883 pcm_buffer_empty = false; 1766 pcm_buffer_empty = false;
1884 return ptr; 1767 return ptr;
@@ -1905,7 +1788,7 @@ size_t enc_unget_pcm_data(size_t size)
1905 size = old_avail; 1788 size = old_avail;
1906 1789
1907 pcm_enc_pos = (pcm_rd_pos - size) & PCM_CHUNK_MASK; 1790 pcm_enc_pos = (pcm_rd_pos - size) & PCM_CHUNK_MASK;
1908 SET_PCM_POS(pcm_rd_pos, pcm_enc_pos); 1791 pcm_rd_pos = pcm_enc_pos;
1909 1792
1910 return size; 1793 return size;
1911 } 1794 }