现在录音出现一个问题是应用程序显示能够正常运行,录完后但是其大小显示0字节,我没有插MIC,但是我认为也应该有数据的,我是做底层驱动的,对于android的上层应用程序不清楚,这程序在手机上可以用的。我不清楚是不是因为我没有插MIC而出现的问题。

解决方案 »

  1.   

    创建MediaRecorder需要设置麦克风:mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      

  2.   

    需要设置使用MIC,不然没有声音的
      

  3.   

    没有声音数据也不应该是0字节,楼主是不是用自带的soundrecorder程序啊,可以回放的啊。有时候非法拨出SDcard也会导致录音数据丢失。
      

  4.   


     ++  MediaRecorder.AudioSource.MIC  设置输出文件的格式
         MediaRecorder.OutputFormat.DEFFAULT 设置音频文件的编码
      

  5.   

    上层的应用程序是直接调用soundrecorder的程序,可是录音还是为0字节,我是录完后,就查看文件大小的,就是0字节,调试驱动发现在调用 s3c6400_ac97_hifi_prepare函数,就不动了,不知道为什么,我的平台是s3c6410 Android2.1 ,现在头大的很。
      

  6.   

    现在调试发现在录音启动时,理论上应该调用snd_pcm_capture_open但是不知道怎么回事竟然是调用snd_pcm_playback_open,在其后的调用函数中均是调用snd_pcm_playback_ioctl,而不是录音应该调用的
    snd_pcm_capture_ioctl。我去查看了alsa_lib的源码,发现在open设备时是根据stream的值来判断的,如果是录音,stream应该是1,但是现在从内核信息输出来看,传入的stream是0。不清楚到底是什么情况导致的。请教各位大虾。
      

  7.   

    提供个调试方法: 
       录音0字节可能是数据没有上来,这个时候你需要确定一下你的kernel是不是对的。首先你可以使用asla_aplay 来调试看看是否能够录音。 如果你不会用这个bin,那你看看代码,很简单的。 如果你还是不会用,ok,你可以在audiohardwarealsa中readi中讲buffer的数据写到文件里面,看看是否有数据!!! 然后你用audition听听(因为这里可能是pcm信号),如果有数据了,ok,说明你kernel里面的数据应该是对的,but,因为如果你上层是用AMRNB,那么你必须是用8kHZ的采样率。  你先测测看, 如果再有问题,以后继续
      

  8.   

    我这个问题不是没有采集到数据不写文件,而是打开的设备就错了。
    这是我调试的信息
    Enter __snd_open minor =0x0
    Enter __snd_open minor =0x10   //这个设备是对应了播放设备,如果是录音的话,这个minor应该是32
    Enter snd_pcm_playback_open   //这个应该是snd_pcm_capture_open,所以这下面所调用的函数都错了啊
    Enter snd_pcm_open 
    Enter snd_pcm_open_file 
    Enter snd_pcm_open_substream stream is 0
    Enter snd_pcm_attach_substream stream = 0
    Enter snd_pcm_hw_constraints_init 
    Entered s3c24xx_pcm_open
    Enter snd_pcm_hw_constraints_complete 
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0x81204101
    Enter snd_pcm_info_user device 0   subdevice 0  stream 0  card 0  dev_class 0 dev_subclass 0  subdevices_count 1 subdevices_avail 0 
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0x80044100
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0x40044102
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc0844123
    Enter snd_pcm_sync_ptr 
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4110
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc25c4111
    Entered s3c6400_ac97_hw_params substream->stream 0
    Entered s3c24xx_pcm_hw_params, params = (null) 
    params c03e58e8, client c03e5934, channel 37
    IRQ 74/AC97 PCM Stereo out: IRQF_DISABLED is not guaranteed on shared IRQs
    Entered s3c24xx_pcm_hw_params, line 282 
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc0844123
    Enter snd_pcm_sync_ptr 
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc0684113
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0x00004140
    Entered s3c24xx_pcm_prepare
    Entered s3c24xx_audio_buffdone
    Entered s3c24xx_audio_buffdone
    Entered s3c24xx_audio_buffdone
    Entered s3c24xx_audio_buffdone
    Entered s3c24xx_pcm_enqueue
    dma_loaded: 0
    dma_loaded: 1
    Entered s3c6400_ac97_write: reg=0x2a, val=0x411
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0x2c, val=0xac44
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_hifi_prepare substream->stream = 0
    Entered s3c6400_ac97_write: reg=0x26, val=0x0
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0xc, val=0x808
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0x3c, val=0xf803
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0x3e, val=0xb990
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0x2, val=0x404
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0x4, val=0x606
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Entered s3c6400_ac97_write: reg=0x1c, val=0x12aa
    Entered s3c6400_ac97_irq: AC_GLBSTAT = 0x400003
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc0844123
    Enter snd_pcm_sync_ptr 
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0xc0684113
    Enter snd_pcm_playback_ioctl 
    Enter snd_pcm_playback_ioctl1 
    Enter snd_pcm_common_ioctl1 cmd = 0x00004144
    函数到这儿就不跑了,这个cmd所调用的函数是snd_pcm_drain,如果能够录音的话,这儿会继续打印数据的,这个录音调试信息和我播放的打印信息是一样。我查看了alsa_lib的源码,发现他open的filename绝对是pcmC0D0p而不是pcmC0D0c,这个filename的区分是根据stream来区分的,stream为0就是pcmC0D0p,1就是pcmC0D0c,现在从内核来看,他传递过来的stream是0,而不是1。这个问题很困惑。
      

  9.   

    我用alsa_aplay测试过了,是可以录音的。
      

  10.   

    我怀疑是在open录音的stream的时候,        snd_pcm_open(&handle->handle, "default", direction(handle->devices), 0);应该要传入是playback还是capture,就是第三个参数。