Reputation: 1219
Hello I am encoding the wav data into the ogg vorbis in android. I am using the a simple JNI wrapper for the libogg-vorbis library from Xiph.org. When I create the object of VorbisFileOutputStream
then program throw exeception java.lang.UnsatisfiedLinkError: create
VorbisFileOutputStream.java
public class VorbisFileOutputStream extends AudioOutputStream {
// The index into native memory where the ogg stream info is stored.
private final int oggStreamIdx;
private VorbisInfo info;
private static final int VORBIS_BLOCK_SIZE = 1024;
static {
System.loadLibrary("ogg");
System.loadLibrary("vorbis");
System.loadLibrary("vorbis-stream");
}
public VorbisFileOutputStream (String fname, VorbisInfo s) throws IOException {
info = s;
oggStreamIdx = this.create(fname, s);
}
public VorbisFileOutputStream (String fname) throws IOException {
oggStreamIdx = this.create(fname, new VorbisInfo());
}
@Override
public void close() throws IOException {
this.closeStreamIdx(this.oggStreamIdx);
}
/**
* Write PCM data to ogg. This assumes that you pass your streams in interleaved.
* @param buffer
* @param offset
* @param length
* @return
* @throws java.io.IOException
*/
@Override
public void write(final short [] buffer, int offset, int length) throws IOException {
this.writeStreamIdx(this.oggStreamIdx, buffer, offset, length);
}
private native int writeStreamIdx(int idx, short [] pcmdata, int offset, int size) throws IOException;
private native void closeStreamIdx(int idx) throws IOException;
private native int create(String path, VorbisInfo s) throws IOException;
@Override
public int getSampleRate() {
return info.sampleRate;
}
}
MainActivity.java
try {
vorbisFileOutputStream = new VorbisFileOutputStream(
"/sdcard/demo.ogg");
} catch (IOException e) {
e.printStackTrace();
}
while (isRecording) {
// gets the voice output from microphone to byte format
recorder.read(sData, 0, bufferSize / 2);
System.out.println("Short writing to file" + sData.toString());
try {
// writes the data to file from buffer stores the voice buffer
dataOutputStream.write(short2byte(sData));
vorbisFileOutputStream.write(short2byte(sData));
} catch (IOException e) {
e.printStackTrace();
}
}
Error log :
04-15 16:04:00.515: E/AndroidRuntime(2299): FATAL EXCEPTION: AudioRecorder Thread
04-15 16:04:00.515: E/AndroidRuntime(2299): java.lang.UnsatisfiedLinkError: create
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.VorbisFileOutputStream.create(Native Method)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.VorbisFileOutputStream.<init>(VorbisFileOutputStream.java:33)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.MainActivity.writeAudioDataToFile(MainActivity.java:111)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.MainActivity.access$0(MainActivity.java:93)
04-15 16:04:00.515: E/AndroidRuntime(2299): at com.example.app.MainActivity$1.run(MainActivity.java:48)
04-15 16:04:00.515: E/AndroidRuntime(2299): at java.lang.Thread.run(Thread.java:1019)
Any idea ??
Upvotes: 0
Views: 597
Reputation: 684
First include the .so files in your class by using this code
static
{
System.loadLibrary("library_name"); // Left the 'lib' prefix from .so file
}
Upvotes: 0