Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108778
  • 博文数量: 18
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-19 17:27
个人简介

linux Driver工程师

文章分类

全部博文(18)

文章存档

2016年(1)

2015年(17)

我的朋友

分类: LINUX

2015-04-02 14:39:23

一般的ALSA(如在host文件夹下)为PC上的
tinyalsa为android或camdroid上的

注:不用本测试文件也可以哒,用camdroid原生的tinyplay:
tinymix 16 1            //也是设置tinymix
tinymix 1 29            //调节音量 0~31
tinyplay /mnt/extsd/1KHz_0dB.wav    //前两部不设置这一步会:Error playing sample 的哦~

言归正传,测试文件如下:

点击(此处)折叠或打开

  1. #include <string.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <cutils/log.h>


  5. #define bool int
  6. #define true 1
  7. #define false 0

  8. typedef struct{
  9.     int vol;
  10.     int voice;
  11. }volumeTable;

  12. volumeTable VolNum[]={{0,29},{1,24},{2,19}};

  13. int getCDRVolume()
  14. {
  15.     FILE * fp = NULL ;
  16.     char str[64]={0};
  17.     int volume=1;
  18.     if((fp = fopen("/data/menu.cfg", "r")) == NULL){
  19.         ALOGD("open /data/menu.cfg failed");
  20.         if((fp = fopen("/system/res/cfg/menu.cfg", "r")) == NULL){
  21.             ALOGD("open /system/res/cfg/menu.cfg failed");    
  22.             return VolNum[1].voice;
  23.         }
  24.     }
  25.     bool flag1=true,flag2=false;
  26.     while(fgets(str,sizeof(str),fp)!=NULL){
  27.         if(flag1){
  28.          if (strncmp(str+1, "voicevol", strlen("voicevol")) == 0) {
  29.                 flag1=false;
  30.                 flag2=true;
  31.             }
  32.         }
  33.         if(flag2){
  34.          if (strncmp(str, "current", strlen("current")) == 0) {
  35.          char *ret = strstr(str, "=");
  36.      ret += 1;
  37.                  volume = atoi(ret);
  38.                  break;        
  39.             }

  40.         }
  41.         memset(str, 0, sizeof(char)*64);
  42.     }
  43.     if(fp)
  44.         fclose(fp);
  45.     return VolNum[volume].voice;

  46. }


  47. int main(int argc, char **argv)
  48. {
  49.     char player[128]="tinyplay ";
  50.     char setVol[64]={0};
  51.     sprintf(setVol, "tinymix 1 %d", getCDRVolume());
  52.     ALOGD("<***setVol:%s***>",setVol);
  53.     system("tinymix 16 1");
  54.     system(setVol);
  55.     strcat(player, argv[1]);
  56.     system(player);
  57.     return 0;
  58. }
然后,camdroid.mk文件如下:

点击(此处)折叠或打开

  1. #
  2. # 1. Set the path and clear environment
  3. #     TARGET_PATH := $(call my-dir)
  4. #     include $(ENV_CLEAR)
  5. #
  6. # 2. Set the source files and headers files
  7. #    TARGET_SRC := xxx_1.c xxx_2.c
  8. #    TARGET_INc := xxx_1.h xxx_2.h
  9. #
  10. # 3. Set the output target
  11. #    TARGET_MODULE := xxx
  12. #
  13. # 4. Include the main makefile
  14. #    include $(BUILD_BIN)
  15. #
  16. # Before include the build makefile, you can set the compilaion
  17. # flags, e.g. TARGET_ASFLAGS TARGET_CFLAGS TARGET_CPPFLAGS
  18. #

  19. LOCAL_PATH:= $(call my-dir)

  20. ########################################
  21. include $(CLEAR_VARS)
  22. LOCAL_SHARED_LIBRARIES := \
  23.         libcutils

  24. LOCAL_SRC_FILES := startup_music.c
  25. LOCAL_MODULE_TAGS := optional
  26. LOCAL_MODULE := startup_music
  27. include $(BUILD_EXECUTABLE)

使用本测试文件:
(cd  system/bin) //设置了环境变量的话就不用进入目录了
(./) startup_music  //运行测试程序,也就是设置tinymix
tinyplay  /mnt/extsd/1KHz_0dB.wav  //手动设置(即开头的注:)或者运行本测试程序设置tinymix之后 才可以正常播放音乐



其实本测试程序用处不大(勿喷哦,说了手动也可以设置的嘛~),只用来理解其中的原理,内核空间的ALSA还不是很明白,改日续~



阅读(5530) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

angrad2015-05-16 02:08:54

good notes!!