Commit 00d004db authored by Takashi Sakamoto's avatar Takashi Sakamoto Committed by Takashi Iwai

ALSA: firewire-motu: code refactoring for MOTU data block processing layer

This is code refactoring for MOTU data block processing layer so that
it can receive list of packet descriptor.
Signed-off-by: default avatarTakashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 806653b7
...@@ -117,19 +117,25 @@ int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate, ...@@ -117,19 +117,25 @@ int amdtp_motu_set_parameters(struct amdtp_stream *s, unsigned int rate,
return 0; return 0;
} }
static void read_pcm_s32(struct amdtp_stream *s, static void read_pcm_s32(struct amdtp_stream *s, struct snd_pcm_substream *pcm,
struct snd_pcm_runtime *runtime, __be32 *buffer, unsigned int data_blocks,
__be32 *buffer, unsigned int data_blocks) unsigned int pcm_frames)
{ {
struct amdtp_motu *p = s->protocol; struct amdtp_motu *p = s->protocol;
unsigned int channels, remaining_frames, i, c; unsigned int channels = p->pcm_chunks;
struct snd_pcm_runtime *runtime = pcm->runtime;
unsigned int pcm_buffer_pointer;
int remaining_frames;
u8 *byte; u8 *byte;
u32 *dst; u32 *dst;
int i, c;
pcm_buffer_pointer = s->pcm_buffer_pointer + pcm_frames;
pcm_buffer_pointer %= runtime->buffer_size;
channels = p->pcm_chunks;
dst = (void *)runtime->dma_area + dst = (void *)runtime->dma_area +
frames_to_bytes(runtime, s->pcm_buffer_pointer); frames_to_bytes(runtime, pcm_buffer_pointer);
remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; remaining_frames = runtime->buffer_size - pcm_buffer_pointer;
for (i = 0; i < data_blocks; ++i) { for (i = 0; i < data_blocks; ++i) {
byte = (u8 *)buffer + p->pcm_byte_offset; byte = (u8 *)buffer + p->pcm_byte_offset;
...@@ -147,19 +153,25 @@ static void read_pcm_s32(struct amdtp_stream *s, ...@@ -147,19 +153,25 @@ static void read_pcm_s32(struct amdtp_stream *s,
} }
} }
static void write_pcm_s32(struct amdtp_stream *s, static void write_pcm_s32(struct amdtp_stream *s, struct snd_pcm_substream *pcm,
struct snd_pcm_runtime *runtime, __be32 *buffer, unsigned int data_blocks,
__be32 *buffer, unsigned int data_blocks) unsigned int pcm_frames)
{ {
struct amdtp_motu *p = s->protocol; struct amdtp_motu *p = s->protocol;
unsigned int channels, remaining_frames, i, c; unsigned int channels = p->pcm_chunks;
struct snd_pcm_runtime *runtime = pcm->runtime;
unsigned int pcm_buffer_pointer;
int remaining_frames;
u8 *byte; u8 *byte;
const u32 *src; const u32 *src;
int i, c;
pcm_buffer_pointer = s->pcm_buffer_pointer + pcm_frames;
pcm_buffer_pointer %= runtime->buffer_size;
channels = p->pcm_chunks;
src = (void *)runtime->dma_area + src = (void *)runtime->dma_area +
frames_to_bytes(runtime, s->pcm_buffer_pointer); frames_to_bytes(runtime, pcm_buffer_pointer);
remaining_frames = runtime->buffer_size - s->pcm_buffer_pointer; remaining_frames = runtime->buffer_size - pcm_buffer_pointer;
for (i = 0; i < data_blocks; ++i) { for (i = 0; i < data_blocks; ++i) {
byte = (u8 *)buffer + p->pcm_byte_offset; byte = (u8 *)buffer + p->pcm_byte_offset;
...@@ -303,7 +315,7 @@ static unsigned int process_tx_data_blocks(struct amdtp_stream *s, ...@@ -303,7 +315,7 @@ static unsigned int process_tx_data_blocks(struct amdtp_stream *s,
struct snd_pcm_substream *pcm) struct snd_pcm_substream *pcm)
{ {
struct amdtp_motu *p = s->protocol; struct amdtp_motu *p = s->protocol;
unsigned int pcm_frames; unsigned int pcm_frames = 0;
trace_data_block_sph(s, desc->data_blocks, desc->ctx_payload); trace_data_block_sph(s, desc->data_blocks, desc->ctx_payload);
trace_data_block_message(s, desc->data_blocks, desc->ctx_payload); trace_data_block_message(s, desc->data_blocks, desc->ctx_payload);
...@@ -312,11 +324,9 @@ static unsigned int process_tx_data_blocks(struct amdtp_stream *s, ...@@ -312,11 +324,9 @@ static unsigned int process_tx_data_blocks(struct amdtp_stream *s,
read_midi_messages(s, desc->ctx_payload, desc->data_blocks); read_midi_messages(s, desc->ctx_payload, desc->data_blocks);
if (pcm) { if (pcm) {
read_pcm_s32(s, pcm->runtime, desc->ctx_payload, read_pcm_s32(s, pcm, desc->ctx_payload, desc->data_blocks,
desc->data_blocks); pcm_frames);
pcm_frames = desc->data_blocks; pcm_frames = desc->data_blocks;
} else {
pcm_frames = 0;
} }
return pcm_frames; return pcm_frames;
...@@ -368,8 +378,8 @@ static unsigned int process_rx_data_blocks(struct amdtp_stream *s, ...@@ -368,8 +378,8 @@ static unsigned int process_rx_data_blocks(struct amdtp_stream *s,
const struct pkt_desc *desc, const struct pkt_desc *desc,
struct snd_pcm_substream *pcm) struct snd_pcm_substream *pcm)
{ {
struct amdtp_motu *p = (struct amdtp_motu *)s->protocol; struct amdtp_motu *p = s->protocol;
unsigned int pcm_frames; unsigned int pcm_frames = 0;
/* TODO: how to interact control messages between userspace? */ /* TODO: how to interact control messages between userspace? */
...@@ -377,12 +387,11 @@ static unsigned int process_rx_data_blocks(struct amdtp_stream *s, ...@@ -377,12 +387,11 @@ static unsigned int process_rx_data_blocks(struct amdtp_stream *s,
write_midi_messages(s, desc->ctx_payload, desc->data_blocks); write_midi_messages(s, desc->ctx_payload, desc->data_blocks);
if (pcm) { if (pcm) {
write_pcm_s32(s, pcm->runtime, desc->ctx_payload, write_pcm_s32(s, pcm, desc->ctx_payload, desc->data_blocks,
desc->data_blocks); pcm_frames);
pcm_frames = desc->data_blocks; pcm_frames = desc->data_blocks;
} else { } else {
write_pcm_silence(s, desc->ctx_payload, desc->data_blocks); write_pcm_silence(s, desc->ctx_payload, desc->data_blocks);
pcm_frames = 0;
} }
write_sph(s, desc->ctx_payload, desc->data_blocks); write_sph(s, desc->ctx_payload, desc->data_blocks);
......
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