diyAudio (
-   Software Tools (
-   -   Android signal generator app (

beun 30th October 2010 04:12 AM

Android signal generator app
I have wasted some serious nights programming my first free Android app. It is a signal generator that can create sine, triangle, square, white noise and pink noise signals. They can also be AM, FM or PM modulated in any combination and swept in frequency. The modulation waveform is either a sine, triangle or square and the frequency sweep can be linear or logarithmic. The noise signals do not repeat.

By default the triangle and square wave are anti-aliased and are recalculated upon a frequency change.

As an future upgrade I plan to add (the non-functioning button is already present) an arbitrary waveform function that lets you generate signals built from mathematical primitives. So if you want a sinc signal for example you just type in sin(x)/x and your sinc signal is there.

The link to the android market is: FuncGen Signal Generator - Android td.attachrow { font: 11px Verdana,Arial,Helvetica,sans-serif; color: rgb(0, 0, 0); border-color: rgb(0, 0, 0); }td.attachheader { font: 11px Verdana,Arial,Helvetica,sans-serif; color: rgb(0, 0, 0); border-color: rgb(0, 0, 0); background-color: rgb(209, 215, 220); }table.attachtable { font: 12px Verdana,Arial,Helvetica,sans-serif; color: rgb(0, 0, 0); border-color: rgb(0, 0, 0); border-collapse: collapse; }

SY 30th October 2010 04:26 AM

Very cool! What's the bandwidth you can get?

beun 30th October 2010 04:44 AM

Its limited by the 44.1KHz sample rate of the phone DAC so currently it is hardware and software limited from 1Hz to 20KHz. Additionally on my G1 there seems to be a pretty bad high pass characteristic that cuts off the low end. Your mileage may vary on other phones.

bnbgn 3rd December 2010 07:15 AM

1hz is pretty low.... that would be cool if those smartphones had an moduel to have the vibrator run as a subwoofer from 30hz down. "Set your phone on a firm pillow for an acoustic experience"

beun 7th December 2010 04:14 AM

That would indeed be cool.

Rodeodave 17th February 2011 02:40 PM

Man, I simply love this app. And I just found out that it's from a fellow diyaudio member, so it's even more cool. Was looking at the waveform with my Lithuanian oscilloscope the other day...looks very promising. The square wave @1kHz still looks quite usable, the sines and triangle look very good.
Have you made any %THD measurements?
I think I have noticed a couple of mV offset on my SGS, but that's probably the output stage. Nothing that a cap wouldn't fix...

Apparently the "SpectralPro Analyzer" app goes up to 24kHz (48kHz sampling rate), so maybe there's a way to make the output go faster? I have to add that I'm in no way affiliated to the author of said app, just wanted to mention it.

Now if I only found a way to run a signal generator app together with a spectral analyzer app...

beun 2nd March 2011 05:08 AM

I haven't made any THD measurements but the internal math is double precision so the distortion is going to be limited by the phone's DAC.

I am working on an update, so in the options I can put an adjustable upper frequency limit instead of an hard coded constant.

rproch 27th August 2011 03:16 AM

I like the app a lot! Nice job!

Are you, by any chance, willing to share some of your code? I am developing an app that includes some pitch generation, in order to play tones that a musician can use to tune to. It's not quite as extensive as yours, just a simple sine wave, which I have mostly working, but for some reason, the pitch is not completely steady, and will occasionally shift up or down in a pretty noticeable matter. Yours does not seem to do this though, so I am wondering what you did different.

I got my pitch generation code from this tutorial: Badlogic Games Fun with AudioTrack

Totally fine if you don't feel like sharing your code, but any help would be greatly appreciated!

beun 27th August 2011 05:05 AM


I actually started with the same piece of code that you found, the difference is how I generate the frequencies. This is how I do it:

1) I set the sample rate at 44100, even it the hardware allows a higher sample rate, this just makes the programming easier.
2) Define an array of shorts with length 44100
3) Fill the array with exactly one period of the signal you want to generate, in your case a sine
4) Now in a separate thread step though this array in a circular fashion (index = (index + step) % 44099) and write the value you land on to the audio buffer.

The frequency of the generated signal is controlled with the value of the step, if the step is 1 the output frequency is 1Hz, with a step of two the output frequency will be 2Hz etc. This way you can generate frequencies in steps of 1Hz.

The basic code looks like: (sorry for the crappy formatting)

public class ifillbuff implements Runnable{
public void run()
android.os.Process.setThreadPriority(android.os.Pr ocess.THREAD_PRIORITY_URGENT_AUDIO);

while( play )
for( int i = 0; i < samples.length; i++ )
samples[i] = AndroidAudioDevice.sigBuffer[angle];
catch (ArrayIndexOutOfBoundsException e){
angle = (angle + ifreq) % 44099;

where samples is the audiodevice sample buffer and sigBuffer is the short array of length 44100 filled with a sine wave.

I hope this clarifies the procedure.

rproch 27th August 2011 05:19 PM

Thanks. That makes a lot of sense. It's working great now!

All times are GMT. The time now is 02:30 AM.

Search Engine Optimisation provided by DragonByte SEO (Pro) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
Resources saved on this page: MySQL 18.75%
vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2018 DragonByte Technologies Ltd.
Copyright ©1999-2018 diyAudio