FS#2127 - Faster & smaller recording routines

Attached to Project: Rockbox
Opened by Jens Arnold (amiconn) - Monday, 05 April 2004, 12:08 GMT
Last edited by Jens Arnold (amiconn) - Tuesday, 04 May 2004, 12:13 GMT
Task Type Patches
Status Closed
Assigned To No-one
Operating System
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


This patch contains 2 changes to the recording routines:

(1) There are recorder models with different
active/inactive levels of the PR pin to request data
from the MAS. The original routines use 2 different
loops to account for that (in drain_dma_buffer() and

This patch unifies these 2 different loops by using xor
to toggle the PR pin within the loops and setting the
correct initial "inactive" value in mpeg_init(). This

- no speed gain or loss
- 178 bytes less code in total
- 102 bytes less code in IRAM

These modified C routines are used if you uncomment the
#define PREFER_C_RECORDING at the top.

(2) Optimized transfer loops in assembler. These do not
"wait at least 5 cycles before the data is read" but
always wait for the PRTW level change. That delivers:

- approx. 50% speedup (sorry I cannot measure this)
- another 32 bytes less code in total
- another 4 bytes less code in IRAM

I did a test recording of > 2 hrs at 44.1 kHz, stereo,
Q=7 and did not get any incomplete frames and no
audible glitches.

The xor toggling of PR is not protected from accidental
changes by other parts of Rockbox since both Linus and
I agree that this would be too defensive coding style.
This task depends upon

Closed by  Jens Arnold (amiconn)
Tuesday, 04 May 2004, 12:13 GMT
Reason for closing:  Accepted
Comment by Jens Arnold (amiconn) - Saturday, 10 April 2004, 10:24 GMT

Ptach updated to adapt to the latest changes in mpeg.c