I setup Raspberry Pi with external usb sound blaster sound card. My Goal is to be able to record and play audio simultaneously. I setup and configured it to be the default sound card as follows:

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install rpi-update
  4. sudo rpi-update
  5. Modified /etc/modprobe.d/alsa-base.conf and added the following to force the default sound module (snd_bcm2835) to be disabled while the usb sound module (snd-usb-audio) is enabled options snd-usb-audio index=0
    options snd_bcm2835 index=1
  6. Tested the sound card by playing file audio using aplay soundFile.wav

    To test the full duplex i used the following simple java program that read and play audio kinda of a loopback with different Audio formats but no audio heard.

    import java.io.; import javax.sound.sampled.;

     public class test1
         public static void main(String[] args)
         AudioFormat pcmAF =new AudioFormat(8000, 8, 1,true, true);//new AudioFormat(8000, 8, 1,false, false);
              //new AudioFormat(8000f,16,1,true,true);
              //new AudioFormat(8000f,16,1,true,true)
             //new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 16000.0f, 16, 1, 2, 16000.0f, true);  
             // new AudioFormat(24000f,8,1,true,true);
             // new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 16000.0f, 16, 1, 2, 16000.0f, true);
            ///new AudioFormat(8000f,16,1,true,true);
            // new AudioFormat(8000, 8, 1,true, true);//11025
            DataLine.Info info = new
            TargetDataLine targetLine = (TargetDataLine)AudioSystem.getLine(info);
            DataLine.Info info1 = new DataLine.Info(SourceDataLine.class,pcmAF);
            SourceDataLine sourceLine = (SourceDataLine)AudioSystem.getLine(info1);
            byte[] buf = new byte[1024];
            int bytesRead;
            while (true)
               System.out.println("READING  SOUND ");
                bytesRead = targetLine.read(buf,0,buf.length);
                System.out.println("->"+ bytesRead);
                catch (Exception e)

    Any idea why and what need to be done to achieve that ?

  • Do you specifically want to play/record simultaneously in Java, or just in general on the Pi. Have you tried arecord and aplay simultaneously? alsaloop can be used to loop input to output on a sound card. – Fred Sep 20 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.