1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
26 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
27 #ifdef HAVE_SPDIF_POWER
36 /* Some audio sources may require a boosted CPU */
37 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
39 #define AUDIO_CPU_BOOST
45 #ifdef AUDIO_CPU_BOOST
46 static void audio_cpu_boost(bool state
)
48 static bool cpu_boosted
= false;
50 if (state
!= cpu_boosted
)
55 } /* audio_cpu_boost */
56 #endif /* AUDIO_CPU_BOOST */
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) **/
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
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 */
81 spdif_set_output_source(source
82 IF_SPDIF_POWER_(, global_settings
.spdif_enable
));
83 #endif /* HAVE_SPDIF_OUT */
87 /* Switch radio off or on per source and flags. */
88 if (source
!= AUDIO_SRC_FMRADIO
)
90 else if (flags
& SRCF_FMRADIO_PAUSED
)
96 /* set hardware inputs */
97 audio_input_mux(source
, flags
);
98 } /* audio_set_source */
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
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 */
120 #ifdef AUDIO_CPU_BOOST
121 static void audio_cpu_boost(bool state
)
124 } /* audio_cpu_boost */
125 #endif /* AUDIO_CPU_BOOST */
127 void audio_set_output_source(int source
)
130 } /* audio_set_output_source */
132 void audio_set_input_source(int source
, unsigned flags
)
136 } /* audio_set_input_source */
139 int audio_get_spdif_sample_rate(void)
142 } /* audio_get_spdif_sample_rate */
143 #endif /* HAVE_SPDIF_IN */
145 #endif /* !SIMULATOR */