From e7f29cd8083a359b3766260e4a89c4324563f720 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Mon, 13 Nov 2023 15:31:23 +0100 Subject: [PATCH] move package, interface audio --- .../src/androidMain/AndroidManifest.xml | 1 + .../noisecapture/AndroidAudioSource.kt | 37 +++++++++++++++++++ .../noisecapture/CreateAudioSource.kt | 8 ++++ .../noise_planet/noisecapture/MainActivity.kt | 1 - .../noisecapture}/Platform.android.kt | 2 + .../noise_planet/noisecapture/Test.android.kt | 1 - .../noise_planet/noisecapture}/App.kt | 2 + .../noisecapture/AudioCallback.kt | 5 +++ .../noise_planet/noisecapture/AudioSource.kt | 26 +++++++++++++ .../noise_planet/noisecapture}/Greeting.kt | 2 + .../noise_planet/noisecapture}/Platform.kt | 2 + .../org/noise_planet/noisecapture/Test.kt | 1 - .../noisecapture}/MainViewController.kt | 2 + .../noisecapture}/Platform.ios.kt | 2 + .../org/noise_planet/noisecapture/Test.ios.kt | 1 - 15 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/AndroidAudioSource.kt create mode 100644 NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/CreateAudioSource.kt rename NoiseCapture/src/androidMain/kotlin/{ => org/noise_planet/noisecapture}/Platform.android.kt (82%) rename NoiseCapture/src/commonMain/kotlin/{ => org/noise_planet/noisecapture}/App.kt (97%) create mode 100644 NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioCallback.kt create mode 100644 NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioSource.kt rename NoiseCapture/src/commonMain/kotlin/{ => org/noise_planet/noisecapture}/Greeting.kt (77%) rename NoiseCapture/src/commonMain/kotlin/{ => org/noise_planet/noisecapture}/Platform.kt (66%) rename NoiseCapture/src/iosMain/kotlin/{ => org/noise_planet/noisecapture}/MainViewController.kt (75%) rename NoiseCapture/src/iosMain/kotlin/{ => org/noise_planet/noisecapture}/Platform.ios.kt (85%) diff --git a/NoiseCapture/src/androidMain/AndroidManifest.xml b/NoiseCapture/src/androidMain/AndroidManifest.xml index b87d944..84afc08 100644 --- a/NoiseCapture/src/androidMain/AndroidManifest.xml +++ b/NoiseCapture/src/androidMain/AndroidManifest.xml @@ -1,6 +1,7 @@ + + return AudioSource.InitializeErrorCode.INITIALIZE_SAMPLE_RATE_NOT_SUPPORTED + minimalBufferSize > bufferSize -> + return AudioSource.InitializeErrorCode.INITIALIZE_WRONG_BUFFER_SIZE + } + audioRecord = AudioRecord(MediaRecorder.AudioSource.VOICE_RECOGNITION, sampleRate, channel, encoding, bufferSize) + return AudioSource.InitializeErrorCode.INITIALIZE_OK + } + + override fun release() { + TODO("Not yet implemented") + } + + override fun getMicrophoneLocation(): AudioSource.MicrophoneLocation { + TODO("Not yet implemented") + } +} diff --git a/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/CreateAudioSource.kt b/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/CreateAudioSource.kt new file mode 100644 index 0000000..ba1f241 --- /dev/null +++ b/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/CreateAudioSource.kt @@ -0,0 +1,8 @@ +package org.noise_planet.noisecapture + +import org.noise_planet.noisecapture.AndroidAudioSource +import org.noise_planet.noisecapture.AudioSource + +actual fun CreateAudioSource(): AudioSource { + return AndroidAudioSource() +} diff --git a/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/MainActivity.kt b/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/MainActivity.kt index 90c3989..4aadfcd 100644 --- a/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/MainActivity.kt +++ b/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/MainActivity.kt @@ -1,6 +1,5 @@ package org.noise_planet.noisecapture -import App import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent diff --git a/NoiseCapture/src/androidMain/kotlin/Platform.android.kt b/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/Platform.android.kt similarity index 82% rename from NoiseCapture/src/androidMain/kotlin/Platform.android.kt rename to NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/Platform.android.kt index 4f3ea05..92d27f1 100644 --- a/NoiseCapture/src/androidMain/kotlin/Platform.android.kt +++ b/NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/Platform.android.kt @@ -1,3 +1,5 @@ +package org.noise_planet.noisecapture + import android.os.Build class AndroidPlatform : Platform { diff --git a/NoiseCapture/src/androidUnitTest/kotlin/org/noise_planet/noisecapture/Test.android.kt b/NoiseCapture/src/androidUnitTest/kotlin/org/noise_planet/noisecapture/Test.android.kt index e4f70aa..93eed1a 100644 --- a/NoiseCapture/src/androidUnitTest/kotlin/org/noise_planet/noisecapture/Test.android.kt +++ b/NoiseCapture/src/androidUnitTest/kotlin/org/noise_planet/noisecapture/Test.android.kt @@ -1,6 +1,5 @@ package org.noise_planet.noisecapture -import Greeting import org.junit.Assert.assertTrue import org.junit.Test diff --git a/NoiseCapture/src/commonMain/kotlin/App.kt b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/App.kt similarity index 97% rename from NoiseCapture/src/commonMain/kotlin/App.kt rename to NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/App.kt index 280d039..0477954 100644 --- a/NoiseCapture/src/commonMain/kotlin/App.kt +++ b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/App.kt @@ -1,3 +1,5 @@ +package org.noise_planet.noisecapture + import androidx.compose.animation.AnimatedVisibility import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column diff --git a/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioCallback.kt b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioCallback.kt new file mode 100644 index 0000000..ca4d910 --- /dev/null +++ b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioCallback.kt @@ -0,0 +1,5 @@ +package org.noise_planet.noisecapture + +interface AudioCallback { + fun onAudio(samples: FloatArray) +} diff --git a/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioSource.kt b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioSource.kt new file mode 100644 index 0000000..f2a98a6 --- /dev/null +++ b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioSource.kt @@ -0,0 +1,26 @@ +package org.noise_planet.noisecapture + +/** + * Common interface to access Audio samples from device microphone + * As each device + */ +interface AudioSource { + enum class MicrophoneLocation { LOCATION_UNKNOWN, LOCATION_MAIN_BODY, + LOCATION_MAIN_BODY_MOVABLE, LOCATION_PERIPHERAL } + + enum class InitializeErrorCode { INITIALIZE_OK, INITIALIZE_WRONG_BUFFER_SIZE, + INITIALIZE_SAMPLE_RATE_NOT_SUPPORTED} + /** + * @param sampleRate Sample rate in Hz + * @param bufferSize Buffer size in bytes + * @return InitializeErrorCode instance + */ + fun setup(sampleRate: Int, bufferSize: Int, callback: AudioCallback) : InitializeErrorCode + + fun release() + + fun getMicrophoneLocation() : MicrophoneLocation + +} + +expect fun CreateAudioSource(): AudioSource diff --git a/NoiseCapture/src/commonMain/kotlin/Greeting.kt b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/Greeting.kt similarity index 77% rename from NoiseCapture/src/commonMain/kotlin/Greeting.kt rename to NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/Greeting.kt index 887d835..c7d4a98 100644 --- a/NoiseCapture/src/commonMain/kotlin/Greeting.kt +++ b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/Greeting.kt @@ -1,3 +1,5 @@ +package org.noise_planet.noisecapture + class Greeting { private val platform = getPlatform() diff --git a/NoiseCapture/src/commonMain/kotlin/Platform.kt b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/Platform.kt similarity index 66% rename from NoiseCapture/src/commonMain/kotlin/Platform.kt rename to NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/Platform.kt index 87ca3ff..b6dc2e7 100644 --- a/NoiseCapture/src/commonMain/kotlin/Platform.kt +++ b/NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/Platform.kt @@ -1,3 +1,5 @@ +package org.noise_planet.noisecapture + interface Platform { val name: String } diff --git a/NoiseCapture/src/commonTest/kotlin/org/noise_planet/noisecapture/Test.kt b/NoiseCapture/src/commonTest/kotlin/org/noise_planet/noisecapture/Test.kt index 67954e6..3ed8a27 100644 --- a/NoiseCapture/src/commonTest/kotlin/org/noise_planet/noisecapture/Test.kt +++ b/NoiseCapture/src/commonTest/kotlin/org/noise_planet/noisecapture/Test.kt @@ -1,6 +1,5 @@ package org.noise_planet.noisecapture -import Greeting import kotlin.test.Test import kotlin.test.assertTrue diff --git a/NoiseCapture/src/iosMain/kotlin/MainViewController.kt b/NoiseCapture/src/iosMain/kotlin/org/noise_planet/noisecapture/MainViewController.kt similarity index 75% rename from NoiseCapture/src/iosMain/kotlin/MainViewController.kt rename to NoiseCapture/src/iosMain/kotlin/org/noise_planet/noisecapture/MainViewController.kt index f483884..8b4a9c7 100644 --- a/NoiseCapture/src/iosMain/kotlin/MainViewController.kt +++ b/NoiseCapture/src/iosMain/kotlin/org/noise_planet/noisecapture/MainViewController.kt @@ -1,3 +1,5 @@ +package org.noise_planet.noisecapture + import androidx.compose.ui.window.ComposeUIViewController fun MainViewController() = ComposeUIViewController { App() } diff --git a/NoiseCapture/src/iosMain/kotlin/Platform.ios.kt b/NoiseCapture/src/iosMain/kotlin/org/noise_planet/noisecapture/Platform.ios.kt similarity index 85% rename from NoiseCapture/src/iosMain/kotlin/Platform.ios.kt rename to NoiseCapture/src/iosMain/kotlin/org/noise_planet/noisecapture/Platform.ios.kt index 5cef987..e286e9b 100644 --- a/NoiseCapture/src/iosMain/kotlin/Platform.ios.kt +++ b/NoiseCapture/src/iosMain/kotlin/org/noise_planet/noisecapture/Platform.ios.kt @@ -1,3 +1,5 @@ +package org.noise_planet.noisecapture + import platform.UIKit.UIDevice class IOSPlatform: Platform { diff --git a/NoiseCapture/src/iosTest/kotlin/org/noise_planet/noisecapture/Test.ios.kt b/NoiseCapture/src/iosTest/kotlin/org/noise_planet/noisecapture/Test.ios.kt index 0aecefe..10e6faa 100644 --- a/NoiseCapture/src/iosTest/kotlin/org/noise_planet/noisecapture/Test.ios.kt +++ b/NoiseCapture/src/iosTest/kotlin/org/noise_planet/noisecapture/Test.ios.kt @@ -1,6 +1,5 @@ package org.noise_planet.noisecapture -import Greeting import kotlin.test.Test import kotlin.test.assertTrue