You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using libusb-1.0.27 to read PCM data from a microphone device that supports the UAC protocol. I've tested it on both Windows 10 and Ubuntu (18.04.6), and the results show that they can both retrieve PCM data properly. However, on Windows, when I playback this PCM data, there is significant noise, and the recorded sound becomes very faint, while everything works fine on Ubuntu. I've tried different drivers on Windows, including WinUSB (v6.1.7600.16385), libusb-win32 (v1.2.7.3), libusbK (v3.1.0.0), but the results are the same. The code used on both platforms is exactly the same.
My test code
constuint16_t VID = 0x1403;
constuint16_t PID = 0x3592;
constint IFACE_NUM = 1;
constint ALTERNATE_SETTING = 1;
constint EP_ISO_IN = 0x82;
constint PACKET_SIZE = 294;
constint NUM_TRANSFERS = 10;
constint NUM_PACKETS = 10;
static FILE* fout = NULL;
staticint bFirst = 1;
staticvoid WINAPI transfer_callback(structlibusb_transfer* xfr)
{
if (bFirst)
{
bFirst = 0;
fout = fopen("./output_data.pcm", "w+");
if (fout == NULL)
{
printf("erro to open file[%d %s] \n", __LINE__, __FUNCTION__);
}
}
int i = 0;
if (fout)
{
for (i = 0; i < xfr->num_iso_packets; i++)
{
structlibusb_iso_packet_descriptor* pack = &xfr->iso_packet_desc[i];
if (pack->status != LIBUSB_TRANSFER_COMPLETED)
{
printf("erro transfer status %d %s [%d %s]\n", pack->status, libusb_error_name(pack->status), __LINE__, __FUNCTION__);
break;
}
constuint8_t* data = libusb_get_iso_packet_buffer_simple(xfr, i);
printf("get out data %d [%d %s]\n", pack->actual_length, __LINE__, __FUNCTION__);
fwrite(data, 1, pack->actual_length, fout);
}
}
if (libusb_submit_transfer(xfr) < 0) {
printf("error re-submitting !!!!!!!exit ----------[%d %s]\n", __LINE__, __FUNCTION__);
exit(1);
}
else
{
printf("re-submint ok !\n");
}
}
intmain(int argc, char* argv[]) {
int ret = libusb_init(NULL);
libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_DEBUG);
if (ret < 0) {
printf("Initialize libusb failed: %s\n", libusb_error_name(ret));
return -1;
}
libusb_device_handle* devh = libusb_open_device_with_vid_pid(NULL, VID, PID);
if (devh == NULL) {
printf("Open device failed\n");
return -1;
}
ret = libusb_kernel_driver_active(devh, IFACE_NUM);
if (ret == 1)
{
ret = libusb_detach_kernel_driver(devh, IFACE_NUM);
if (ret < 0)
{
printf("Detach kernel failed [%d %s]\n", __LINE__, __FUNCTION__);
libusb_close(NULL);
libusb_exit(NULL);
return -1;
}
}
ret = libusb_claim_interface(devh, IFACE_NUM);
if (ret < 0)
{
printf("erro claming interface %s %d [%d %s]\n", libusb_error_name(ret), ret, __LINE__, __FUNCTION__);
return -1;
}
libusb_set_interface_alt_setting(devh, IFACE_NUM, ALTERNATE_SETTING);
int endpointBytesPerPacket = PACKET_SIZE;
int packetsPerTransfer = NUM_PACKETS;
int totalTransferSize = PACKET_SIZE * NUM_PACKETS;
unsignedchar* transferBuffers[NUM_TRANSFERS];
structlibusb_transfer* transfers[NUM_TRANSFERS];
for (int i = 0; i < NUM_TRANSFERS; i++)
{
transfers[i] = libusb_alloc_transfer(packetsPerTransfer);
if (!transfers[i])
{
printf("alloc transfer err [%d %s]o\n", __LINE__, __FUNCTION__);
return -1;
}
transferBuffers[i] = newuint8_t[totalTransferSize];
memset(transferBuffers[i], 0, totalTransferSize);
libusb_fill_iso_transfer(transfers[i], devh, EP_ISO_IN, transferBuffers[i], totalTransferSize, packetsPerTransfer, transfer_callback, NULL, 1000);
libusb_set_iso_packet_lengths(transfers[i], endpointBytesPerPacket);
}
for (int i = 0; i < NUM_TRANSFERS; i++) {
ret = libusb_submit_transfer(transfers[i]);
if (ret == 0)
{
printf("transfer submint ok ! start capture[%d %s]\n", __LINE__, __FUNCTION__);
}
else
{
printf(" transfer submint erro %d %s [%d %s]\n", ret, libusb_error_name(ret), __LINE__, __FUNCTION__);
return -1;
}
}
while (1)
{
ret = libusb_handle_events(NULL);
if (ret != LIBUSB_SUCCESS)
{
printf("handle event erro ,exit! [%d %s]\n", __LINE__, __FUNCTION__);
break;
}
}
for (int i = 0; i < NUM_TRANSFERS; i++) {
ret = libusb_cancel_transfer(transfers[i]);
if (ret != 0) {
printf("cancel transfer failed %s %d [%d %s]\n", libusb_error_name(ret), ret, __LINE__, __FUNCTION__);
continue;
}
libusb_free_transfer(transfers[i]);
}
libusb_release_interface(devh, 0);
if (devh)
{
libusb_close(devh);
}
libusb_exit(NULL);
return0;
}
Hi libusb team,
I'm using libusb-1.0.27 to read PCM data from a microphone device that supports the UAC protocol. I've tested it on both Windows 10 and Ubuntu (18.04.6), and the results show that they can both retrieve PCM data properly. However, on Windows, when I playback this PCM data, there is significant noise, and the recorded sound becomes very faint, while everything works fine on Ubuntu. I've tried different drivers on Windows, including WinUSB (v6.1.7600.16385), libusb-win32 (v1.2.7.3), libusbK (v3.1.0.0), but the results are the same. The code used on both platforms is exactly the same.
My test code
The Device Info
The text was updated successfully, but these errors were encountered: