Any way to create an arbitrary tone with Basic4android? - basic4android

Is there any way with Basic4Android to make it emit a sound of arbitrary frequency (meaning, I don't want to have pre-recorded sound files) and duration?
In some "traditional" Basic languages this would be done via e.g. a BEEP command followed by the desired frequency and duration.
Basic4Android doesn't seem to support any equivalent command.
I am looking for this feature in order to program a Morse Code generating app and for this purpose I need to stay flexible regarding the audio frequency tone (must be user selectable) between e.g. 500Hz and lets say 1000 Hz as well as variable duration in milliseconds (in order to be able to generate variable user selectable speeds of the morse code dashes and dots and silent breaks inbetween)...
It's simply not practical or near to impossible to do this with prerecorded WAV's or you would end up in a huge WAV collection for all frequency/speed combinations.
It seems to be possible in Android to do so, see example here:
http://marblemice.blogspot.com/2010/...n-android.html
As far as I can interpret this code it calculates a sine wave tone "on the fly" at the desired frequency into a buffer array and uses that buffer data to generate and play it as a PCM stream.
Since above code seems to be quite simple I wonder if a clever Java programming guy would come up with a simple Basic4Android "Tone Generator" library which others could use for this purpose?
Unfortunately, I am only an old fashioned VisualBasic guy and making my first steps with Basic4Android...for creating my own library my skills are simply too lousy.

The Audio library was updated and you can now use the Beeper object to play "beep" sounds.
Dim b As Beeper
b.Initialize(300, 500) '300 milliseconds, 500hz
b.Beep
Updated library link

This is definitely possible to do on Android, in a java-based application. I don't know if Basic4Android can do this "natively" (I'd never heard of Basic4Android before this), but it appears that you can create libraries in java that can then be accessed by Basic4Android, so it would be theoretically possible to create a java library that does this and then call it from your B4A app.
However, since this would entail learning some java and the Android plugin for Eclipse anyway, maybe you should just take the plunge and learn java for Android? I'm a long-term Visual Basic guy myself (started in 1995), and it wasn't really that difficult to transition to C# and thence to java.

Related

Does Web Audio have any plans of making limiters, imager, saturator, or multiband compressors?

I have checked the interfaces that web audio offers. Pizzicato.js offers a great library for these effects, but it is a pitty that some of the best and essential effects are missing, like a limiter, multi-band compressor, parametric equalizer, saturator, stereo imager. I was just wondering if there any plans for them where i can check if they are willing to make these in the future. Just don't know where i could ask.
Thanks
WebAudio is a collection of fairly elemental base processors. There's really no higher order effects, because instead, it provides the foundational elements with which to build the effects.
For example, there's a dynamics compressor, but there's no variMU emulation, or FET circuit, or even your run of the mill digital compressor. But, using the pieces that the API does have, you can build out or model a compressor that behaves however you want. Just think it through and figure out how the signal needs to be processed and you'll find pretty much every component you need to achieve it. If not, the AudioWorklet(the successor to the deprecated ScriptProcessorNode) can fill in the blanks.
That being said, you would build a limiter using the DynamicsCompressor, and use BiquadFilters and DynamicsCompressors to build a multiband comp. You'd use the WaveShaper to build things like tape saturators, overdrive, and bit crushers. And you can create an imager or stereo widener effect using things like the PannerNode and one of the AudioParams (setValueAtTime() is probably the simplest).
WebAudio isn't really plug & play, but it's what you'd use to build something that is. If you'd rather skip the tedium of building your own DSPs, I can't really blame you, it's not easy. But there's plenty of sadists out there who already did, and many are made by very imaginative and talented engineers. A couple libraries worth checking out would be Tuna.js which is a very user friendly/straight forward effects library, or Tone.js for something much more fleshed out and complete.
According to the docs several already seem to be implemented:
Compressor: https://developer.mozilla.org/en-US/docs/Web/API/DynamicsCompressorNode
EQ: https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode
Saturator can probaby be impemented using: https://developer.mozilla.org/en-US/docs/Web/API/ConvolverNode

easy to create DSP app maker?

I am making an EEG bio-feedback'product' for a friend and I need a simple but DSP-powerful application builder.
Here is my situation:
I have built the HW to measure the brainwave signals and need to create a user panel for my friend to use it. The HW sends a stream of ascii out a serial port. The data packets send the amplitude value at a rate of 250 packets per second. Brain waves of interest are below 30 HZ so this is more than fast enough sampling.
I am prototyping the DSP user panel in LabVIEW which makes it incredibly easy to do sophisticated DSP with a custom control panel. However, my friend just wants a plug and play product and I can hardly install LabVIEW on his PC, so here is my challenge: I am wondering if there is a design application that I can use to create the final application for him.
I have no problem if it is text based but I don't have the capacity to sit down with a full-on programming language to make the front panel controls, internal DSP and serial port processor, so the application would hopefully provide the designer easy to tool-up GUI and easy to access DSP library. I am up to coding stuff to interpret the serial data format and manage the general flow of the data to get it processed and sent to the front panel, but all the fussy details of setting up some programming IDE and installing a bunch of libraries to make the front panel is more than I can take on right now.
BTW, I also put this together in a private edition of Matlab but again that is no good for my friend.
Any ideas? I know there are high-level application builders around but they usually target beginners. I am so spoiled by Labview! I have no problem with the actual coding like in C, Basic, or maybe Python, it's all the environment-building I don't want to get pulled into.
If you want a stand alone executable, you can use LabVIEW's application builder to create one. The app builder ships with LV pro, but can be purchased separately for cheaper versions. This won't let your friend modify the code, but I understand that's what you want.
There are also numerous ways to create plugin systems, if that's needed in your case. You can find various tutorials on that.
Be aware that some toolkits and modules require that you purchase distribution licenses as well. You would need to check whether you're using such a module.

