[DEV] update java interfaec of Input and output
This commit is contained in:
parent
3a0ab73a3a
commit
09e32a815a
@ -16,18 +16,28 @@ import android.util.Log;
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class OrchestraInterfaceInput extends Thread implements OrchestraConstants {
|
public class OrchestraInterfaceInput implements Runnable, OrchestraConstants {
|
||||||
|
private Thread m_thread = null;
|
||||||
private int m_uid = -1;
|
private int m_uid = -1;
|
||||||
private OrchestraNative m_orchestraNativeHandle;
|
private OrchestraNative m_orchestraNativeHandle;
|
||||||
public static final int SAMPLE_FREQ_44100 = 44100;
|
|
||||||
private boolean m_stop = false;
|
private boolean m_stop = false;
|
||||||
|
private boolean m_suspend = false;
|
||||||
private AudioRecord m_audio = null;
|
private AudioRecord m_audio = null;
|
||||||
|
private int m_sampleRate = 48000;
|
||||||
|
private int m_nbChannel = 2;
|
||||||
|
private int m_format = 1;
|
||||||
|
private int m_bufferSize = BUFFER_SIZE;
|
||||||
|
|
||||||
public OrchestraInterfaceInput(int id, OrchestraNative instance, int idDevice, int freq, int nbChannel, int format) {
|
public OrchestraInterfaceInput(int _id, OrchestraNative _instance, int _idDevice, int _sampleRate, int _nbChannel, int _format) {
|
||||||
Log.d("InterfaceInput", "new: output");
|
Log.d("InterfaceInput", "new: Input");
|
||||||
m_uid = id;
|
m_uid = _id;
|
||||||
m_orchestraNativeHandle = instance;
|
m_orchestraNativeHandle = _instance;
|
||||||
m_stop = false;
|
m_stop = false;
|
||||||
|
m_suspend = false;
|
||||||
|
m_sampleRate = _sampleRate;
|
||||||
|
m_nbChannel = _nbChannel;
|
||||||
|
m_format = _format;
|
||||||
|
m_bufferSize = BUFFER_SIZE * m_nbChannel;
|
||||||
}
|
}
|
||||||
public int getUId() {
|
public int getUId() {
|
||||||
return m_uid;
|
return m_uid;
|
||||||
@ -35,49 +45,75 @@ public class OrchestraInterfaceInput extends Thread implements OrchestraConstant
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.e("InterfaceInput", "RUN (start)");
|
Log.e("InterfaceInput", "RUN (start)");
|
||||||
int sampleFreq = 48000;
|
|
||||||
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||||
int nbChannels = 2;
|
|
||||||
// we keep the minimum buffer size, otherwite the delay is too big ...
|
// we keep the minimum buffer size, otherwite the delay is too big ...
|
||||||
int bufferSize = AudioRecord.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
|
// TODO : int bufferSize = AudioRecord.getMinBufferSize(m_sampleRate, channelConfig, audioFormat);
|
||||||
|
int config = 0;
|
||||||
|
if (m_nbChannel == 1) {
|
||||||
|
config = AudioFormat.CHANNEL_IN_MONO;
|
||||||
|
} else {
|
||||||
|
config = AudioFormat.CHANNEL_IN_STEREO;
|
||||||
|
}
|
||||||
// Create a streaming AudioTrack for music playback
|
// Create a streaming AudioTrack for music playback
|
||||||
short[] streamBuffer = new short[bufferSize];
|
short[] streamBuffer = new short[m_bufferSize];
|
||||||
m_audio = new AudioRecord(MediaRecorder.AudioSource.MIC,
|
m_audio = new AudioRecord(MediaRecorder.AudioSource.MIC,
|
||||||
sampleFreq,
|
m_sampleRate,
|
||||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
|
config,
|
||||||
AudioFormat.ENCODING_PCM_16BIT,
|
audioFormat,
|
||||||
bufferSize);
|
m_bufferSize);
|
||||||
m_audio.startRecording();
|
m_audio.startRecording();
|
||||||
m_stop = false;
|
|
||||||
|
|
||||||
while (m_stop == false) {
|
while ( m_stop == false
|
||||||
|
&& m_suspend == false) {
|
||||||
// Stream PCM data into the local buffer
|
// Stream PCM data into the local buffer
|
||||||
m_audio.read(streamBuffer, 0, BUFFER_SIZE);
|
m_audio.read(streamBuffer, 0, m_bufferSize);
|
||||||
// Send it to C++
|
// Send it to C++
|
||||||
m_orchestraNativeHandle.record(m_uid, streamBuffer, BUFFER_SIZE/nbChannels);
|
m_orchestraNativeHandle.record(m_uid, streamBuffer, m_bufferSize/m_nbChannel);
|
||||||
}
|
}
|
||||||
m_audio.stop();
|
m_audio.stop();
|
||||||
m_audio = null;
|
m_audio = null;
|
||||||
streamBuffer = null;
|
streamBuffer = null;
|
||||||
Log.e("InterfaceInput", "RUN (stop)");
|
Log.e("InterfaceInput", "RUN (stop)");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void autoStart() {
|
||||||
|
m_stop=false;
|
||||||
|
if (m_suspend == false) {
|
||||||
|
Log.e("InterfaceInput", "Create thread");
|
||||||
|
m_thread = new Thread(this);
|
||||||
|
Log.e("InterfaceInput", "start thread");
|
||||||
|
m_thread.start();
|
||||||
|
Log.e("InterfaceInput", "start thread (done)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void autoStop() {
|
public void autoStop() {
|
||||||
if(m_audio == null) {
|
if(m_audio == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_stop=true;
|
m_stop=true;
|
||||||
|
m_thread = null;
|
||||||
|
/*
|
||||||
|
try {
|
||||||
|
super.join();
|
||||||
|
} catch(InterruptedException e) { }
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
public void activityResume() {
|
public void activityResume() {
|
||||||
if(m_audio == null) {
|
m_suspend = false;
|
||||||
return;
|
if (m_stop == false) {
|
||||||
|
Log.i("InterfaceInput", "Resume audio stream : " + m_uid);
|
||||||
|
m_thread = new Thread(this);
|
||||||
|
m_thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void activityPause() {
|
public void activityPause() {
|
||||||
if(m_audio == null) {
|
if(m_audio == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
m_suspend = true;
|
||||||
|
Log.i("InterfaceInput", "Pause audio stream : " + m_uid);
|
||||||
|
m_thread = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,12 +20,20 @@ public class OrchestraInterfaceOutput extends Thread implements OrchestraConstan
|
|||||||
private boolean m_stop = false;
|
private boolean m_stop = false;
|
||||||
private boolean m_suspend = false;
|
private boolean m_suspend = false;
|
||||||
private AudioTrack m_audio = null;
|
private AudioTrack m_audio = null;
|
||||||
|
private int m_sampleRate = 48000;
|
||||||
|
private int m_nbChannel = 2;
|
||||||
|
private int m_format = 1;
|
||||||
|
private int m_bufferSize = BUFFER_SIZE;
|
||||||
|
|
||||||
public OrchestraInterfaceOutput(int id, OrchestraNative instance, int idDevice, int freq, int nbChannel, int format) {
|
public OrchestraInterfaceOutput(int _id, OrchestraNative _instance, int _idDevice, int _sampleRate, int _nbChannel, int _format) {
|
||||||
Log.d("InterfaceOutput", "new: output");
|
Log.d("InterfaceOutput", "new: output");
|
||||||
m_uid = id;
|
m_uid = _id;
|
||||||
m_orchestraNativeHandle = instance;
|
m_orchestraNativeHandle = _instance;
|
||||||
m_stop = false;
|
m_stop = true;
|
||||||
|
m_sampleRate = _sampleRate;
|
||||||
|
m_nbChannel = _nbChannel;
|
||||||
|
m_format = _format;
|
||||||
|
m_bufferSize = BUFFER_SIZE * m_nbChannel;
|
||||||
}
|
}
|
||||||
public int getUId() {
|
public int getUId() {
|
||||||
return m_uid;
|
return m_uid;
|
||||||
@ -33,28 +41,34 @@ public class OrchestraInterfaceOutput extends Thread implements OrchestraConstan
|
|||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
Log.e("InterfaceOutput", "RUN (start)");
|
Log.e("InterfaceOutput", "RUN (start)");
|
||||||
int sampleFreq = 48000; //AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_MUSIC);
|
|
||||||
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_STEREO;
|
||||||
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||||
int nbChannels = 2;
|
|
||||||
// we keep the minimum buffer size, otherwite the delay is too big ...
|
// we keep the minimum buffer size, otherwite the delay is too big ...
|
||||||
int bufferSize = AudioTrack.getMinBufferSize(sampleFreq, channelConfig, audioFormat);
|
//int bufferSize = AudioTrack.getMinBufferSize(m_sampleRate, channelConfig, audioFormat);
|
||||||
|
int config = 0;
|
||||||
|
if (m_nbChannel == 1) {
|
||||||
|
config = AudioFormat.CHANNEL_OUT_MONO;
|
||||||
|
} else if (m_nbChannel == 4) {
|
||||||
|
config = AudioFormat.CHANNEL_OUT_QUAD;
|
||||||
|
} else {
|
||||||
|
config = AudioFormat.CHANNEL_OUT_STEREO;
|
||||||
|
}
|
||||||
// Create a streaming AudioTrack for music playback
|
// Create a streaming AudioTrack for music playback
|
||||||
short[] streamBuffer = new short[bufferSize];
|
short[] streamBuffer = new short[m_bufferSize];
|
||||||
m_audio = new AudioTrack(AudioManager.STREAM_MUSIC,
|
m_audio = new AudioTrack(AudioManager.STREAM_MUSIC,
|
||||||
sampleFreq,
|
m_sampleRate,
|
||||||
AudioFormat.CHANNEL_CONFIGURATION_STEREO,
|
config,
|
||||||
AudioFormat.ENCODING_PCM_16BIT,
|
audioFormat,
|
||||||
bufferSize,
|
m_bufferSize,
|
||||||
AudioTrack.MODE_STREAM);
|
AudioTrack.MODE_STREAM);
|
||||||
m_audio.play();
|
m_audio.play();
|
||||||
//m_audio.setPositionNotificationPeriod(2048);
|
//m_audio.setPositionNotificationPeriod(2048);
|
||||||
|
|
||||||
while (m_stop == false) {
|
while (m_stop == false) {
|
||||||
// Fill buffer with PCM data from C++
|
// Fill buffer with PCM data from C++
|
||||||
m_orchestraNativeHandle.playback(m_uid, streamBuffer, BUFFER_SIZE/nbChannels);
|
m_orchestraNativeHandle.playback(m_uid, streamBuffer, m_bufferSize/m_nbChannel);
|
||||||
// Stream PCM data into the music AudioTrack
|
// Stream PCM data into the music AudioTrack
|
||||||
m_audio.write(streamBuffer, 0, BUFFER_SIZE);
|
m_audio.write(streamBuffer, 0, m_bufferSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_audio.flush();
|
m_audio.flush();
|
||||||
@ -63,22 +77,32 @@ public class OrchestraInterfaceOutput extends Thread implements OrchestraConstan
|
|||||||
streamBuffer = null;
|
streamBuffer = null;
|
||||||
Log.e("InterfaceOutput", "RUN (stop)");
|
Log.e("InterfaceOutput", "RUN (stop)");
|
||||||
}
|
}
|
||||||
|
public void autoStart() {
|
||||||
|
m_stop=false;
|
||||||
|
this.start();
|
||||||
|
}
|
||||||
public void autoStop() {
|
public void autoStop() {
|
||||||
if(m_audio == null) {
|
if(m_audio == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_stop=true;
|
m_stop=true;
|
||||||
|
try {
|
||||||
|
super.join();
|
||||||
|
} catch(InterruptedException e) { }
|
||||||
}
|
}
|
||||||
public void activityResume() {
|
public void activityResume() {
|
||||||
if(m_audio == null) {
|
if (m_audio != null) {
|
||||||
return;
|
Log.i("InterfaceOutput", "Resume audio stream : " + m_uid);
|
||||||
|
m_audio.play();
|
||||||
}
|
}
|
||||||
m_audio.play();
|
|
||||||
}
|
}
|
||||||
public void activityPause() {
|
public void activityPause() {
|
||||||
if(m_audio == null) {
|
if(m_audio == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_audio.pause();
|
if (m_audio != null) {
|
||||||
|
Log.i("InterfaceOutput", "Pause audio stream : " + m_uid);
|
||||||
|
m_audio.pause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,25 +22,25 @@ import java.util.Vector;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class OrchestraManager implements OrchestraManagerCallback, OrchestraConstants {
|
public class OrchestraManager implements OrchestraManagerCallback, OrchestraConstants {
|
||||||
private OrchestraNative orchestraHandle;
|
private OrchestraNative m_orchestraHandle;
|
||||||
private int uid = 0;
|
private int m_uid = 0;
|
||||||
private Vector<OrchestraInterfaceOutput> outputList;
|
private Vector<OrchestraInterfaceOutput> m_outputList;
|
||||||
private Vector<OrchestraInterfaceInput> inputList;
|
private Vector<OrchestraInterfaceInput> m_inputList;
|
||||||
|
|
||||||
public OrchestraManager() {
|
public OrchestraManager() {
|
||||||
// set the java evironement in the C sources :
|
// set the java evironement in the C sources :
|
||||||
orchestraHandle = new OrchestraNative(this);
|
m_orchestraHandle = new OrchestraNative(this);
|
||||||
outputList = new Vector<OrchestraInterfaceOutput>();
|
m_outputList = new Vector<OrchestraInterfaceOutput>();
|
||||||
inputList = new Vector<OrchestraInterfaceInput>();
|
m_inputList = new Vector<OrchestraInterfaceInput>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeviceCount() {
|
public int getDeviceCount() {
|
||||||
Log.e("Manager", "Get device List");
|
Log.e("Manager", "Get device List");
|
||||||
return 1;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDeviceProperty(int idDevice) {
|
public String getDeviceProperty(int _idDevice) {
|
||||||
if (idDevice == 0) {
|
if (_idDevice == 0) {
|
||||||
return "{\n"
|
return "{\n"
|
||||||
+ " name:'speaker',\n"
|
+ " name:'speaker',\n"
|
||||||
+ " type:'output',\n"
|
+ " type:'output',\n"
|
||||||
@ -49,148 +49,151 @@ public class OrchestraManager implements OrchestraManagerCallback, OrchestraCons
|
|||||||
+ " format:['int16'],\n"
|
+ " format:['int16'],\n"
|
||||||
+ " default:true\n"
|
+ " default:true\n"
|
||||||
+ "}";
|
+ "}";
|
||||||
|
} else if (_idDevice == 1) {
|
||||||
|
return "{\n"
|
||||||
|
+ " name:'microphone',\n"
|
||||||
|
+ " type:'input',\n"
|
||||||
|
+ " sample-rate:[8000,16000,24000,32000,48000,96000],\n"
|
||||||
|
+ " channels:['front-left','front-right'],\n"
|
||||||
|
+ " format:['int16'],\n"
|
||||||
|
+ " default:true\n"
|
||||||
|
+ "}";
|
||||||
} else {
|
} else {
|
||||||
return "{}";
|
return "{}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int openDeviceOutput(int idDevice, int freq, int nbChannel, int format) {
|
public int openDeviceOutput(int _idDevice, int _freq, int _nbChannel, int _format) {
|
||||||
OrchestraInterfaceOutput iface = new OrchestraInterfaceOutput(uid, orchestraHandle, idDevice, freq, nbChannel, format);
|
OrchestraInterfaceOutput iface = new OrchestraInterfaceOutput(m_uid, m_orchestraHandle, _idDevice, _freq, _nbChannel, _format);
|
||||||
uid++;
|
m_uid++;
|
||||||
Log.e("Manager", "Open device Output: " + idDevice + " with UID=" + (uid-1));
|
Log.e("Manager", "Open device Output: " + _idDevice + " with m_uid=" + (m_uid-1));
|
||||||
if (iface != null) {
|
if (iface != null) {
|
||||||
outputList.add(iface);
|
m_outputList.add(iface);
|
||||||
Log.e("Manager", "Added element count=" + outputList.size());
|
Log.e("Manager", "Added element count=" + m_outputList.size());
|
||||||
return uid-1;
|
return m_uid-1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int openDeviceInput(int idDevice, int freq, int nbChannel, int format) {
|
public int openDeviceInput(int _idDevice, int _freq, int _nbChannel, int _format) {
|
||||||
OrchestraInterfaceInput iface = new OrchestraInterfaceInput(uid, orchestraHandle, idDevice, freq, nbChannel, format);
|
OrchestraInterfaceInput iface = new OrchestraInterfaceInput(m_uid, m_orchestraHandle, _idDevice, _freq, _nbChannel, _format);
|
||||||
uid++;
|
m_uid++;
|
||||||
Log.e("Manager", "Open device Input: " + idDevice + " with UID=" + (uid-1));
|
Log.e("Manager", "Open device Input: " + _idDevice + " with m_uid=" + (m_uid-1));
|
||||||
if (iface != null) {
|
if (iface != null) {
|
||||||
inputList.add(iface);
|
m_inputList.add(iface);
|
||||||
return uid-1;
|
return m_uid-1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean closeDevice(int uniqueID) {
|
public boolean closeDevice(int _uniqueID) {
|
||||||
Log.e("Manager", "Close device : " + uniqueID);
|
Log.e("Manager", "Close device : " + _uniqueID);
|
||||||
if (uniqueID<0) {
|
if (_uniqueID<0) {
|
||||||
Log.e("Manager", "Can not Close device with UID: " + uniqueID);
|
Log.e("Manager", "Can not Close device with m_uid: " + _uniqueID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// find the Element with his ID:
|
// find the Element with his ID:
|
||||||
if (inputList != null) {
|
if (m_inputList != null) {
|
||||||
for (int iii=0; iii<inputList.size(); iii++) {
|
for (int iii=0; iii<m_inputList.size(); iii++) {
|
||||||
if (inputList.get(iii) == null) {
|
if (m_inputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (inputList.get(iii).getUId() == uniqueID) {
|
if (m_inputList.get(iii).getUId() == _uniqueID) {
|
||||||
// find it ...
|
// find it ...
|
||||||
inputList.remove(iii);
|
m_inputList.remove(iii);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (outputList != null) {
|
if (m_outputList != null) {
|
||||||
for (int iii=0; iii<outputList.size(); iii++) {
|
for (int iii=0; iii<m_outputList.size(); iii++) {
|
||||||
if (outputList.get(iii) == null) {
|
if (m_outputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (outputList.get(iii).getUId() == uniqueID) {
|
if (m_outputList.get(iii).getUId() == _uniqueID) {
|
||||||
// find it ...
|
// find it ...
|
||||||
outputList.remove(iii);
|
m_outputList.remove(iii);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.e("Manager", "Can not start device with UID: " + uniqueID + " Element does not exist ...");
|
Log.e("Manager", "Can not start device with m_uid: " + _uniqueID + " Element does not exist ...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean start(int uniqueID) {
|
public boolean start(int _uniqueID) {
|
||||||
Log.e("Manager", "start device : " + uniqueID);
|
Log.e("Manager", "start device : " + _uniqueID);
|
||||||
if (uniqueID<0) {
|
if (_uniqueID<0) {
|
||||||
Log.e("Manager", "Can not start device with UID: " + uniqueID);
|
Log.e("Manager", "Can not start device with m_uid: " + _uniqueID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// find the Element with his ID:
|
// find the Element with his ID:
|
||||||
if (inputList != null) {
|
if (m_inputList != null) {
|
||||||
for (int iii=0; iii<inputList.size(); iii++) {
|
for (int iii=0; iii<m_inputList.size(); iii++) {
|
||||||
if (inputList.get(iii) == null) {
|
if (m_inputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (inputList.get(iii).getUId() == uniqueID) {
|
if (m_inputList.get(iii).getUId() == _uniqueID) {
|
||||||
// find it ...
|
// find it ...
|
||||||
inputList.get(iii).start();
|
m_inputList.get(iii).autoStart();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (outputList != null) {
|
if (m_outputList != null) {
|
||||||
for (int iii=0; iii<outputList.size(); iii++) {
|
for (int iii=0; iii<m_outputList.size(); iii++) {
|
||||||
if (outputList.get(iii) == null) {
|
if (m_outputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (outputList.get(iii).getUId() == uniqueID) {
|
if (m_outputList.get(iii).getUId() == _uniqueID) {
|
||||||
// find it ...
|
// find it ...
|
||||||
outputList.get(iii).start();
|
m_outputList.get(iii).autoStart();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.e("Manager", "Can not start device with UID: " + uniqueID + " Element does not exist ...");
|
Log.e("Manager", "Can not start device with UID: " + _uniqueID + " Element does not exist ...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean stop(int uniqueID) {
|
public boolean stop(int _uniqueID) {
|
||||||
Log.e("Manager", "stop device : " + uniqueID);
|
Log.e("Manager", "stop device : " + _uniqueID);
|
||||||
if (uniqueID<0) {
|
if (_uniqueID<0) {
|
||||||
Log.e("Manager", "Can not stop device with UID: " + uniqueID);
|
Log.e("Manager", "Can not stop device with UID: " + _uniqueID);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// find the Element with his ID:
|
// find the Element with his ID:
|
||||||
if (inputList != null) {
|
if (m_inputList != null) {
|
||||||
for (int iii=0; iii<inputList.size(); iii++) {
|
for (int iii=0; iii<m_inputList.size(); iii++) {
|
||||||
if (inputList.get(iii) == null) {
|
if (m_inputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (inputList.get(iii).getUId() == uniqueID) {
|
if (m_inputList.get(iii).getUId() == _uniqueID) {
|
||||||
// find it ...
|
// find it ...
|
||||||
inputList.get(iii).autoStop();
|
m_inputList.get(iii).autoStop();
|
||||||
try {
|
|
||||||
inputList.get(iii).join();
|
|
||||||
} catch(InterruptedException e) { }
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (outputList != null) {
|
if (m_outputList != null) {
|
||||||
for (int iii=0; iii<outputList.size(); iii++) {
|
for (int iii=0; iii<m_outputList.size(); iii++) {
|
||||||
if (outputList.get(iii) == null) {
|
if (m_outputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (outputList.get(iii).getUId() == uniqueID) {
|
if (m_outputList.get(iii).getUId() == _uniqueID) {
|
||||||
// find it ...
|
// find it ...
|
||||||
outputList.get(iii).autoStop();
|
m_outputList.get(iii).autoStop();
|
||||||
try {
|
|
||||||
outputList.get(iii).join();
|
|
||||||
} catch(InterruptedException e) { }
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.e("Manager", "Can not stop device with UID: " + uniqueID + " Element does not exist ...");
|
Log.e("Manager", "Can not stop device with UID: " + _uniqueID + " Element does not exist ...");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -208,44 +211,44 @@ public class OrchestraManager implements OrchestraManagerCallback, OrchestraCons
|
|||||||
public void onResume() {
|
public void onResume() {
|
||||||
Log.w("Manager", "onResume ...");
|
Log.w("Manager", "onResume ...");
|
||||||
// find the Element with his ID:
|
// find the Element with his ID:
|
||||||
if (inputList != null) {
|
if (m_inputList != null) {
|
||||||
for (int iii=0; iii<inputList.size(); iii++) {
|
for (int iii=0; iii<m_inputList.size(); iii++) {
|
||||||
if (inputList.get(iii) == null) {
|
if (m_inputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
inputList.get(iii).activityResume();
|
m_inputList.get(iii).activityResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (outputList != null) {
|
if (m_outputList != null) {
|
||||||
for (int iii=0; iii<outputList.size(); iii++) {
|
for (int iii=0; iii<m_outputList.size(); iii++) {
|
||||||
if (outputList.get(iii) == null) {
|
if (m_outputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
outputList.get(iii).activityResume();
|
m_outputList.get(iii).activityResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void onPause() {
|
public void onPause() {
|
||||||
Log.w("Manager", "onPause ...");
|
Log.w("Manager", "onPause ...");
|
||||||
// find the Element with his ID:
|
// find the Element with his ID:
|
||||||
if (inputList != null) {
|
if (m_inputList != null) {
|
||||||
for (int iii=0; iii<inputList.size(); iii++) {
|
for (int iii=0; iii<m_inputList.size(); iii++) {
|
||||||
if (inputList.get(iii) == null) {
|
if (m_inputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
inputList.get(iii).activityPause();
|
m_inputList.get(iii).activityPause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (outputList != null) {
|
if (m_outputList != null) {
|
||||||
for (int iii=0; iii<outputList.size(); iii++) {
|
for (int iii=0; iii<m_outputList.size(); iii++) {
|
||||||
if (outputList.get(iii) == null) {
|
if (m_outputList.get(iii) == null) {
|
||||||
Log.e("Manager", "Null input element: " + iii);
|
Log.e("Manager", "Null input element: " + iii);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
outputList.get(iii).activityPause();
|
m_outputList.get(iii).activityPause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,10 +10,10 @@ package org.musicdsp.orchestra;
|
|||||||
|
|
||||||
public interface OrchestraManagerCallback {
|
public interface OrchestraManagerCallback {
|
||||||
public int getDeviceCount();
|
public int getDeviceCount();
|
||||||
public String getDeviceProperty(int idDevice);
|
public String getDeviceProperty(int _idDevice);
|
||||||
public int openDeviceInput(int idDevice, int sampleRate, int nbChannel, int format);
|
public int openDeviceInput(int _idDevice, int _sampleRate, int _nbChannel, int _format);
|
||||||
public int openDeviceOutput(int idDevice, int sampleRate, int nbChannel, int format);
|
public int openDeviceOutput(int _idDevice, int _sampleRate, int _nbChannel, int _format);
|
||||||
public boolean closeDevice(int uniqueID);
|
public boolean closeDevice(int _uniqueID);
|
||||||
public boolean start(int uniqueID);
|
public boolean start(int _uniqueID);
|
||||||
public boolean stop(int uniqueID);
|
public boolean stop(int _uniqueID);
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,9 @@ import java.lang.RuntimeException;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class OrchestraNative {
|
public class OrchestraNative {
|
||||||
public <T extends OrchestraManagerCallback> OrchestraNative(T managerInstance) {
|
public <T extends OrchestraManagerCallback> OrchestraNative(T _managerInstance) {
|
||||||
try {
|
try {
|
||||||
NNsetJavaManager(managerInstance);
|
NNsetJavaManager(_managerInstance);
|
||||||
} catch (java.lang.UnsatisfiedLinkError e) {
|
} catch (java.lang.UnsatisfiedLinkError e) {
|
||||||
Log.e("Orchestra", "JNI binding not present ...");
|
Log.e("Orchestra", "JNI binding not present ...");
|
||||||
throw new RuntimeException("Orchestra binding not present ...");
|
throw new RuntimeException("Orchestra binding not present ...");
|
||||||
@ -27,17 +27,17 @@ public class OrchestraNative {
|
|||||||
NNsetJavaManagerRemove();
|
NNsetJavaManagerRemove();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playback(int flowId, short[] bufferData, int nbChunk) {
|
public void playback(int _flowId, short[] _bufferData, int _nbChunk) {
|
||||||
NNPlayback(flowId, bufferData, nbChunk);
|
NNPlayback(_flowId, _bufferData, _nbChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void record(int flowId, short[] bufferData, int nbChunk) {
|
public void record(int _flowId, short[] _bufferData, int _nbChunk) {
|
||||||
NNRecord(flowId, bufferData, nbChunk);
|
NNRecord(_flowId, _bufferData, _nbChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
private native <T extends OrchestraManagerCallback> void NNsetJavaManager(T managerInstance);
|
private native <T extends OrchestraManagerCallback> void NNsetJavaManager(T _managerInstance);
|
||||||
private native void NNsetJavaManagerRemove();
|
private native void NNsetJavaManagerRemove();
|
||||||
private native void NNPlayback(int flowId, short[] bufferData, int nbChunk);
|
private native void NNPlayback(int _flowId, short[] _bufferData, int _nbChunk);
|
||||||
private native void NNRecord(int flowId, short[] bufferData, int nbChunk);
|
private native void NNRecord(int _flowId, short[] _bufferData, int _nbChunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,11 +143,6 @@ bool audio::orchestra::api::Android::probeDeviceOpen(uint32_t _device,
|
|||||||
const audio::orchestra::StreamOptions& _options) {
|
const audio::orchestra::StreamOptions& _options) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
ATA_INFO("Probe : device=" << _device << " channels=" << _channels << " firstChannel=" << _firstChannel << " sampleRate=" << _sampleRate);
|
ATA_INFO("Probe : device=" << _device << " channels=" << _channels << " firstChannel=" << _firstChannel << " sampleRate=" << _sampleRate);
|
||||||
|
|
||||||
if (_mode != audio::orchestra::mode_output) {
|
|
||||||
ATA_ERROR("Can not start a device input or duplex for Android ...");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
m_mode = _mode;
|
m_mode = _mode;
|
||||||
m_userFormat = _format;
|
m_userFormat = _format;
|
||||||
m_nUserChannels[modeToIdTable(m_mode)] = _channels;
|
m_nUserChannels[modeToIdTable(m_mode)] = _channels;
|
||||||
|
Loading…
Reference in New Issue
Block a user