summaryrefslogtreecommitdiff
path: root/apps/audio_path.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/audio_path.c')
-rw-r--r--apps/audio_path.c145
1 files changed, 145 insertions, 0 deletions
diff --git a/apps/audio_path.c b/apps/audio_path.c
new file mode 100644
index 0000000000..998b2988c9
--- /dev/null
+++ b/apps/audio_path.c
@@ -0,0 +1,145 @@
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 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
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
35
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
42
43#ifndef SIMULATOR
44
45#ifdef AUDIO_CPU_BOOST
46static void audio_cpu_boost(bool state)
47{
48 static bool cpu_boosted = false;
49
50 if (state != cpu_boosted)
51 {
52 cpu_boost(state);
53 cpu_boosted = state;
54 }
55} /* audio_cpu_boost */
56#endif /* AUDIO_CPU_BOOST */
57
58/**
59 * Selects an audio source for recording or playback
60 * powers/unpowers related devices and sets up monitoring.
61 */
62void audio_set_input_source(int source, unsigned flags)
63{
64 /** Do power up/down of associated device(s) **/
65
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 */
71
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 */
84
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
95
96 /* set hardware inputs */
97 audio_input_mux(source, flags);
98} /* audio_set_source */
99
100#ifdef HAVE_SPDIF_IN
101/**
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.
106 */
107int audio_get_spdif_sample_rate(void)
108{
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 */
115
116#else /* SIMULATOR */
117
118/** Sim stubs **/
119
120#ifdef AUDIO_CPU_BOOST
121static void audio_cpu_boost(bool state)
122{
123 (void)state;
124} /* audio_cpu_boost */
125#endif /* AUDIO_CPU_BOOST */
126
127void audio_set_output_source(int source)
128{
129 (void)source;
130} /* audio_set_output_source */
131
132void audio_set_input_source(int source, unsigned flags)
133{
134 (void)source;
135 (void)flags;
136} /* audio_set_input_source */
137
138#ifdef HAVE_SPDIF_IN
139int audio_get_spdif_sample_rate(void)
140{
141 return FREQ_44;
142} /* audio_get_spdif_sample_rate */
143#endif /* HAVE_SPDIF_IN */
144
145#endif /* !SIMULATOR */