From e42a3194de3b4fb9cd3e7cbd2e0ff17fea804b72 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Thu, 8 Dec 2011 19:20:00 +0000 Subject: AS3525v1/v2: Fix problems with volume of recorded material by converting 14-bit samples to 16-bit. Remove duplicate samples from recorded data and support proper samplerate since ADC runs 1/2 the codec clock. Support monitoring mono on both output channels by feeding data manually to I2SOUT under the right conditions. DMA is no longer used for recording since frames must be processed as described above but it does allow full-duplex audio. Miscellaneous change includes a proper constant (HW_SAMPR_DEFAULT) to reset the hardware samplerate when recording is closed. PP5024 and AS3525 have different default recording rates (22kHz and 44kHz respectively) but both have half-speed ADC. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31180 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/as3525/audio-as3525.c | 52 +++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'firmware/target/arm/as3525/audio-as3525.c') diff --git a/firmware/target/arm/as3525/audio-as3525.c b/firmware/target/arm/as3525/audio-as3525.c index 10c6161881..e4bb39b406 100644 --- a/firmware/target/arm/as3525/audio-as3525.c +++ b/firmware/target/arm/as3525/audio-as3525.c @@ -24,16 +24,33 @@ #include "audio.h" #include "audiohw.h" #include "sound.h" +#include "general.h" int audio_channels = 2; +#if CONFIG_CPU == AS3525 +int audio_output_source = AUDIO_SRC_PLAYBACK; +#endif + void audio_set_output_source(int source) { bitset32(&CGU_PERI, CGU_I2SOUT_APB_CLOCK_ENABLE); - if (source == AUDIO_SRC_PLAYBACK) - I2SOUT_CONTROL &= ~(1<<5); + + if ((unsigned)source >= AUDIO_NUM_SOURCES) + source = AUDIO_SRC_PLAYBACK; + + bool loopback = source != AUDIO_SRC_PLAYBACK; + +#if CONFIG_CPU == AS3525 + loopback = loopback && audio_channels > 1; + + audio_output_source = source; +#endif + + if (loopback) + I2SOUT_CONTROL |= (1<<5); /* loopback from i2sin fifo */ else - I2SOUT_CONTROL |= 1<<5; /* source = loopback from i2sin fifo */ + I2SOUT_CONTROL &= ~(1<<5); /* normal i2sout */ } void audio_input_mux(int source, unsigned flags) @@ -108,4 +125,33 @@ void audio_input_mux(int source, unsigned flags) } last_source = source; + +#if CONFIG_CPU == AS3525 + /* Sync on behalf of change in number of channels */ + audio_set_output_source(audio_output_source); +#endif } + +#ifdef CONFIG_SAMPR_TYPES +unsigned int pcm_sampr_to_hw_sampr(unsigned int samplerate, + unsigned int type) +{ +#ifdef HAVE_RECORDING + if (samplerate != HW_SAMPR_RESET && type == SAMPR_TYPE_REC) + { + /* Check if the samplerate is in the list of recordable rates. + * Fail to default if not */ + int index = round_value_to_list32(samplerate, rec_freq_sampr, + REC_NUM_FREQ, false); + if (samplerate != rec_freq_sampr[index]) + samplerate = REC_SAMPR_DEFAULT; + + samplerate *= 2; /* Recording rates are 1/2 the codec clock */ + } +#endif /* HAVE_RECORDING */ + + return samplerate; + (void)type; +} +#endif /* CONFIG_SAMPR_TYPES */ + -- cgit v1.2.3