Re: [Alsa-user] Get SPDIF-in sample rate

2017-07-19 Thread Denis Shulyaka
2017-07-19 8:46 GMT+02:00 Clemens Ladisch <clem...@ladisch.de>:

> The HID interface is managed by another driver.  The kernel driver
> already knows how to write to these registers with a control request
> instead (see below).  Could you check if a control read request works,
> or if the response still goes through the HID pipe?
>

I've tried that, but unfortunately it didn't work. The input request reads
zero bytes.
Well, I think that means I'll have to use my workarount with libhidapi.
Below is my code. I don't feel very confident on all those bmRequestType,
bRequest, wValue and other parameters, I just used the ones from your
example. May be later I will be able to sniff the communication of the card
with its proprietary Windows driver, and if I get a different results I'll
revert back to you.

int cm106_read(libusb_device_handle *handle, char reg, uint16_t *data)
{
int res;
unsigned char buf[4] = {0x30,   // 0x20 to write, 0x30 to read
0x00,   // DATAL
0x00,   // DATAH
reg};   // Register address

if ((res = libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT |
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_ENDPOINT,

LIBUSB_REQUEST_SET_CONFIGURATION, 0, 0, buf, 4, 0)) != 4)
return res;

if ((res = libusb_control_transfer(handle, LIBUSB_ENDPOINT_IN |
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_ENDPOINT,

LIBUSB_REQUEST_SET_CONFIGURATION, 0, 0, buf, 4, 0)) < 0) // <-- THIS
FUNCTION RETURNS 0
return res;

if (res != 3)
{
fprintf(stderr, "DEBUG Invalid response length"
return -1;
}

if (buf[0] & 0xe0 != 0x20)  // No register data in the input
{
fprintf(stderr, "DEBUG data: %02X %02X %02X\n", buf[0],
buf[1], buf[2]);
return -1;
}

*data = (((uint16_t)buf[2]) << 8) + buf[1];
return 0;
}

// Just for completeness, the below function successfully writes the data
into cm106 registers
int cm106_write(libusb_device_handle *handle, char reg, uint16_t data)
{
unsigned char buf[4] = {0x20,   // 0x20 to write,
0x30 to read
data & 0xff,// DATAL
(data >> 8) & 0xff, // DATAH
reg};   // Register address

return libusb_control_transfer(handle, LIBUSB_ENDPOINT_OUT |
LIBUSB_REQUEST_TYPE_CLASS | LIBUSB_RECIPIENT_ENDPOINT,

LIBUSB_REQUEST_SET_CONFIGURATION, 0, 0, buf, 4, 0);
}


Thank you for your support!

Best regards
Denis Shulyaka
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Get SPDIF-in sample rate

2017-07-18 Thread Denis Shulyaka
2017-07-18 8:47 GMT+02:00 Clemens Ladisch <clem...@ladisch.de>:

> In general, SPDIF inputs do not resample, and if you try to record with
> the wrong sample rate, the result has the original sample rate and is
> just labelled wrong.
>

That is a good news, but I would still prefer to know the sample rate
because if I want to output it, I would need to open the output device with
the correct sample rate, or I will still have a resampling.

> Does ALSA provide any general interface for the userspace applications
> > that indicates the SPDIF source sample rate?
>
> Yes, but the USB audio driver does not implement it because the USB
> audio specification does not define such an interface between the driver
> and the device.
>

What could I use if I had a non-USB sound card with SPDIF-in?


> At the moment, you have to write the code yourself.  But if you've
> tested it, we would be interested in integrating it into the kernel
> driver.
>

The below program outputs the current SPDIF-In sample rate of my card. The
only problem with it is that my sense of perfection hurts when I'm working
around the driver like that. All device-specific parts should be in kernel.

[root@speaker cm106spdif]# gcc cm106spdif.c -l hidapi-libusb
[root@speaker cm106spdif]# ./a.out
44.1K
[root@speaker cm106spdif]# cat cm106spdif.c
#include 
#include 
#include 
#include 
#include 

