Hello, I am trying to store microphone data from the Nordic Thingy by modifying the Nordic Thingy Android app.
The Thingy firmware encodes the digital microphone data into ADPCM, and the Thingy app decodes it into 16 bit PCM data.
By modifying the Thingy app, I write the decoded pcm data into a .pcm file on my phone and then read the file into Matlab but when I plot the data in matlab it looks like this which I'm sure is not what PCM data should look like
Can anyone help? I am completely stumped. Here is the code that I modified from the Thingy app in the file ThingyConnection.java
} else if (characteristic.equals(mMicrophoneCharacteristic)) {
String ROOT_PATH = Environment.getExternalStorageDirectory().getPath() + "/Audio/";
File folder = new File(ROOT_PATH);
if (!folder.exists()) {
folder.mkdir();
}
String sFileTimestamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
if(wFile == null) {
try {
wFile = new FileOutputStream(new File(ROOT_PATH + sFileTimestamp + ".pcm"));
//wFile.write(WAV_HEADER);
} catch (IOException e) {
e.printStackTrace();
Log.d("thing",e.getMessage());
}
}
if (mAdpcmDecoder != null) {
if (mMtu == ThingyUtils.MAX_MTU_SIZE_THINGY) { //Pre lollipop devices may not have the max mtu size hence the check
final byte[] data = new byte[131];
final byte[] tempData = characteristic.getValue();
System.arraycopy(tempData, 0, data, 0, 131);
mAdpcmDecoder.add(data);
if (data != null) {
if (data.length != 0) {
try {
final byte[] pcm = decode(data);
wFile.write(pcm);
} catch (IOException e) {
e.printStackTrace();
}
}
}