How would I modify ZXing to optimize for a specific barcode type?

ZXing currently performs poorly in my tests of Code 39 and Code 128, which are the only 1D barcode types we're interested in for our apps.
What strategy could we take for optimizing the ZXing code for these types?
What parts of the ZXing source code should we focus on if we wanted to, e.g., start by telling it to stop trying to look for and interpret the other 1D barcode formats (I'm assuming this would help it's success rate in identifying 39/129)?
The biggest thing you can do is to not scan for every other format. Just scan with Code39Reader and Code128Reader, and not MultiFormatReader (or, use it, but send hints to restrict the formats that are considered). In an Android app, this will mean that it can examine more frames for just your formats.
If you have a very fast mobile device -- or are working on a desktop computer -- enable TRY_HARDER mode.
If you want to hack the code -- the biggest thing to focus on for detection of 1D barcodes is the Binarizer. If you have a few months and background in image processing you can probably write something better.
The latter is part of the for-pay release of the Barcode Scanner app, called Barcode Scanner+. If you are willing to part with $3 you can see how much difference better image processing may make to your use case.

Easy and straight-forward FFT of MP3 file

I have a MP3 file and need to constantly detect and show Hz value of this playing MP3 file. A bit of googling shows that I have 2 opportunities: use FFT or use Apple Accelerate framework. Unfortunately I haven't found any easy to use sample of neither. All samples, like AurioTouch etc, need tons of code to get simple number for sample buffer. Is there any easy example for pitch detection for iOS?
For example I've found https://github.com/clindsey/pkmFFT, but it's missing some files that its' author has removed. Anything working like that?
I'm afraid not. Working with sound is generally hard, and Core Audio makes no exception. Now to the matter at hand.
FFT is an algorithm for transforming input from time domain to frequency domain. Is not necessarily linked with sound processing, you can use it for other things other than sound as well.
Accelerate is an Apple provided framework, which among many other things offer an FFT implementation. So, you actually don't have two options there, just one and its implementation.
Now, depending on what you want to do(e.g. if you favour speed over accuracy, robustness over simplicity etc) and the type of waveform you have(simple, complex, human speech, music), FFT may be not enough on its own or not even the right choice for your task. There are other options, auto-correlation, zero-crossing, cepstral analysis, maximum likelihood to mention some. But none are trivial, except for zero-crossing, which also gives you the poorest results and will fail to work with complex waveforms.
Here is a good place to start:
http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html
There are also other question on SO.
However, as indicated by other answers, this is not something that can just be "magically" done. Even if you license code from someone (eg, iZotope, and z-plane both make excellent code for doing what you want to do), you still need to understand what's going on to get data in and out of their libraries.
If you need fast pitch detection go with http://www.schmittmachine.com/dywapitchtrack.html
You'll find a IOS sample code inside.
If you need FFT you should use Apple Accelerate framework.
Hope this help

Suitability of CodeNameOne for image processing application

We need to build an image processing application for smartphones (mainly for iPhone). The operations consist of:
image filtering
composite geometrical transformation
region growing
Also, the user is required to specify (touch) some parts of the image. Those parts would serve as inputs for the app. Example: eyes and lip in a face.
We have built a desktop version of this app. The processing part is quite heavy and we extensively used BufferedImage class.
Should we use CodeNameOne for building this app? If not then what alternatives do you suggest?
Please consider the following factors:
Performance
Ease of writing the code (for image processing)
I gave an answer for this in our discussion forum but I think its a worthwhile question for a duplicate post:
Generally for most platforms you should be fine in terms of performance except for iOS & arguably Windows Phone.
Codename One is optimized for common use cases, since iOS doesn't allow for JIT's it can never be as fast as Java on the desktop since its really hard to do some optimizations e.g. array bound check elimination. So every access to an array will contain a branch check which can be pretty expensive for image processing.
Add to that the fact that we don't have any image processing API's other than basic ARGB and you can get the "picture", it just won't be efficient or easy.
The problem is that this is a very specific field, I highly doubt you will find any solution that will help you with this sort of code. So your only approach AFAIK is to build native code to do the actual image processing heavy lifting.
You can do this with Codename One by using the NativeInterface API which allows you to invoke critical code in native code and use cn1lib's to wrap them as libraries. You would then be able to get native performance for that portion of the code but this would only make sense for critical sections in the code. If you write a lot of native code the benefits of Codename One start to dissipate and you might as well go to native.