[DEV] rename android interface for java
This commit is contained in:
parent
36b0231a11
commit
3a0ab73a3a
@ -1,92 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN, Kevin BILLONNEAU
|
||||
*
|
||||
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.musicdsp.orchestra;
|
||||
|
||||
import android.media.AudioTrack;
|
||||
// Replace by :
|
||||
import android.media.AudioRecord;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
|
||||
public class InterfaceInput extends Thread implements Constants {
|
||||
private int uid = -1;
|
||||
private Orchestra ORCHESTRA;
|
||||
public static final int SAMPLE_FREQ_44100 = 44100;
|
||||
private boolean m_stopAudioThreads = false;
|
||||
private AudioTrack m_musicTrack = null;
|
||||
|
||||
public InterfaceInput(int id, Orchestra instance, int idDevice, int freq, int nbChannel, int format) {
|
||||
Log.d("InterfaceInput", "new: output");
|
||||
uid = id;
|
||||
ORCHESTRA = instance;
|
||||
m_stopAudioThreads = false;
|
||||
}
|
||||
public int getUId() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
|
||||
public void run() {
|
||||
Log.e("InterfaceInput", "RUN (start)");
|
||||
int sampleFreq = SAMPLE_FREQ_44100; //AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
|
||||
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
int nbChannels = 2;
|
||||
// we keep the minimum buffer size, otherwite the delay is too big ...
|
||||
int bufferSize = AudioTrack.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
|
||||
// Create a streaming AudioTrack for music playback
|
||||
short[] streamBuffer = new short[bufferSize];
|
||||
m_musicTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||
SAMPLE_FREQ_44100,
|
||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
|
||||
AudioFormat.ENCODING_PCM_16BIT,
|
||||
bufferSize,
|
||||
AudioTrack.MODE_STREAM);
|
||||
m_musicTrack.play();
|
||||
m_stopAudioThreads = false;
|
||||
//m_musicTrack.setPositionNotificationPeriod(2048);
|
||||
|
||||
|
||||
// TODO : ....
|
||||
while (!m_stopAudioThreads) {
|
||||
// Fill buffer with PCM data from C++
|
||||
ORCHESTRA.playback(uid, streamBuffer, BUFFER_SIZE);
|
||||
// Stream PCM data into the music AudioTrack
|
||||
m_musicTrack.write(streamBuffer, 0, BUFFER_SIZE);
|
||||
}
|
||||
|
||||
m_musicTrack.flush();
|
||||
m_musicTrack.stop();
|
||||
m_musicTrack = null;
|
||||
streamBuffer = null;
|
||||
Log.e("InterfaceInput", "RUN (stop)");
|
||||
}
|
||||
public void Pause() {
|
||||
if(m_musicTrack == null) {
|
||||
return;
|
||||
}
|
||||
m_musicTrack.pause();
|
||||
}
|
||||
public void Resume() {
|
||||
if(m_musicTrack == null) {
|
||||
return;
|
||||
}
|
||||
m_musicTrack.play();
|
||||
}
|
||||
public void AutoStop() {
|
||||
if(m_musicTrack == null) {
|
||||
return;
|
||||
}
|
||||
m_stopAudioThreads=true;
|
||||
}
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
/**
|
||||
* @author Edouard DUPIN, Kevin BILLONNEAU
|
||||
*
|
||||
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
package org.musicdsp.orchestra;
|
||||
|
||||
import android.media.AudioTrack;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class InterfaceOutput extends Thread implements Constants {
|
||||
private int uid = -1;
|
||||
private Orchestra ORCHESTRA;
|
||||
public static final int SAMPLE_FREQ_44100 = 44100;
|
||||
private boolean m_stopAudioThreads = false;
|
||||
private AudioTrack m_musicTrack = null;
|
||||
|
||||
public InterfaceOutput(int id, Orchestra instance, int idDevice, int freq, int nbChannel, int format) {
|
||||
Log.d("InterfaceOutput", "new: output");
|
||||
uid = id;
|
||||
ORCHESTRA = instance;
|
||||
m_stopAudioThreads = false;
|
||||
}
|
||||
public int getUId() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Log.e("InterfaceOutput", "RUN (start)");
|
||||
int sampleFreq = SAMPLE_FREQ_44100; //AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
|
||||
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
int nbChannels = 2;
|
||||
// we keep the minimum buffer size, otherwite the delay is too big ...
|
||||
int bufferSize = AudioTrack.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
|
||||
// Create a streaming AudioTrack for music playback
|
||||
short[] streamBuffer = new short[bufferSize];
|
||||
m_musicTrack = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||
SAMPLE_FREQ_44100,
|
||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
|
||||
AudioFormat.ENCODING_PCM_16BIT,
|
||||
bufferSize,
|
||||
AudioTrack.MODE_STREAM);
|
||||
m_musicTrack.play();
|
||||
m_stopAudioThreads = false;
|
||||
//m_musicTrack.setPositionNotificationPeriod(2048);
|
||||
|
||||
while (!m_stopAudioThreads) {
|
||||
// Fill buffer with PCM data from C++
|
||||
ORCHESTRA.playback(uid, streamBuffer, BUFFER_SIZE/nbChannels);
|
||||
// Stream PCM data into the music AudioTrack
|
||||
m_musicTrack.write(streamBuffer, 0, BUFFER_SIZE);
|
||||
}
|
||||
|
||||
m_musicTrack.flush();
|
||||
m_musicTrack.stop();
|
||||
m_musicTrack = null;
|
||||
streamBuffer = null;
|
||||
Log.e("InterfaceOutput", "RUN (stop)");
|
||||
}
|
||||
public void Pause() {
|
||||
if(m_musicTrack == null) {
|
||||
return;
|
||||
}
|
||||
m_musicTrack.pause();
|
||||
}
|
||||
public void Resume() {
|
||||
if(m_musicTrack == null) {
|
||||
return;
|
||||
}
|
||||
m_musicTrack.play();
|
||||
}
|
||||
public void AutoStop() {
|
||||
if(m_musicTrack == null) {
|
||||
return;
|
||||
}
|
||||
m_stopAudioThreads=true;
|
||||
}
|
||||
}
|
@ -8,6 +8,6 @@
|
||||
|
||||
package org.musicdsp.orchestra;
|
||||
|
||||
public interface Constants {
|
||||
public interface OrchestraConstants {
|
||||
public static final int BUFFER_SIZE = 512;
|
||||
}
|
83
android/org/musicdsp/orchestra/OrchestraInterfaceInput.java
Normal file
83
android/org/musicdsp/orchestra/OrchestraInterfaceInput.java
Normal file
@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @author Edouard DUPIN, Kevin BILLONNEAU
|
||||
*
|
||||
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
|
||||
package org.musicdsp.orchestra;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaRecorder;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
|
||||
public class OrchestraInterfaceInput extends Thread implements OrchestraConstants {
|
||||
private int m_uid = -1;
|
||||
private OrchestraNative m_orchestraNativeHandle;
|
||||
public static final int SAMPLE_FREQ_44100 = 44100;
|
||||
private boolean m_stop = false;
|
||||
private AudioRecord m_audio = null;
|
||||
|
||||
public OrchestraInterfaceInput(int id, OrchestraNative instance, int idDevice, int freq, int nbChannel, int format) {
|
||||
Log.d("InterfaceInput", "new: output");
|
||||
m_uid = id;
|
||||
m_orchestraNativeHandle = instance;
|
||||
m_stop = false;
|
||||
}
|
||||
public int getUId() {
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Log.e("InterfaceInput", "RUN (start)");
|
||||
int sampleFreq = 48000;
|
||||
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
int nbChannels = 2;
|
||||
// we keep the minimum buffer size, otherwite the delay is too big ...
|
||||
int bufferSize = AudioRecord.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
|
||||
// Create a streaming AudioTrack for music playback
|
||||
short[] streamBuffer = new short[bufferSize];
|
||||
m_audio = new AudioRecord(MediaRecorder.AudioSource.MIC,
|
||||
sampleFreq,
|
||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
|
||||
AudioFormat.ENCODING_PCM_16BIT,
|
||||
bufferSize);
|
||||
m_audio.startRecording();
|
||||
m_stop = false;
|
||||
|
||||
while (m_stop == false) {
|
||||
// Stream PCM data into the local buffer
|
||||
m_audio.read(streamBuffer, 0, BUFFER_SIZE);
|
||||
// Send it to C++
|
||||
m_orchestraNativeHandle.record(m_uid, streamBuffer, BUFFER_SIZE/nbChannels);
|
||||
}
|
||||
m_audio.stop();
|
||||
m_audio = null;
|
||||
streamBuffer = null;
|
||||
Log.e("InterfaceInput", "RUN (stop)");
|
||||
}
|
||||
public void autoStop() {
|
||||
if(m_audio == null) {
|
||||
return;
|
||||
}
|
||||
m_stop=true;
|
||||
}
|
||||
public void activityResume() {
|
||||
if(m_audio == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
public void activityPause() {
|
||||
if(m_audio == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
84
android/org/musicdsp/orchestra/OrchestraInterfaceOutput.java
Normal file
84
android/org/musicdsp/orchestra/OrchestraInterfaceOutput.java
Normal file
@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @author Edouard DUPIN, Kevin BILLONNEAU
|
||||
*
|
||||
* @copyright 2015, Edouard DUPIN, all right reserved
|
||||
*
|
||||
* @license APACHE v2.0 (see license file)
|
||||
*/
|
||||
package org.musicdsp.orchestra;
|
||||
|
||||
import android.media.AudioTrack;
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioManager;
|
||||
import android.media.AudioRecord;
|
||||
import android.util.Log;
|
||||
|
||||
|
||||
public class OrchestraInterfaceOutput extends Thread implements OrchestraConstants {
|
||||
private int m_uid = -1;
|
||||
private OrchestraNative m_orchestraNativeHandle;
|
||||
private boolean m_stop = false;
|
||||
private boolean m_suspend = false;
|
||||
private AudioTrack m_audio = null;
|
||||
|
||||
public OrchestraInterfaceOutput(int id, OrchestraNative instance, int idDevice, int freq, int nbChannel, int format) {
|
||||
Log.d("InterfaceOutput", "new: output");
|
||||
m_uid = id;
|
||||
m_orchestraNativeHandle = instance;
|
||||
m_stop = false;
|
||||
}
|
||||
public int getUId() {
|
||||
return m_uid;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
Log.e("InterfaceOutput", "RUN (start)");
|
||||
int sampleFreq = 48000; //AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
|
||||
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
int nbChannels = 2;
|
||||
// we keep the minimum buffer size, otherwite the delay is too big ...
|
||||
int bufferSize = AudioTrack.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
|
||||
// Create a streaming AudioTrack for music playback
|
||||
short[] streamBuffer = new short[bufferSize];
|
||||
m_audio = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||
sampleFreq,
|
||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
|
||||
AudioFormat.ENCODING_PCM_16BIT,
|
||||
bufferSize,
|
||||
AudioTrack.MODE_STREAM);
|
||||
m_audio.play();
|
||||
//m_audio.setPositionNotificationPeriod(2048);
|
||||
|
||||
while (m_stop == false) {
|
||||
// Fill buffer with PCM data from C++
|
||||
m_orchestraNativeHandle.playback(m_uid, streamBuffer, BUFFER_SIZE/nbChannels);
|
||||
// Stream PCM data into the music AudioTrack
|
||||
m_audio.write(streamBuffer, 0, BUFFER_SIZE);
|
||||
}
|
||||
|
||||
m_audio.flush();
|
||||
m_audio.stop();
|
||||
m_audio = null;
|
||||
streamBuffer = null;
|
||||
Log.e("InterfaceOutput", "RUN (stop)");
|
||||
}
|
||||
public void autoStop() {
|
||||
if(m_audio == null) {
|
||||
return;
|
||||
}
|
||||
m_stop=true;
|
||||
}
|
||||
public void activityResume() {
|
||||
if(m_audio == null) {
|
||||
return;
|
||||
}
|
||||
m_audio.play();
|
||||
}
|
||||
public void activityPause() {
|
||||
if(m_audio == null) {
|
||||
return;
|
||||
}
|
||||
m_audio.pause();
|
||||
}
|
||||
}
|
@ -13,25 +13,25 @@ import java.util.Vector;
|
||||
|
||||
//import org.musicdsp.orchestra.Constants;
|
||||
//import org.musicdsp.orchestra.ManagerCallback;
|
||||
import org.musicdsp.orchestra.Orchestra;
|
||||
import org.musicdsp.orchestra.InterfaceOutput;
|
||||
import org.musicdsp.orchestra.InterfaceInput;
|
||||
//import org.musicdsp.orchestra.Orchestra;
|
||||
//import org.musicdsp.orchestra.InterfaceOutput;
|
||||
//import org.musicdsp.orchestra.InterfaceInput;
|
||||
|
||||
/**
|
||||
* @brief Class :
|
||||
*
|
||||
*/
|
||||
public class Manager implements ManagerCallback, Constants {
|
||||
private Orchestra orchestraHandle;
|
||||
public class OrchestraManager implements OrchestraManagerCallback, OrchestraConstants {
|
||||
private OrchestraNative orchestraHandle;
|
||||
private int uid = 0;
|
||||
private Vector<InterfaceOutput> outputList;
|
||||
private Vector<InterfaceInput> inputList;
|
||||
private Vector<OrchestraInterfaceOutput> outputList;
|
||||
private Vector<OrchestraInterfaceInput> inputList;
|
||||
|
||||
public Manager() {
|
||||
public OrchestraManager() {
|
||||
// set the java evironement in the C sources :
|
||||
orchestraHandle = new Orchestra(this);
|
||||
outputList = new Vector<InterfaceOutput>();
|
||||
inputList = new Vector<InterfaceInput>();
|
||||
orchestraHandle = new OrchestraNative(this);
|
||||
outputList = new Vector<OrchestraInterfaceOutput>();
|
||||
inputList = new Vector<OrchestraInterfaceInput>();
|
||||
}
|
||||
|
||||
public int getDeviceCount() {
|
||||
@ -55,7 +55,7 @@ public class Manager implements ManagerCallback, Constants {
|
||||
}
|
||||
|
||||
public int openDeviceOutput(int idDevice, int freq, int nbChannel, int format) {
|
||||
InterfaceOutput iface = new InterfaceOutput(uid, orchestraHandle, idDevice, freq, nbChannel, format);
|
||||
OrchestraInterfaceOutput iface = new OrchestraInterfaceOutput(uid, orchestraHandle, idDevice, freq, nbChannel, format);
|
||||
uid++;
|
||||
Log.e("Manager", "Open device Output: " + idDevice + " with UID=" + (uid-1));
|
||||
if (iface != null) {
|
||||
@ -67,7 +67,7 @@ public class Manager implements ManagerCallback, Constants {
|
||||
}
|
||||
|
||||
public int openDeviceInput(int idDevice, int freq, int nbChannel, int format) {
|
||||
InterfaceInput iface = new InterfaceInput(uid, orchestraHandle, idDevice, freq, nbChannel, format);
|
||||
OrchestraInterfaceInput iface = new OrchestraInterfaceInput(uid, orchestraHandle, idDevice, freq, nbChannel, format);
|
||||
uid++;
|
||||
Log.e("Manager", "Open device Input: " + idDevice + " with UID=" + (uid-1));
|
||||
if (iface != null) {
|
||||
@ -166,7 +166,7 @@ public class Manager implements ManagerCallback, Constants {
|
||||
}
|
||||
if (inputList.get(iii).getUId() == uniqueID) {
|
||||
// find it ...
|
||||
inputList.get(iii).AutoStop();
|
||||
inputList.get(iii).autoStop();
|
||||
try {
|
||||
inputList.get(iii).join();
|
||||
} catch(InterruptedException e) { }
|
||||
@ -182,7 +182,7 @@ public class Manager implements ManagerCallback, Constants {
|
||||
}
|
||||
if (outputList.get(iii).getUId() == uniqueID) {
|
||||
// find it ...
|
||||
outputList.get(iii).AutoStop();
|
||||
outputList.get(iii).autoStop();
|
||||
try {
|
||||
outputList.get(iii).join();
|
||||
} catch(InterruptedException e) { }
|
||||
@ -195,18 +195,59 @@ public class Manager implements ManagerCallback, Constants {
|
||||
}
|
||||
public void onCreate() {
|
||||
Log.w("Manager", "onCreate ...");
|
||||
// nothing to do ...
|
||||
}
|
||||
public void onStart() {
|
||||
Log.w("Manager", "onStart ...");
|
||||
// nothing to do ...
|
||||
}
|
||||
public void onRestart() {
|
||||
Log.w("Manager", "onRestart ...");
|
||||
// nothing to do ...
|
||||
}
|
||||
public void onResume() {
|
||||
Log.w("Manager", "onResume ...");
|
||||
// find the Element with his ID:
|
||||
if (inputList != null) {
|
||||
for (int iii=0; iii<inputList.size(); iii++) {
|
||||
if (inputList.get(iii) == null) {
|
||||
Log.e("Manager", "Null input element: " + iii);
|
||||
continue;
|
||||
}
|
||||
inputList.get(iii).activityResume();
|
||||
}
|
||||
}
|
||||
if (outputList != null) {
|
||||
for (int iii=0; iii<outputList.size(); iii++) {
|
||||
if (outputList.get(iii) == null) {
|
||||
Log.e("Manager", "Null input element: " + iii);
|
||||
continue;
|
||||
}
|
||||
outputList.get(iii).activityResume();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onPause() {
|
||||
Log.w("Manager", "onPause ...");
|
||||
// find the Element with his ID:
|
||||
if (inputList != null) {
|
||||
for (int iii=0; iii<inputList.size(); iii++) {
|
||||
if (inputList.get(iii) == null) {
|
||||
Log.e("Manager", "Null input element: " + iii);
|
||||
continue;
|
||||
}
|
||||
inputList.get(iii).activityPause();
|
||||
}
|
||||
}
|
||||
if (outputList != null) {
|
||||
for (int iii=0; iii<outputList.size(); iii++) {
|
||||
if (outputList.get(iii) == null) {
|
||||
Log.e("Manager", "Null input element: " + iii);
|
||||
continue;
|
||||
}
|
||||
outputList.get(iii).activityPause();
|
||||
}
|
||||
}
|
||||
}
|
||||
public void onStop() {
|
||||
Log.w("Manager", "onStop ...");
|
@ -8,7 +8,7 @@
|
||||
|
||||
package org.musicdsp.orchestra;
|
||||
|
||||
public interface ManagerCallback {
|
||||
public interface OrchestraManagerCallback {
|
||||
public int getDeviceCount();
|
||||
public String getDeviceProperty(int idDevice);
|
||||
public int openDeviceInput(int idDevice, int sampleRate, int nbChannel, int format);
|
@ -12,8 +12,8 @@ import java.lang.UnsatisfiedLinkError;
|
||||
import java.lang.RuntimeException;
|
||||
import android.util.Log;
|
||||
|
||||
public class Orchestra {
|
||||
public <T extends ManagerCallback> Orchestra(T managerInstance) {
|
||||
public class OrchestraNative {
|
||||
public <T extends OrchestraManagerCallback> OrchestraNative(T managerInstance) {
|
||||
try {
|
||||
NNsetJavaManager(managerInstance);
|
||||
} catch (java.lang.UnsatisfiedLinkError e) {
|
||||
@ -31,8 +31,13 @@ public class Orchestra {
|
||||
NNPlayback(flowId, bufferData, nbChunk);
|
||||
}
|
||||
|
||||
private native <T extends ManagerCallback> void NNsetJavaManager(T managerInstance);
|
||||
public void record(int flowId, short[] bufferData, int nbChunk) {
|
||||
NNRecord(flowId, bufferData, nbChunk);
|
||||
}
|
||||
|
||||
private native <T extends OrchestraManagerCallback> void NNsetJavaManager(T managerInstance);
|
||||
private native void NNsetJavaManagerRemove();
|
||||
private native void NNPlayback(int flowId, short[] bufferData, int nbChunk);
|
||||
private native void NNRecord(int flowId, short[] bufferData, int nbChunk);
|
||||
}
|
||||
|
@ -1564,7 +1564,7 @@ unlock:
|
||||
|
||||
|
||||
bool audio::orchestra::api::Alsa::isMasterOf(std11::shared_ptr<audio::orchestra::Api> _api) {
|
||||
std11::shared_ptr<audio::orchestra::api::Alsa> slave = dynamic_pointer_cast<audio::orchestra::api::Alsa>(_api);
|
||||
std11::shared_ptr<audio::orchestra::api::Alsa> slave = std::dynamic_pointer_cast<audio::orchestra::api::Alsa>(_api);
|
||||
if (slave == nullptr) {
|
||||
ATA_ERROR("NULL ptr API (not ALSA ...)");
|
||||
return false;
|
||||
|
@ -103,6 +103,36 @@ void audio::orchestra::api::Android::playback(int16_t* _dst, int32_t _nbChunk) {
|
||||
audio::orchestra::Api::tickStreamTime();
|
||||
}
|
||||
|
||||
void audio::orchestra::api::Android::record(int16_t* _dst, int32_t _nbChunk) {
|
||||
int32_t doStopStream = 0;
|
||||
audio::Time streamTime = getStreamTime();
|
||||
std::vector<enum audio::orchestra::status> status;
|
||||
if (m_doConvertBuffer[modeToIdTable(m_mode)] == true) {
|
||||
ATA_VERBOSE("Need playback data " << int32_t(_nbChunk) << " userbuffer size = " << m_userBuffer[audio::orchestra::mode_output].size() << "pointer=" << int64_t(&m_userBuffer[audio::orchestra::mode_output][0]));
|
||||
convertBuffer((char*)&m_userBuffer[audio::orchestra::mode_input][0], (char*)_dst, m_convertInfo[audio::orchestra::mode_input]);
|
||||
doStopStream = m_callback(&m_userBuffer[m_mode][0],
|
||||
streamTime,
|
||||
nullptr,
|
||||
audio::Time(),
|
||||
uint32_t(_nbChunk),
|
||||
status);
|
||||
} else {
|
||||
ATA_VERBOSE("Need playback data " << int32_t(_nbChunk) << " pointer=" << int64_t(_dst));
|
||||
doStopStream = m_callback(_dst,
|
||||
streamTime,
|
||||
nullptr,
|
||||
audio::Time(),
|
||||
uint32_t(_nbChunk),
|
||||
status);
|
||||
|
||||
}
|
||||
if (doStopStream == 2) {
|
||||
abortStream();
|
||||
return;
|
||||
}
|
||||
audio::orchestra::Api::tickStreamTime();
|
||||
}
|
||||
|
||||
bool audio::orchestra::api::Android::probeDeviceOpen(uint32_t _device,
|
||||
audio::orchestra::mode _mode,
|
||||
uint32_t _channels,
|
||||
|
@ -51,6 +51,7 @@ namespace audio {
|
||||
const audio::orchestra::StreamOptions& _options);
|
||||
public:
|
||||
void playback(int16_t* _dst, int32_t _nbChunk);
|
||||
void record(int16_t* _dst, int32_t _nbChunk);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -97,10 +97,10 @@ class AndroidOrchestraContext {
|
||||
ATA_ERROR("C->java: NULLPTR jvm interface");
|
||||
return;
|
||||
}
|
||||
ATA_DEBUG("C->java: try load org/musicdsp/orchestra/Orchestra class");
|
||||
m_javaClassOrchestra = m_JavaVirtualMachinePointer->FindClass("org/musicdsp/orchestra/Orchestra" );
|
||||
ATA_DEBUG("C->java: try load org/musicdsp/orchestra/OrchestraNative class");
|
||||
m_javaClassOrchestra = m_JavaVirtualMachinePointer->FindClass("org/musicdsp/orchestra/OrchestraNative" );
|
||||
if (m_javaClassOrchestra == 0) {
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/Orchestra class");
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/OrchestraNative class");
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
return;
|
||||
@ -108,7 +108,7 @@ class AndroidOrchestraContext {
|
||||
/* The object field extends Activity and implement OrchestraCallback */
|
||||
m_javaClassOrchestraCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback);
|
||||
if(m_javaClassOrchestraCallback == nullptr) {
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/ManagerCallback class");
|
||||
ATA_ERROR("C->java : Can't find org/musicdsp/orchestra/OrchestraManagerCallback class");
|
||||
// remove access on the virtual machine :
|
||||
m_JavaVirtualMachinePointer = nullptr;
|
||||
return;
|
||||
@ -378,6 +378,20 @@ class AndroidOrchestraContext {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
void record(int32_t _id, int16_t* _dst, int32_t _nbChunk) {
|
||||
auto it = m_instanceList.begin();
|
||||
while (it != m_instanceList.end()) {
|
||||
auto elem = it->lock();
|
||||
if (elem == nullptr) {
|
||||
it = m_instanceList.erase(it);
|
||||
continue;
|
||||
}
|
||||
if (elem->getUId() == _id) {
|
||||
elem->record(_dst, _nbChunk);
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static std::shared_ptr<AndroidOrchestraContext> s_localContext;
|
||||
@ -442,9 +456,9 @@ enum audio::orchestra::error audio::orchestra::api::android::abortStream(int32_t
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void Java_org_musicdsp_orchestra_Orchestra_NNsetJavaManager(JNIEnv* _env,
|
||||
jclass _classBase,
|
||||
jobject _objCallback) {
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNsetJavaManager(JNIEnv* _env,
|
||||
jclass _classBase,
|
||||
jobject _objCallback) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
ATA_INFO("*******************************************");
|
||||
ATA_INFO("** Creating Orchestra context **");
|
||||
@ -460,7 +474,7 @@ extern "C" {
|
||||
s_nbContextRequested++;
|
||||
}
|
||||
|
||||
void Java_org_musicdsp_orchestra_Orchestra_NNsetJavaManagerRemove(JNIEnv* _env, jclass _cls) {
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNsetJavaManagerRemove(JNIEnv* _env, jclass _cls) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
ATA_INFO("*******************************************");
|
||||
ATA_INFO("** remove Orchestra Pointer **");
|
||||
@ -474,11 +488,11 @@ extern "C" {
|
||||
s_localContext.reset();
|
||||
}
|
||||
}
|
||||
void Java_org_musicdsp_orchestra_Orchestra_NNPlayback(JNIEnv* _env,
|
||||
void* _reserved,
|
||||
jint _id,
|
||||
jshortArray _location,
|
||||
jint _nbChunk) {
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNPlayback(JNIEnv* _env,
|
||||
void* _reserved,
|
||||
jint _id,
|
||||
jshortArray _location,
|
||||
jint _nbChunk) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
if (s_localContext == nullptr) {
|
||||
ATA_ERROR("Call audio with no more Low level interface");
|
||||
@ -497,5 +511,28 @@ extern "C" {
|
||||
_env->ReleaseShortArrayElements(_location, dst, 0);
|
||||
//}
|
||||
}
|
||||
void Java_org_musicdsp_orchestra_OrchestraNative_NNRecord(JNIEnv* _env,
|
||||
void* _reserved,
|
||||
jint _id,
|
||||
jshortArray _location,
|
||||
jint _nbChunk) {
|
||||
std::unique_lock<std::mutex> lock(jvm_basics::getMutexJavaVM());
|
||||
if (s_localContext == nullptr) {
|
||||
ATA_ERROR("Call audio with no more Low level interface");
|
||||
return;
|
||||
}
|
||||
// get the short* pointer from the Java array
|
||||
jboolean isCopy;
|
||||
jshort* dst = _env->GetShortArrayElements(_location, &isCopy);
|
||||
if (dst != nullptr) {
|
||||
//ATA_INFO("Need audioData " << int32_t(_nbChunk));
|
||||
s_localContext->record(int32_t(_id), static_cast<short*>(dst), int32_t(_nbChunk));
|
||||
}
|
||||
// TODO : Understand why it did not work corectly ...
|
||||
//if (isCopy == JNI_TRUE) {
|
||||
// release the short* pointer
|
||||
_env->ReleaseShortArrayElements(_location, dst, 0);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,14 +63,14 @@ def create(target):
|
||||
# IOsX core
|
||||
myModule.add_optionnal_module_depend('CoreAudio', ["c++", "-DORCHESTRA_BUILD_IOS_CORE"])
|
||||
elif target.name=="Android":
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/Constants.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/ManagerCallback.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/Orchestra.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/InterfaceInput.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/InterfaceOutput.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/Manager.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/OrchestraConstants.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/OrchestraManagerCallback.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/OrchestraNative.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/OrchestraInterfaceInput.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/OrchestraInterfaceOutput.java')
|
||||
myModule.add_src_file('android/org/musicdsp/orchestra/OrchestraManager.java')
|
||||
# create inter language interface
|
||||
myModule.add_src_file('org.musicdsp.orchestra.Constants.javah')
|
||||
myModule.add_src_file('org.musicdsp.orchestra.OrchestraConstants.javah')
|
||||
myModule.add_path(tools.get_current_path(__file__) + '/android/', type='java')
|
||||
myModule.add_module_depend(['SDK', 'jvm-basics', 'ejson'])
|
||||
myModule.add_export_flag('c++', ['-DORCHESTRA_BUILD_JAVA'])
|
||||
@ -95,15 +95,15 @@ def create(target):
|
||||
##################################################################
|
||||
def tool_generate_add_java_section_in_class(target, module, package_name):
|
||||
module.pkg_add("GENERATE_SECTION__IMPORT", [
|
||||
"import org.musicdsp.orchestra.Manager;"
|
||||
"import org.musicdsp.orchestra.OrchestraManager;"
|
||||
])
|
||||
module.pkg_add("GENERATE_SECTION__DECLARE", [
|
||||
"private Manager m_audioManagerHandle;"
|
||||
"private OrchestraManager m_audioManagerHandle;"
|
||||
])
|
||||
module.pkg_add("GENERATE_SECTION__CONSTRUCTOR", [
|
||||
"// load audio maneger if it does not work, it is not critical ...",
|
||||
"try {",
|
||||
" m_audioManagerHandle = new Manager();",
|
||||
" m_audioManagerHandle = new OrchestraManager();",
|
||||
"} catch (RuntimeException e) {",
|
||||
" Log.e(\"" + package_name + "\", \"Can not load Audio interface (maybe not really needed) :\" + e);",
|
||||
"}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user