Skip to content

Commit 4f14e1b

Browse files
committed
AudioRecord
use the aac-encode opensource project to create m4a audio file and can pause.
1 parent 028dd69 commit 4f14e1b

418 files changed

Lines changed: 54730 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.androidleaf.audiorecord"
4+
android:versionCode="1"
5+
android:versionName="1.0" >
6+
7+
<uses-sdk
8+
android:minSdkVersion="8"
9+
android:targetSdkVersion="19" />
10+
11+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
12+
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
13+
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
14+
15+
<application
16+
android:allowBackup="true"
17+
android:icon="@drawable/ic_launcher"
18+
android:label="@string/app_name"
19+
>
20+
<activity
21+
android:name="com.androidleaf.audiorecord.RecordAct"
22+
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
23+
android:label="@string/app_name" >
24+
<intent-filter>
25+
<action android:name="android.intent.action.MAIN" />
26+
<category android:name="android.intent.category.LAUNCHER" />
27+
</intent-filter>
28+
</activity>
29+
</application>
30+
31+
</manifest>
Binary file not shown.

audio_record_demo/AudioRecoder_Release/gen/android/support/v7/appcompat/R.java

Lines changed: 616 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** Automatically generated file. DO NOT MODIFY */
2+
package com.androidleaf.audiorecord;
3+
4+
public final class BuildConfig {
5+
public final static boolean DEBUG = true;
6+
}

audio_record_demo/AudioRecoder_Release/gen/com/androidleaf/audiorecord/R.java

