-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
89 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/AndroidAudioSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import android.annotation.SuppressLint | ||
import android.media.AudioFormat | ||
import android.media.AudioRecord | ||
import android.media.MediaRecorder | ||
|
||
class AndroidAudioSource : AudioSource { | ||
private lateinit var audioRecord: AudioRecord | ||
|
||
@SuppressLint("MissingPermission") | ||
override fun setup( | ||
sampleRate: Int, | ||
bufferSize: Int, | ||
callback: AudioCallback | ||
): AudioSource.InitializeErrorCode { | ||
val channel = AudioFormat.CHANNEL_IN_MONO | ||
val encoding = AudioFormat.ENCODING_PCM_FLOAT | ||
val minimalBufferSize = AudioRecord.getMinBufferSize(sampleRate, channel, encoding) | ||
when { | ||
minimalBufferSize == AudioRecord.ERROR_BAD_VALUE || minimalBufferSize == AudioRecord.ERROR -> | ||
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") | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/CreateAudioSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
} |
1 change: 0 additions & 1 deletion
1
NoiseCapture/src/androidMain/kotlin/org/noise_planet/noisecapture/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...rc/androidMain/kotlin/Platform.android.kt → ...e_planet/noisecapture/Platform.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import android.os.Build | ||
|
||
class AndroidPlatform : Platform { | ||
|
1 change: 0 additions & 1 deletion
1
NoiseCapture/src/androidUnitTest/kotlin/org/noise_planet/noisecapture/Test.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import Greeting | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Test | ||
|
||
|
2 changes: 2 additions & 0 deletions
2
NoiseCapture/src/commonMain/kotlin/App.kt → ...tlin/org/noise_planet/noisecapture/App.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioCallback.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
interface AudioCallback { | ||
fun onAudio(samples: FloatArray) | ||
} |
26 changes: 26 additions & 0 deletions
26
NoiseCapture/src/commonMain/kotlin/org/noise_planet/noisecapture/AudioSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
2 changes: 2 additions & 0 deletions
2
...Capture/src/commonMain/kotlin/Greeting.kt → ...org/noise_planet/noisecapture/Greeting.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
class Greeting { | ||
private val platform = getPlatform() | ||
|
||
|
2 changes: 2 additions & 0 deletions
2
...Capture/src/commonMain/kotlin/Platform.kt → ...org/noise_planet/noisecapture/Platform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
interface Platform { | ||
val name: String | ||
} | ||
|
1 change: 0 additions & 1 deletion
1
NoiseCapture/src/commonTest/kotlin/org/noise_planet/noisecapture/Test.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import Greeting | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
|
2 changes: 2 additions & 0 deletions
2
.../src/iosMain/kotlin/MainViewController.kt → ...planet/noisecapture/MainViewController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import androidx.compose.ui.window.ComposeUIViewController | ||
|
||
fun MainViewController() = ComposeUIViewController { App() } |
2 changes: 2 additions & 0 deletions
2
...apture/src/iosMain/kotlin/Platform.ios.kt → ...noise_planet/noisecapture/Platform.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import platform.UIKit.UIDevice | ||
|
||
class IOSPlatform: Platform { | ||
|
1 change: 0 additions & 1 deletion
1
NoiseCapture/src/iosTest/kotlin/org/noise_planet/noisecapture/Test.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
package org.noise_planet.noisecapture | ||
|
||
import Greeting | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
|