ALSA: firewire-lib: simplify function to calculate the number of data blocks
This function is called according to conditions between the value of syt and streaming mode(blocking or non-blocking). To simplify caller's work, this commit push these conditions to the function. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
a2064710ba
commit
875be09160
1 changed files with 27 additions and 22 deletions
|
@ -321,17 +321,25 @@ void amdtp_stream_pcm_prepare(struct amdtp_stream *s)
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(amdtp_stream_pcm_prepare);
|
EXPORT_SYMBOL(amdtp_stream_pcm_prepare);
|
||||||
|
|
||||||
static unsigned int calculate_data_blocks(struct amdtp_stream *s)
|
static unsigned int calculate_data_blocks(struct amdtp_stream *s,
|
||||||
|
unsigned int syt)
|
||||||
{
|
{
|
||||||
unsigned int phase, data_blocks;
|
unsigned int phase, data_blocks;
|
||||||
|
|
||||||
if (s->flags & CIP_BLOCKING)
|
/* Blocking mode. */
|
||||||
data_blocks = s->syt_interval;
|
if (s->flags & CIP_BLOCKING) {
|
||||||
else if (!cip_sfc_is_base_44100(s->sfc)) {
|
/* This module generate empty packet for 'no data'. */
|
||||||
/* Sample_rate / 8000 is an integer, and precomputed. */
|
if (syt == CIP_SYT_NO_INFO)
|
||||||
data_blocks = s->data_block_state;
|
data_blocks = 0;
|
||||||
|
else
|
||||||
|
data_blocks = s->syt_interval;
|
||||||
|
/* Non-blocking mode. */
|
||||||
} else {
|
} else {
|
||||||
phase = s->data_block_state;
|
if (!cip_sfc_is_base_44100(s->sfc)) {
|
||||||
|
/* Sample_rate / 8000 is an integer, and precomputed. */
|
||||||
|
data_blocks = s->data_block_state;
|
||||||
|
} else {
|
||||||
|
phase = s->data_block_state;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This calculates the number of data blocks per packet so that
|
* This calculates the number of data blocks per packet so that
|
||||||
|
@ -341,16 +349,17 @@ static unsigned int calculate_data_blocks(struct amdtp_stream *s)
|
||||||
* as possible in the sequence (to prevent underruns of the
|
* as possible in the sequence (to prevent underruns of the
|
||||||
* device's buffer).
|
* device's buffer).
|
||||||
*/
|
*/
|
||||||
if (s->sfc == CIP_SFC_44100)
|
if (s->sfc == CIP_SFC_44100)
|
||||||
/* 6 6 5 6 5 6 5 ... */
|
/* 6 6 5 6 5 6 5 ... */
|
||||||
data_blocks = 5 + ((phase & 1) ^
|
data_blocks = 5 + ((phase & 1) ^
|
||||||
(phase == 0 || phase >= 40));
|
(phase == 0 || phase >= 40));
|
||||||
else
|
else
|
||||||
/* 12 11 11 11 11 ... or 23 22 22 22 22 ... */
|
/* 12 11 11 11 11 ... or 23 22 22 22 22 ... */
|
||||||
data_blocks = 11 * (s->sfc >> 1) + (phase == 0);
|
data_blocks = 11 * (s->sfc >> 1) + (phase == 0);
|
||||||
if (++phase >= (80 >> (s->sfc >> 1)))
|
if (++phase >= (80 >> (s->sfc >> 1)))
|
||||||
phase = 0;
|
phase = 0;
|
||||||
s->data_block_state = phase;
|
s->data_block_state = phase;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return data_blocks;
|
return data_blocks;
|
||||||
|
@ -647,11 +656,7 @@ static void handle_out_packet(struct amdtp_stream *s, unsigned int syt)
|
||||||
if (s->packet_index < 0)
|
if (s->packet_index < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* this module generate empty packet for 'no data' */
|
data_blocks = calculate_data_blocks(s, syt);
|
||||||
if (!(s->flags & CIP_BLOCKING) || (syt != CIP_SYT_NO_INFO))
|
|
||||||
data_blocks = calculate_data_blocks(s);
|
|
||||||
else
|
|
||||||
data_blocks = 0;
|
|
||||||
|
|
||||||
buffer = s->buffer.packets[s->packet_index].buffer;
|
buffer = s->buffer.packets[s->packet_index].buffer;
|
||||||
buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
|
buffer[0] = cpu_to_be32(ACCESS_ONCE(s->source_node_id_field) |
|
||||||
|
|
Loading…
Add table
Reference in a new issue