PocketMagic

PocketMagic

Where Technology meets magic


Android
45 Posts
BlackBerry
4 Posts
Electronics
68 Posts
Hardware
120 Posts
High Voltage
49 Posts
iPhone
4 Posts
Linux
2 Posts
Nuclear
20 Posts
Optics
11 Posts
Photography
7 Posts
Photoshop
3 Posts
Research
19 Posts
Reviews
18 Posts
Robotics
8 Posts
Security
7 Posts
Software
73 Posts
Symbian
2 Posts
Tubes
18 Posts
Windows
3 Posts
Windows Mobile
11 Posts

Top Articles!       See PocketMagic on Facebook


uRADMonitor - Online Radiation monitoring station | 14868 Views | Rate 70.13
uRADMonitor - Online Radiation monitoring station
Bluetooth and iOS - Use Bluetooth in your iPhone apps | 17942 Views | Rate 58.06
Bluetooth and iOS - Use Bluetooth in your iPhone apps
NMEA GPS Library for AVR Microcontrollers | 4798 Views | Rate 56.45
NMEA GPS Library for AVR Microcontrollers
Programmatically Injecting Events on Android - Part 2 | 4943 Views | Rate 44.53
Programmatically Injecting Events on Android - Part 2
Building a robot – Part 2 | 4573 Views | Rate 44.4
Building a robot – Part 2
Simple Switched power Supplies | 16023 Views | Rate 41.73
Simple Switched power Supplies
Capacitor Discharge Microspot Welder / Cutter | 11267 Views | Rate 36.35
Capacitor Discharge Microspot Welder / Cutter
Developing for Blackberry 10 | 71 Views | Rate 35.5
Developing for Blackberry 10

 
  

Android Native Play Sound using /dev/msm_pcm_out


By Radu Motisan Posted on November 18th, 2010 , 1623 Views (Rate 1.77)



  




Following my previous article, where I presented that it is possible to write a native C application to directly extract the screen's framebuffer data and save it as a BMP, for the purpose of making screen captures, I will give another example of using the NDK to compile a C code that would play sounds on your Android, by directly interfacing the PCM device: /dev/msm_pcm_out

There is an old sample in the Google Android code that does just that and more: playwav.c . It can be compiled using the NDK and Cygwin, as presented here:
android native play sound

Simply copy the binary to your Android, and play a wave file by calling:

./playsound -play learn.wav

Easy, and a nice surprise to hear sounds coming from your Android, without having any top level interfaces running for that purpose.
The project files:
NativePlayWav






  

More on PocketMagic:

Programmatically Injecting Events on Android - Part 1 | 10131 Views | Rate 26.18
Programmatically Injecting Events on Android - Part 1
Atmega8 and enc28J60 for ethernet support | 7201 Views | Rate 24.49
Atmega8 and enc28J60 for ethernet support
How to set the AVR Fusebits | 1689 Views | Rate 23.79
How to set the AVR Fusebits
ATMega128 and HD44780 LCD using 3 Wires with the 74HC164 | 2035 Views | Rate 22.87
ATMega128 and HD44780 LCD using 3 Wires with the 74HC164
CDV-742 Dosimeter and CDV-750 Dosimeter Charger | 109 Views | Rate 21.8
CDV-742 Dosimeter and CDV-750 Dosimeter Charger
Dual H-Bridge for controlling two motors | 1181 Views | Rate 21.47
Dual H-Bridge for controlling two motors

6 Responses to “Android Native Play Sound using /dev/msm_pcm_out”

  1. 1
    Victor:

    Hey Radu,

    I don’t have rwx access in /data/data, I only have rw- in /sdcard :D .
    I tried using abd root, but I get an error: adbd cannot run as root in production builds

    Any hints on how I could test your app ?

    10x

  2. 2
    Radu Motisan:

    Hi Victor, thanks for dropping by.

    I don’t think you will be able to get this work , if you don’t have root access, since the little native code needs access to /dev/msm_pcm_out

    By any chance can you try it on a different phone, or ROOT you own?

  3. 3
    Victor:

    Hi Radu,
    Thanks for the quick answer and sorry for my delayed one :) .
    I wanted to write an app that would work on standard issue Android devices. I guess I’ll have to use the latest NDK for low-latency sound playback and target phones having at least v2.3.
    Thanks again for everything!

  4. 4
    Anandhi:

    Hi Radu,

    I just came across this, and though I am new to the environment, was able to get through most of the above steps. I wish to test this on the android emulator, and then add some processing code to the file before getting it onto a phone. However on the emulator, when i get to the “chmod +x playwav” step i get the error “bad mode”. And if i try “./playwav -play learn.wav” anway, i get the message “pcm_play: cannot open audio device: No such file or directory”. Could you help me run this on the emulator, please?

    Thanks a lot.

  5. 5
    Fred:

    I have same problem like you “cannot open audio device: No such file or directory” is because i have old android (2.2 froyo)? any body confirm if /dev/msm_pcm_out is found in froyo ?
    i am using “samsung galaxy S”.

    Thanks.

  6. 6
    Anonymous:

    Hi,
    I have /dev/msm_pcm_out, but playwav does not play anything at all.
    I get no errors, it just fills buffers and then gets stuck trying to fill more buffers, but obviously they never empty.
    I’m using an Htc Desire Z.
    Thanks

Thank you for commenting. Your comment won't show until approved, which can take some time.

Please copy the string SHeKiT to the field below: