Skip to content

Commit a73f920

Browse files
committed
Add minimal Oboe audio library example
Based on the demo in the oboe-rs repo this is a minimal example that runs with GameActivity and plays a 440Hz sine wave
1 parent bb8eeb7 commit a73f920

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1175
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ exclude = [
77
"examples/agdk-mainloop",
88
"examples/agdk-winit-wgpu",
99
"examples/agdk-egui",
10+
"examples/agdk-oboe",
1011
"examples/na-mainloop",
1112
"examples/na-winit-wgpu",
1213
"examples/na-subclass-jni"

examples/agdk-oboe/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties
16+
*.so
17+
18+
# Added by cargo
19+
20+
/target
21+
Cargo.lock

examples/agdk-oboe/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/agdk-oboe/.idea/compiler.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/agdk-oboe/.idea/gradle.xml

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/agdk-oboe/.idea/misc.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/agdk-oboe/.idea/vcs.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/agdk-oboe/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "agdk-oboe"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
log = "0.4"
10+
android_logger = "0.11.0"
11+
android-activity = { path="../../android-activity", features = ["game-activity"] }
12+
oboe = { version = "0.4", features = ["java-interface"] }
13+
atomic_float = "0.1"
14+
15+
[lib]
16+
name="main"
17+
crate_type=["cdylib"]

examples/agdk-oboe/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This is a minimal test application based on `GameActivity` that just
2+
runs a mainloop based on android_activity::poll_events() and plays a
3+
sine wave audio test using the Oboe audio library.
4+
5+
```
6+
export ANDROID_NDK_HOME="path/to/ndk"
7+
export ANDROID_HOME="path/to/sdk"
8+
9+
rustup target add aarch64-linux-android
10+
cargo install cargo-ndk
11+
12+
cargo ndk -t arm64-v8a -o app/src/main/jniLibs/ build
13+
./gradlew build
14+
./gradlew installDebug
15+
adb shell am start -n co.realfit.agdkoboe/.MainActivity
16+
```

examples/agdk-oboe/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

examples/agdk-oboe/app/build.gradle

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
compileSdk 31
7+
8+
defaultConfig {
9+
applicationId "co.realfit.agdkoboe"
10+
minSdk 28
11+
targetSdk 31
12+
versionCode 1
13+
versionName "1.0"
14+
15+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16+
}
17+
18+
buildTypes {
19+
release {
20+
minifyEnabled false
21+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22+
}
23+
debug {
24+
minifyEnabled false
25+
//packagingOptions {
26+
// doNotStrip '**/*.so'
27+
//}
28+
//debuggable true
29+
}
30+
}
31+
compileOptions {
32+
sourceCompatibility JavaVersion.VERSION_1_8
33+
targetCompatibility JavaVersion.VERSION_1_8
34+
}
35+
}
36+
37+
dependencies {
38+
39+
implementation 'androidx.appcompat:appcompat:1.4.1'
40+
implementation 'com.google.android.material:material:1.5.0'
41+
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
42+
testImplementation 'junit:junit:4.13.2'
43+
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
44+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
45+
46+
// To use the Android Frame Pacing library
47+
//implementation "androidx.games:games-frame-pacing:1.9.1"
48+
49+
// To use the Android Performance Tuner
50+
//implementation "androidx.games:games-performance-tuner:1.5.0"
51+
52+
// To use the Games Activity library
53+
implementation "androidx.games:games-activity:1.1.0"
54+
55+
// To use the Games Controller Library
56+
//implementation "androidx.games:games-controller:1.1.0"
57+
58+
// To use the Games Text Input Library
59+
//implementation "androidx.games:games-text-input:1.1.0"
60+
}
61+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="co.realfit.agdkoboe">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="AGDK Oboe"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.RustTemplate">
12+
<activity
13+
android:name=".MainActivity"
14+
android:configChanges="orientation|screenSize|screenLayout|keyboardHidden"
15+
android:exported="true">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
<category android:name="android.intent.category.LAUNCHER" />
19+
</intent-filter>
20+
21+
<meta-data android:name="android.app.lib_name" android:value="main" />
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package co.realfit.agdkoboe;
2+
3+
import androidx.appcompat.app.AppCompatActivity;
4+
import androidx.core.view.WindowCompat;
5+
import androidx.core.view.WindowInsetsCompat;
6+
import androidx.core.view.WindowInsetsControllerCompat;
7+
8+
import com.google.androidgamesdk.GameActivity;
9+
10+
import android.os.Bundle;
11+
import android.content.pm.PackageManager;
12+
import android.os.Build.VERSION;
13+
import android.os.Build.VERSION_CODES;
14+
import android.os.Bundle;
15+
import android.view.View;
16+
import android.view.WindowManager;
17+
18+
public class MainActivity extends GameActivity {
19+
20+
static {
21+
// Load the STL first to workaround issues on old Android versions:
22+
// "if your app targets a version of Android earlier than Android 4.3
23+
// (Android API level 18),
24+
// and you use libc++_shared.so, you must load the shared library before any other
25+
// library that depends on it."
26+
// See https://developer.android.com/ndk/guides/cpp-support#shared_runtimes
27+
//System.loadLibrary("c++_shared");
28+
29+
// Load the native library.
30+
// The name "android-game" depends on your CMake configuration, must be
31+
// consistent here and inside AndroidManifect.xml
32+
System.loadLibrary("main");
33+
}
34+
35+
private void hideSystemUI() {
36+
// This will put the game behind any cutouts and waterfalls on devices which have
37+
// them, so the corresponding insets will be non-zero.
38+
if (VERSION.SDK_INT >= VERSION_CODES.P) {
39+
getWindow().getAttributes().layoutInDisplayCutoutMode
40+
= WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS;
41+
}
42+
// From API 30 onwards, this is the recommended way to hide the system UI, rather than
43+
// using View.setSystemUiVisibility.
44+
View decorView = getWindow().getDecorView();
45+
WindowInsetsControllerCompat controller = new WindowInsetsControllerCompat(getWindow(),
46+
decorView);
47+
controller.hide(WindowInsetsCompat.Type.systemBars());
48+
controller.hide(WindowInsetsCompat.Type.displayCutout());
49+
controller.setSystemBarsBehavior(
50+
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE);
51+
}
52+
53+
@Override
54+
protected void onCreate(Bundle savedInstanceState) {
55+
// When true, the app will fit inside any system UI windows.
56+
// When false, we render behind any system UI windows.
57+
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
58+
hideSystemUI();
59+
// You can set IME fields here or in native code using GameActivity_setImeEditorInfoFields.
60+
// We set the fields in native_engine.cpp.
61+
// super.setImeEditorInfoFields(InputType.TYPE_CLASS_TEXT,
62+
// IME_ACTION_NONE, IME_FLAG_NO_FULLSCREEN );
63+
super.onCreate(savedInstanceState);
64+
}
65+
66+
public boolean isGooglePlayGames() {
67+
PackageManager pm = getPackageManager();
68+
return pm.hasSystemFeature("com.google.android.play.feature.HPE_EXPERIENCE");
69+
}
70+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0" />
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0" />
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000" />
30+
</vector>

0 commit comments

Comments
 (0)