OSDN Git Service

Added volume control feature.
authorShinichiro Nakamura <shinta.main.jp@gmail.com>
Sun, 15 Jul 2012 20:41:12 +0000 (05:41 +0900)
committerShinichiro Nakamura <shinta.main.jp@gmail.com>
Sun, 15 Jul 2012 20:41:12 +0000 (05:41 +0900)
firm/sample/sample1/os/task_audio.c
firm/sample/sample1/os/task_audio.h
firm/sample/sample1/os/task_input.c
firm/sample/sample1/os/task_menu.c

index a62248c..ff54dca 100644 (file)
@@ -4,16 +4,8 @@
 #include "pff.h"
 #include "lib.h"
 
-#define AUDIO_CMD_PULSE 'p'
-#define AUDIO_CMD_PLAY  'd'
-
-void audio_pulse(void)
-{
-  char *p;
-  p = kz_kmalloc(1);
-  p[0] = AUDIO_CMD_PULSE;
-  kz_send(MSGBOX_ID_AUDIO, 1, p);
-}
+#define AUDIO_CMD_PLAY      'd'
+#define AUDIO_CMD_VOLUME    'v'
 
 int audio_play(int (*readfunc)(void *buf, int siz))
 {
@@ -37,6 +29,21 @@ int audio_play(int (*readfunc)(void *buf, int siz))
   return (siz == cnt) ? 1 : 0;
 }
 
+int audio_volume(const int left, const int right)
+{
+  char *p;
+  p = kz_kmalloc(4);
+  p[0] = AUDIO_CMD_VOLUME;
+  p[1] = 0;
+  p[2] = 255 - left;
+  p[3] = 255 - right;
+  if ((0 <= left) && (left <= 255) && (0 <= right) && (right <= 255)) {
+      kz_send(MSGBOX_ID_AUDIO, 4, p);
+      return 1;
+  }
+  return 0;
+}
+
 static int waitfunc(void)
 {
     kz_wait();
@@ -46,20 +53,18 @@ static int waitfunc(void)
 static int audio_cmdproc(char *p)
 {
   int cmd = p[0];
-  volatile int i;
-
   switch (cmd) {
-  case AUDIO_CMD_PULSE:
-    vs1011e_sinetest_init();
-    for (i = 0; i < 2000; i++) { }
-    vs1011e_sinetest_fini();
-    break;
   case AUDIO_CMD_PLAY:
     vs1011e_play_with_data(
         &p[8],
         ((unsigned char)p[4] << 8) | ((unsigned char)p[5] << 0),
         waitfunc);
     break;
+  case AUDIO_CMD_VOLUME:
+    puts("L:"); putxval(p[2], 2); puts("\n");
+    puts("R:"); putxval(p[3], 2); puts("\n");
+    vs1011e_volume_write(p[2], p[3]);
+    break;
   default:
     break;
   }
index 3277aac..86bd94c 100644 (file)
@@ -1,8 +1,9 @@
 #ifndef TASK_AUDIO_H
 #define TASK_AUDIO_H
 
-void audio_pulse(void);
 int audio_play(int (*readfunc)(void *buf, int siz));
+int audio_volume(const int left, const int right);
+
 int task_audio(int argc, char *argv[]);
 
 #endif
index 32c88b3..59c271d 100644 (file)
@@ -118,7 +118,7 @@ int task_input(int argc, char *argv[])
           display_led_write(1, 0);
           display_led_toggle(0);
         }
-        if (40 < nx) {
+        if (0 < nx) {
           nx--;
         }
       } else {
@@ -147,7 +147,6 @@ int task_input(int argc, char *argv[])
         putxval(data[2], 2);
         putxval(data[3], 2);
         puts("\n");
-        audio_pulse();
         display_led_toggle(2);
       }
       bitcnt = 0;
index 7e06c90..d431ebc 100644 (file)
@@ -6,6 +6,10 @@
 #include "kozos.h"
 #include "lib.h"
 
+FATFS fatfs;
+DIR dir;
+FILINFO filinfo;
+
 static int readfunc(void *buf, int siz)
 {
     WORD cnt;
@@ -19,9 +23,14 @@ static int play(const char *filename)
     if (r != FR_OK) {
         return 1;
     }
+    int cnt = 0;
     while (audio_play(readfunc)) {
+        if (((cnt++) % 32) == 0) {
+            display_draw_progressbar(5, 20, 121 - 5, 25, 0, 100, fatfs.fptr * 100 / fatfs.fsize);
+        }
         kz_wait();
     }
+    display_draw_progressbar(5, 20, 121 - 5, 25, 0, 100, fatfs.fptr * 100 / fatfs.fsize);
     return 0;
 }
 
@@ -49,15 +58,13 @@ static int is_music_file(const char *filename)
 int task_menu(int argc, char *argv[])
 {
 #if 0
-  FATFS fatfs;
-  DIR dir;
-  FILINFO filinfo;
-
   display_clear();
   display_draw_logo(  0, 0, 2);
   display_draw_box(0, 0, 121, 31, 1);
   display_draw_text(40, 4, "KOZOS EXPBRD #00");
 
+  audio_volume(250, 250);
+
   while (1) {
       if (pf_mount(&fatfs)) {
           continue;
@@ -84,7 +91,9 @@ int task_menu(int argc, char *argv[])
   display_draw_box(0, 0, 121, 31, 1);
   display_draw_text(40, 4, "KOZOS EXPBRD #00");
 
-  kz_sleep();
+  while (1) {
+      kz_sleep();
+  }
 #endif
 
   return 0;