@Alex
This patch will solve WAV writing issue. I confirmed.
- current code has no buffer
- If write speed is not enough, wav data will lost
- This patch adding a queue for reading. and write_q_task will write asyncronous. So It has no data lost.
- But actually write speed is not enough, NotifyBox will telling "Use more faster card"
*Now I can write CBR3.0 and WAV recording together with no data lost.
*tested WAV recording + CBR 2.0 CBR 2.5 CBR 2.8
Please test this on your side.
diff -r ae36c8b5889b src/beep.c
--- a/src/beep.c Sun Sep 02 02:50:47 2012 +0900
+++ b/src/beep.c Tue Sep 04 11:33:29 2012 +0900
@@ -322,12 +322,73 @@
return ans;
}
+
+
+typedef struct _write_q {
+ int multiplex;
+ void *buf;
+ struct _write_q *next;
+}WRITE_Q;
+
+#define QBUF_SIZE 4
+#define QBUF_MAX 20
+WRITE_Q *rootq;
+
+static void add_write_q(void *buf){
+ WRITE_Q *tmpq = rootq;
+ WRITE_Q *newq;
+
+ int i=0;
+ while(tmpq->next){
+ tmpq = tmpq->next;
+ i++;
+ }
+ if(i > QBUF_MAX){
+ NotifyBox(2000,"Lost WAV data\nUse more faster card");
+ return;
+ }
+
+ if(tmpq->multiplex < QBUF_SIZE){
+ if(!tmpq->buf){
+ tmpq->buf = alloc_dma_memory(WAV_BUF_SIZE*QBUF_SIZE);
+ }
+ int offset = WAV_BUF_SIZE * tmpq->multiplex;
+ memcpy(tmpq->buf + offset,buf,WAV_BUF_SIZE);
+ tmpq->multiplex++;
+ }else{
+ newq = AllocateMemory(sizeof(WRITE_Q));
+ memset(newq,0,sizeof(WRITE_Q));
+ newq->buf = alloc_dma_memory(WAV_BUF_SIZE*QBUF_SIZE);
+ memcpy(newq->buf ,buf,WAV_BUF_SIZE);
+ newq->multiplex++;
+ tmpq->next = newq;
+ }
+}
+
+static void write_q_dump(){
+ WRITE_Q *tmpq = rootq;
+ WRITE_Q *prevq;
+
+ while(tmpq->next){
+ prevq = tmpq;
+ tmpq = tmpq->next;
+ FIO_WriteFile(file, UNCACHEABLE(tmpq->buf), WAV_BUF_SIZE * tmpq->multiplex);
+ free_dma_memory(tmpq->buf);
+ prevq->next = tmpq->next;
+ FreeMemory(tmpq);
+ tmpq = prevq;
+ }
+}
+
+
+
+
static void asif_rec_continue_cbr()
{
if (file == INVALID_PTR) return;
void* buf = wav_buf[wav_ibuf];
- FIO_WriteFile(file, UNCACHEABLE(buf), WAV_BUF_SIZE);
+ add_write_q(buf);
if (audio_recording == 2)
{
@@ -504,6 +565,21 @@
static void wav_playback_do();
static void wav_record_do();
+
+static void write_q_task()
+{
+ TASK_LOOP
+ {
+ if (audio_recording==1 || rootq->next)
+ {
+ write_q_dump();
+ }
+ msleep(500);
+ }
+}
+
+TASK_CREATE( "write_q_task", write_q_task, 0, 0x16, 0x1000 );
+
static void beep_task()
{
TASK_LOOP
@@ -846,7 +922,10 @@
{
wav_buf[0] = alloc_dma_memory(WAV_BUF_SIZE);
wav_buf[1] = alloc_dma_memory(WAV_BUF_SIZE);
-
+ rootq = AllocateMemory(sizeof(WRITE_Q));
+ memset(rootq,0,sizeof(WRITE_Q));
+ rootq->multiplex=100;
+
beep_sem = create_named_semaphore( "beep_sem", 0 );
menu_add( "Audio", beep_menus, COUNT(beep_menus) );
find_next_wav(0,1);
@1%
I just found your post now. Anyway, I can done without shoot_malloc. Do you know where is already described what is difference of AllocateMemory /allocate_dma_memory/shoot_malloc....
I know only these malloc is getting different memory spaces. But I don't know which one is best to use something.