skin tags: fix the id3 track/disc numbers in conditionals
[maemo-rb.git] / apps / audio_path.c
blob9ef748382fa8a004b665edd49ad6ddc4171836c3
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 * 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 ****************************************************************************/
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
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
45 #if ((CONFIG_PLATFORM & PLATFORM_NATIVE) || defined(SAMSUNG_YPR0))
47 #ifdef AUDIO_CPU_BOOST
48 static void audio_cpu_boost(bool state)
50 static bool cpu_boosted = false;
52 if (state != cpu_boosted)
54 cpu_boost(state);
55 cpu_boosted = state;
57 } /* audio_cpu_boost */
58 #endif /* AUDIO_CPU_BOOST */
60 /**
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) **/
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 */
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 */
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
98 /* set hardware inputs */
99 audio_input_mux(source, flags);
100 } /* audio_set_source */
102 #ifdef HAVE_SPDIF_IN
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.
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 /* PLATFORM_HOSTED */
120 /** Sim stubs **/
122 #ifdef AUDIO_CPU_BOOST
123 static void audio_cpu_boost(bool state)
125 (void)state;
126 } /* audio_cpu_boost */
127 #endif /* AUDIO_CPU_BOOST */
129 void audio_set_output_source(int source)
131 (void)source;
132 } /* audio_set_output_source */
134 void audio_set_input_source(int source, unsigned flags)
136 (void)source;
137 (void)flags;
138 #if CONFIG_TUNER
139 /* Switch radio off or on per source and flags. */
140 if (source != AUDIO_SRC_FMRADIO)
141 radio_stop();
142 else if (flags & SRCF_FMRADIO_PAUSED)
143 radio_pause();
144 else
145 radio_start();
146 #endif
147 } /* audio_set_input_source */
149 #ifdef HAVE_SPDIF_IN
150 int audio_get_spdif_sample_rate(void)
152 return FREQ_44;
153 } /* audio_get_spdif_sample_rate */
154 #endif /* HAVE_SPDIF_IN */
156 #endif /* PLATFORM_NATIVE */