This is wav writting buffering patch.
diff -r ae36c8b5889b src/beep.c
--- a/src/beep.c Sun Sep 02 02:50:47 2012 +0900
+++ b/src/beep.c Mon Sep 03 19:53:43 2012 +0900
@@ -172,7 +172,10 @@
static FILE* file = INVALID_PTR;
#define WAV_BUF_SIZE 8192
static int16_t* wav_buf[2] = {0,0};
+#define WBUF_SIZE 16
+static int16_t* write_buf[WBUF_SIZE];
static int wav_ibuf = 0;
+static int write_ibuf = 0;
static void asif_continue_cbr()
{
@@ -327,7 +330,18 @@
if (file == INVALID_PTR) return;
void* buf = wav_buf[wav_ibuf];
- FIO_WriteFile(file, UNCACHEABLE(buf), WAV_BUF_SIZE);
+ memcpy(write_buf[write_ibuf],buf,WAV_BUF_SIZE);
+ if (write_ibuf==(WBUF_SIZE-1)){
+ int i;
+ for(i=0;i<WBUF_SIZE;i++){
+ void* writebuf = write_buf[i];
+ FIO_WriteFile( file, UNCACHEABLE(writebuf), WAV_BUF_SIZE );
+ }
+ write_ibuf=0;
+ }else{
+ wav_ibuf = !wav_ibuf;
+ write_ibuf++;
+ }
if (audio_recording == 2)
{
@@ -338,7 +352,6 @@
return;
}
SetNextASIFADCBuffer(buf, WAV_BUF_SIZE);
- wav_ibuf = !wav_ibuf;
}
void WAV_Record(char* filename, int show_progress)
@@ -358,7 +371,7 @@
SetSamplingRate(48000, 1);
MEM(0xC092011C) = 4; // SetASIFADCModeSingleINT16
- wav_ibuf = 0;
+ wav_ibuf=0;
StartASIFDMAADC(buf1, WAV_BUF_SIZE, buf2, WAV_BUF_SIZE, asif_rec_continue_cbr, 0);
while (audio_recording)
{
@@ -846,6 +859,10 @@
{
wav_buf[0] = alloc_dma_memory(WAV_BUF_SIZE);
wav_buf[1] = alloc_dma_memory(WAV_BUF_SIZE);
+ int i=0;
+ for(i=0;i<WBUF_SIZE;i++){
+ write_buf[i] = alloc_dma_memory(WAV_BUF_SIZE);
+ }
beep_sem = create_named_semaphore( "beep_sem", 0 );
menu_add( "Audio", beep_menus, COUNT(beep_menus) );
But result is not so good.
sound is some time lost and memcpy overhead increase CPU& mem.
You can change buffer size (how many buffers aggreate to write) by WBUF_SIZE ....
MSG added
This code is just only provide a write aggregation.
Not providing async write/read.