diff --git a/.idea/misc.xml b/.idea/misc.xml index 44bc9b2..3d21ecd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 11cd6c9..62186c6 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,20 +2,30 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/de/mal_richtig/toney/MainActivity.java b/app/src/main/java/de/mal_richtig/toney/MainActivity.java index 0e6ed45..904cbe2 100644 --- a/app/src/main/java/de/mal_richtig/toney/MainActivity.java +++ b/app/src/main/java/de/mal_richtig/toney/MainActivity.java @@ -2,6 +2,15 @@ package de.mal_richtig.toney; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; +import android.widget.TextView; + +import be.tarsos.dsp.AudioDispatcher; +import be.tarsos.dsp.AudioEvent; +import be.tarsos.dsp.AudioProcessor; +import be.tarsos.dsp.io.android.AudioDispatcherFactory; +import be.tarsos.dsp.pitch.PitchDetectionHandler; +import be.tarsos.dsp.pitch.PitchDetectionResult; +import be.tarsos.dsp.pitch.PitchProcessor; public class MainActivity extends AppCompatActivity { @@ -9,5 +18,60 @@ public class MainActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); + + AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(44100,512*8,0); + + PitchDetectionHandler pdh = new PitchDetectionHandler() { + @Override + public void handlePitch(PitchDetectionResult result,AudioEvent e) { + final float pitchInHz = result.getPitch(); + runOnUiThread(new Runnable() { + @Override + public void run() { + TextView text = (TextView) findViewById(R.id.key_major); + text.setText("" + pitchInHz); + } + }); + } + }; + AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.DYNAMIC_WAVELET, 44100, 512*8, pdh); + dispatcher.addAudioProcessor(p); + new Thread(dispatcher,"Audio Dispatcher").start(); + } + + public void processPitch(float pitchInHz) { + + TextView noteText = (TextView) findViewById(R.id.key_major); + + //pitchText.setText("" + pitchInHz); + + if(pitchInHz >= 110 && pitchInHz < 123.47) { + //A + noteText.setText("A"); + } + else if(pitchInHz >= 123.47 && pitchInHz < 130.81) { + //B + noteText.setText("B"); + } + else if(pitchInHz >= 130.81 && pitchInHz < 146.83) { + //C + noteText.setText("C"); + } + else if(pitchInHz >= 146.83 && pitchInHz < 164.81) { + //D + noteText.setText("D"); + } + else if(pitchInHz >= 164.81 && pitchInHz <= 174.61) { + //E + noteText.setText("E"); + } + else if(pitchInHz >= 174.61 && pitchInHz < 185) { + //F + noteText.setText("F"); + } + else if(pitchInHz >= 185 && pitchInHz < 196) { + //G + noteText.setText("G"); + } } } diff --git a/app/src/main/java/de/mal_richtig/toney/SplashActivity.java b/app/src/main/java/de/mal_richtig/toney/SplashActivity.java new file mode 100644 index 0000000..0335b65 --- /dev/null +++ b/app/src/main/java/de/mal_richtig/toney/SplashActivity.java @@ -0,0 +1,75 @@ +package de.mal_richtig.toney; + +import android.Manifest; +import android.content.Context; +import android.content.Intent; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.support.v4.app.ActivityCompat; +import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.widget.Toast; + +/** + * Created by ermo on 07.06.17. + */ + +public class SplashActivity extends AppCompatActivity { + + private static final int PERMISSION_REQUEST_CODE = 1; + private static final int MAX_REQUESTS = 3; + private int requestTryCounter = 0; + + @Override + protected void onResume() { + super.onResume(); + + if (ContextCompat.checkSelfPermission(getApplicationContext(), + Manifest.permission.RECORD_AUDIO) + != PackageManager.PERMISSION_GRANTED) { + + // request the permission. + if(requestTryCounter < MAX_REQUESTS) { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.RECORD_AUDIO}, + PERMISSION_REQUEST_CODE); + + requestTryCounter++; + } + + } else { + Intent intent = new Intent(this, MainActivity.class); + startActivity(intent); + finish(); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, + String permissions[], int[] grantResults) { + + Context context = getApplicationContext(); + + switch (requestCode) { + case PERMISSION_REQUEST_CODE: { + // If request is cancelled, the result arrays are empty. + if (grantResults.length > 0 + && grantResults[0] == PackageManager.PERMISSION_GRANTED) { + + // permission was granted, yay! + Log.i("XDE", "yay!"); + + } else { + Log.i("XDE", "doom"); + // permission denied, boo! + Toast.makeText(context, "Toney can't work without audio permission!", + Toast.LENGTH_LONG).show(); + } + return; + } + default: + Log.e("RequestPermission", "unexpected permission code"); + } + } +} diff --git a/app/src/main/res/drawable/activity_splash.xml b/app/src/main/res/drawable/activity_splash.xml new file mode 100644 index 0000000..cd719e4 --- /dev/null +++ b/app/src/main/res/drawable/activity_splash.xml @@ -0,0 +1,13 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 888733f..c84bc64 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -6,4 +6,198 @@ android:layout_height="match_parent" tools:context="de.mal_richtig.toney.MainActivity"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/mipmap-hdpi/logo_toney.png b/app/src/main/res/mipmap-hdpi/logo_toney.png new file mode 100644 index 0000000..4540636 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/logo_toney.png differ diff --git a/app/src/main/res/mipmap-mdpi/logo_toney.png b/app/src/main/res/mipmap-mdpi/logo_toney.png new file mode 100644 index 0000000..7336f7f Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/logo_toney.png differ diff --git a/app/src/main/res/mipmap-xhdpi/logo_toney.png b/app/src/main/res/mipmap-xhdpi/logo_toney.png new file mode 100644 index 0000000..9f3b528 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/logo_toney.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/logo_toney.png b/app/src/main/res/mipmap-xxhdpi/logo_toney.png new file mode 100644 index 0000000..21f803c Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/logo_toney.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/logo_toney.png b/app/src/main/res/mipmap-xxxhdpi/logo_toney.png new file mode 100644 index 0000000..daf0285 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/logo_toney.png differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 737e9b4..2668799 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,7 +1,6 @@ - #ccc - #777 - #000 - #000 + #fa0 + #d30 + #f3d diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5885930..fa812ef 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,4 +8,8 @@ @color/colorAccent + + diff --git a/logo-toney.png b/logo-toney.png new file mode 100644 index 0000000..0fc80bf Binary files /dev/null and b/logo-toney.png differ diff --git a/logo-toney.svg b/logo-toney.svg new file mode 100644 index 0000000..27dbdcc --- /dev/null +++ b/logo-toney.svg @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + +