Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alsa aplay plays dual channel 32-bit sampled audio, only one channel can hear the sound #380

Merged
merged 23 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
672d2a5
test
gh-sxp Jul 22, 2022
796d25e
test
gh-sxp Jul 22, 2022
9b69500
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Jul 30, 2022
9bf536a
ffmpeg pushes RTMP with error conversion failed
gh-sxp Jul 30, 2022
0aa295c
Merge branch 'dev' into dev
zhangxiaojingCAN Jul 30, 2022
0ab5ba7
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Aug 9, 2022
d99c909
Merge branch 'dev' of github.com:gh-sxp/k510_buildroot into dev
gh-sxp Aug 9, 2022
4af138c
encod JPEG, QP exceeds 51 coredump
gh-sxp Aug 9, 2022
b92fab1
modify jpeg maxqp value
gh-sxp Aug 9, 2022
4bc37bf
modify maxqp
gh-sxp Aug 9, 2022
1a8f1e6
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Aug 16, 2022
1f08606
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Aug 23, 2022
10bdf9e
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Aug 28, 2022
0266765
DAC output error, left and right channels reversed
gh-sxp Aug 28, 2022
aa9b70c
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Sep 4, 2022
f95de29
Multi channel RTSP audio push problem
gh-sxp Sep 4, 2022
1e2c196
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Sep 18, 2022
5964c56
play 16k noise
gh-sxp Sep 18, 2022
202a7bd
Merge branch 'dev' into dev
zhangxiaojingCAN Sep 19, 2022
968f567
Merge remote-tracking branch 'upstream/dev' into dev
gh-sxp Nov 6, 2022
1f5cd2e
Merge branch 'dev' of github.com:gh-sxp/k510_buildroot into dev
gh-sxp Nov 6, 2022
fe58153
aplay play 32 bit sampled audio only one channel has sound
gh-sxp Nov 6, 2022
f2546b7
Merge branch 'dev' into dev
zhangxiaojingCAN Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions package/encode_app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2218,15 +2218,20 @@ int parse_cmd(int argc, char *argv[])
}
else if(strcmp(argv[i], "-enableGDR") == 0)
{
pCtx->Cfg[cur_ch].bEnableGDR = true;
pCtx->Cfg[cur_ch].FreqIDR = atoi(argv[i+1]);
if (pCtx->Cfg[cur_ch].FreqIDR <= 0)
int nFreqIDR = atoi(argv[i+1]);
if (nFreqIDR < 0)
{
printf("gdr fresh period error\n");
return -1;
}
else if (nFreqIDR > 0)
{
pCtx->Cfg[cur_ch].bEnableGDR = true;
pCtx->Cfg[cur_ch].FreqIDR = nFreqIDR;


printf("enable gdr and fresh peroid %d\n", pCtx->Cfg[cur_ch].FreqIDR);
printf("enable gdr and fresh peroid %d\n", nFreqIDR);
}
}
else if (strcmp(argv[i], "-GDRMode") == 0)
{
Expand Down
99 changes: 99 additions & 0 deletions package/patches/linux/0037-nau8822-capture-mixaudio-32bit.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
From 85d4e88f86fe879f770127ff54e30954be01f906 Mon Sep 17 00:00:00 2001
From: gh-sxp <sunxiaopeng@canaan-creative.com>
Date: Sun, 6 Nov 2022 14:47:21 +0800
Subject: [PATCH] nau8822-capture-mixaudio-32bit

---
sound/core/pcm_lib.c | 63 ++++++++++++++++++++++++++++++++------------
1 file changed, 46 insertions(+), 17 deletions(-)

diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 5f69b44..4b1b360 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1969,36 +1969,65 @@ static int default_read_copy(struct snd_pcm_substream *substream,
struct snd_soc_pcm_runtime *rtd = substream->private_data;
int i =0;
void* pDmaPtr = NULL;
- short mixData = 0;
- short*pData = NULL;
- static const int AUDIO_DATA_MAX = 32767; // 2^15(short)
- static const int AUDIO_DATA_MIN = -32768;
+ int*p32Data = NULL;
+ int mix32Data = 0;
+
+ short*p16Data = NULL;
+ short mix16Data = 0;
+ static const int AUDIO_DATA16_MAX = 32767; // 2^15(short)
+ static const int AUDIO_DATA16_MIN = -32768;
+ static const int AUDIO_DATA32_MAX = 2147483647; // 2^31(int)
+ static const int AUDIO_DATA32_MIN = -2147483648;

//mix left and right channel
//only process audio codec is nau8822 and pcm capture
if (SNDRV_PCM_STREAM_CAPTURE == substream->stream && 1 == rtd->num_codecs && (0 == strcmp(rtd->codec_dai->name,"nau8822-hifi")))
{
- // only process stereo channel and 16 bit
- if (2 == substream->runtime->channels &&
- (substream->runtime->format >= SNDRV_PCM_FORMAT_S16_LE && substream->runtime->format <= SNDRV_PCM_FORMAT_U16_BE ))
+ // only process stereo channel and 16/32 bit
+ if (2 == substream->runtime->channels)
{
+
pDmaPtr = get_dma_ptr(substream->runtime, channel, hwoff);
- pData = (short*)pDmaPtr;
- for (i =0;i< bytes/4;i++)
+ if (substream->runtime->format >= SNDRV_PCM_FORMAT_S16_LE && substream->runtime->format <= SNDRV_PCM_FORMAT_U16_BE)
{
- mixData = *pData + *(pData+1);
- if (mixData > AUDIO_DATA_MAX)
+ p16Data = (short*)pDmaPtr;
+ for (i =0;i< bytes/4;i++)
{
- mixData = AUDIO_DATA_MAX;
+ mix16Data = *p16Data + *(p16Data+1);
+ if (mix16Data > AUDIO_DATA16_MAX)
+ {
+ mix16Data = AUDIO_DATA16_MAX;
+ }
+ else if (mix16Data < AUDIO_DATA16_MIN)
+ {
+ mix16Data = AUDIO_DATA16_MIN;
+ }
+ *p16Data = mix16Data;
+ *(p16Data+1) = mix16Data;
+ p16Data += 2;
}
- else if (mixData < AUDIO_DATA_MIN)
+ }
+ else if (substream->runtime->format >= SNDRV_PCM_FORMAT_S32_LE && substream->runtime->format <= SNDRV_PCM_FORMAT_U32_BE)
+ {
+ p32Data = (int*)pDmaPtr;
+ for (i =0;i< bytes/8;i++)
{
- mixData = AUDIO_DATA_MIN;
+ mix32Data = *p32Data + *(p32Data+1);
+ if (mix32Data > AUDIO_DATA32_MAX)
+ {
+ mix32Data = AUDIO_DATA32_MAX;
+ }
+ else if (mix32Data < AUDIO_DATA32_MIN)
+ {
+ mix32Data = AUDIO_DATA32_MIN;
+ }
+ *p32Data = mix32Data;
+ *(p32Data+1) = mix32Data;
+ p32Data += 2;
}
- *pData = mixData;
- *(pData+1) = mixData;
- pData += 2;
}
+
+
if (copy_to_user((void __user *)buf,
pDmaPtr,
bytes))
--
2.36.1