嗨,首先感谢您阅读我的问题!
我有一个设备,它给我的输出基本上只是一个 RS232 串行信号(1200 波特,8 个数据位,无奇偶校验位,一个停止位)。此输出通过 3.5 毫米音频插孔进入我的安卓手机。
我想将每个数据位存储到一个变量中,显示或计算一些东西,当下一个位进入时,它应该覆盖变量。
在我将数据位放入变量中后,我确切地知道如何处理它,但我不知道如何进行基本的输入/流/从音频插孔读取...
我找到了这个,但对我帮助不大:Android serial port via audio jack 也许是这样的:Android: Need to record mic input
请帮帮我,谢谢!
编辑:关于我的信号的更多信息有效载荷以 9 字节数据包传输:
1: command byte as ASCII character ('I','A','S','L','R','C' or ' ')
2-6: time in ASCII chars (2:34:56)
7: checksum (64 + sum of time digits)
8: CR (carriage return, ASCII code 0x0D)
9: LF (line feed, ASCII code 0x0A)
Edit2:我还认为我必须将输入存储到缓冲区中,然后从缓冲区中读取信号......但是如何将来自音频插孔的串行输入写入缓冲区?
Edit3:也许这样的事情会起作用:
try
{
int N = AudioRecord.getMinBufferSize(8000,AudioFormat.CHANNEL_IN_MONO,AudioFormat.ENCODING_PCM_16BIT);
recorder = new AudioRecord(AudioSource.MIC, 1200, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10);
track = new AudioTrack(AudioManager.STREAM_MUSIC, 1200,
AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, N*10, AudioTrack.MODE_STREAM);
recorder.startRecording();
track.play();
/*
* Loops until something outside of this thread stops it.
* Reads the data from the recorder and writes it to the audio track for playback.
*/
while(!stopped)
{
Log.i("Map", "Writing new data to buffer");
short[] buffer = buffers[ix++ % buffers.length];
N = recorder.read(buffer,0,buffer.length);
track.write(buffer, 0, buffer.length);
}
}
catch(Throwable x)
{
Log.w("Audio", "Error reading voice audio", x);
}
/*
* Frees the thread's resources after the loop completes so that it can be run again
*/
finally
{
recorder.stop();
recorder.release();
track.stop();
track.release();
}
}