Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Audio signal path management APIs |
| 11 | * |
| 12 | * Copyright (C) 2007 by Michael Sevakis |
| 13 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; either version 2 |
| 17 | * of the License, or (at your option) any later version. |
Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 18 | * |
| 19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 20 | * KIND, either express or implied. |
| 21 | * |
| 22 | ****************************************************************************/ |
| 23 | #include "system.h" |
| 24 | #include "cpu.h" |
| 25 | #include "audio.h" |
| 26 | #include "general.h" |
| 27 | #include "settings.h" |
| 28 | #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT) |
| 29 | #ifdef HAVE_SPDIF_POWER |
| 30 | #include "power.h" |
| 31 | #endif |
| 32 | #include "spdif.h" |
| 33 | #endif |
| 34 | #if CONFIG_TUNER |
| 35 | #include "radio.h" |
| 36 | #endif |
| 37 | |
| 38 | /* Some audio sources may require a boosted CPU */ |
| 39 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
| 40 | #ifdef HAVE_SPDIF_REC |
| 41 | #define AUDIO_CPU_BOOST |
| 42 | #endif |
| 43 | #endif |
| 44 | |
| 45 | #ifndef SIMULATOR |
| 46 | |
| 47 | #ifdef AUDIO_CPU_BOOST |
| 48 | static void audio_cpu_boost(bool state) |
| 49 | { |
| 50 | static bool cpu_boosted = false; |
| 51 | |
| 52 | if (state != cpu_boosted) |
| 53 | { |
| 54 | cpu_boost(state); |
| 55 | cpu_boosted = state; |
| 56 | } |
| 57 | } /* audio_cpu_boost */ |
| 58 | #endif /* AUDIO_CPU_BOOST */ |
| 59 | |
| 60 | /** |
| 61 | * Selects an audio source for recording or playback |
| 62 | * powers/unpowers related devices and sets up monitoring. |
| 63 | */ |
| 64 | void audio_set_input_source(int source, unsigned flags) |
| 65 | { |
| 66 | /** Do power up/down of associated device(s) **/ |
| 67 | |
| 68 | /** SPDIF **/ |
| 69 | #ifdef AUDIO_CPU_BOOST |
| 70 | /* Always boost for SPDIF */ |
| 71 | audio_cpu_boost(source == AUDIO_SRC_SPDIF); |
| 72 | #endif /* AUDIO_CPU_BOOST */ |
| 73 | |
| 74 | #ifdef HAVE_SPDIF_POWER |
| 75 | /* Check if S/PDIF output power should be switched off or on. NOTE: assumes |
| 76 | both optical in and out is controlled by the same power source, which is |
| 77 | the case on H1x0. */ |
| 78 | spdif_power_enable((source == AUDIO_SRC_SPDIF) || |
| 79 | global_settings.spdif_enable); |
| 80 | #endif /* HAVE_SPDIF_POWER */ |
| 81 | /* Set the appropriate feed for spdif output */ |
| 82 | #ifdef HAVE_SPDIF_OUT |
| 83 | spdif_set_output_source(source |
| 84 | IF_SPDIF_POWER_(, global_settings.spdif_enable)); |
| 85 | #endif /* HAVE_SPDIF_OUT */ |
| 86 | |
| 87 | /** Tuner **/ |
| 88 | #if CONFIG_TUNER |
| 89 | /* Switch radio off or on per source and flags. */ |
| 90 | if (source != AUDIO_SRC_FMRADIO) |
| 91 | radio_stop(); |
| 92 | else if (flags & SRCF_FMRADIO_PAUSED) |
| 93 | radio_pause(); |
| 94 | else |
| 95 | radio_start(); |
| 96 | #endif |
| 97 | |
| 98 | /* set hardware inputs */ |
| 99 | audio_input_mux(source, flags); |
| 100 | } /* audio_set_source */ |
| 101 | |
| 102 | #ifdef HAVE_SPDIF_IN |
| 103 | /** |
| 104 | * Return SPDIF sample rate index in audio_master_sampr_list. Since we base |
| 105 | * our reading on the actual SPDIF sample rate (which might be a bit |
| 106 | * inaccurate), we round off to the closest sample rate that is supported by |
| 107 | * SPDIF. |
| 108 | */ |
| 109 | int audio_get_spdif_sample_rate(void) |
| 110 | { |
| 111 | unsigned long measured_rate = spdif_measure_frequency(); |
| 112 | /* Find which SPDIF sample rate we're closest to. */ |
| 113 | return round_value_to_list32(measured_rate, audio_master_sampr_list, |
| 114 | SAMPR_NUM_FREQ, false); |
| 115 | } /* audio_get_spdif_sample_rate */ |
| 116 | #endif /* HAVE_SPDIF_IN */ |
| 117 | |
| 118 | #else /* SIMULATOR */ |
| 119 | |
| 120 | /** Sim stubs **/ |
| 121 | |
| 122 | #ifdef AUDIO_CPU_BOOST |
| 123 | static void audio_cpu_boost(bool state) |
| 124 | { |
| 125 | (void)state; |
| 126 | } /* audio_cpu_boost */ |
| 127 | #endif /* AUDIO_CPU_BOOST */ |
| 128 | |
| 129 | void audio_set_output_source(int source) |
| 130 | { |
| 131 | (void)source; |
| 132 | } /* audio_set_output_source */ |
| 133 | |
| 134 | void audio_set_input_source(int source, unsigned flags) |
| 135 | { |
| 136 | (void)source; |
| 137 | (void)flags; |
| 138 | } /* audio_set_input_source */ |
| 139 | |
| 140 | #ifdef HAVE_SPDIF_IN |
| 141 | int audio_get_spdif_sample_rate(void) |
| 142 | { |
| 143 | return FREQ_44; |
| 144 | } /* audio_get_spdif_sample_rate */ |
| 145 | #endif /* HAVE_SPDIF_IN */ |
| 146 | |
| 147 | #endif /* !SIMULATOR */ |