Lines changed: 3165 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* AUTO-GENERATED FILE. DO NOT MODIFY.
2+
*
3+
* This class was automatically generated by the
4+
* aapt tool from the resource data it found. It
5+
* should not be modified by hand.
6+
*/
7+
package com.todoroo.aacenc;
8+
9+
public final class R {
10+
public static final class drawable {
11+
public static final int ic_launcher = 0x7f02005c;
12+
}
13+
public static final class id {
14+
public static final int play = 0x7f0a003d;
15+
public static final int text = 0x7f0a003e;
16+
public static final int write = 0x7f0a003c;
17+
}
18+
public static final class layout {
19+
public static final int main = 0x7f030018;
20+
}
21+
public static final class raw {
22+
public static final int isoparser = 0x7f050000;
23+
}
24+
public static final class string {
25+
public static final int app_name = 0x7f0b000e;
26+
public static final int hello = 0x7f0b000d;
27+
}
28+
}
50.2 KB
Loading
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
LOCAL_PATH := $(call my-dir)
2+
3+
include $(CLEAR_VARS)
4+
include $(LOCAL_PATH)/Config.mk
5+
6+
LOCAL_MODULE := aac-encoder
7+
8+
ENC_SRC := src
9+
10+
LOCAL_C_INCLUDES := $(LOCAL_PATH)/inc
11+
12+
LOCAL_SRC_FILES = \
13+
aac-enc.c \
14+
$(ENC_SRC)/cmnMemory.c \
15+
basic_op/basicop2.c \
16+
basic_op/oper_32b.c \
17+
$(ENC_SRC)/aac_rom.c \
18+
$(ENC_SRC)/aacenc.c \
19+
$(ENC_SRC)/aacenc_core.c \
20+
$(ENC_SRC)/adj_thr.c \
21+
$(ENC_SRC)/band_nrg.c \
22+
$(ENC_SRC)/bit_cnt.c \
23+
$(ENC_SRC)/bitbuffer.c \
24+
$(ENC_SRC)/bitenc.c \
25+
$(ENC_SRC)/block_switch.c \
26+
$(ENC_SRC)/channel_map.c \
27+
$(ENC_SRC)/dyn_bits.c \
28+
$(ENC_SRC)/grp_data.c \
29+
$(ENC_SRC)/interface.c \
30+
$(ENC_SRC)/line_pe.c \
31+
$(ENC_SRC)/memalign.c \
32+
$(ENC_SRC)/ms_stereo.c \
33+
$(ENC_SRC)/pre_echo_control.c \
34+
$(ENC_SRC)/psy_configuration.c \
35+
$(ENC_SRC)/psy_main.c \
36+
$(ENC_SRC)/qc_main.c \
37+
$(ENC_SRC)/quantize.c \
38+
$(ENC_SRC)/sf_estim.c \
39+
$(ENC_SRC)/spreading.c \
40+
$(ENC_SRC)/stat_bits.c \
41+
$(ENC_SRC)/tns.c \
42+
$(ENC_SRC)/transform.c
43+
44+
ifeq ($(VOTT), v5)
45+
LOCAL_SRC_FILES += \
46+
$(ENC_SRC)/asm/ARMV5E/AutoCorrelation_v5.s \
47+
$(ENC_SRC)/asm/ARMV5E/band_nrg_v5.s \
48+
$(ENC_SRC)/asm/ARMV5E/CalcWindowEnergy_v5.s \
49+
$(ENC_SRC)/asm/ARMV5E/PrePostMDCT_v5.s \
50+
$(ENC_SRC)/asm/ARMV5E/R4R8First_v5.s \
51+
$(ENC_SRC)/asm/ARMV5E/Radix4FFT_v5.s
52+
endif
53+
54+
ifeq ($(VOTT), v7)
55+
LOCAL_SRC_FILES += \
56+
$(ENC_SRC)/asm/ARMV5E/AutoCorrelation_v5.s \
57+
$(ENC_SRC)/asm/ARMV5E/band_nrg_v5.s \
58+
$(ENC_SRC)/asm/ARMV5E/CalcWindowEnergy_v5.s \
59+
$(ENC_SRC)/asm/ARMV7/PrePostMDCT_v7.s \
60+
$(ENC_SRC)/asm/ARMV7/R4R8First_v7.s \
61+
$(ENC_SRC)/asm/ARMV7/Radix4FFT_v7.s
62+
endif
63+
64+
LOCAL_ARM_MODE := arm
65+
66+
LOCAL_LDLIBS := -llog
67+
68+
LOCAL_STATIC_LIBRARIES :=
69+
LOCAL_SHARED_LIBRARIES :=
70+
71+
LOCAL_CFLAGS := $(VO_CFLAGS)
72+
73+
ifeq ($(VOTT), v5)
74+
LOCAL_CFLAGS += -DARMV5E -DARM_INASM -DARMV5_INASM
75+
LOCAL_C_INCLUDES += $(ENC_SRC)/asm/ARMV5E
76+
endif
77+
78+
ifeq ($(VOTT), v7)
79+
LOCAL_CFLAGS += -DARMV5E -DARMV7Neon -DARM_INASM -DARMV5_INASM -DARMV6_INASM
80+
LOCAL_C_INCLUDES += $(ENC_SRC)/asm/ARMV5E
81+
LOCAL_C_INCLUDES += $(ENC_SRC)/asm/ARMV7
82+
endif
83+
84+
include $(BUILD_SHARED_LIBRARY)
85+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#
2+
# This configure file is just for Linux projects against Android
3+
#
4+
5+
VOPRJ :=
6+
VONJ :=
7+
8+
# WARNING:
9+
# Using v7 breaks generic build
10+
ifeq ($(TARGET_ARCH),arm)
11+
VOTT := v5
12+
else
13+
VOTT := pc
14+
endif
15+
16+
# Do we also need to check on ARCH_ARM_HAVE_ARMV7A? - probably not
17+
ifeq ($(ARCH_ARM_HAVE_NEON),true)
18+
VOTT := v7
19+
endif
20+
21+
VOTEST := 0
22+
23+
VO_CFLAGS:=-DLINUX
24+
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
#include <string.h>
2+
#include <stdio.h>
3+
#include <jni.h>
4+
#include <inc/voAAC.h>
5+
#include <inc/cmnMemory.h>
6+
#include <android/log.h>
7+
8+
#define DEBUG 0
9+
10+
#if DEBUG
11+
#define LOG(msg, args...) __android_log_print(ANDROID_LOG_ERROR, "aac-enc", msg, ## args)
12+
#else
13+
#define LOG(msg, args...)
14+
#endif
15+
16+
/* utility functions */
17+
18+
void throwException(JNIEnv* env, const char *name, const char *msg)
19+
{
20+
jclass cls = (*env)->FindClass(env, name);
21+
/* if cls is NULL, an exception has already been thrown */
22+
if (cls != NULL) {
23+
(*env)->ThrowNew(env, cls, msg);
24+
}
25+
/* free the local ref */
26+
(*env)->DeleteLocalRef(env, cls);
27+
}
28+
29+
/* internal storage */
30+
31+
FILE* outfile;
32+
33+
VO_AUDIO_CODECAPI codec_api;
34+
VO_HANDLE handle = 0;
35+
VO_AUDIO_CODECAPI codec_api = { 0 };
36+
VO_MEM_OPERATOR mem_operator = { 0 };
37+
VO_CODEC_INIT_USERDATA user_data;
38+
AACENC_PARAM params = { 0 };
39+
40+
/* java native functions */
41+
42+
void
43+
Java_com_todoroo_aacenc_AACEncoder_init( JNIEnv* env,
44+
jobject thiz,
45+
int bitrate,
46+
int channels,
47+
int sampleRate,
48+
int bitsPerSample,
49+
jstring outputFile)
50+
{
51+
52+
if (bitsPerSample != 16) {
53+
throwException(env, "java/lang/IllegalArgumentException",
54+
"Unsupported sample depth. Only 16 bits per sample is supported");
55+
return;
56+
}
57+
58+
voGetAACEncAPI(&codec_api);
59+
60+
mem_operator.Alloc = cmnMemAlloc;
61+
mem_operator.Copy = cmnMemCopy;
62+
mem_operator.Free = cmnMemFree;
63+
mem_operator.Set = cmnMemSet;
64+
mem_operator.Check = cmnMemCheck;
65+
user_data.memflag = VO_IMF_USERMEMOPERATOR;
66+
user_data.memData = &mem_operator;
67+
codec_api.Init(&handle, VO_AUDIO_CodingAAC, &user_data);
68+
69+
params.sampleRate = sampleRate;
70+
params.bitRate = bitrate;
71+
params.nChannels = channels;
72+
params.adtsUsed = 1;
73+
74+
if (codec_api.SetParam(handle, VO_PID_AAC_ENCPARAM, &params) != VO_ERR_NONE) {
75+
throwException(env, "java/lang/IllegalArgumentException",
76+
"Unable to set encoding parameters");
77+
return;
78+
}
79+
80+
const char* output_file = (*env)->GetStringUTFChars(env, outputFile, (jboolean) 0);
81+
outfile = fopen(output_file, "wb");
82+
LOG("writing to %s", output_file);
83+
(*env)->ReleaseStringUTFChars(env, outputFile, output_file);
84+
85+
LOG("initialized handle: %x", handle);
86+
87+
}
88+
89+
void
90+
Java_com_todoroo_aacenc_AACEncoder_encode( JNIEnv* env,
91+
jobject thiz,
92+
jbyteArray inputArray)
93+
{
94+
95+
LOG("writing to handle: %x", handle);
96+
97+
jbyte* buffer = (*env)->GetByteArrayElements(env, inputArray, (jboolean) 0);
98+
int inputSize = (*env)->GetArrayLength(env, inputArray);
99+
100+
VO_CODECBUFFER input = { 0 }, output = { 0 };
101+
VO_AUDIO_OUTPUTINFO output_info = { 0 };
102+
103+
int readSize = params.nChannels * 2 * 1024;
104+
uint16_t* outbuf = (uint16_t*) malloc(readSize * 2);
105+
106+
LOG("input buffer: %d", inputSize);
107+
108+
/* GET OUTPUT DATA */
109+
int i;
110+
for(i = 0; i < inputSize; i += readSize) {
111+
112+
input.Buffer = buffer + i;
113+
input.Length = readSize;
114+
codec_api.SetInputData(handle, &input);
115+
116+
output.Buffer = outbuf;
117+
output.Length = readSize * 2;
118+
119+
int status = codec_api.GetOutputData(handle, &output, &output_info);
120+
if (status == VO_ERR_INPUT_BUFFER_SMALL)
121+
break;
122+
123+
if (status == VO_ERR_OUTPUT_BUFFER_SMALL) {
124+
LOG("output buffer was too small, read %d", output_info.InputUsed);
125+
} else if (status != VO_ERR_NONE) {
126+
char message[100];
127+
sprintf(message, "Unable to encode frame: %x", status);
128+
throwException(env, "java/lang/RuntimeException", message);
129+
return;
130+
}
131+
132+
fwrite(outbuf, 1, output.Length, outfile);
133+
}
134+
135+
LOG("finished output");
136+
(*env)->ReleaseByteArrayElements(env, inputArray, buffer, JNI_ABORT);
137+
free(outbuf);
138+
}
139+
140+
void
141+
Java_com_todoroo_aacenc_AACEncoder_uninit( JNIEnv* env,
142+
jobject thiz)
143+
{
144+
145+
fclose(outfile);
146+
codec_api.Uninit(handle);
147+
148+
}
149+
150+
JNIEXPORT jint JNICALL
151+
JNI_OnLoad (JavaVM * vm, void * reserved)
152+
{
153+
return JNI_VERSION_1_6;
154+
}

0 commit comments

Comments
 (0)