B4A Library AudioRecord Library

This is an Audio Recording Library based on the Android AudioRecord object which allows capturing of sound input to a data file for further processing (maybe realtime if we're lucky).

Included in the demo program is a WAV file header routine that allows saving captured sound as an uncompressed wav file.

Please read the documentation of the AudioRecord object. It's a little more complicated that the media recorder version, but gives additional flexibility.

Please test it and hopefully we can get it to work well for us.

Added libs 1.01 - Additional constants and Capitalized

12/6/2012 Artest updated to better manage thread on closedown.

For use with V2 of B4a (more specifically the latest threading library) you'll need to add a parameter to the start thread call in artest. Line 89, Record.Start("Recording",Null) becomes Record.Start(Null,"Recording",Null)

artest 1155
 

Attachments

  • AudioRecord1.01.zip
    4.9 KB · Views: 2,853
  • artest1.02.zip
    8.2 KB · Views: 1,071
Last edited:

Highwinder

Active Member
Licensed User
Longtime User
Stevel05,

Your AudioRecord library is not showing up in the Library documentation page (click here).

Can you add it? Would love to see all the details so I know how I can use it, and without the full documentation, it can't live up to its full potential!

Thanks!

Highwinder
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
Steve, what were talking about when you mentioned sine wave stuff, and how would I do it?

Also, when you tried my app did you notice it getting lots of noise even in a silent room, do you know how I could reduce that?
 

Highwinder

Active Member
Licensed User
Longtime User
Steve, what were talking about when you mentioned sine wave stuff, and how would I do it?

Also, when you tried my app did you notice it getting lots of noise even in a silent room, do you know how I could reduce that?

I noticed the VU meter app that was posted here never dropped below 20db on my Motorola Atrix 4G no matter how quiet the room was. I see other sound metering apps out there having the same problems, so it seems that there are different metering values for different devices.
 

Highwinder

Active Member
Licensed User
Longtime User
This is an Audio Recording Library based on the Android AudioRecord object which allows capturing of sound input to a data file for further processing (maybe realtime if we're lucky)....

Steve,

How do we record to MP3? Anybody that writes a recording library is gioing to get this question, so just a heads up.

Is recording to MP3 possible here? if so, how?

Thanks. :)

PS: Still missing a documentation page for your library....
 

stevel05

Expert
Licensed User
Longtime User
Android is missing an mp3 encoder. The system will decode on demand with some players. There are a few libraries available, some require the ndk, and I believe some are pure java. I don t know how complex these are and as importantly what the licencing will be as the Mp3 format is not open source afaik.

Sent from my HTC Sensation XE with Beats Audio Z715e using Tapatalk 2
 

stevel05

Expert
Licensed User
Longtime User
The documentation for the Java library which will be the same, is available here I don't know how to update the B4A documentation.
 

stevel05

Expert
Licensed User
Longtime User
@ NeoThechni, to record a sinewave you would need a sinewave generator, or download a sinewave soundfile from the internet then play it into the mic or line in of your device. Theoretically your graphed output should be the same as the input, maybe the amplitude would be different.

@Highwinder & NeoTechni, the problem with background noise is probably to do with, or not helped by, onboard auto recording level which will raise the level of background noise when there is no or very little foreground noise. I don't think there will be anything that can be done about this.
 

Highwinder

Active Member
Licensed User
Longtime User
Android is missing an mp3 encoder. The system will decode on demand with some players. There are a few libraries available, some require the ndk, and I believe some are pure java. I don t know how complex these are and as importantly what the licencing will be as the Mp3 format is not open source afaik.

Steve,

Luckily, a code example was just posted by NeoTechni that demonstrates recording to MP3 via the AudioRecorder library from XverhelstX.

However, I need your AudioTack library for playback of MP3 files due to some sound processing I want to accomplish. Is your AudioTrack library capable of reading/playing MP3 files? If so, could you provide an example of how this might be demonstrated? I've seen the example for handling WAV files, but really need to stick with the MP3 format. There is little documentation on your library, so maybe you could assist? Massive thanks!
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
Hi,

As with my response to your PM re audio record, The codecs available to the Media Recorder object on which audiorecorder is based are not generally available before API Level 16 (JellyBean) so you should be able to do this in the near future, but not until someone can wrap the MediaCodec library for B4a. And then only on Jellybean and later devices. To be available to audio record and audio track on older devices you will need a third party codec library to be complied for android and wrapped for B4a.

The only documentation available is provided at Android developers, see the link in the previous post, as the library is simply a wrapper, the methods and constants are one for one comparable, I'm afraid this is the only documentation we have to work with.
 
Last edited:

Highwinder

Active Member
Licensed User
Longtime User
Hi,

As with my response to your PM re audio record, The codecs available to the Media Recorder object on which audiorecorder is based are not generally available before API Level 16 (JellyBean) so you should be able to do this in the near future, but not until someone can wrap the MediaCodec library for B4a. And then only on Jellybean and later devices. To be available to audio record and audio track on older devices you will need a third party codec library to be complied for android and wrapped for B4a.

The only documentation available is provided at Android developers, see the link in the previous post, as the library is simply a wrapper, the methods and constants are one for one comparable, I'm afraid this is the only documentation we have to work with.


Ok, thanks for the response, and I really do appreciate your efforts and support (and patience). This has been driving me crazy. All I'm trying to do is record an MP3 with the MIC and play the MP3 back at a different speed. I cannot believe the roadblocks I continue to keep slamming up against every step of the way. :BangHead:

SoundPool is too limited and problematic, and AudioRecord doesn't do MP3. It appears I have a choice between WAV and nothing. :sign0148:
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
It appears I have a choice between WAV and nothing

For now. Android is still immature when it comes to audio processing. Hopefully it will improve and seems to be going in the right direction albeit slowly.
 

Highwinder

Active Member
Licensed User
Longtime User
Hi,

As with my response to your PM re audio record, The codecs available to the Media Recorder object on which audiorecorder is based are not generally available before API Level 16 (JellyBean) so you should be able to do this in the near future, but not until someone can wrap the MediaCodec library for B4a. And then only on Jellybean and later devices. To be available to audio record and audio track on older devices you will need a third party codec library to be complied for android and wrapped for B4a.

The only documentation available is provided at Android developers, see the link in the previous post, as the library is simply a wrapper, the methods and constants are one for one comparable, I'm afraid this is the only documentation we have to work with.

Again, a huge thanks to your reply, both by IM and this post above. Looks like I'm using WAV format for compatibility alone, so thanks for the details. And again, great job on th elibraries. Keep 'em comin'! :)
 

Djembefola

Active Member
Licensed User
Longtime User
All I'm trying to do is record an MP3 with the MIC and play the MP3 back at a different speed...It appears I have a choice between WAV and nothing. :sign0148:

I would be happy, if i could manage this with WAV files! Android is really far behind in audio editing and i don't even dream of being able to do this with an mp3 file.

Playback with variable speed needs time and pitch correction. This is an ambitious task. You can't do that with a compressed mp3 file. You need to decode the mp3 file into an uncompressed wav byte array, apply a time/pitch correction and then re-encode the file into an mp3 file.

Just to give you an idea how difficult it is: wavelab, a powerful windows sound editing software, needs several minutes to do this job with a large mp3 file.
 

Highwinder

Active Member
Licensed User
Longtime User
For now. Android is still immature when it comes to audio processing. Hopefully it will improve and seems to be going in the right direction albeit slowly.

True, but meanwhile, 90% of my customers are between API 7 and 10.

But again, thank you. My hat is off to anyone who is writing libraries for B4A, they are BADLY needed. Libraries are the lifeblood of B4A.
 

Highwinder

Active Member
Licensed User
Longtime User
I would be happy, if i could manage this with WAV files! Android is really far behind in audio editing and i don't even dream of being able to do this with an mp3 file.

Playback with variable speed needs time and pitch correction. This is an ambitious task. You can't do that with a compressed mp3 file. You need to decode the mp3 file into an uncompressed wav byte array, apply a time/pitch correction and then re-encode the file into an mp3 file.

Just to give you an idea how difficult it is: wavelab, a powerful windows sound editing software, needs several minutes to do this job with a large mp3 file.

Your wish has been granted. Playback at different speeds can easily be done with SoundPool. Steve's AudioTrack library does as well.
 

Djembefola

Active Member
Licensed User
Longtime User
Your wish has been granted. Playback at different speeds can easily be done with SoundPool. Steve's AudioTrack library does as well.

With Soundpool and Audiotrack it is possible to change the playrate.
But changing the playrate leads to a pitch change.
 

Highwinder

Active Member
Licensed User
Longtime User
Steve,

Having resigned myself to the fact that it is dictated, "Thou shalt record to WAV" (ok fine, time to move on), I have taken a look at the project that AHilton was working on and posted earlier in this thread. It is the project that records using AudioRecord and does near real-time output through the speaker using AudioTrack. This is a brilliant little project that I wish I had seen a long time ago because it gets extremely close to something I have been working on (currently a stalled project). As such, having just noticed this, I thought I'd come groveling to the gurus with a question:

How does one go about basically doing the same exact thing that AHilton was doing, but instead of doing the real-time playback between AudioRecord and AudioTrack through the speaker, I want to send the already-processed audio (from AudioTrack) out to a WAV file for later playback instead of real-time to the speaker.

Key point: I need to ensure the processed audio (sound effects such as reverb, speed change, etc) makes it into the WAV file itself - not just change playback properties during playback. This is so that any player that plays the WAV file in the future will be playing the sound with effects already part of the recording. The completed WAV file is a file that will be transmitted from the device to other devices for payback using any variety of media playback software that can play WAV files. This is a critical function.

It seems like AHilton was EXTREMELY close to what I'm interested in doing, so it probably wouldn't require much of a change to what he had already posted. And I would like to offer a profound kudos and cheers to AHilton for not only working that code up, but posting it for all to see. I consider it incredibly helpful, as I really don't know much about sound processing and formats, so I would love to hear from you (Steve) or AHilton. This will be a real lifesaver if I can get this working, especially since AHilton appears to have already invented this wheel. Again, I really wish I would have seen that conversation between you two as it was happening a long time ago.

(insert pathetic groveling here)
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Steve,

Luckily, a code example was just posted by NeoTechni that demonstrates recording to MP3 via the AudioRecorder library from XverhelstX.

Where was the example posted?
 
Top