Skip to content

Instantly share code, notes, and snippets.

View eyqs's full-sized avatar
💭
blorp

Eugene Y. Q. Shen eyqs

💭
blorp
View GitHub Profile
@slightfoot
slightfoot / gist:6330866
Last active December 12, 2022 22:31
Android Tone Generator
// Usage:
// AudioTrack tone = generateTone(440, 250);
// tone.play();
//
private AudioTrack generateTone(double freqHz, int durationMs)
{
int count = (int)(44100.0 * 2.0 * (durationMs / 1000.0)) & ~1;
short[] samples = new short[count];
for(int i = 0; i < count; i += 2){
short sample = (short)(Math.sin(2 * Math.PI * i / (44100.0 / freqHz)) * 0x7FFF);