Add support for 18157Hz

This commit is contained in:
Gwilym Kuiper 2021-10-29 15:50:48 +01:00
parent 26620e850e
commit c6e7827e34
4 changed files with 19 additions and 2 deletions

View file

@ -17,6 +17,9 @@ debug = true
[lib]
proc-macro = true
[features]
freq18157 = []
[dependencies]
hound = "3.4.0"
syn = "1.0.73"

View file

@ -12,6 +12,11 @@ use std::{
};
use syn::parse_macro_input;
#[cfg(not(feature = "freq18157"))]
const FREQUENCY: u32 = 10512;
#[cfg(feature = "freq18157")]
const FREQUENCY: u32 = 18157;
#[proc_macro]
pub fn include_wav(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as syn::LitStr);
@ -43,8 +48,9 @@ pub fn include_wav(input: TokenStream) -> TokenStream {
assert_eq!(
wav_reader.spec().sample_rate,
10512,
"agb currently only supports sample rate of 10512Hz"
FREQUENCY,
"agb currently only supports sample rate of {}Hz",
FREQUENCY
);
let samples = samples_from_reader(wav_reader);

View file

@ -17,6 +17,7 @@ debug = true
[features]
default = ["alloc"]
alloc = []
freq18157 = ["agb_sound_converter/freq18157"]
[dependencies]
bitflags = "1.2"

View file

@ -91,9 +91,16 @@ impl Mixer {
// I've picked one frequency that works nicely. But there are others that work nicely
// which we may want to consider in the future: http://deku.gbadev.org/program/sound1.html
#[cfg(not(feature = "freq18157"))]
const SOUND_FREQUENCY: i32 = 10512;
#[cfg(not(feature = "freq18157"))]
const SOUND_BUFFER_SIZE: usize = 176;
#[cfg(feature = "freq18157")]
const SOUND_FREQUENCY: i32 = 18157;
#[cfg(feature = "freq18157")]
const SOUND_BUFFER_SIZE: usize = 304;
fn set_asm_buffer_size() {
extern "C" {
static mut agb_rs__buffer_size: usize;