PCM: remove partial sample buffer. Not needed
This commit is contained in:
parent
c1b8e87918
commit
2efb594f50
@ -125,8 +125,7 @@ struct pcm_decode_s
|
|||||||
|
|
||||||
uint8_t subsample; /* Fast forward rate: See AUDIO_SUBSAMPLE_* defns */
|
uint8_t subsample; /* Fast forward rate: See AUDIO_SUBSAMPLE_* defns */
|
||||||
uint8_t skip; /* Number of samples to be skipped */
|
uint8_t skip; /* Number of samples to be skipped */
|
||||||
uint8_t npartial; /* Size of the partial sample */
|
uint8_t npartial; /* Size of the partially copied sample */
|
||||||
uint8_t partial[4]; /* Holds the partial sample */
|
|
||||||
|
|
||||||
/* REVISIT: I think we could get rid of all of this special buffer
|
/* REVISIT: I think we could get rid of all of this special buffer
|
||||||
* processing. It seems like we should be able to do the sub-sampling
|
* processing. It seems like we should be able to do the sub-sampling
|
||||||
@ -817,7 +816,7 @@ static FAR struct ap_buffer_s *pcm_subsample(FAR struct pcm_decode_s *priv,
|
|||||||
|
|
||||||
skipsize = priv->align * (priv->subsample - 1);
|
skipsize = priv->align * (priv->subsample - 1);
|
||||||
|
|
||||||
/* Let's deal with any partial sample data from the last buffer */
|
/* Let's deal with any partial samples from the last buffer */
|
||||||
|
|
||||||
if (priv->npartial > 0)
|
if (priv->npartial > 0)
|
||||||
{
|
{
|
||||||
@ -832,37 +831,28 @@ static FAR struct ap_buffer_s *pcm_subsample(FAR struct pcm_decode_s *priv,
|
|||||||
|
|
||||||
if (priv->npartial + srcsize < priv->align)
|
if (priv->npartial + srcsize < priv->align)
|
||||||
{
|
{
|
||||||
dest = &priv->partial[priv->npartial];
|
/* Update the partial sample size */
|
||||||
src = &apb->samp[apb->curbyte];
|
|
||||||
memcpy(dest, src, srcsize);
|
|
||||||
|
|
||||||
priv->npartial += srcsize;
|
priv->npartial += srcsize;
|
||||||
apb->curbyte += srcsize;
|
|
||||||
goto exit_apb_empty;
|
/* And just return the buffer with no modification */
|
||||||
|
|
||||||
|
return apb;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No, we do at least have enough to complete the partial sample */
|
/* No, we do at least have enough to complete the sample. Copy copy data
|
||||||
/* Copy the first part of the partial sample that was saved from
|
* from the new audio buffer to complete the sample.
|
||||||
* the last buffer.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
src = priv->partial;
|
|
||||||
for (i = 0; i < priv->npartial; i++)
|
|
||||||
{
|
|
||||||
*dest++ = *src++;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->npartial = 0;
|
|
||||||
|
|
||||||
/* Now copy data from new audio buffer to complete the sample */
|
|
||||||
|
|
||||||
src = &apb->samp[apb->curbyte];
|
src = &apb->samp[apb->curbyte];
|
||||||
for (i = 0; i < priv->align; i++)
|
for (i = priv->npartial; i < priv->align; i++)
|
||||||
{
|
{
|
||||||
*dest++ = *src++;
|
*dest++ = *src++;
|
||||||
apb->curbyte++;
|
apb->curbyte++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priv->npartial = 0;
|
||||||
|
|
||||||
/* Update the number of bytes in the working buffer and reset the skip
|
/* Update the number of bytes in the working buffer and reset the skip
|
||||||
* value
|
* value
|
||||||
*/
|
*/
|
||||||
@ -904,55 +894,41 @@ static FAR struct ap_buffer_s *pcm_subsample(FAR struct pcm_decode_s *priv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have skipped over the required number of bytes and we are ready
|
/* Copy the sample from the audio buffer into the working buffer. */
|
||||||
* to take the next sample. Is there space for a whole sample in the
|
|
||||||
* buffer?
|
|
||||||
*/
|
|
||||||
|
|
||||||
else if (srcsize < priv->align)
|
|
||||||
{
|
|
||||||
/* No.. copy the partial sample to the partial sample buffer */
|
|
||||||
|
|
||||||
dest = priv->partial;
|
|
||||||
for (i = 0; i < srcsize; i++)
|
|
||||||
{
|
|
||||||
*dest++ = *src++;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->npartial = srcsize;
|
|
||||||
apb->curbyte += srcsize;
|
|
||||||
|
|
||||||
/* We are finished with this audio buffer. On the next buffer,
|
|
||||||
* the fact that skip == 0 and that priv->npartial > 0 will kick
|
|
||||||
* off the re-synchronization logic at the beginning of this
|
|
||||||
* function.
|
|
||||||
*/
|
|
||||||
|
|
||||||
goto exit_apb_empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Plenty of space! Copy the sample from the audio buffer into the
|
|
||||||
* working buffer.
|
|
||||||
*/
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
unsigned int copysize;
|
||||||
|
|
||||||
|
/* Do we have space for the whole sample? */
|
||||||
|
|
||||||
|
if (srcsize < priv->align)
|
||||||
|
{
|
||||||
|
/* No.. this is a partial copy */
|
||||||
|
|
||||||
|
copysize = srcsize;
|
||||||
|
priv->npartial = srcsize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
copysize = priv->align;
|
||||||
|
priv->skip = skipsize;
|
||||||
|
}
|
||||||
|
|
||||||
/* Now copy the sample from new audio buffer to working buffer */
|
/* Now copy the sample from new audio buffer to working buffer */
|
||||||
|
|
||||||
for (i = 0; i < priv->align; i++)
|
for (i = 0; i < copysize; i++)
|
||||||
{
|
{
|
||||||
*dest++ = *src++;
|
*dest++ = *src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update indices and sizes and reset the skip value */
|
/* Update indices and sizes and reset the skip value */
|
||||||
|
|
||||||
apb->curbyte += priv->align;
|
apb->curbyte += copysize;
|
||||||
srcsize -= priv->align;
|
srcsize -= copysize;
|
||||||
|
|
||||||
work->nbytes += priv->align;
|
work->nbytes += copysize;
|
||||||
destsize -= priv->align;
|
destsize -= copysize;
|
||||||
|
|
||||||
priv->skip = skipsize;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1001,43 +977,42 @@ static FAR struct ap_buffer_s *pcm_subsample(FAR struct pcm_decode_s *priv,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We have skipped over the required number of bytes and we are
|
/* Copy the sample from the end of the audio buffer to the beginning. */
|
||||||
* ready to take the next sample. Is there space for a whole
|
|
||||||
* sample in the buffer?
|
|
||||||
*/
|
|
||||||
|
|
||||||
else if (srcsize < priv->align)
|
|
||||||
{
|
|
||||||
/* No.. copy the partial sample to the partial sample buffer */
|
|
||||||
|
|
||||||
dest = priv->partial;
|
|
||||||
for (i = 0; i < srcsize; i++)
|
|
||||||
{
|
|
||||||
*dest++ = *src++;
|
|
||||||
}
|
|
||||||
|
|
||||||
priv->npartial = srcsize;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Plenty of space! Copy the sample from the end of the audio
|
|
||||||
* buffer to the beginning.
|
|
||||||
*/
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
unsigned int copysize;
|
||||||
|
|
||||||
|
/* Do we have space for the whole sample? */
|
||||||
|
|
||||||
|
if (srcsize < priv->align)
|
||||||
|
{
|
||||||
|
/* No.. this is a partial copy */
|
||||||
|
|
||||||
|
copysize = srcsize;
|
||||||
|
priv->npartial = srcsize;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Copy the whole sample and re-arm the skip size */
|
||||||
|
|
||||||
|
copysize = priv->align;
|
||||||
|
priv->skip = skipsize;
|
||||||
|
}
|
||||||
|
|
||||||
/* Now copy the sample from new audio buffer to working buffer */
|
/* Now copy the sample from new audio buffer to working buffer */
|
||||||
|
|
||||||
for (i = 0; i < priv->align; i++)
|
for (i = 0; i < copysize; i++)
|
||||||
{
|
{
|
||||||
*dest++ = *src++;
|
*dest++ = *src++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update indices and sizes and reset the skip value */
|
/* Updates bytes available in the source buffer and bytes
|
||||||
|
* remaining in the dest buffer.
|
||||||
|
*/
|
||||||
|
|
||||||
srcsize -= priv->align;
|
srcsize -= copysize;
|
||||||
destsize -= priv->align;
|
destsize -= copysize;
|
||||||
priv->skip = skipsize;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user