int cm106_read(hid_device *handle, char reg, uint16_t *data)
{
unsigned char buf[5] = {0x00,// report id for hidapi
0x30,// 0x20 to write, 0x30 to read
0x00,// DATAL
0x00,// DATAH
reg};// Register address

if (hid_write(handle, buf, 5) != 5)
return -1;

if (hid_read(handle, buf, 5) != 3)
return -2;

if (buf[0] & 0xe0 != 0x20)// No register data in the input report
return -3;

*data = (((uint16_t)buf[2]) << 8) + buf[1];
return 0;
}

int cm106_write(hid_device *handle, char reg, uint16_t data)
{
unsigned char buf[5] = {0x00,// report id for hidapi
0x20,// 0x20 to write, 0x30 to read
data & 0xff,// DATAL
(data >> 8),// DATAH
reg};// Register address

if (hid_write(handle, buf, 5) != 5)
return -1;

return 0;
}

int main(void)
{
hid_device *handle;
uint16_t data = 0;
unsigned char SPDFI_FREQ;

if ( !(handle = hid_open(0xd8c, 0x102, NULL)) )
err(1, "hid_open: %ls", hid_error(handle));

if (cm106_read(handle, 3, ) < 0)
err(2, "read: %ls", hid_error(handle));

//printf("data=%04X\n", data);

SPDFI_FREQ = (data & 0x0180) >> 7;

switch(SPDFI_FREQ)
{
case 0:
printf("44.1K\n");
break;

case 2:
printf("48K\n");
break;

case 3:
printf("32K\n");
    break;
default:
printf("reserved\n");
}

hid_close(handle);
hid_exit();
return 0;
}


Best regards,
Denis Shulyaka
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


[Alsa-user] Get SPDIF-in sample rate

2017-07-17 Thread Denis Shulyaka
Hi,

I have a CM106-based usb sound card (0d8c:0102) with SPDIF-In. My aim is to
decode the compressed audio formats that may come from this source. And the
first task for this is to get the original sample rate of the source to
avoid any resampling.
According to the CM106 datasheet, one can read the SPDIF-In sample rate
from SPDFI_FREQ bits (8~7 of register 03).
What is the correct way to do so? Can ALSA read those register bits? Does
ALSA provide any general interface for the userspace applications that
indicates the SPDIF source sample rate? Should I attempt to communicate
with the hardware with libusb, or can I do it with ALSA only?

Please advise.

Best regards,
Denis Shulyaka
--
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Hardware loopback

2014-06-30 Thread Denis Shulyaka
Hi,

2014-01-16 12:04 GMT+04:00 Clemens Ladisch cladi...@googlemail.com:

 Denis Shulyaka wrote:
  2014/1/14 Clemens Ladisch cladi...@googlemail.com:
  This device's descriptor do not define a mixer control
  for this control.
 
  Apparently, you have to set the SPDIFMIX bit.
 
  Well, do you have any idea on how can I do it? I'm OK with compiling a
  custom kernel, but I don't have any experience with ALSA code. Just a
  small hint would be appreciated) Can I somehow define it in the
  descriptor?

 This is not a mixer control that could be described with a descriptor;
 one needs to write a custom control that writes to that vendor-specific
 register.

 I'll write a patch ...


 Regards,
 Clemens


Well, I've finally managed to set the SPDIFMIX bit in by modifying the
snd_usb_cm6206_boot_quirk() function. However it led me to another problem:
PCM streams are played fine and are routed to the analog speakers without
CPU interaction, but DTS streams sound like a loud noise.
Do I understand it right that the card hardware is not able to decode DTS
itself and it merely relies on a proprietary software driver for DTS
support? Can Alsa and PulseAudio deal with DTS? I just need to get the idea
what DTS is...

Best regards,
Denis Shulyaka
--
Open source business process management suite built on Java and Eclipse
Turn processes into business applications with Bonita BPM Community Edition
Quickly connect people, data, and systems into organized workflows
Winner of BOSSIE, CODIE, OW2 and Gartner awards
http://p.sf.net/sfu/Bonitasoft___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Hardware loopback

