blob: f5edcbfa315788d0eae7a8cb5b32d5a37b88056d [file] [log] [blame]
Takashi Sakamoto59558152015-09-19 11:21:55 +09001/*
2 * AM824 format in Audio and Music Data Transmission Protocol (IEC 61883-6)
3 *
4 * Copyright (c) 2015 Takashi Sakamoto <o-takashi@sakamocchi.jp>
5 *
6 * Licensed under the terms of the GNU General Public License, version 2.
7 */
8
9#include "amdtp-am824.h"
10
11#define CIP_FMT_AM 0x10
12
Takashi Sakamoto51c29fd2015-09-19 11:21:56 +090013/* "Clock-based rate control mode" is just supported. */
14#define AMDTP_FDF_AM824 0x00
15
16/**
17 * amdtp_am824_set_parameters - set stream parameters
18 * @s: the AMDTP stream to configure
19 * @rate: the sample rate
20 * @pcm_channels: the number of PCM samples in each data block, to be encoded
21 * as AM824 multi-bit linear audio
22 * @midi_ports: the number of MIDI ports (i.e., MPX-MIDI Data Channels)
23 * @double_pcm_frames: one data block transfers two PCM frames
24 *
25 * The parameters must be set before the stream is started, and must not be
26 * changed while the stream is running.
27 */
28int amdtp_am824_set_parameters(struct amdtp_stream *s, unsigned int rate,
29 unsigned int pcm_channels,
30 unsigned int midi_ports,
31 bool double_pcm_frames)
32{
33 int err;
34
35 err = amdtp_stream_set_parameters(s, rate, pcm_channels, midi_ports);
36 if (err < 0)
37 return err;
38
39 s->fdf = AMDTP_FDF_AM824 | s->sfc;
40
41 /*
42 * In IEC 61883-6, one data block represents one event. In ALSA, one
43 * event equals to one PCM frame. But Dice has a quirk at higher
44 * sampling rate to transfer two PCM frames in one data block.
45 */
46 if (double_pcm_frames)
47 s->frame_multiplier = 2;
48 else
49 s->frame_multiplier = 1;
50
51 return 0;
52}
53EXPORT_SYMBOL_GPL(amdtp_am824_set_parameters);
54
Takashi Sakamoto59558152015-09-19 11:21:55 +090055/**
56 * amdtp_am824_init - initialize an AMDTP stream structure to handle AM824
57 * data block
58 * @s: the AMDTP stream to initialize
59 * @unit: the target of the stream
60 * @dir: the direction of stream
61 * @flags: the packet transmission method to use
62 */
63int amdtp_am824_init(struct amdtp_stream *s, struct fw_unit *unit,
64 enum amdtp_stream_direction dir, enum cip_flags flags)
65{
66 return amdtp_stream_init(s, unit, dir, flags, CIP_FMT_AM);
67}
68EXPORT_SYMBOL_GPL(amdtp_am824_init);