Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flutter sample app #758

Merged
merged 5 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Examples_Flutter/superpowered_player_with_effects/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
.packages
build/

.vscode/
33 changes: 33 additions & 0 deletions Examples_Flutter/superpowered_player_with_effects/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled.

version:
revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
channel: stable

project_type: plugin_ffi

# Tracks metadata for the flutter migrate command
migration:
platforms:
- platform: root
create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
- platform: android
create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
- platform: ios
create_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2
base_revision: d3d8effc686d73e0114d71abdcccef63fa1f25d2

# User provided section

# List of Local paths (relative to this file) that should be
# ignored by the migrate tool.
#
# Files that are not part of the templates will be ignored by default.
unmanaged_files:
- 'lib/main.dart'
- 'ios/Runner.xcodeproj/project.pbxproj'
40 changes: 40 additions & 0 deletions Examples_Flutter/superpowered_player_with_effects/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Superpowered Player with Effects Flutter Sample App

A [FFI plugin](https://docs.flutter.dev/platform-integration/android/c-interop) project integrating SuperpoweredSDK.
## How to run:
`cd scripts`
* Android: build_android.sh
* iOS: build_ios.sh

## Project structure

This template uses the following structure:

* `src`: Contains the native source code shared by all platforms
* `android/cpp` : Android specific native code
* `ios/Classes` : iOS specific native code

* `lib`: Contains the Dart code that defines the API of the plugin, and which
calls into the native code using `dart:ffi`.

* platform folders (`android`, `ios`, etc.): Contains the build files
for building and bundling the native code library with the platform application.

## Building and bundling native code

The native build systems that are invoked by FFI (and method channel) plugins are:

* For Android: Gradle, which invokes the Android NDK for native builds.
* See the documentation in android/build.gradle.
* For iOS and MacOS: Xcode, via CocoaPods.
* See the documentation in ios/superpowered_player_with_effects.podspec.
* See the documentation in macos/superpowered_player_with_effects.podspec.

## Binding to native code

To use the native code, bindings in Dart are needed.
To avoid writing these by hand, they are generated from the header file
(`src/superpowered_player_with_effects.h`) by `package:ffigen`.
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.


Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# The Flutter tooling requires that developers have CMake 3.10 or later
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)

project(superpowered_player_with_effects_library)
set(CMAKE_VERBOSE_MAKEFILE on)
# Set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# now build app's shared lib
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS} -g -UNDEBUG -DDEBUG=1")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS} -Os")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -UNDEBUG -DDEBUG=1")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -Os")


file(TO_CMAKE_PATH ${PATH_TO_SUPERPOWERED} PATH_TO_SUPERPOWERED)
include_directories(${PATH_TO_SUPERPOWERED})

add_library(superpowered_player_with_effects SHARED
"../src/superpowered_player_with_effects.cpp"
"../src/SuperpoweredEngineExample.cpp"
"cpp/SuperpoweredEngineExampleAndroid.cpp"
${PATH_TO_SUPERPOWERED}/OpenSource/SuperpoweredAndroidAudioIO.cpp
)

# link the native library against the following libraries
target_link_libraries (
superpowered_player_with_effects
log
android
OpenSLES
${PATH_TO_SUPERPOWERED}/libSuperpoweredAndroid${ANDROID_ABI}.a
)

set_target_properties(superpowered_player_with_effects PROPERTIES
PUBLIC_HEADER superpowered_player_with_effects.h
OUTPUT_NAME "superpowered_player_with_effects"
)

target_compile_definitions(superpowered_player_with_effects PUBLIC DART_SHARED_LIB)
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// The Android Gradle Plugin builds the native code with the Android NDK.

group 'com.example.superpowered_player_with_effects'
version '1.0'
def superpowered_sdk_path = new File(projectDir, '../../../Superpowered')

buildscript {
repositories {
google()
mavenCentral()
}

dependencies {
// The Android Gradle Plugin knows how to build native code with the NDK.
classpath 'com.android.tools.build:gradle:7.3.0'
}
}

rootProject.allprojects {
repositories {
google()
mavenCentral()
}
}

apply plugin: 'com.android.library'

android {
// Bumping the plugin compileSdkVersion requires all clients of this plugin
// to bump the version in their app.
compileSdkVersion 31

defaultConfig {
minSdkVersion 16

ndk { // these platforms cover 99.9% percent of all Android devices
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}

externalNativeBuild {
cmake {
arguments '-DANDROID_PLATFORM=android-24', "-DANDROID_TOOLCHAIN=clang", "-DANDROID_ARM_NEON=TRUE", "-DPATH_TO_SUPERPOWERED:STRING=${superpowered_sdk_path}"
cFlags "-O3", "-fsigned-char" // full optimization, char data type is signed
cppFlags "-fsigned-char", "-I${superpowered_sdk_path}"
}
}
}

// Invoke the shared CMake build with the Android Gradle Plugin.
externalNativeBuild {
cmake {
path "CMakeLists.txt"

// The default CMake version for the Android Gradle Plugin is 3.10.2.
// https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
//
// The Flutter tooling requires that developers have CMake 3.10 or later
// installed. You should not increase this version, as doing so will cause
// the plugin to fail to compile for some customers of the plugin.
// version "3.10.2"
}
}

// Bumping the plugin ndkVersion requires all clients of this plugin to bump
// the version in their app and to download a newer version of the NDK.
ndkVersion '25.1.8937393'

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdint.h>
#include <math.h>

#include "../../src/SuperpoweredEngineExample.h"
#include "SuperpoweredSimple.h"

#ifdef __ANDROID__

static bool audioProcessingAndroid(void *clientdata, short int *audioIO, int numberOfFrames, int samplerate) {
auto example = static_cast<SuperpoweredEngineExample *>(clientdata);
float playerOutput[numberOfFrames * 2];

bool hasAudio = example->audioProcessing(playerOutput, (uint32_t) numberOfFrames, (uint32_t) samplerate);
Superpowered::FloatToShortInt(playerOutput, audioIO, (unsigned int)numberOfFrames);
return hasAudio;
}

void SuperpoweredEngineExample::platformCleanup() {
delete androidEngine;
}

void SuperpoweredEngineExample::platformInit() {
androidEngine = new SuperpoweredAndroidAudioIO(
48000,
512,
false,
true,
audioProcessingAndroid,
this
);
}

void SuperpoweredEngineExample::platformStartEngine() {
androidEngine->start();
}

void SuperpoweredEngineExample::platformStopEngine() {
androidEngine->stop();
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'superpowered_player_with_effects'
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.superpowered_player_with_effects">

<uses-permission android:name="android.permission.INTERNET" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.packages
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# superpowered_player_with_effects_example

Demonstrates how to use the superpowered_player_with_effects plugin.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.

# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include: package:flutter_lints/flutter.yaml

linter:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at
# https://dart-lang.github.io/linter/lints/index.html.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
gradle-wrapper.jar
/.gradle
/captures/
/gradlew
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
**/*.keystore
**/*.jks
Loading