2014-01-14 Thread Denis Shulyaka
  1 PCM
  AudioStreaming Interface Descriptor:
bLength14
bDescriptorType36
bDescriptorSubtype  2 (FORMAT_TYPE)
bFormatType 1 (FORMAT_TYPE_I)
bNrChannels 2
bSubframeSize   2
bBitResolution 16
bSamFreqType2 Discrete
tSamFreq[ 0]44100
tSamFreq[ 1]48000
  Endpoint Descriptor:
bLength 9
bDescriptorType 5
bEndpointAddress 0x85  EP 5 IN
bmAttributes5
  Transfer TypeIsochronous
  Synch Type   Asynchronous
  Usage Type   Data
wMaxPacketSize 0x00c8  1x 200 bytes
bInterval   1
bRefresh0
bSynchAddress   0
AudioControl Endpoint Descriptor:
  bLength 7
  bDescriptorType37
  bDescriptorSubtype  1 (EP_GENERAL)
  bmAttributes 0x01
Sampling Frequency
  bLockDelayUnits 0 Undefined
  wLockDelay  0 Undefined
Interface Descriptor:
  bLength 9
  bDescriptorType 4
  bInterfaceNumber3
  bAlternateSetting   0
  bNumEndpoints   1
  bInterfaceClass 3 Human Interface Device
  bInterfaceSubClass  0 No Subclass
  bInterfaceProtocol  0 None
  iInterface  0
HID Device Descriptor:
  bLength 9
  bDescriptorType33
  bcdHID   1.00
  bCountryCode0 Not supported
  bNumDescriptors 1
  bDescriptorType34 Report
  wDescriptorLength  50
 Report Descriptors:
   ** UNAVAILABLE **
  Endpoint Descriptor:
bLength 7
bDescriptorType 5
bEndpointAddress 0x81  EP 1 IN
bmAttributes3
  Transfer TypeInterrupt
  Synch Type   None
  Usage Type   Data
wMaxPacketSize 0x0003  1x 3 bytes
bInterval   1
Device Status: 0x
  (Bus Powered)
pi@speaker ~ $

Best regards,
Denis Shulyaka


lsusb_v
Description: Binary data
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Hardware loopback

2014-01-14 Thread Denis Shulyaka
Hi,

2014/1/14 Clemens Ladisch cladi...@googlemail.com:
 This device's descriptor do not define a mixer control
 for this control.

 Apparently, you have to set the SPDIFMIX bit.

Well, do you have any idea on how can I do it? I'm OK with compiling a
custom kernel, but I don't have any experience with ALSA code. Just a
small hint would be appreciated) Can I somehow define it in the
descriptor?

Best regards,
Denis Shulyaka

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


[Alsa-user] Hardware loopback

2014-01-13 Thread Denis Shulyaka
Hi list,

Please forgive if it's the wrong place to post this question.

I'm trying to build a sound server connected to my speaker set  that will
act as:
1) SPDIF receiver from TV
2) Network sound server

My hardware:
1) Raspberry Pi
2) USB sound card based on CM106 chip.

My Software:
1) Raspbian
2) Linux 3.10.25
3) Pulseaudio 2.0 (will try to compile 4.0 tonight)

For this to work as a SPDIF receiver I need to somehow connect SPDIF IN and
analog out. So my question is, What is the best way to configure it? If I
get it right, I have three options here:
1) Configure a loopback on hardware level for the best latency and CPU usage
2) Configure a loopback on alsa level
3) Configure a loopback on pulseaudio level since I will use it for mixing
anyway

I am currently trying to understand if my hardware supports Option 1. I
have found a CM106 datasheet which suggests that setting bit 2 (SPDIFLOOP)
of register REG1 will enable SPDIF loop-back, however it is not clear
whether the sound from SPDIF IN will be routed to SPDIF OUT or analog
output and also whether this feature is what I'm looking for.

If the first option is not available, I would also ask for your advice on
which of the two last options is preferable.

