1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Audio signal path management APIs
12 * Copyright (C) 2007 by Michael Sevakis
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.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
28 #if defined(HAVE_SPDIF_IN) || defined(HAVE_SPDIF_OUT)
29 #ifdef HAVE_SPDIF_POWER
38 /* Some audio sources may require a boosted CPU */
39 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
41 #define AUDIO_CPU_BOOST
47 #ifdef AUDIO_CPU_BOOST
48 static void audio_cpu_boost(bool state
)
50 static bool cpu_boosted
= false;
52 if (state
!= cpu_boosted
)
57 } /* audio_cpu_boost */
58 #endif /* AUDIO_CPU_BOOST */
61 * Selects an audio source for recording or playback
62 * powers/unpowers related devices and sets up monitoring.
64 void audio_set_input_source(int source
, unsigned flags
)
66 /** Do power up/down of associated device(s) **/
69 #ifdef AUDIO_CPU_BOOST
70 /* Always boost for SPDIF */
71 audio_cpu_boost(source
== AUDIO_SRC_SPDIF
);
72 #endif /* AUDIO_CPU_BOOST */
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
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 */
83 spdif_set_output_source(source
84 IF_SPDIF_POWER_(, global_settings
.spdif_enable
));
85 #endif /* HAVE_SPDIF_OUT */
89 /* Switch radio off or on per source and flags. */
90 if (source
!= AUDIO_SRC_FMRADIO
)
92 else if (flags
& SRCF_FMRADIO_PAUSED
)
98 /* set hardware inputs */
99 audio_input_mux(source
, flags
);
100 } /* audio_set_source */
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
109 int audio_get_spdif_sample_rate(void)
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 */
118 #else /* SIMULATOR */
122 #ifdef AUDIO_CPU_BOOST
123 static void audio_cpu_boost(bool state
)
126 } /* audio_cpu_boost */
127 #endif /* AUDIO_CPU_BOOST */
129 void audio_set_output_source(int source
)
132 } /* audio_set_output_source */
134 void audio_set_input_source(int source
, unsigned flags
)
139 /* Switch radio off or on per source and flags. */
140 if (source
!= AUDIO_SRC_FMRADIO
)
142 else if (flags
& SRCF_FMRADIO_PAUSED
)
147 } /* audio_set_input_source */
150 int audio_get_spdif_sample_rate(void)
153 } /* audio_get_spdif_sample_rate */
154 #endif /* HAVE_SPDIF_IN */
156 #endif /* !SIMULATOR */