summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-10-12 11:09:55 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-10-12 15:33:32 +0000
commit078c34e951049741cd6681e0219561eec67e071b (patch)
tree734edf13fae68177e832d9869061777eb424d481
parent01dc81cd943719dc0ba380774b332f6c2ee0d67e (diff)
downloadrockbox-078c34e951049741cd6681e0219561eec67e071b.tar.gz
rockbox-078c34e951049741cd6681e0219561eec67e071b.zip
hosted: More PCM muting work
* Track mute state, only call hw if actual change is needed * Don't unmute in audiohw_postinit() * sample rate tracking fixes * erosq: Don't start up muted Change-Id: I004f787a4b7ea73c16b6ec9818ec29a12c89f46b
-rw-r--r--firmware/drivers/audio/erosqlinux_codec.c13
-rw-r--r--firmware/drivers/audio/rocker_codec.c12
-rw-r--r--firmware/drivers/audio/xduoolinux_codec.c13
-rw-r--r--firmware/export/erosqlinux_codec.h1
-rw-r--r--firmware/target/hosted/pcm-alsa.c14
5 files changed, 31 insertions, 22 deletions
diff --git a/firmware/drivers/audio/erosqlinux_codec.c b/firmware/drivers/audio/erosqlinux_codec.c
index 9336083d58..d56e32c6ff 100644
--- a/firmware/drivers/audio/erosqlinux_codec.c
+++ b/firmware/drivers/audio/erosqlinux_codec.c
@@ -42,7 +42,7 @@ static int inited = 0;
42 42
43static long int vol_l_hw = 255; 43static long int vol_l_hw = 255;
44static long int vol_r_hw = 255; 44static long int vol_r_hw = 255;
45static long int last_ps = 0; 45static long int last_ps = -1;
46 46
47static void hw_open(void) 47static void hw_open(void)
48{ 48{
@@ -62,6 +62,11 @@ void audiohw_mute(int mute)
62{ 62{
63 logf("mute %d", mute); 63 logf("mute %d", mute);
64 64
65 if (muted == mute)
66 return;
67
68 muted = mute;
69
65 if(mute) 70 if(mute)
66 { 71 {
67 long int ps0 = 0; 72 long int ps0 = 0;
@@ -69,10 +74,8 @@ void audiohw_mute(int mute)
69 } 74 }
70 else 75 else
71 { 76 {
72 last_ps = 0;
73 erosq_get_outputs(); 77 erosq_get_outputs();
74 } 78 }
75 muted = mute;
76} 79}
77 80
78int erosq_get_outputs(void) { 81int erosq_get_outputs(void) {
@@ -115,14 +118,14 @@ void audiohw_preinit(void)
115 logf("hw preinit"); 118 logf("hw preinit");
116 alsa_controls_init(); 119 alsa_controls_init();
117 hw_open(); 120 hw_open();
118 audiohw_mute(true); /* Start muted to avoid the POP */ 121// audiohw_mute(true); /* Start muted to avoid the POP */
122 audiohw_mute(false);
119 inited = 1; 123 inited = 1;
120} 124}
121 125
122void audiohw_postinit(void) 126void audiohw_postinit(void)
123{ 127{
124 logf("hw postinit"); 128 logf("hw postinit");
125 erosq_get_outputs(); // Unmutes
126} 129}
127 130
128void audiohw_close(void) 131void audiohw_close(void)
diff --git a/firmware/drivers/audio/rocker_codec.c b/firmware/drivers/audio/rocker_codec.c
index e5573df843..e34cb87e9b 100644
--- a/firmware/drivers/audio/rocker_codec.c
+++ b/firmware/drivers/audio/rocker_codec.c
@@ -32,6 +32,8 @@ static int fd_hw;
32static long int vol_l_hw = 255; 32static long int vol_l_hw = 255;
33static long int vol_r_hw = 255; 33static long int vol_r_hw = 255;
34 34
35static int muted = -1;
36
35static void hw_open(void) 37static void hw_open(void)
36{ 38{
37 fd_hw = open("/dev/snd/controlC0", O_RDWR); 39 fd_hw = open("/dev/snd/controlC0", O_RDWR);
@@ -46,6 +48,11 @@ static void hw_close(void)
46 48
47void audiohw_mute(int mute) 49void audiohw_mute(int mute)
48{ 50{
51 if (muted == mute)
52 return;
53
54 muted = mute;
55
49 if(mute) 56 if(mute)
50 { 57 {
51 long int ps0 = 0; 58 long int ps0 = 0;
@@ -67,10 +74,7 @@ void audiohw_preinit(void)
67 74
68void audiohw_postinit(void) 75void audiohw_postinit(void)
69{ 76{
70 long int hp = 2; 77 logf("hw postinit");
71
72 /* Output port switch set to Headphones */
73 //alsa_controls_set_ints("Output Port Switch", 1, &hp); // Unmute happens on PCM start
74} 78}
75 79
76void audiohw_close(void) 80void audiohw_close(void)
diff --git a/firmware/drivers/audio/xduoolinux_codec.c b/firmware/drivers/audio/xduoolinux_codec.c
index 59ef562d0a..f9642812d3 100644
--- a/firmware/drivers/audio/xduoolinux_codec.c
+++ b/firmware/drivers/audio/xduoolinux_codec.c
@@ -41,7 +41,7 @@ static int inited = 0;
41 41
42static long int vol_l_hw = 255; 42static long int vol_l_hw = 255;
43static long int vol_r_hw = 255; 43static long int vol_r_hw = 255;
44static long int last_ps = 0; 44static long int last_ps = -1;
45 45
46static void hw_open(void) 46static void hw_open(void)
47{ 47{
@@ -61,6 +61,11 @@ void audiohw_mute(int mute)
61{ 61{
62 logf("mute %d", mute); 62 logf("mute %d", mute);
63 63
64 if (muted == mute)
65 return;
66
67 muted = mute;
68
64 if(mute) 69 if(mute)
65 { 70 {
66 long int ps0 = 0; 71 long int ps0 = 0;
@@ -68,10 +73,8 @@ void audiohw_mute(int mute)
68 } 73 }
69 else 74 else
70 { 75 {
71 last_ps = 0;
72 xduoo_get_outputs(); 76 xduoo_get_outputs();
73 } 77 }
74 muted = mute;
75} 78}
76 79
77int xduoo_get_outputs(void){ 80int xduoo_get_outputs(void){
@@ -124,14 +127,12 @@ void audiohw_preinit(void)
124 hw_open(); 127 hw_open();
125 audiohw_mute(true); /* Start muted to avoid the POP */ 128 audiohw_mute(true); /* Start muted to avoid the POP */
126 inited = 1; 129 inited = 1;
130// const char * const codec_pmdown = "/sys/devices/platform/ingenic-x3ii.0/x3ii-ak4490-i2s/pmdown_time"; // in ms, defaults 5000
127} 131}
128 132
129void audiohw_postinit(void) 133void audiohw_postinit(void)
130{ 134{
131// const char * const codec_pmdown = "/sys/devices/platform/ingenic-x3ii.0/x3ii-ak4490-i2s/pmdown_time"; // in ms, defaults 5000
132
133 logf("hw postinit"); 135 logf("hw postinit");
134 // xduoo_get_outputs(); // Unmute happens upon playback.
135} 136}
136 137
137void audiohw_close(void) 138void audiohw_close(void)
diff --git a/firmware/export/erosqlinux_codec.h b/firmware/export/erosqlinux_codec.h
index 8a3afbfe3c..1dd9b7e6c6 100644
--- a/firmware/export/erosqlinux_codec.h
+++ b/firmware/export/erosqlinux_codec.h
@@ -5,6 +5,7 @@
5 5
6AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -74, 6, -25) 6AUDIOHW_SETTING(VOLUME, "dB", 0, 1, -74, 6, -25)
7 7
8//#define AUDIOHW_NEEDS_INITIAL_UNMUTE
8 9
9void audiohw_mute(int mute); 10void audiohw_mute(int mute);
10void erosq_set_output(int ps); 11void erosq_set_output(int ps);
diff --git a/firmware/target/hosted/pcm-alsa.c b/firmware/target/hosted/pcm-alsa.c
index 428902b82e..db86a790d2 100644
--- a/firmware/target/hosted/pcm-alsa.c
+++ b/firmware/target/hosted/pcm-alsa.c
@@ -454,7 +454,6 @@ void cleanup(void)
454 snd_pcm_close(handle); 454 snd_pcm_close(handle);
455} 455}
456 456
457
458void pcm_play_dma_init(void) 457void pcm_play_dma_init(void)
459{ 458{
460 int err; 459 int err;
@@ -533,9 +532,6 @@ static void pcm_dma_apply_settings_nolock(void)
533 /* Sony NWZ linux driver uses a nonstandard mecanism to set the sampling rate */ 532 /* Sony NWZ linux driver uses a nonstandard mecanism to set the sampling rate */
534 audiohw_set_frequency(pcm_sampr); 533 audiohw_set_frequency(pcm_sampr);
535#endif 534#endif
536#ifdef AUDIOHW_MUTE_ON_SRATE_CHANGE
537 audiohw_mute(false);
538#endif
539 /* (Will be unmuted by pcm resuming) */ 535 /* (Will be unmuted by pcm resuming) */
540 } 536 }
541} 537}
@@ -564,7 +560,7 @@ void pcm_play_dma_stop(void)
564 snd_pcm_nonblock(handle, 0); 560 snd_pcm_nonblock(handle, 0);
565 snd_pcm_drain(handle); 561 snd_pcm_drain(handle);
566 snd_pcm_nonblock(handle, 1); 562 snd_pcm_nonblock(handle, 1);
567 last_sample_rate = 0; 563// last_sample_rate = 0;
568#ifdef AUDIOHW_MUTE_ON_PAUSE 564#ifdef AUDIOHW_MUTE_ON_PAUSE
569 audiohw_mute(true); 565 audiohw_mute(true);
570#endif 566#endif
@@ -579,7 +575,7 @@ void pcm_play_dma_start(const void *addr, size_t size)
579 pcm_data = addr; 575 pcm_data = addr;
580 pcm_size = size; 576 pcm_size = size;
581 577
582#if !defined(AUDIOHW_MUTE_ON_PAUSE) || !defined(AUDIOHW_MUTE_ON_SRATE_CHANGE) 578#if !defined(AUDIOHW_MUTE_ON_PAUSE) && defined(AUDIOHW_MUTE_ON_SRATE_CHANGE)
583 audiohw_mute(false); 579 audiohw_mute(false);
584#endif 580#endif
585 581
@@ -615,7 +611,7 @@ void pcm_play_dma_start(const void *addr, size_t size)
615 logf("Start error: %s\n", snd_strerror(err)); 611 logf("Start error: %s\n", snd_strerror(err));
616 return; 612 return;
617 } 613 }
618#ifdef AUDIOHW_MUTE_ON_PAUSE 614#if defined(AUDIOHW_MUTE_ON_PAUSE)
619 audiohw_mute(false); 615 audiohw_mute(false);
620#endif 616#endif
621 if (err == 0) 617 if (err == 0)
@@ -652,6 +648,10 @@ const void * pcm_play_dma_get_peak_buffer(int *count)
652void pcm_play_dma_postinit(void) 648void pcm_play_dma_postinit(void)
653{ 649{
654 audiohw_postinit(); 650 audiohw_postinit();
651
652#ifdef AUDIOHW_NEEDS_INITIAL_UNMUTE
653 audiohw_mute(false);
654#endif
655} 655}
656 656
657void pcm_set_mixer_volume(int volume) 657void pcm_set_mixer_volume(int volume)