I have been searching for a reason why my VS1063a isn't gracefully cancelling my Encoding. The decoding piece is working just fine. My difficulty is asserting SM_CANCEL and having the encoding end gracefully. I followed the example code, and I can't seem to see where i'm going sideways. I am attaching the Record Logic. I confirm that the SM_CANCEL is being set, and I can confirm it then gets cleared, but the encoding sometimes fails to stop.
I am assuming that the number of RECWORDS never stops, but I don't know why that is. Is there a setup that i'm missing ?
Code: Select all
void VS1063RecordFile(FILE *writeFp) {
static u_int8 recBuf[REC_BUFFER_SIZE];
u_int32 nextReportPos=0; // File pointer where to next collect/report
u_int32 fileSize = 0;
int volLevel = ReadSci(SCI_VOL) & 0xFF;
playerState = psPlayback;
/* Initialize recording */
/* This clock is high enough for both Ogg and MP3. */
WriteSci(SCI_CLOCKF, HZ_TO_SC_FREQ(12288000) | SC_MULT_53_50X | SC_ADD_53_00X);
// MP3 Recording setup
WriteSci(SCI_RECRATE, 48000);
WriteSci(SCI_RECGAIN, 0);
WriteSci(SCI_RECMODE, RM_63_FORMAT_MP3 | RM_63_ADC_MODE_LEFT);
WriteSci(SCI_RECQUALITY, RQ_MODE_VBR | RQ_MULT_1000 | 48);
audioFormat = afMp3;
// These 2 Lines will start the recording
WriteSci(SCI_MODE, ReadSci(SCI_MODE) | SM_LINE1 | SM_ENCODE);
WriteSci(SCI_AIADDR, 0x0050); /* Activate recording! */
while (playerState != psStopped) {
int n;
/* See if there is some data available */
if ((n = ReadSci(SCI_RECWORDS)) > 0) {
int i;
u_int8 *rbp = recBuf;
n = min(n, REC_BUFFER_SIZE/2);
for (i=0; i<n; i++) {
u_int16 w = ReadSci(SCI_RECDATA);
*rbp++ = (u_int8)(w >> 8);
*rbp++ = (u_int8)(w & 0xFF);
}
fwrite(recBuf, 1, 2*n, writeFp);
fileSize += 2*n;
} else {
/* The following read from SCI_RECWORDS may appear redundant.
But it's not: SCI_RECWORDS needs to be rechecked AFTER we
have seen that SM_CANCEL have cleared. */
if (playerState != psPlayback && !(ReadSci(SCI_MODE) & SM_CANCEL) && !ReadSci(SCI_RECWORDS)) {
playerState = psStopped;
}
}
if (fileSize - nextReportPos >= REPORT_INTERVAL) {
u_int16 sampleRate = ReadSci(SCI_AUDATA);
nextReportPos += REPORT_INTERVAL;
printf("\r%ldKiB %lds %uHz %s %s",
fileSize/1024,
ReadVS10xxMem32Counter(PAR_SAMPLE_COUNTER) /
(sampleRate & 0xFFFE),
sampleRate & 0xFFFE,
(sampleRate & 1) ? "stereo" : "mono",
afName[audioFormat]);
fflush(stdout);
}
} /* while (playerState != psStopped) */
/* We need to check whether the file had an odd length.
That information is available in the MSB of PAR_END_FILL_BYTE.
In that case, the 8 LSB's are the missing byte, so we'll add
it to the output file. */
{
u_int16 lastByte;
lastByte = ReadVS10xxMem(PAR_END_FILL_BYTE);
if (lastByte & 0x8000U) {
printf("\nOdd length recording\n");
} else {
printf("\nEven length recording\n");
}
}
/* Finally, reset the VS10xx software, including realoading the
patches package, to make sure everything is set up properly. */
VSTestInitSoftware(0);
printf("************* EXITING RECORDING ***************\n");
}