Skip to content

Commit

Permalink
Merge pull request #131 from remotv/develop
Browse files Browse the repository at this point in the history
Develop -> master
  • Loading branch information
SkyeOfBreeze committed Sep 22, 2021
2 parents dacb295 + 73df95f commit cfc3f5f
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ android {
applicationId "tv.remo.android.controller"
minSdkVersion 16
targetSdkVersion 28
versionCode 21
versionName "0.19.3"
versionCode 22
versionName "0.20.0"
multiDexEnabled true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<string name="microphoneSettingsTitle">Microphone</string>
<string name="microphoneSettingsSummary">Volume, Bitrate</string>
<string name="micVolumeBoostTitle">Volume Boost</string>
<string name="micMultiplyTitle">Mic Buffer Multiplier (Adjust if choppy)</string>
<!--Audio/Speaker-->
<string name="audioSettingsTitle">Audio and Commands</string>
<string name="audioSettingsSummary">Text to Speech, Device Volume, Commands</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/settings_microphone.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
app:entries="@array/volume_mic_list"
app:entryValues="@array/volume_mic_list_values"/>

<androidx.preference.ListPreference
app:key="@string/micAudioBufferMultiplierKey"
app:title="@string/micMultiplyTitle"
app:defaultValue="2"
app:useSimpleSummaryProvider="true"
app:entries="@array/volume_mic_list"
app:entryValues="@array/volume_mic_list_values"/>

<androidx.preference.ListPreference
app:key="@string/micAudioBitrateKey"
app:title="@string/bitrate"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class RemoSettingsUtil(context : Context, sharedPreferences: SharedPreferences)
val microphoneEnabled = BooleanPref(context, sharedPreferences, R.string.microphoneSettingsEnableKey, false)
val micVolume = StringPref(context, sharedPreferences, R.string.micVolumeBoostKey, "1")
val microphoneBitrate = StringPref(context, sharedPreferences, R.string.micAudioBitrateKey, "64")
val microphoneBufferMultiplier = StringPref(context, sharedPreferences, R.string.micAudioBufferMultiplierKey, "2")

//tts related settings
val textToSpeechEnabled = BooleanPref(context, sharedPreferences, R.string.audioSettingsEnableKey, false)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package tv.remo.android.controller.sdk.components.audio

import org.btelman.controlsdk.streaming.audio.retrievers.BasicMicrophoneAudioRetriever
import tv.remo.android.controller.sdk.RemoSettingsUtil

class RemoAudioRetriever : BasicMicrophoneAudioRetriever() {
override fun enableInternal() {
context?.let {
recordingThread.bufferSizeMultiplier = RemoSettingsUtil.with(it).microphoneBufferMultiplier.getPref().toFloatOrNull() ?: 2f
}

super.enableInternal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import org.btelman.controlsdk.hardware.interfaces.HardwareDriver
import org.btelman.controlsdk.models.ComponentHolder
import org.btelman.controlsdk.streaming.enums.Orientation
import org.btelman.controlsdk.streaming.factories.AudioProcessorFactory
import org.btelman.controlsdk.streaming.factories.AudioRetrieverFactory
import org.btelman.controlsdk.streaming.factories.VideoProcessorFactory
import org.btelman.controlsdk.streaming.factories.VideoRetrieverFactory
import org.btelman.controlsdk.streaming.models.CameraDeviceInfo
Expand All @@ -20,6 +21,7 @@ import tv.remo.android.controller.sdk.components.RemoCommandHandler
import tv.remo.android.controller.sdk.components.RemoSocketComponent
import tv.remo.android.controller.sdk.components.audio.RemoAudioComponent
import tv.remo.android.controller.sdk.components.audio.RemoAudioProcessor
import tv.remo.android.controller.sdk.components.audio.RemoAudioRetriever
import tv.remo.android.controller.sdk.components.hardware.HardwareWatchdogComponent
import tv.remo.android.controller.sdk.components.video.Camera1Override
import tv.remo.android.controller.sdk.components.video.RemoVideoComponent
Expand Down Expand Up @@ -63,6 +65,7 @@ object ComponentBuilderUtil {
}

if(settings.microphoneEnabled.getPref()){
AudioRetrieverFactory.putClassInBundle(RemoAudioRetriever::class.java, this)
val audioComponent = ComponentHolder(RemoAudioComponent::class.java, this, threadPriority = Process.THREAD_PRIORITY_MORE_FAVORABLE)
streamList.add(audioComponent)
}
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/res/values/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<string name="microphoneSettingsEnableKey">microphoneSettingsEnable</string>
<string name="micVolumeBoostKey">micVolumeBoostKey</string>
<string name="micAudioBitrateKey">micAudioBitrateKey</string>
<string name="micAudioBufferMultiplierKey">micAudioBufferMultiplierKey</string>

<string name="audioSettingsEnableKey">audioSettingsEnable</string>
<string name="audioSettingsTTSGroupKey">ttsCategoryKey</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.btelman.controlsdk.streaming.utils.AudioUtil
*/
open class BasicMicrophoneAudioRetriever : BaseAudioRetriever(), AudioRecordingThread.AudioDataReceivedListener {

private val recordingThread = AudioRecordingThread(this)
protected var recordingThread = AudioRecordingThread(this)

private var dataArray : AudioPacket? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import android.util.Log;

public class AudioRecordingThread {
private float bufferSizeMultiplier = 1;

public interface AudioDataReceivedListener {
void onAudioDataReceived(short[] data);
}
Expand All @@ -43,12 +45,7 @@ public void startRecording() {
return;

mShouldContinue = true;
mThread = new Thread(new Runnable() {
@Override
public void run() {
record();
}
});
mThread = new Thread(this::record);
mThread.start();
}

Expand All @@ -73,14 +70,17 @@ private void record() {
bufferSize = SAMPLE_RATE * 2;
}

short[] audioBuffer = new short[bufferSize / 2];
short[] audioBuffer = new short[(int) (bufferSize * bufferSizeMultiplier)];

AudioRecord record = new AudioRecord(MediaRecorder.AudioSource.DEFAULT,
SAMPLE_RATE,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSize);

Log.v(LOG_TAG, "Buffer Size : " + bufferSize);
Log.v(LOG_TAG, "Buffer Size Multiplier: " + bufferSizeMultiplier);

if (record.getState() != AudioRecord.STATE_INITIALIZED) {
Log.e(LOG_TAG, "Audio Record can't initialize!");
return;
Expand All @@ -103,5 +103,17 @@ private void record() {

Log.v(LOG_TAG, String.format("Recording stopped. Samples read: %d", shortsRead));
}

public float getBufferSizeMultiplier() {
return bufferSizeMultiplier;
}

/**
* Set the buffer size multiplier. The audio recording must be stopped and restarted for this to take affect
* @param bufferSizeMultiplier
*/
public void setBufferSizeMultiplier(float bufferSizeMultiplier) {
this.bufferSizeMultiplier = bufferSizeMultiplier;
}
}

0 comments on commit cfc3f5f

Please sign in to comment.