I am attempting to create a spectrogram visualisation in Android. I use the android device to record sound in .PCM format and then convert this to .WAV so that it can be analysed using the musicg library https://code.google.com/p/musicg/.
Using musicg I can create a spectrogram of the recorded .WAV and from this spectrogram I can extract the frequency time domain data as a double[][].
What I am trying to work out next is how to visualise this data in Android. Any help would be appreciated.
Following user3161880 answer, I have tried the following but I am not getting anything drawn to screen. I can draw a circle as shown in user3161880 answer. Any ideas why this wouldn't work?
private static class SpectrogramView extends View {
private Paint paint = new Paint();
private double [][] data;
public SpectrogramView(Context context, double [][] data) {
super(context);
this.data = data;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (data != null) {
paint.setStrokeWidth(1);
canvas.drawColor(Color.WHITE);
int width = data.length;
int height = data[0].length;
for(int i = 0; i < width; i++) {
for(int j = 0; j < height; j++) {
int value;
value = 255 - (int)(data[i][j] * 255);
paint.setColor(value<<16|value<<8|value|255<<24);
canvas.drawPoint(i, height-1-j, paint);
}
}
} else {
System.err.println("Data Corrupt");
}
//draw circle
/*paint.setColor(Color.RED);
canvas.drawColor(Color.BLUE);
canvas.drawCircle(100.0f, 100.0f, 50.0f, paint);*/
}
}