$25 : A Piano Sample

Ohanian

Active Member
Licensed User
Longtime User
@ilan

check your Paypal account plz.
Confirmation number: 28T51510XL023135A.

I’ll appreciate if you spend some time and make a better sample supporting multi touch (if you have time) and I’ll pay for that.
 

ilan

Expert
Licensed User
Longtime User
thanx for the donation

I’ll appreciate if you spend some time and make a better sample supporting multi touch (if you have time) and I’ll pay for that.

i will try to do that but cannot promise :)
 

LucaMs

Expert
Licensed User
Longtime User
You should use a sound generator. I tried the Beeper object of the Audio library; result: very bad :D

... and using this library?

(or this code from StackOverflow:
B4X:
public class PlaySound extends Activity {
// originally from http://marblemice.blogspot.com/2010/04/generate-and-play-tone-in-android.html
// and modified by Steve Pomeroy <steve@staticfree.info>
private final int duration = 3; // seconds
private final int sampleRate = 8000;
private final int numSamples = duration * sampleRate;
private final double sample[] = new double[numSamples];
private final double freqOfTone = 440; // hz

private final byte generatedSnd[] = new byte[2 * numSamples];

Handler handler = new Handler();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}

@Override
protected void onResume() {
super.onResume();

// Use a new tread as this can take a while
final Thread thread = new Thread(new Runnable() {
public void run() {
genTone();
handler.post(new Runnable() {

public void run() {
playSound();
}
});
}
});
thread.start();
}

void genTone(){
// fill out the array
for (int i = 0; i < numSamples; ++i) {
sample[i] = Math.sin(2 * Math.PI * i / (sampleRate/freqOfTone));
}

// convert to 16 bit pcm sound array
// assumes the sample buffer is normalised.
int idx = 0;
for (final double dVal : sample) {
// scale to maximum amplitude
final short val = (short) ((dVal * 32767));
// in 16 bit wav PCM, first byte is the low order byte
generatedSnd[idx++] = (byte) (val & 0x00ff);
generatedSnd[idx++] = (byte) ((val & 0xff00) >>> 8);

}
}

void playSound(){
final AudioTrack audioTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, numSamples,
AudioTrack.MODE_STATIC);
audioTrack.write(generatedSnd, 0, generatedSnd.length);
audioTrack.play();
}
}
)


[Very nice formatting :)]
 
Last edited:

ilan

Expert
Licensed User
Longtime User
I’ll appreciate if you spend some time and make a better sample supporting multi touch (if you have time) and I’ll pay for that.

ok my friend, i had to create a complete new project and do it in a different way but now it supports Multi Touch.
i hope you like it. :)

and I’ll pay for that.
consider the hard work i did :p

tell me if its working, you will need the Gestures Lib: https://www.b4x.com/android/forum/threads/gestures-multi-touch-library.7421/#content from @agraham

have fun :)

EDIT: new version, fixed a small performance issue
 

Attachments

  • piano example 2.zip
    330.1 KB · Views: 439
Last edited:

Ohanian

Active Member
Licensed User
Longtime User
Hi,

You’re a rapid coder ;)

I just need the code, the graphic is already done, and the app is published, we’re improving it according to user’s feedback.

It’s weekend here, so please wait a few days for a feedback. But it seems ok for me.

And if you’re interested here’re some screenshots.
 

Attachments

  • 02.jpg
    02.jpg
    65.2 KB · Views: 410
  • 03.jpg
    03.jpg
    67.3 KB · Views: 404
  • otaghe sazhaye irani.jpg
    otaghe sazhaye irani.jpg
    63.6 KB · Views: 416

ilan

Expert
Licensed User
Longtime User
Hi,

You’re a rapid coder ;)

I just need the code, the graphic is already done, and the app is published, we’re improving it according to user’s feedback.

It’s weekend here, so please wait a few days for a feedback. But it seems ok for me.

And if you’re interested here’re some screenshots.

i like the graphics, are you drawing them by yourself?
 

Ohanian

Active Member
Licensed User
Longtime User
hi
no , we have a small team.
coders and a designer.
 

Ohanian

Active Member
Licensed User
Longtime User
@ilan

check your Paypal account please.
Confirmation Number: 5JA40971JM690431R
 
Top