Thanks in advance!

Best regards,
Denis Shulyaka
--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user


Re: [Alsa-user] Hardware loopback

2014-01-13 Thread Denis Shulyaka
Hi Clemens,

2014/1/13 Clemens Ladisch cladi...@googlemail.com
 As you can see in the block diagram, the S/PDIF input can be routed to
 both the S/PDIF output and to the analong front outputs.  Loopback
 usually means the same kind of connection, so there should be a normal
 mixer control for the front output.


Thank you for the response.

Unfortunately I am unable to find such control myself.
Below is my amixer output:

pi@speaker ~ $ amixer -c 0 info
Card hw:0 'Device'/'USB Sound Device at usb-bcm2708_usb-1.2.1, full speed'
  Mixer name: 'USB Mixer'
  Components: 'USB0d8c:0102'
  Controls  : 15
  Simple ctrls  : 6
pi@speaker ~ $ amixer -c 0 scontents
Simple mixer control 'Speaker',0
  Capabilities: pvolume pswitch pswitch-joined penum
  Playback channels: Front Left - Front Right - Rear Left - Rear Right
- Front Center - Woofer - Side Left - Side Right
  Limits: Playback 0 - 197
  Mono:
  Front Left: Playback 90 [46%] [-20.06dB] [on]
  Front Right: Playback 90 [46%] [-20.06dB] [on]
  Rear Left: Playback 90 [46%] [-20.06dB] [on]
  Rear Right: Playback 90 [46%] [-20.06dB] [on]
  Front Center: Playback 90 [46%] [-20.06dB] [on]
  Woofer: Playback 90 [46%] [-20.06dB] [on]
  Side Left: Playback 90 [46%] [-20.06dB] [on]
  Side Right: Playback 90 [46%] [-20.06dB] [on]
Simple mixer control 'PCM',0
  Capabilities: cvolume cswitch cswitch-joined penum
  Capture channels: Front Left - Front Right
  Limits: Capture 0 - 6928
  Front Left: Capture 4096 [59%] [0.01dB] [on]
  Front Right: Capture 4096 [59%] [0.01dB] [on]
Simple mixer control 'PCM Capture Source',0
  Capabilities: enum
  Items: 'Mic' 'Line' 'IEC958 In' 'Mixer'
  Item0: 'IEC958 In'
Simple mixer control 'Line',0
  Capabilities: pvolume cvolume pswitch pswitch-joined cswitch
cswitch-joined penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: Playback 0 - 8065 Capture 0 - 6928
  Front Left: Playback 6144 [76%] [0.01dB] [off] Capture 0 [0%] [-16.00dB] [off]
  Front Right: Playback 6144 [76%] [0.01dB] [off] Capture 0 [0%]
[-16.00dB] [off]
Simple mixer control 'Mic',0
  Capabilities: pvolume cvolume pswitch pswitch-joined cswitch
cswitch-joined penum
  Playback channels: Front Left - Front Right
  Capture channels: Front Left - Front Right
  Limits: Playback 0 - 8065 Capture 0 - 6928
  Front Left: Playback 6153 [76%] [0.03dB] [off] Capture 4096 [59%]
[0.01dB] [on]
  Front Right: Playback 6153 [76%] [0.03dB] [off] Capture 4096 [59%]
[0.01dB] [on]
Simple mixer control 'IEC958 In',0
  Capabilities: cswitch cswitch-joined penum
  Capture channels: Mono
  Mono: Capture [on]


The two controls related to SPDIF In are 'PCM Capture Source' and
'IEC958 In'. I'm not sure what they mean. The latter seems to
enable/disable the mix of the SPDIF In into capture stream (i.e.,
Input). For the first one I have no idea.
I will try to experiment with different values of the controls, but
unfortunately for the following two weeks I will not have any SPDIF
signal source to play with.

Best regards,
Denis Shulyaka

--
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments  Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431iu=/4140/ostg.clktrk
___
Alsa-user mailing list
Alsa-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/alsa-user