pygame.mixer with USB soundcard causes (snd_pcm_recover) below 48000 Hz - usb

I have created a Python program to play a song when a button is pressed. I am using a USB sound card and pygame.mixer to load songs and play them randomly when the button is pressed. The songs are 16-bit little-endian signed WAV files at 44100 Hz (but I don't think this matters).
OS: Raspbian (Debian 8 (Jessie))
Hardware: Raspberry Pi Zero
When I initialize the mixer at 44100 Hz like so:
pygame.mixer.init(44100,-16,2,2048)
I get the following error printed many times when I run my program:
ALSA lib pcm.c:7843:(snd_pcm_recover) underrun occurred
I get this before I even play any songs.
However, if I initialize at 48000 Hz, I do not get the underrun occurred message. But my files play back at 48000 Hz! So they are faster and at higher frequency.
Any clues as to why this happens and how I can fix it? I will accept workarounds using other packages to play the files.

Related

Why the AudioUnit collect 940bytes per frame under the earphone with lightning plug

I am a iOS developer from China, and I developed a recording application based on AudioUnit. When I tested it on my iPhone6s using the 3.5 mm plug earphone,it worded well and it collected 1024 bytes per frame. But when I tested it on those iPhone which don't have 3.5mm plug, the AudioUnit collected 940 bytes per frame and it reported error.
I tried to test my app on my iPhone 6s using the lightning plug earphone, and it also worked well.
The Remote iOS Audio Unit can change the size of the data in the callback from the requested duration, depending on OS state and audio hardware used.
The difference between 1024 and 940 samples in the callback buffer usually means the Audio Unit is resampling the data from a sample rate of 48000 to a sample rate of 44100 sps. That can happen because the hardware sample rate is different on different iPhone models (48000 on newer ones, 44100 on early models), and your app might be requesting a sample rate different from the device hardware sample rate.

Backup STM32 firmware using command line tools

I have a console STM32 ST-LINK utility. It is able to dump firmware to bin file. But the problem is in parameters. GUI version shows address and size in the upper "Memory display" groupbox. But how do I know the memory size parameter without GUI ST-LINK utility? Here is a parameter list for console version:
-Dump<Address> <Memory_Size> <File_Path>
Because you know your micro model you know the FLASH memory size and layout. ST-LINK utility does not provide any method of the chip identification
You can work it around by resetting the target first and saving the output to the file:
ST-LINK_CLI.exe -Rst
STM32 ST-LINK CLI v3.2.0.0
STM32 ST-LINK Command Line Interface
ST-LINK SN : 0670FF485550755187194938
ST-LINK Firmware version : V2J29M18
Connected via SWD.
SWD Frequency = 4000K.
Then you can call another program (self written) to parse the result and get the uC model and memory size. Then you can execute the ST-LINK_CLI with the calculated parameters.
Target voltage = 3.3 V.
Connection mode : Normal.
Device ID:0x449
Device flash Size : 1024 Kbytes
Device family :STM32F74x/F75x
MCU Reset.

Android Things SPI Burst Length NXP i.MX7D

I'm using the NXP i.MX7D with Android Things to read images from a camera via SPI. The image is broken down into packets of 244 bytes but it appears that the Android Things drivers only handle bursts of 64 bytes before the CS and CLK are deasserted for a period of time. The problem is that this invalidates the packet.
To change this behavior, I can toggle the BURST_LENGTH field in the ECSPI_CONREG register. I do not think I have the ability to change a register through Android Things but I think I can using the NDK and a C program. If I make this change will the Android Things SPI driver work as is or will I have to craft my own in C?

Connecting four axis digital readout encoder serial to usb in linux

For a milling machine I need to connect magnetic linear sensors which output a quadrature signal in order to read the position of 4 axes. The professional digital readouts are rather expensive. After some searching I tried to use an Arduino board and Yuri's digital readout Android software. I kept having issues with the bluetooth connection between my tablet and the Arduino failing.
I've since settled on a four axis serial to USB box, sold by a company which is involved the precision measurement industry. Now my issue is that the software supplied by the vendor for the converter box is only offered for Microsoft Windows. I'd like to run a Raspberry Pi 3 as my readout instead of dedicating a laptop.
I'm reading that running x86 on ARM is possible via QEMU or a paid software option. I'd rather not have to run WINE or a full Windows installation. I think it's possible to make this work in Linux on a Pi3 with a little bit of code. Where I think I will have the most trouble is that the Windows software requires some manner of special code to 'authenticate' the USB box.
Internally the box has a PIC18F45K22 8-bit RISC chip and a MC74HC86A XOR chip. I suspect the latter is used to combine the signals of the four axes before output. The USB to serial chip is a common FTDI FT232RL which I can see connects as ttyUSB0. Running 'screen' against that device has produced no output.
The specification of the microcontroller indicates that it is re-programmable with 1024 bytes of EEPROM. Among the other code they've flashed to the chip, would they have programmed in the 'authentication' code mentioned earlier? Short of de-compiling the Windows program, can I interrogate the device across USB without ruining it?
The microcontroller manufacturer site seems to have reasonable documentation and even code samples. Assuming the flashed code isn't obfuscated, could I download the contents of the EEPROM? From there I suspect I could see what commands are required to initialize the box. I could either remove the 'authentication' or re-write the program in its' entirety and flash it.

How to set the volume of a USB soundcard?

I am a total newbie when it comes to programming or even talking directly to drivers. The thing I want to do is hooking up my Raspberry Pi with a 5.1 external USB-soundcard. I would really like to use the Creative Sound Blaster X-Fi Surround Pro for that but Creative only provides Windows drivers. Which basically means I will have to write my own driver. While I assume that it will be quite easy to do the audio playback (I have done a fair amount of audio processing in my life) I don't have a clue how to set the USB card volume. I am honestly mostly irritated that the Sound Blaster has its own external volume control (which is the main reason for me to use it). Just applying a simple gain factor on the bit stream would be really easy.
My question is: Could it be that I would have to just set the system volume and that the volume control on the sound card just transfers values to the USB host which I then would have to make sense of?
In case you do not know the Sound Blaster card, would that be the standard way of doing things?
I have the same soundcard and am doing the same thing with the Raspberry Pi. The command you're looking for is:
$ alsamixer
This will open up a terminal-friendly GUI for modifying the audio output volume. You should see the Raspberry Pi onboard audio driver BCM2835 and associated devices alongside your USB audio.
Alternatively, you can set the volume with a simple amixer command:
$ amixer -c 0 set Master 100%
which sets the volume of card 0 to 100%.
It's more than likely that the USB soundcard isn't being chosen as the default and is card 1, rather than card 0.
Check the following guides for further information on RasPi / USB Audio Setup:
http://drewlustro.com/hi-fi-audio-via-airplay-on-raspberry-pi
http://audioplastic.org/blog/2013/01/10/AP1/