diyAudio

diyAudio (http://www.diyaudio.com/forums/)
-   Software Tools (http://www.diyaudio.com/forums/software-tools/)
-   -   Android signal generator app (http://www.diyaudio.com/forums/software-tools/176284-android-signal-generator-app.html)

beun 30th October 2010 03: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 03:26 AM

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

beun 30th October 2010 03: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 06: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 03:14 AM

That would indeed be cool.

Rodeodave 17th February 2011 01: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 04: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 02: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 04:05 AM

rproch,

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++ )
{
try{
samples[i] = AndroidAudioDevice.sigBuffer[angle];
}
catch (ArrayIndexOutOfBoundsException e){
}
angle = (angle + ifreq) % 44099;
}
device.writeSamples(samples);
}
}
};

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 04:19 PM

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


All times are GMT. The time now is 06:16 AM.


vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2014 DragonByte Technologies Ltd.
Copyright 1999-2014 diyAudio


Content Relevant URLs by vBSEO 3.3.2