Explicitly set the dialog's result code for TTS / Encoder windows. Fixes an issue...
[Rockbox.git] / apps / audio_path.c
blob998b2988c9afdc18648e5ecd2d6521b64e16d4f6
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Audio signal path management APIs
12 * Copyright (C) 2007 by Michael Sevakis
14 * All files in this archive are subject to the GNU General Public License.
15 * See the file COPYING in the source tree root for full license agreement.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "system.h"
22 #include "cpu.h"
23 #include "audio.h"
24 #include "general.h"
25 #include "settings.h"
26 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
27 #ifdef HAVE_SPDIF_POWER
28 #include "power.h"
29 #endif
30 #include "spdif.h"
31 #endif
32 #if CONFIG_TUNER
33 #include "radio.h"
34 #endif
36 /* Some audio sources may require a boosted CPU */
37 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
38 #ifdef HAVE_SPDIF_REC
39 #define AUDIO_CPU_BOOST
40 #endif
41 #endif
43 #ifndef SIMULATOR
45 #ifdef AUDIO_CPU_BOOST
46 static void audio_cpu_boost(bool state)
48 static bool cpu_boosted = false;
50 if (state != cpu_boosted)
52 cpu_boost(state);
53 cpu_boosted = state;
55 } /* audio_cpu_boost */
56 #endif /* AUDIO_CPU_BOOST */
58 /**
59 * Selects an audio source for recording or playback
60 * powers/unpowers related devices and sets up monitoring.
62 void audio_set_input_source(int source, unsigned flags)
64 /** Do power up/down of associated device(s) **/
66 /** SPDIF **/
67 #ifdef AUDIO_CPU_BOOST
68 /* Always boost for SPDIF */
69 audio_cpu_boost(source == AUDIO_SRC_SPDIF);
70 #endif /* AUDIO_CPU_BOOST */
72 #ifdef HAVE_SPDIF_POWER
73 /* Check if S/PDIF output power should be switched off or on. NOTE: assumes
74 both optical in and out is controlled by the same power source, which is
75 the case on H1x0. */
76 spdif_power_enable((source == AUDIO_SRC_SPDIF) ||
77 global_settings.spdif_enable);
78 #endif /* HAVE_SPDIF_POWER */
79 /* Set the appropriate feed for spdif output */
80 #ifdef HAVE_SPDIF_OUT
81 spdif_set_output_source(source
82 IF_SPDIF_POWER_(, global_settings.spdif_enable));
83 #endif /* HAVE_SPDIF_OUT */
85 /** Tuner **/
86 #if CONFIG_TUNER
87 /* Switch radio off or on per source and flags. */
88 if (source != AUDIO_SRC_FMRADIO)
89 radio_stop();
90 else if (flags & SRCF_FMRADIO_PAUSED)
91 radio_pause();
92 else
93 radio_start();
94 #endif
96 /* set hardware inputs */
97 audio_input_mux(source, flags);
98 } /* audio_set_source */
100 #ifdef HAVE_SPDIF_IN
102 * Return SPDIF sample rate index in audio_master_sampr_list. Since we base
103 * our reading on the actual SPDIF sample rate (which might be a bit
104 * inaccurate), we round off to the closest sample rate that is supported by
105 * SPDIF.
107 int audio_get_spdif_sample_rate(void)
109 unsigned long measured_rate = spdif_measure_frequency();
110 /* Find which SPDIF sample rate we're closest to. */
111 return round_value_to_list32(measured_rate, audio_master_sampr_list,
112 SAMPR_NUM_FREQ, false);
113 } /* audio_get_spdif_sample_rate */
114 #endif /* HAVE_SPDIF_IN */
116 #else /* SIMULATOR */
118 /** Sim stubs **/
120 #ifdef AUDIO_CPU_BOOST
121 static void audio_cpu_boost(bool state)
123 (void)state;
124 } /* audio_cpu_boost */
125 #endif /* AUDIO_CPU_BOOST */
127 void audio_set_output_source(int source)
129 (void)source;
130 } /* audio_set_output_source */
132 void audio_set_input_source(int source, unsigned flags)
134 (void)source;
135 (void)flags;
136 } /* audio_set_input_source */
138 #ifdef HAVE_SPDIF_IN
139 int audio_get_spdif_sample_rate(void)
141 return FREQ_44;
142 } /* audio_get_spdif_sample_rate */
143 #endif /* HAVE_SPDIF_IN */
145 #endif /* !SIMULATOR */