summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/SOURCES3
-rw-r--r--apps/audio_path.c145
-rw-r--r--apps/debug_menu.c4
-rw-r--r--apps/playback.c4
-rw-r--r--apps/plugin.c7
-rw-r--r--apps/plugin.h7
-rw-r--r--apps/plugins/test_sampr.c6
-rw-r--r--apps/recorder/radio.c8
-rw-r--r--apps/recorder/recording.c107
-rw-r--r--apps/recorder/recording.h4
10 files changed, 184 insertions, 111 deletions
diff --git a/apps/SOURCES b/apps/SOURCES
index ccc481b07b..ccb9ca2772 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -86,6 +86,9 @@ recorder/radio.c
86recorder/recording.c 86recorder/recording.c
87#endif 87#endif
88#if CONFIG_CODEC == SWCODEC 88#if CONFIG_CODEC == SWCODEC
89#if INPUT_SRC_CAPS != 0
90audio_path.c
91#endif /* INPUT_SRC_CAPS != 0 */
89pcmbuf.c 92pcmbuf.c
90playback.c 93playback.c
91codecs.c 94codecs.c
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 */
diff --git a/apps/debug_menu.c b/apps/debug_menu.c
index 404d82c63e..691e9f5070 100644
--- a/apps/debug_menu.c
+++ b/apps/debug_menu.c
@@ -693,7 +693,7 @@ static bool dbg_spdif(void)
693 bool done = false; 693 bool done = false;
694 bool spdif_src_on; 694 bool spdif_src_on;
695 int spdif_source = spdif_get_output_source(&spdif_src_on); 695 int spdif_source = spdif_get_output_source(&spdif_src_on);
696 spdif_set_output_source(AUDIO_SRC_SPDIF, true); 696 spdif_set_output_source(AUDIO_SRC_SPDIF IF_SPDIF_POWER_(, true));
697 697
698 lcd_setmargins(0, 0); 698 lcd_setmargins(0, 0);
699 lcd_clear_display(); 699 lcd_clear_display();
@@ -844,7 +844,7 @@ static bool dbg_spdif(void)
844 break; 844 break;
845 } 845 }
846 846
847 spdif_set_output_source(spdif_source, spdif_src_on); 847 spdif_set_output_source(spdif_source IF_SPDIF_POWER_(, spdif_src_on));
848 848
849#ifdef HAVE_SPDIF_POWER 849#ifdef HAVE_SPDIF_POWER
850 spdif_power_enable(global_settings.spdif_enable); 850 spdif_power_enable(global_settings.spdif_enable);
diff --git a/apps/playback.c b/apps/playback.c
index b48bcc8c26..9cd82de9b6 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -3301,8 +3301,8 @@ static void audio_stop_playback(void)
3301 3301
3302static void audio_play_start(size_t offset) 3302static void audio_play_start(size_t offset)
3303{ 3303{
3304#if defined(HAVE_RECORDING) || CONFIG_TUNER 3304#if INPUT_SRC_CAPS != 0
3305 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); 3305 audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
3306#endif 3306#endif
3307 3307
3308 /* Wait for any previously playing audio to flush - TODO: Not necessary? */ 3308 /* Wait for any previously playing audio to flush - TODO: Not necessary? */
diff --git a/apps/plugin.c b/apps/plugin.c
index a63e5cd6ee..79ecae9a1f 100644
--- a/apps/plugin.c
+++ b/apps/plugin.c
@@ -349,11 +349,12 @@ static const struct plugin_api rockbox_api = {
349 pcm_stop_recording, 349 pcm_stop_recording,
350 pcm_calculate_rec_peaks, 350 pcm_calculate_rec_peaks,
351 audio_set_recording_gain, 351 audio_set_recording_gain,
352 audio_set_output_source,
353 rec_set_source,
354#endif /* HAVE_RECORDING */ 352#endif /* HAVE_RECORDING */
355 353#if INPUT_SRC_CAPS != 0
354 audio_set_output_source,
355 audio_set_input_source,
356#endif 356#endif
357#endif /* CONFIG_CODEC == SWCODEC */
357 358
358 /* playback control */ 359 /* playback control */
359 playlist_amount, 360 playlist_amount,
diff --git a/apps/plugin.h b/apps/plugin.h
index 2c8b328fe1..bc6adffab2 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -448,11 +448,12 @@ struct plugin_api {
448 void (*pcm_stop_recording)(void); 448 void (*pcm_stop_recording)(void);
449 void (*pcm_calculate_rec_peaks)(int *left, int *right); 449 void (*pcm_calculate_rec_peaks)(int *left, int *right);
450 void (*audio_set_recording_gain)(int left, int right, int type); 450 void (*audio_set_recording_gain)(int left, int right, int type);
451 void (*audio_set_output_source)(int monitor);
452 void (*rec_set_source)(int source, unsigned flags);
453#endif /* HAVE_RECORDING */ 451#endif /* HAVE_RECORDING */
454 452#if INPUT_SRC_CAPS != 0
453 void (*audio_set_output_source)(int monitor);
454 void (*audio_set_input_source)(int source, unsigned flags);
455#endif 455#endif
456#endif /* CONFIG_CODEC == SWCODC */
456 457
457 /* playback control */ 458 /* playback control */
458 int (*playlist_amount)(void); 459 int (*playlist_amount)(void);
diff --git a/apps/plugins/test_sampr.c b/apps/plugins/test_sampr.c
index 253c592eaa..e1511e3dfd 100644
--- a/apps/plugins/test_sampr.c
+++ b/apps/plugins/test_sampr.c
@@ -199,9 +199,9 @@ void play_waveform(void)
199 rb->audio_stop(); 199 rb->audio_stop();
200 rb->sound_set(SOUND_VOLUME, rb->sound_default(SOUND_VOLUME)); 200 rb->sound_set(SOUND_VOLUME, rb->sound_default(SOUND_VOLUME));
201 201
202#ifdef HAVE_RECORDING 202#ifdef INPUT_SRC_CAPS != 0
203 /* Select playback */ 203 /* Select playback */
204 rb->rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); 204 rb->audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
205#endif 205#endif
206 206
207#ifdef HAVE_ADJUSTABLE_CPU_FREQ 207#ifdef HAVE_ADJUSTABLE_CPU_FREQ
@@ -210,7 +210,7 @@ void play_waveform(void)
210 210
211 rb->pcm_set_frequency(rb->hw_freq_sampr[freq]); 211 rb->pcm_set_frequency(rb->hw_freq_sampr[freq]);
212 212
213#ifdef HAVE_RECORDING 213#ifdef INPUT_SRC_CAPS != 0
214 /* Recordable targets can play back from other sources */ 214 /* Recordable targets can play back from other sources */
215 rb->audio_set_output_source(AUDIO_SRC_PLAYBACK); 215 rb->audio_set_output_source(AUDIO_SRC_PLAYBACK);
216#endif 216#endif
diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c
index 9f3228be1f..23e820e835 100644
--- a/apps/recorder/radio.c
+++ b/apps/recorder/radio.c
@@ -509,9 +509,9 @@ int radio_screen(void)
509 509
510 /* turn on radio */ 510 /* turn on radio */
511#if CONFIG_CODEC == SWCODEC 511#if CONFIG_CODEC == SWCODEC
512 rec_set_source(AUDIO_SRC_FMRADIO, 512 audio_set_input_source(AUDIO_SRC_FMRADIO,
513 (radio_status == FMRADIO_PAUSED) ? 513 (radio_status == FMRADIO_PAUSED) ?
514 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING); 514 SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
515#else 515#else
516 if (radio_status == FMRADIO_OFF) 516 if (radio_status == FMRADIO_OFF)
517 radio_start(); 517 radio_start();
@@ -985,7 +985,7 @@ int radio_screen(void)
985 else 985 else
986 { 986 {
987#if CONFIG_CODEC == SWCODEC 987#if CONFIG_CODEC == SWCODEC
988 rec_set_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); 988 audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
989#else 989#else
990 radio_stop(); 990 radio_stop();
991#endif 991#endif
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 5738a34949..226ff9a17f 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -547,80 +547,6 @@ int rec_create_directory(void)
547 return 0; 547 return 0;
548} 548}
549 549
550#if CONFIG_CODEC == SWCODEC && !defined(SIMULATOR)
551
552# ifdef HAVE_SPDIF_REC
553# ifdef HAVE_ADJUSTABLE_CPU_FREQ
554static void rec_boost(bool state)
555{
556 static bool cpu_boosted = false;
557
558 if (state != cpu_boosted)
559 {
560 cpu_boost(state);
561 cpu_boosted = state;
562 }
563}
564# endif
565# endif
566
567/**
568 * Selects an audio source for recording or playback
569 * powers/unpowers related devices and sets up monitoring.
570 * Here because it calls app code and used only for HAVE_RECORDING atm.
571 * Would like it in pcm_record.c.
572 *
573 * Behaves like a firmware function in that it does not use global settings
574 * to determine the state.
575 *
576 * The order of setting monitoring may need tweaking dependent upon the
577 * selected source to get the smoothest transition.
578 */
579void rec_set_source(int source, unsigned flags)
580{
581 /** Do power up/down of associated device(s) **/
582
583 /** SPDIF **/
584#ifdef HAVE_SPDIF_REC
585 /* Always boost for SPDIF */
586 rec_boost(source == AUDIO_SRC_SPDIF);
587#endif /* HAVE_SPDIF_IN */
588
589#ifdef HAVE_SPDIF_POWER
590 /* Check if S/PDIF output power should be switched off or on. NOTE: assumes
591 both optical in and out is controlled by the same power source, which is
592 the case on H1x0. */
593 spdif_power_enable((source == AUDIO_SRC_SPDIF) ||
594 global_settings.spdif_enable);
595 /* Set the appropriate feed for spdif output */
596#ifdef HAVE_SPDIF_OUT
597 spdif_set_output_source(source, global_settings.spdif_enable);
598#endif
599#else /* !HAVE_SPDIF_POWER */
600#ifdef HAVE_SPDIF_OUT
601 spdif_set_output_source(source, true);
602#endif
603#endif /* !HAVE_SPDIF_POWER */
604
605 /** Tuner **/
606#if CONFIG_TUNER
607 /* Switch radio off or on per source and flags. */
608 if (source != AUDIO_SRC_FMRADIO)
609 radio_stop();
610 else if (flags & SRCF_FMRADIO_PAUSED)
611 radio_pause();
612 else
613 radio_start();
614#endif
615
616 /* set hardware inputs */
617 audio_set_source(source, flags);
618
619 peak_meter_playback((flags & SRCF_RECORDING) == 0);
620 peak_meter_enabled = true;
621} /* rec_set_source */
622#endif /* CONFIG_CODEC == SWCODEC && !defined(SIMULATOR) */
623
624void rec_init_recording_options(struct audio_recording_options *options) 550void rec_init_recording_options(struct audio_recording_options *options)
625{ 551{
626 options->rec_source = global_settings.rec_source; 552 options->rec_source = global_settings.rec_source;
@@ -637,6 +563,18 @@ void rec_init_recording_options(struct audio_recording_options *options)
637#endif 563#endif
638} 564}
639 565
566#if CONFIG_CODEC == SWCODEC && !defined (SIMULATOR)
567void rec_set_source(int source, unsigned flags)
568{
569 /* Set audio input source, power up/down devices */
570 audio_set_input_source(source, flags);
571
572 /* Set peakmeters for recording or reset to playback */
573 peak_meter_playback((flags & SRCF_RECORDING) == 0);
574 peak_meter_enabled = true;
575}
576#endif /* CONFIG_CODEC == SWCODEC && !defined (SIMULATOR) */
577
640void rec_set_recording_options(struct audio_recording_options *options) 578void rec_set_recording_options(struct audio_recording_options *options)
641{ 579{
642#if CONFIG_CODEC != SWCODEC 580#if CONFIG_CODEC != SWCODEC
@@ -2062,20 +2000,6 @@ void rec_set_source(int source, unsigned flags)
2062 flags = flags; 2000 flags = flags;
2063} 2001}
2064 2002
2065#ifdef HAVE_SPDIF_IN
2066#ifdef HAVE_SPDIF_POWER
2067void audio_set_spdif_power_setting(bool on)
2068{
2069 on = on;
2070}
2071
2072bool audio_get_spdif_power_setting(void)
2073{
2074 return true;
2075}
2076#endif /* HAVE_SPDIF_POWER */
2077#endif /* HAVE_SPDIF_IN */
2078
2079void audio_set_recording_options(struct audio_recording_options *options) 2003void audio_set_recording_options(struct audio_recording_options *options)
2080{ 2004{
2081 options = options; 2005 options = options;
@@ -2088,13 +2012,12 @@ void audio_set_recording_gain(int left, int right, int type)
2088 type = type; 2012 type = type;
2089} 2013}
2090 2014
2091void audio_set_output_source(int source) 2015void audio_record(const char *filename)
2092{ 2016{
2093 source = source; 2017 filename = filename;
2094} 2018}
2095 2019
2096 2020void audio_new_file(const char *filename)
2097void audio_record(const char *filename)
2098{ 2021{
2099 filename = filename; 2022 filename = filename;
2100} 2023}
diff --git a/apps/recorder/recording.h b/apps/recorder/recording.h
index 3ca1f35834..50a73856cf 100644
--- a/apps/recorder/recording.h
+++ b/apps/recorder/recording.h
@@ -29,7 +29,7 @@ int rec_create_directory(void);
29extern bool recording_start_automatic; 29extern bool recording_start_automatic;
30 30
31#if CONFIG_CODEC == SWCODEC 31#if CONFIG_CODEC == SWCODEC
32/* handles device powerup and sets audio source */ 32/* handles device powerup, sets audio source and peakmeter mode */
33void rec_set_source(int source, unsigned flags); 33void rec_set_source(int source, unsigned flags);
34#endif /* CONFIG_CODEC == SW_CODEC */ 34#endif /* CONFIG_CODEC == SW_CODEC */
35 35
@@ -47,4 +47,4 @@ void rec_record(void);
47/* creates unique filename and starts recording */ 47/* creates unique filename and starts recording */
48void rec_new_file(void); 48void rec_new_file(void);
49 49
50#endif 50#endif /* RECORDING_H */