Skip to content
This repository was archived by the owner on Oct 9, 2019. It is now read-only.

Commit 1b40cc0

Browse files
author
Don Turner
committed
Renaming project to HelloLowLatencyOutput, adding licenses and readme
1 parent 0cb5026 commit 1b40cc0

30 files changed

+388
-38
lines changed

CONTRIBUTING.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# How to become a contributor and submit your own code
2+
3+
## Contributor License Agreements
4+
5+
We'd love to accept your sample apps and patches! Before we can take them, we
6+
have to jump a couple of legal hurdles.
7+
8+
Please fill out either the individual or corporate Contributor License Agreement
9+
(CLA).
10+
11+
* If you are an individual writing original source code and you're sure you
12+
own the intellectual property, then you'll need to sign an [individual CLA]
13+
(http://code.google.com/legal/individual-cla-v1.0.html).
14+
* If you work for a company that wants to allow you to contribute your work,
15+
then you'll need to sign a [corporate CLA]
16+
(http://code.google.com/legal/corporate-cla-v1.0.html).
17+
18+
Follow either of the two links above to access the appropriate CLA and
19+
instructions for how to sign and return it. Once we receive it, we'll be able to
20+
accept your pull requests.
21+
22+
## Contributing a Patch
23+
24+
1. Sign a Contributor License Agreement, if you have not yet done so (see
25+
details above).
26+
1. Create your change to the repo in question.
27+
* Fork the desired repo, develop and test your code changes.
28+
* Ensure that your code is clear and comprehensible.
29+
* Ensure that your code has an appropriate set of unit tests which all pass.
30+
1. Submit a pull request.
31+
1. The repo owner will review your request. If it is approved, the change will
32+
be merged. If it needs additional work, the repo owner will respond with
33+
useful comments.
34+
35+
## Contributing a New Sample App
36+
37+
1. Sign a Contributor License Agreement, if you have not yet done so (see
38+
details above).
39+
1. Create your own repo for your app following this naming convention:
40+
* mirror-{app-name}-{language or plaform}
41+
* apps: quickstart, photohunt-server, photohunt-client
42+
* example: mirror-quickstart-android
43+
* For multi-language apps, concatenate the primary languages like this:
44+
mirror-photohunt-server-java-python.
45+
46+
1. Create your sample app in this repo.
47+
* Be sure to clone the README.md, CONTRIBUTING.md and LICENSE files from the
48+
googlecast repo.
49+
* Ensure that your code is clear and comprehensible.
50+
* Ensure that your code has an appropriate set of unit tests which all pass.
51+
* Instructional value is the top priority when evaluating new app proposals for
52+
this collection of repos.
53+
1. Submit a request to fork your repo in googlecast organization.
54+
1. The repo owner will review your request. If it is approved, the sample will
55+
be merged. If it needs additional work, the repo owner will respond with
56+
useful comments.

HelloLowLatency/app/src/main/res/values/strings.xml

-3
This file was deleted.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id="HelloLowLatencyOutput" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="java-gradle" name="Java-Gradle">
5+
<configuration>
6+
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
7+
<option name="BUILDABLE" value="false" />
8+
</configuration>
9+
</facet>
10+
</component>
11+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
12+
<exclude-output />
13+
<content url="file://$MODULE_DIR$">
14+
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
15+
</content>
16+
<orderEntry type="inheritedJdk" />
17+
<orderEntry type="sourceFolder" forTests="false" />
18+
</component>
19+
</module>

HelloLowLatencyOutput/README

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Low Latency Audio Output
2+
========================
3+
4+
This sample demonstrates how to achieve the lowest possible output latency on an Android device.
5+
6+
TODO
7+
---
8+
- App crashes on orientation change
File renamed without changes.

HelloLowLatency/app/app.iml HelloLowLatencyOutput/app/app.iml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="HelloLowLatency" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="HelloLowLatencyOutput" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -71,6 +71,8 @@
7171
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
7272
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
7373
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
74+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.0.1/jars" />
75+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.0.1/jars" />
7476
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7577
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
7678
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
@@ -86,10 +88,10 @@
8688
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
8789
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
8890
</content>
89-
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
91+
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
9092
<orderEntry type="sourceFolder" forTests="false" />
91-
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
92-
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
93-
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
93+
<orderEntry type="library" exported="" name="appcompat-v7-23.0.1" level="project" />
94+
<orderEntry type="library" exported="" name="support-v4-23.0.1" level="project" />
95+
<orderEntry type="library" exported="" name="support-annotations-23.0.1" level="project" />
9496
</component>
9597
</module>

HelloLowLatency/app/build.gradle HelloLowLatencyOutput/app/build.gradle

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ apply plugin: 'com.android.model.application'
22

33
model {
44
android{
5-
compileSdkVersion = 22
6-
buildToolsVersion = "22.0.1"
5+
compileSdkVersion = 23
6+
buildToolsVersion = "23.0.1"
77

88
defaultConfig.with {
99
minSdkVersion.apiLevel = 22
1010
targetSdkVersion.apiLevel = 22
11-
applicationId = "com.example.hellolowlatency"
11+
applicationId = "com.example.hellolowlatencyoutput"
1212
versionName = "3.0"
1313
versionCode = 3
1414
}
1515
}
1616

1717
android.ndk {
18-
moduleName += "hello_low_latency"
18+
moduleName += "hello_low_latency_output"
1919
ldLibs += "OpenSLES"
2020
ldLibs += "log"
2121
}
@@ -25,10 +25,13 @@ model {
2525
isMinifyEnabled = false
2626
proguardFiles += file('proguard-rules.pro')
2727
}
28+
debug {
29+
isJniDebuggable = true
30+
}
2831
}
2932
}
3033

3134
dependencies {
3235
compile fileTree(dir: 'libs', include: ['*.jar'])
33-
compile 'com.android.support:appcompat-v7:22.2.0'
36+
compile 'com.android.support:appcompat-v7:23.0.1'
3437
}

HelloLowLatency/app/src/main/AndroidManifest.xml HelloLowLatencyOutput/app/src/main/AndroidManifest.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.example.proaudio.hellolowlatency" >
3+
package="com.example.hellolowlatencyoutput" >
44

55
<application
66
android:allowBackup="true"
@@ -19,5 +19,5 @@
1919

2020
</application>
2121

22-
<uses-feature android:name="android.hardware.audio.low_latency" android:required="false" />
22+
<uses-feature android:name="android.hardware.audio.low_latency" android:required="true" />
2323
</manifest>

HelloLowLatency/app/src/main/java/com/example/proaudio/hellolowlatency/MainActivity.java HelloLowLatencyOutput/app/src/main/java/com/example/hellolowlatencyoutput/MainActivity.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
package com.example.proaudio.hellolowlatency;
1+
/*
2+
* Copyright 2015 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.hellolowlatencyoutput;
218

319
import android.content.Context;
420
import android.content.pm.PackageManager;
@@ -13,7 +29,7 @@
1329
public class MainActivity extends AppCompatActivity {
1430

1531
static {
16-
System.loadLibrary("hello_low_latency");
32+
System.loadLibrary("hello_low_latency_output");
1733
}
1834

1935
public static native void playTone();
@@ -35,7 +51,6 @@ protected void onCreate(Bundle savedInstanceState) {
3551
//Check for low latency feature
3652
PackageManager pm = getPackageManager();
3753
boolean claimsFeature = pm.hasSystemFeature(PackageManager.FEATURE_AUDIO_LOW_LATENCY);
38-
3954
log("Has low latency audio feature? " + claimsFeature);
4055

4156
//Check for optimal output sample rate and buffer size

HelloLowLatency/app/src/main/jni/player.c HelloLowLatencyOutput/app/src/main/jni/player.c

+34-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2015 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
#include <assert.h>
218
#include <jni.h>
319
#include <math.h>
@@ -12,28 +28,27 @@
1228

1329
// logging
1430
#include <android/log.h>
15-
#define APPNAME "HelloLowLatency"
31+
#define APPNAME "HelloLowLatencyOutput"
1632

1733
// engine interfaces
1834
static SLObjectItf engineObject = NULL;
19-
static SLEngineItf engineEngine;
35+
static SLEngineItf engineEngine = NULL;
2036

2137
// output mix interfaces
2238
static SLObjectItf outputMixObject = NULL;
2339

2440
// buffer queue player interfaces
2541
static SLObjectItf bqPlayerObject = NULL;
26-
static SLPlayItf bqPlayerPlay;
27-
static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue;
42+
static SLPlayItf bqPlayerPlay = NULL;
43+
static SLAndroidSimpleBufferQueueItf bqPlayerBufferQueue = NULL;
2844

29-
#define CHANNELS 1
45+
#define CHANNELS 1 // 1 for mono, 2 for stereo
3046
#define TWO_PI (3.14159 * 2)
3147

3248
// Each short represents a 16-bit audio sample
33-
static short* squareWaveBuffer;
34-
static short* sineWaveBuffer;
35-
static short* silenceBuffer;
36-
static unsigned int bufferSizeInBytes;
49+
static short* sineWaveBuffer = NULL;
50+
static short* silenceBuffer = NULL;
51+
static unsigned int bufferSizeInBytes = 0;
3752

3853
#define MAXIMUM_AMPLITUDE_VALUE 32767
3954

@@ -45,10 +60,10 @@ static unsigned buffersRemaining = 0;
4560
/**
4661
* Create wave tables with the specified number of frames
4762
*/
48-
void createWaveTables(int frames){
63+
void createWaveTables(unsigned int frames){
4964

5065
// First figure out how many samples we need and allocate memory for the tables
51-
int numSamples = frames * CHANNELS;
66+
unsigned int numSamples = frames * CHANNELS;
5267
silenceBuffer = malloc(sizeof(*silenceBuffer) * numSamples);
5368
sineWaveBuffer = malloc(sizeof(*sineWaveBuffer) * numSamples);
5469
bufferSizeInBytes = numSamples * 2;
@@ -62,15 +77,15 @@ void createWaveTables(int frames){
6277
bufferSizeInBytes);
6378

6479
// Now create the sine wave - we'll just create a single cycle which fills the entire table
65-
float phaseIncrement = TWO_PI/frames;
80+
float phaseIncrement = (float) TWO_PI/frames;
6681
float currentPhase = 0.0;
6782

6883
unsigned int i;
6984
unsigned int j;
7085

7186
for (i = 0; i < frames; i++) {
7287

73-
short sampleValue = sin(currentPhase) * MAXIMUM_AMPLITUDE_VALUE;
88+
short sampleValue = (short) (sin(currentPhase) * MAXIMUM_AMPLITUDE_VALUE);
7489

7590
for (j = 0; j < CHANNELS; j++){
7691
sineWaveBuffer[(i*CHANNELS)+j] = sampleValue;
@@ -84,11 +99,10 @@ void createWaveTables(int frames){
8499
// this callback handler is called every time a buffer finishes playing
85100
void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
86101
{
102+
if (bq == NULL) __android_log_print(ANDROID_LOG_ERROR, APPNAME, "buffer queue was null");
87103
assert(bq == bqPlayerBufferQueue);
88104
assert(NULL == context);
89105

90-
SLresult result;
91-
92106
short* bufferPtr;
93107

94108
if (buffersRemaining > 0) {
@@ -102,18 +116,18 @@ void bqPlayerCallback(SLAndroidSimpleBufferQueueItf bq, void *context)
102116
bufferPtr = silenceBuffer;
103117
}
104118

105-
result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, bufferPtr, bufferSizeInBytes);
119+
SLresult result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, bufferPtr, bufferSizeInBytes);
106120
assert(SL_RESULT_SUCCESS == result);
107121
}
108122

109-
void Java_com_example_proaudio_hellolowlatency_MainActivity_playTone(JNIEnv* env, jclass clazz){
123+
void Java_com_example_hellolowlatencyoutput_MainActivity_playTone(JNIEnv* env, jclass clazz){
110124

111125
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Playing tone");
112126
buffersRemaining = BUFFERS_TO_PLAY;
113127
}
114128

115129
// create the engine and output mix objects
116-
void Java_com_example_proaudio_hellolowlatency_MainActivity_createEngine(JNIEnv* env, jclass clazz)
130+
void Java_com_example_hellolowlatencyoutput_MainActivity_createEngine(JNIEnv* env, jclass clazz)
117131
{
118132
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Creating audio engine");
119133

@@ -147,14 +161,14 @@ void Java_com_example_proaudio_hellolowlatency_MainActivity_createEngine(JNIEnv*
147161

148162

149163
// create buffer queue audio player
150-
void Java_com_example_proaudio_hellolowlatency_MainActivity_createBufferQueueAudioPlayer(JNIEnv* env,
164+
void Java_com_example_hellolowlatencyoutput_MainActivity_createBufferQueueAudioPlayer(JNIEnv* env,
151165
jclass clazz, jint optimalFrameRate, jint optimalFramesPerBuffer)
152166
{
153167
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "Creating audio player with frame rate %d and frames per buffer %d",
154168
optimalFrameRate, optimalFramesPerBuffer);
155169

156170
// create the wave tables which we'll use as the audio signal source
157-
createWaveTables(optimalFramesPerBuffer);
171+
createWaveTables((unsigned int)optimalFramesPerBuffer);
158172

159173
SLresult result;
160174

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">HelloLowLatencyOutput</string>
3+
</resources>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)