Skip to content

Instantly share code, notes, and snippets.

@checko
Created November 19, 2015 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save checko/4596fcff004c22693bad to your computer and use it in GitHub Desktop.
Save checko/4596fcff004c22693bad to your computer and use it in GitHub Desktop.
tinyalsa_hal remove MMAP and replace pcm_write
diff --git a/alsa/tinyalsa_hal.c b/alsa/tinyalsa_hal.c
index a4644ac..2b85b88 100644
--- a/alsa/tinyalsa_hal.c
+++ b/alsa/tinyalsa_hal.c
@@ -16,7 +16,7 @@
/* Copyright (C) 2012-2015 Freescale Semiconductor, Inc. */
#define LOG_TAG "audio_hw_primary"
-//#define LOG_NDEBUG 0
+#define LOG_NDEBUG 0
#include <errno.h>
#include <pthread.h>
@@ -524,7 +524,7 @@ static int start_output_stream_primary(struct imx_stream_out *out)
pcm_device = out->device & (AUDIO_DEVICE_OUT_ALL & ~AUDIO_DEVICE_OUT_AUX_DIGITAL);
if (pcm_device && (adev->active_output[OUTPUT_ESAI] == NULL || adev->active_output[OUTPUT_ESAI]->standby)) {
- out->write_flags[PCM_NORMAL] = PCM_OUT | PCM_MMAP | PCM_MONOTONIC;
+ out->write_flags[PCM_NORMAL] = PCM_OUT | PCM_MONOTONIC;
out->write_threshold[PCM_NORMAL] = PLAYBACK_LONG_PERIOD_COUNT * LONG_PERIOD_SIZE;
out->config[PCM_NORMAL] = pcm_config_mm_out;
@@ -1175,6 +1175,27 @@ static int pcm_read_wrapper(struct pcm *pcm, const void * buffer, size_t bytes)
return ret;
}
+static int s_pcm_write(struct pcm *pcm, void * buffer, size_t bytes)
+{
+ int i;
+ unsigned short *dst;
+ unsigned short *src;
+ unsigned short patten = 0x0000;
+ int rc;
+
+ dst = (unsigned short*)malloc(bytes);
+ src = (unsigned short*)buffer;
+
+ for(i=0 ; i<bytes/2 ; i++)
+ dst[i]=src[i];
+
+ rc = pcm_write(pcm, (void*)dst, bytes);
+ free(dst);
+ return rc;
+
+
+}
static int pcm_write_wrapper(struct pcm *pcm, const void * buffer, size_t bytes, int flags)
{
@@ -1182,7 +1203,7 @@ static int pcm_write_wrapper(struct pcm *pcm, const void * buffer, size_t bytes,
if(flags & PCM_MMAP)
ret = pcm_mmap_write(pcm, (void *)buffer, bytes);
else
- ret = pcm_write(pcm, (void *)buffer, bytes);
+ ret = s_pcm_write(pcm, (void *)buffer, bytes);
if(ret !=0) {
ALOGW("ret %d, pcm write %d error %s", ret, bytes, pcm_get_error(pcm));
@@ -1200,7 +1221,7 @@ static int pcm_write_wrapper(struct pcm *pcm, const void * buffer, size_t bytes,
if(flags & PCM_MMAP)
ret = pcm_mmap_write(pcm, (void *)buffer, bytes);
else
- ret = pcm_write(pcm, (void *)buffer, bytes);
+ ret = s_pcm_write(pcm, (void *)buffer, bytes);
}
return ret;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment