Iterate through memaligned pointer in C++ - android

for an Android Sequencer App, we gave a try to the Superpowered audio engine, which uses the Android NDK and C++. It's a very young project and there are some bugs in it, for example if a sample is too short, the buffers aren't cleared correctly, so I like to clear them by myself. For these, the memory is aligned this way:
bufferA = (float *)memalign(16, (buffersize + 16) * sizeof(float) * 2);
Because I'm a C++ beginner, I don't know how I could iterate through this pointer bufferA to overwrite its values.
Can anybody help? Thanks!

Related

How to implement Sepia tone in C with Native Development Kit (NDK)?

Please, someone could tell me How can I implement Sepia tone in Language C?, In my project I´ve got to implement the code with Android NDK. I´ve found some examples and I must code with this:
outputRed = (inputRed * .393) + (inputGreen *.769) + (inputBlue * .189)
outputGreen = (inputRed * .349) + (inputGreen *.686) + (inputBlue * .168)
outputBlue = (inputRed * .272) + (inputGreen *.534) + (inputBlue * .131)
Sepia toning in C#
http://www.techques.com/question/1-4141150/Convert-bitmap-to-sepia-in-android
How could I implement this code above, but NDK C, please?
I really appreciate if someone can help me or give some tips.
Regards,
Carlos
It´s simple, I´ve got a final project and I need to implement a Android Camera app, so I need to convertir normal photo to Sepia tone, but in code native, it means in C. I´ve found some examples, but all that I find is in C# or ColorMatrix Class. There is an example:
https://bitbucket.org/steven_rudenko/colormatrix
I need to implement Sepia toning in C, but using Android NDK.
Regards,
Carlos

Standard FFT classes/library for Android?

I plan to "visualise" some graphical data via audio. To make it short: I get a bunch of frequencies and related amplitude values out of some image data. This frequency/amplitude table with - lets say 256 pairs of data - has to be converted into related sine-waveforms.
One solution would be to generate sine-waveforms with different frequencies for eeach table entry. That would mean to generate sine waveforms for up to 256 times. But I'd guess that's quite slow. So using FFT-conversion should be a better solution for this?
So my question: is there some kind of fast and easy to use FFT standard available for Android that could be used for this?
In my Android project I used JTranforms which worked flawlessly on Android.
Example code:
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URGENT_AUDIO);
AudioRecord ar = // initialize AudioRecord here;
ar.startRecording();
// Here's the Fast Fourier Transform from JTransforms
DoubleFFT_1D fft = new DoubleFFT_1D(samples.length);
do {
// Read audio to 'samples' array and convert it to double[]
ar.read(samples, 0, samples.length);
// Will store FFT in 'samplesD'
fft.realForward(samplesD);
} while ( /* condition */ );
ar.stop();
ar.release();
UPDATE:
It can be found at JTransforms that is maintained on github here and avaiable as a Maven plugin here.
To use with with recent Gradle versions, do something like:
dependencies {
...
implementation 'com.github.wendykierp:JTransforms:3.1'
}

How to calculate sound frequency in android?

I want to develop app to calculate Sound frequency in Android. Android Device will take
Sound from microphone (i.e. out side sound) and I have one color background screen in app.
on sound frequency changes i have to change background color of screen .
So my question is "How can i get sound frequency"?
is there any android API available?
Please help me out of this problem.
Your problem was solved here EDIT: archived here. Also you can analyze the frequency by using FFT.
EDIT: FFTBasedSpectrumAnalyzer (example code, the link from the comment)
Thanks for Reply I have done this by using sample on
http://som-itsolutions.blogspot.in/2012/01/fft-based-simple-spectrum-analyzer.html
Just modify your code for to calculate sound frequency by using below method
// sampleRate = 44100
public static int calculate(int sampleRate, short [] audioData){
int numSamples = audioData.length;
int numCrossing = 0;
for (int p = 0; p < numSamples-1; p++)
{
if ((audioData[p] > 0 && audioData[p + 1] <= 0) ||
(audioData[p] < 0 && audioData[p + 1] >= 0))
{
numCrossing++;
}
}
float numSecondsRecorded = (float)numSamples/(float)sampleRate;
float numCycles = numCrossing/2;
float frequency = numCycles/numSecondsRecorded;
return (int)frequency;
}
The other answers show how to display a spectrogram. I think the question is how to detect a change in fundamental frequency. This is asked so often on Stack Exchange I wrote a blog entry (with code!) about it:
http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html
Admittedly, the code is in C, but I think you'll find it easy to port.
In short, you must:
low-pass the input signal so that higher frequency overtones are not mistaken for the fundamental frequency (this may not appear to be an issue in your application, since you are just looking for a change in pitch, but I recommend doing it anyway for reasons that are too complex to go into here).
window the signal, using a proper windowing function. To get the most responsive output, you should overlap the windows, which I don't do in my sample code.
Perform an FFT on the data in each window, and calculate the frequency using the index of maximum absolute peak value.
Keep in mind for your application where you probably want to detect the change in pitch accurately and quickly, the FFT method I describe may not be sufficient. You have two options:
There are techniques for increasing the specificity of the pitch tracking using phase information, not just the absolute peak.
Use a time-domain method based on autocorrelation. Yin is an excellent choice. (google for "yin pitch tracking")
Here is a link to the code mentioned. There's also some other useful code there.
https://github.com/gast-lib/gast-lib/blob/master/library/src/root/gast/audio/processing/ZeroCrossing.java
Here's the deal with ZeroCrossings:
It is inaccurate at determining frequency precisely based on recorded audio on an Android. That said, it is still useful for giving your app a general sense that the sound it is hearing is a constant singing tone, versus just noise.
The code here seems to work quite well for determining frequency, (if you can translate it from C# to java)
http://code.google.com/p/yaalp/

Android BitmapFactory.decodeStream loading BGR format?

I want to load .png file via asset manager which is provided by android sdk. AssetManager manager; /........./ BitmapFactory.decodeStream(manager.open(path));
It returns BGR format data but opengl es 2.0 uses RGB format so , Blue seems red , red seems blue, how odd.
Is there any solution for it?
I use Nvıdia Tegra 2 (Android 2.2) device for test the application along with c++ via JNI.
You must know the number of bits for colors, let's say n bit is for a color, so the first n bit represents BLUE, the second n bits represent GREEN and the final n bits represent RED in the input. You need to swap these bit groups into the correct order, like this:
output = (input << (2 * n)) + (input << n >> n) + (input >> (2 * n));
To be able to use this solution you need to find out how much is n.
Recent versions of OpenGL, also provide BGR input formats; OpenGL-ES not, unfortunatly. Since you're on Android you have to deal with OpenGL-ES.
If you're using a fragment shader it is also trivial to apply a rgb→bgr swizzle, which if probably the easiest way to overcome this problem.

Android version of AVAudioPlayer's averagePowerForChannel

Does Android have a similar method to the iPhone AVAudioPlayer's averagePowerForChannel?
I want to get an average reading of the amplitude of as a value.
I don't think there is a built-in function but you can calculate it yourself.
To do this, calculate the root-mean-square average of continuous samples.
rms = sqrt((sample0^2 + sample1^2 + sample2^2 + sample3^2) / numberOfSamples)
The following links should be helpful to you as they contain the full source code to two excellent Android sound related projects.
Ringdroid
Rehearsal Assistant

Categories

Resources