Skip to content

Commit f57e1a9

Browse files
authored
Flutter sample app (#758)
Added Flutter sample app which demonstrates how to integrate Superpowered SDK through the dart:ffi library.
1 parent b2da172 commit f57e1a9

File tree

92 files changed

+3570
-0
lines changed

Some content is hidden

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

92 files changed

+3570
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Miscellaneous
2+
*.class
3+
*.log
4+
*.pyc
5+
*.swp
6+
.DS_Store
7+
.atom/
8+
.buildlog/
9+
.history
10+
.svn/
11+
migrate_working_dir/
12+
13+
# IntelliJ related
14+
*.iml
15+
*.ipr
16+
*.iws
17+
.idea/
18+
19+
# The .vscode folder contains launch configuration and tasks you configure in
20+
# VS Code which you may wish to be included in version control, so this line
21+
# is commented out by default.
22+
#.vscode/
23+
24+
# Flutter/Dart/Pub related
25+
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
26+
/pubspec.lock
27+
**/doc/api/
28+
.dart_tool/
29+
.packages
30+
build/
31+
32+
.vscode/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled.
5+
6+
version:
7+
revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
8+
channel: stable
9+
10+
project_type: plugin_ffi
11+
12+
# Tracks metadata for the flutter migrate command
13+
migration:
14+
platforms:
15+
- platform: root
16+
create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
17+
base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
18+
- platform: android
19+
create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
20+
base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
21+
- platform: ios
22+
create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
23+
base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
24+
25+
# User provided section
26+
27+
# List of Local paths (relative to this file) that should be
28+
# ignored by the migrate tool.
29+
#
30+
# Files that are not part of the templates will be ignored by default.
31+
unmanaged_files:
32+
- 'lib/main.dart'
33+
- 'ios/Runner.xcodeproj/project.pbxproj'
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Superpowered Player with Effects Flutter Sample App
2+
3+
A [FFI plugin](https://docs.flutter.dev/platform-integration/android/c-interop) project integrating SuperpoweredSDK.
4+
## How to run:
5+
`cd scripts`
6+
* Android: build_android.sh
7+
* iOS: build_ios.sh
8+
9+
## Project structure
10+
11+
This template uses the following structure:
12+
13+
* `src`: Contains the native source code shared by all platforms
14+
* `android/cpp` : Android specific native code
15+
* `ios/Classes` : iOS specific native code
16+
17+
* `lib`: Contains the Dart code that defines the API of the plugin, and which
18+
calls into the native code using `dart:ffi`.
19+
20+
* platform folders (`android`, `ios`, etc.): Contains the build files
21+
for building and bundling the native code library with the platform application.
22+
23+
## Building and bundling native code
24+
25+
The native build systems that are invoked by FFI (and method channel) plugins are:
26+
27+
* For Android: Gradle, which invokes the Android NDK for native builds.
28+
* See the documentation in android/build.gradle.
29+
* For iOS and MacOS: Xcode, via CocoaPods.
30+
* See the documentation in ios/superpowered_player_with_effects.podspec.
31+
* See the documentation in macos/superpowered_player_with_effects.podspec.
32+
33+
## Binding to native code
34+
35+
To use the native code, bindings in Dart are needed.
36+
To avoid writing these by hand, they are generated from the header file
37+
(`src/superpowered_player_with_effects.h`) by `package:ffigen`.
38+
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.
39+
40+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.cxx
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# The Flutter tooling requires that developers have CMake 3.10 or later
2+
# installed. You should not increase this version, as doing so will cause
3+
# the plugin to fail to compile for some customers of the plugin.
4+
cmake_minimum_required(VERSION 3.10)
5+
6+
project(superpowered_player_with_effects_library)
7+
set(CMAKE_VERBOSE_MAKEFILE on)
8+
# Set C++ standard to C++17
9+
set(CMAKE_CXX_STANDARD 17)
10+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
11+
set(CMAKE_CXX_EXTENSIONS OFF)
12+
13+
# now build app's shared lib
14+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
16+
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -UNDEBUG -DDEBUG=1")
17+
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -Os")
18+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -UNDEBUG -DDEBUG=1")
19+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Os")
20+
21+
22+
file(TO_CMAKE_PATH ${PATH_TO_SUPERPOWERED} PATH_TO_SUPERPOWERED)
23+
include_directories(${PATH_TO_SUPERPOWERED})
24+
25+
add_library(superpowered_player_with_effects SHARED
26+
"../src/superpowered_player_with_effects.cpp"
27+
"../src/SuperpoweredEngineExample.cpp"
28+
"cpp/SuperpoweredEngineExampleAndroid.cpp"
29+
${PATH_TO_SUPERPOWERED}/OpenSource/SuperpoweredAndroidAudioIO.cpp
30+
)
31+
32+
# link the native library against the following libraries
33+
target_link_libraries (
34+
superpowered_player_with_effects
35+
log
36+
android
37+
OpenSLES
38+
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
39+
)
40+
41+
set_target_properties(superpowered_player_with_effects PROPERTIES
42+
PUBLIC_HEADER superpowered_player_with_effects.h
43+
OUTPUT_NAME "superpowered_player_with_effects"
44+
)
45+
46+
target_compile_definitions(superpowered_player_with_effects PUBLIC DART_SHARED_LIB)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// The Android Gradle Plugin builds the native code with the Android NDK.
2+
3+
group 'com.example.superpowered_player_with_effects'
4+
version '1.0'
5+
def superpowered_sdk_path = new File(projectDir, '../../../Superpowered')
6+
7+
buildscript {
8+
repositories {
9+
google()
10+
mavenCentral()
11+
}
12+
13+
dependencies {
14+
// The Android Gradle Plugin knows how to build native code with the NDK.
15+
classpath 'com.android.tools.build:gradle:7.3.0'
16+
}
17+
}
18+
19+
rootProject.allprojects {
20+
repositories {
21+
google()
22+
mavenCentral()
23+
}
24+
}
25+
26+
apply plugin: 'com.android.library'
27+
28+
android {
29+
// Bumping the plugin compileSdkVersion requires all clients of this plugin
30+
// to bump the version in their app.
31+
compileSdkVersion 31
32+
33+
defaultConfig {
34+
minSdkVersion 16
35+
36+
ndk { // these platforms cover 99.9% percent of all Android devices
37+
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
38+
}
39+
40+
externalNativeBuild {
41+
cmake {
42+
arguments '-DANDROID_PLATFORM=android-24', "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DPATH_TO_SUPERPOWERED:STRING=${superpowered_sdk_path}"
43+
cFlags "-O3", "-fsigned-char" // full optimization, char data type is signed
44+
cppFlags "-fsigned-char", "-I${superpowered_sdk_path}"
45+
}
46+
}
47+
}
48+
49+
// Invoke the shared CMake build with the Android Gradle Plugin.
50+
externalNativeBuild {
51+
cmake {
52+
path "CMakeLists.txt"
53+
54+
// The default CMake version for the Android Gradle Plugin is 3.10.2.
55+
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
56+
//
57+
// The Flutter tooling requires that developers have CMake 3.10 or later
58+
// installed. You should not increase this version, as doing so will cause
59+
// the plugin to fail to compile for some customers of the plugin.
60+
// version "3.10.2"
61+
}
62+
}
63+
64+
// Bumping the plugin ndkVersion requires all clients of this plugin to bump
65+
// the version in their app and to download a newer version of the NDK.
66+
ndkVersion '25.1.8937393'
67+
68+
compileOptions {
69+
sourceCompatibility JavaVersion.VERSION_1_8
70+
targetCompatibility JavaVersion.VERSION_1_8
71+
}
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include <stdint.h>
2+
#include <math.h>
3+
4+
#include "../../src/SuperpoweredEngineExample.h"
5+
#include "SuperpoweredSimple.h"
6+
7+
#ifdef __ANDROID__
8+
9+
static bool audioProcessingAndroid(void *clientdata, short int *audioIO, int numberOfFrames, int samplerate) {
10+
auto example = static_cast<SuperpoweredEngineExample *>(clientdata);
11+
float playerOutput[numberOfFrames * 2];
12+
13+
bool hasAudio = example->audioProcessing(playerOutput, (uint32_t) numberOfFrames, (uint32_t) samplerate);
14+
Superpowered::FloatToShortInt(playerOutput, audioIO, (unsigned int)numberOfFrames);
15+
return hasAudio;
16+
}
17+
18+
void SuperpoweredEngineExample::platformCleanup() {
19+
delete androidEngine;
20+
}
21+
22+
void SuperpoweredEngineExample::platformInit() {
23+
androidEngine = new SuperpoweredAndroidAudioIO(
24+
48000,
25+
512,
26+
false,
27+
true,
28+
audioProcessingAndroid,
29+
this
30+
);
31+
}
32+
33+
void SuperpoweredEngineExample::platformStartEngine() {
34+
androidEngine->start();
35+
}
36+
37+
void SuperpoweredEngineExample::platformStopEngine() {
38+
androidEngine->stop();
39+
}
40+
41+
#endif
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'superpowered_player_with_effects'
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="com.example.superpowered_player_with_effects">
3+
4+
<uses-permission android:name="android.permission.INTERNET" />
5+
6+
</manifest>

0 commit comments

Comments
 (0)