To register and login, use your Google, Twitter, Facebook, LinkedIn, or OpenID credentials.

This is allowing us to stop most spam registrations. We've deleted most of the spam accounts that got through, and we're closely watching for more.

Having problems recording from an Android sound input using libpd

free1000free1000 Posts: 10
edited January 2013 in Pd Everywhere

I'm just setting out with libpd and was very excited to find out about it as I'm currently working on an app that would be improved with some audio filtering and effects.

As a first exercise I simply want to record a sample from the microphone, save it to a file, then load and play that file using PD. Later we'll add effects.

However my initial attempts are not successful. Reading a file and playing it is working nicely on Android, but recording from the mike and writing it to the flash memory/disc is not working on Android, though the patch works fine on Mac OSX.

I was somewhat naively thinking that all I'd need to do is to create a writesf~ object and have it consume the adc~ output, setting the output filename and triggering the start and stop messages.

I can't tell what is going wrong on the devices, and the emulator isn't much use because it doesn't have a microphone.

I'm wondering if I need to insert some kind of buffering in the patch, ie: write to a buffer from the adc output, then read from the buffer into the writesf input?

My source is linked here for the Android Activity which uses libpd

http://pastebin.com/FDrecj3h

And the patch is here

http://pastebin.com/32JaY6xP

Answers

  • Whoops, links are the wrong order, patch is first, Activity is second.

  • NitroooNitrooo Posts: 21

    PdAudio.initAudio(sampleRate, 0, 2, 8, true);

    Maybe this? Zero input channels, try putting a 1 instead.

  • free1000free1000 Posts: 10
    edited January 2013

    Thanks for pointing that out. Sometimes its hard to see the obvious, especially when just learning from tutorial code (with ahem... a certain amount of cut and paste going on).

    It doesn't seem to work though. I did the following

    int inputs = AudioParameters.suggestInputChannels(); PdAudio.initAudio(sampleRate, inputs, 2, 8, true);

    inputs gets set to 2 from AudioParameters on my Samsung device, but Android reports the following whether I use the 2 channel return value or hard code 1 into the input channel position

    01-14 14:52:02.129: E/AudioRecord(1388): Could not get audio input for record source 1 01-14 14:52:02.129: E/libOpenSLES(1388): android_audioRecorder_realize(0x202d10) error creating AudioRecord object 01-14 14:52:02.129: D/AudioRecord(1388): stop 01-14 14:52:02.129: E/Dalekize(1388): java.io.IOException: unable to open Pd audio: 44100, 2, 2

    It looks like a device specific problem as I can successfully get this working now on the Nexus 7. My patch wasn't quite right either.

    I'll try to instantiate an AudioRecord object for the Samsung device to see if I can identify the problem.

  • NitroooNitrooo Posts: 21

    Does recording work if you use the osc~ in your patch as source instead of adc~?

    One more thing. I'm not sure if it could lead to this kind of error, but: have you set the RECORD_AUDIO permission in the AndroidManifest.xml?

  • free1000free1000 Posts: 10
    edited January 2013

    Hey thanks for your suggestions. I did set the RECORD_AUDIO permission.

    I've got things working now. Something it may be useful to know about is that the underlying AudioRecord object was hanging around in memory. As a result on the Samsung phone libpd could not get the input channel. The problem was probably caused by my multiple debug attempts.

    http://stackoverflow.com/questions/4807428/audiorecord-could-not-get-audio-input-for-record-source-1

    I rebooted the device just now and that cleaned things up. This seems to be a particular problem on Samsung devices. Some coping strategies seem necessary.

  • pbrinkmannpbrinkmann Posts: 685 ✭✭

    I occasionally notice weirdness when installing new native components. Rebooting seems like overkill, though. You can probably get the same effect by stopping or deleting the old version of your app.

Sign In or Register to comment.