-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from chenxiaolong/sample-rate
Add support for configurable sample rate
- Loading branch information
Showing
8 changed files
with
226 additions
and
62 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
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
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
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
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
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,47 @@ | ||
@file:Suppress("OPT_IN_IS_NOT_ENABLED") | ||
@file:OptIn(ExperimentalUnsignedTypes::class) | ||
|
||
package com.chiller3.bcr.format | ||
|
||
import android.content.Context | ||
import com.chiller3.bcr.Preferences | ||
import com.chiller3.bcr.R | ||
|
||
object SampleRates { | ||
/** | ||
* Hardcoded list of sample rates supported by every [Format]. | ||
* | ||
* Ideally, there would be a way to query what sample rates are supported for a given audio | ||
* source and then filter that list based on what the [Format] supports. Unfortunately, no such | ||
* API exists. | ||
*/ | ||
val all = uintArrayOf( | ||
8_000u, | ||
12_000u, | ||
16_000u, | ||
24_000u, | ||
48_000u, | ||
) | ||
|
||
/** | ||
* Get the saved sample rate from the preferences. | ||
* | ||
* If the saved sample rate is no longer valid, then null is returned. | ||
*/ | ||
fun fromPreferences(context: Context): UInt? { | ||
val savedSampleRate = Preferences.getSampleRate(context) | ||
|
||
if (savedSampleRate != null && all.contains(savedSampleRate)) { | ||
return savedSampleRate | ||
} | ||
|
||
return null | ||
} | ||
|
||
fun format(context: Context, sampleRate: UInt?): String = | ||
if (sampleRate == null) { | ||
context.getString(R.string.bottom_sheet_sample_rate_native) | ||
} else { | ||
"$sampleRate Hz" | ||
} | ||
} |
Oops, something went wrong.