Commit 193a6a17 authored by Jean-Paul Saman's avatar Jean-Paul Saman

davinci oss: improve clipping and arbritary noise

Audio capturing generated arbritrary noise as if old buffers (or random data) was being played. This patch tries to protect against that by checking boundaries and make some defensive trade-offs. Noise is almost gone, but not entirely.
parent 867b3e77
...@@ -248,8 +248,11 @@ static audio_state_t aic32_state = { ...@@ -248,8 +248,11 @@ static audio_state_t aic32_state = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.output_stream = &output_stream, .output_stream = &output_stream,
.input_stream = &input_stream, .input_stream = &input_stream,
.rd_ref = 0,
.wr_ref = 0,
/* .need_tx_for_rx = 1, //Once the Full Duplex works */ /* .need_tx_for_rx = 1, //Once the Full Duplex works */
.need_tx_for_rx = 0, .need_tx_for_rx = 0,
.data = NULL,
.hw_init = davinci_aic32_initialize, .hw_init = davinci_aic32_initialize,
.hw_shutdown = davinci_aic32_shutdown, .hw_shutdown = davinci_aic32_shutdown,
.client_ioctl = davinci_aic32_ioctl, .client_ioctl = davinci_aic32_ioctl,
...@@ -257,6 +260,7 @@ static audio_state_t aic32_state = { ...@@ -257,6 +260,7 @@ static audio_state_t aic32_state = {
.hw_remove = __exit_p(davinci_aic32_remove), .hw_remove = __exit_p(davinci_aic32_remove),
.hw_suspend = davinci_aic32_suspend, .hw_suspend = davinci_aic32_suspend,
.hw_resume = davinci_aic32_resume, .hw_resume = davinci_aic32_resume,
.pm_dev = NULL,
}; };
/* This will be defined in the audio.h */ /* This will be defined in the audio.h */
......
...@@ -274,6 +274,8 @@ davinci_request_sound_dma(int device_id, const char *device_name, void *data, ...@@ -274,6 +274,8 @@ davinci_request_sound_dma(int device_id, const char *device_name, void *data,
return -ENOMEM; return -ENOMEM;
} }
memset(*channels, 0, sizeof(int) * NUMBER_OF_CHANNELS_TO_LINK);
/* request for the Master channel and setup the params */ /* request for the Master channel and setup the params */
i = 0; i = 0;
err = davinci_request_dma(device_id, device_name, err = davinci_request_dma(device_id, device_name,
...@@ -538,6 +540,7 @@ int audio_sync(struct file *file) ...@@ -538,6 +540,7 @@ int audio_sync(struct file *file)
/*wait for a buffer to become free */ /*wait for a buffer to become free */
if (wait_for_completion_interruptible(&s->wfc)) if (wait_for_completion_interruptible(&s->wfc))
return 0; return 0;
/* /*
* HACK ALERT ! * HACK ALERT !
* To avoid increased complexity in the rest of the code * To avoid increased complexity in the rest of the code
...@@ -545,12 +548,14 @@ int audio_sync(struct file *file) ...@@ -545,12 +548,14 @@ int audio_sync(struct file *file)
* with the start pointer here and don't forget to restore * with the start pointer here and don't forget to restore
* it later. * it later.
*/ */
local_irq_save(flags);
shiftval = s->fragsize - b->offset; shiftval = s->fragsize - b->offset;
if (shiftval > 0) {
b->offset = shiftval; b->offset = shiftval;
b->dma_addr -= shiftval; b->dma_addr -= shiftval;
b->data -= shiftval; b->data -= shiftval;
local_irq_save(flags);
s->bytecount -= shiftval; s->bytecount -= shiftval;
}
if (++s->usr_head >= s->nbfrags) if (++s->usr_head >= s->nbfrags)
s->usr_head = 0; s->usr_head = 0;
...@@ -572,7 +577,7 @@ int audio_sync(struct file *file) ...@@ -572,7 +577,7 @@ int audio_sync(struct file *file)
remove_wait_queue(&s->wq, &wait); remove_wait_queue(&s->wq, &wait);
/* undo the pointer hack above */ /* undo the pointer hack above */
if (shiftval) { if (shiftval > 0) {
local_irq_save(flags); local_irq_save(flags);
b->dma_addr += shiftval; b->dma_addr += shiftval;
b->data += shiftval; b->data += shiftval;
......
...@@ -59,7 +59,7 @@ ...@@ -59,7 +59,7 @@
/***************************** MACROS ************************************/ /***************************** MACROS ************************************/
#undef DEBUG #undef DEBUG
/* #define DEBUG */
#ifdef DEBUG #ifdef DEBUG
#define DPRINTK printk #define DPRINTK printk
#define FN_IN printk("[davinci_audio.c:[%s] start\n", __FUNCTION__) #define FN_IN printk("[davinci_audio.c:[%s] start\n", __FUNCTION__)
...@@ -548,7 +548,7 @@ audio_write(struct file *file, const char *buffer, size_t count, loff_t * ppos) ...@@ -548,7 +548,7 @@ audio_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
chunksize = s->fragsize - b->offset; chunksize = s->fragsize - b->offset;
if (chunksize > count) if (chunksize > count)
chunksize = count; chunksize = count;
DPRINTK("write %d to %d\n", chunksize, s->usr_head); DPRINTK("write %d to %d (0x%p)\n", chunksize, s->usr_head, buffer);
if (copy_from_user(b->data + b->offset, buffer, chunksize)) { if (copy_from_user(b->data + b->offset, buffer, chunksize)) {
DPRINTK("Audio: CopyFrom User failed \n"); DPRINTK("Audio: CopyFrom User failed \n");
complete(&s->wfc); complete(&s->wfc);
...@@ -576,9 +576,9 @@ audio_write(struct file *file, const char *buffer, size_t count, loff_t * ppos) ...@@ -576,9 +576,9 @@ audio_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
audio_process_dma(s); audio_process_dma(s);
} }
if ((buffer - buffer0)) if ((buffer - buffer0)) {
ret = buffer - buffer0; ret = buffer - buffer0;
}
DPRINTK("audio_write: return=%d\n", ret); DPRINTK("audio_write: return=%d\n", ret);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment