I am trying to add a dix to my Alsa conf file, but when I playback using it the sample rate is wrong (it's too slow)
I have the following:
pcm.dmix0 {
type dmix
ipc_key 34521
slave {
pcm "hw:0,0"
format S16_LE
rate 48000
}
hint {
description "DMix of Card0"
}
}
pcm.asym51 {
type asym
playback.pcm "dmix0"
capture.pcm "hw:0,0"
}
pcm.dsp0 {
type plug
slave.pcm "asym51"
}
When I play the audio back directly to the hardware, it plays fine, but I do miss a bit at the start.aplay -D hw:0,0 /usr/share/sounds/alsa/Front_Center.wav
When I use my dsp0 / dmix the rate is much slower than it should be:aplay -D dsp0 /usr/share/sounds/alsa/Front_Center.wav
What am I doing wrong?
Related
So I am working on a project to establish CAN bus communication between raspberry pi 4 and arduino. Unfortunately, I don't have great success. So I already established connection between multiples raspberry pies and it is working perfectly. So to configure my raspberry pi I followed the steps of online tutorial. I added this lines in the /boot/config.txt:
dtoverlay=mcp2515-can0,oscillator=8000000,interupt=12
dtoverlay=spi-bcm2835-overlay
installed the can utilities and initiate the can using
sudo ip link set can0 up type can bitrate 500000
After that I created python code to control the receiving and sending of data to the CAN bus. Here is my code for sending data:
import time
import can
bustype = 'socketcan'
channel = 'can0'
bus = can.interface.Bus(channel=channel, bustype=bustype,bitrate=500000)
while True:
msg = can.Message(arbitration_id=2, data=[0, 0, 0, 0, 0, 0], is_extended_id=False)
bus.send(msg)
time.sleep(0.1)
</code></pre>
and here's is the one for receiving:
import time
import can
bustype = 'socketcan'
channel = 'can0'
bus = can.interface.Bus(channel=channel, bustype=bustype,bitrate=500000)
while True:
print(bus.recv())
time.sleep(0.1)
So for the arduino part I tried using UNO and Mega2560.
My connection on both boards is the same:
VCC --> 5V
GND --> GND
CS --> pin 10
SO --> pin12
SI --> pin11
SCK --> pin 13
INT --> pin 2
Tried multiple libraries on of them https://github.com/Seeed-Studio/Seeed_Arduino_CAN/blob/master/examples/recv_sd/recv_sd.ino
and the https://www.arduinolibraries.info/libraries/can. So I uploaded the example code to the arduino. Here it is:
#include
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("CAN Sender");
// start the CAN bus at 500 kbps
// if (!CAN.begin(500E3)) {
// Serial.println("Starting CAN failed!");
// while (1);
// }
}
void loop() {
// send packet: id is 11 bits, packet can contain up to 8 bytes of data
Serial.print("Sending packet ... ");
CAN.beginPacket(0x12);
CAN.write('h');
CAN.write('e');
CAN.write('l');
CAN.write('l');
CAN.write('o');
CAN.endPacket();
Serial.println("done");
delay(1000);
// send extended packet: id is 29 bits, packet can contain up to 8 bytes of data
Serial.print("Sending extended packet ... ");
CAN.beginExtendedPacket(0xabcdef);
CAN.write('w');
CAN.write('o');
CAN.write('r');
CAN.write('l');
CAN.write('d');
CAN.endPacket();
Serial.println("done");
delay(1000);
}
and when i upload it to the Arduino Uno it gives "Starting CAN failed!", but on the Arduino Mega everything seems to work fine, but both times no data is received by the raspberry pi no matter if i use the python code or simple "candump can0" command. Tried it even with the receiving example :
#include
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("CAN Receiver");
// start the CAN bus at 500 kbps
if (!CAN.begin(500E3)) {
Serial.println("Starting CAN failed!");
while (1);
}
}
void loop() {
// try to parse packet
int packetSize = CAN.parsePacket();
if (packetSize || CAN.packetId() != -1) {
// received a packet
Serial.print("Received ");
if (CAN.packetExtended()) {
Serial.print("extended ");
}
if (CAN.packetRtr()) {
// Remote transmission request, packet contains no data
Serial.print("RTR ");
}
Serial.print("packet with id 0x");
Serial.print(CAN.packetId(), HEX);
if (CAN.packetRtr()) {
Serial.print(" and requested length ");
Serial.println(CAN.packetDlc());
} else {
Serial.print(" and length ");
Serial.println(packetSize);
// only print packet data for non-RTR packets
while (CAN.available()) {
Serial.print((char)CAN.read());
}
Serial.println();
}
Serial.println();
}
}
So I will greatly appreciate help from anybody, because I have struggled with this problem for the last 2 weeks and I really want to solve it. Thank you for your time
So I have finally found a solution. I guess the other libraries had some problem sending data, cause I set everything with the same configuration. However, today I found this library->https://www.arduinolibraries.info/libraries/mcp_can, which helped me program correctly the arduino and it works perfectly in connection with another arduino or raspberry pi.
Hello I am trying to check if a Beaglebone AI is getting correctly I2S from a TIDA-1454 so if I try to arecord test.wav I get:
debian#beaglebone:/etc$ arecord -d 10 ALSA lib
pcm_dsnoop.c:638:(snd_pcm_dsnoop_open) unable to open slave arecord:
main:828: audio open error: No such file or directory
But the card is detected since i get this output from arecord -l:
**** List of CAPTURE Hardware Devices ****
card 1: PCM5102a [PCM5102a], device 0: davinci-mcasp.0-pcm5102a-hifi pcm5102a-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
or arecord -L:
debian#beaglebone:/var/lib/cloud9$ arecord -L
null
Discard all samples (playback) or generate zero samples (capture)
onboard
onboard_capture_left
onboard_playback_left
onboard_capture_right
onboard_playback_right
plug_onboard_capture_left
plug_onboard_playback_left
default
sysdefault:CARD=PCM5102a
PCM5102a,
Default Audio Device
dmix:CARD=PCM5102a,DEV=0
PCM5102a,
Direct sample mixing device
dsnoop:CARD=PCM5102a,DEV=0
PCM5102a,
Direct sample snooping device
hw:CARD=PCM5102a,DEV=0
PCM5102a,
Direct hardware device without any conversions
plughw:CARD=PCM5102a,DEV=0
PCM5102a,
Hardware device with all software conversions
and ALSA configuration:
pcm.onboard{
type hw
card 0
}
ctl.onboard {
type hw
card 0
}
### Dsnoop splited channels
pcm.onboard_capture_left {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
rate 48000
format S32_LE
}
bindings.0 0
}
pcm.onboard_playback_left {
type dmix
ipc_key 33
slave {
pcm "onboard"
channels 2
}
bindings.0 0
}
pcm.onboard_capture_right {
type dsnoop
ipc_key 32
slave {
pcm "onboard"
channels 2
rate 48000
format S32_LE
}
bindings.0 1
}
pcm.onboard_playback_right {
type dmix
ipc_key 33
slave {
pcm "onboard"
channels 2
}
bindings.0 1
}
### PLUGS ##
### used with darkice
### device = plug:plug_onboard_left
pcm.plug_onboard_capture_left{
type plug
slave.pcm "onboard_capture_left"
}
pcm.plug_onboard_playback_left{
type plug
slave.pcm "onboard_playback_left"
}
pcm.!default {
type asym
playback.pcm "plug_onboard_playback_left"
capture.pcm "plug_onboard_capture_left"
}
So what can it be the problem?
When recording you should tell alsa what device to use:
**** List of CAPTURE Hardware Devices ****
card 1: PCM5102a [PCM5102a], device 0: davinci-mcasp.0-pcm5102a-hifi >pcm5102a-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
Your device address is : hw:1,0 (card 1, device 0 )
So :
arecord --device="hw:1,0" test.wav
He should ask you for the format, for instance:
Available format:
- S8
- S16_LE
Then you can add the format :
arecord --device="hw:1,0" -f S16_LE test.wav
My audio go through a pipe by alsa plugin, and this is my asound.conf setting.
pcm.plug_0 {
type plug
slave {
pcm rate48000Hz
channels 8
}
}
pcm.rate48000Hz {
type rate
slave {
pcm writeFile
format S16_LE
rate 48000
}
}
pcm.writeFile {
type file
slave.pcm null
file "/tmp/fifo"
format "raw"
}
The audio consists of 8 channels.
I want them divide into individual channel, and let them go to the pipe.
I try to change my code,
pcm.ch1 {
type dshare
ipc_key 1234
slave {
pcm plug_0
rate 48000
channels 8
}
bindings.0 1
}
pcm.ch2 {
type dshare
ipc_key 1234
slave {
pcm plug_0
rate 48000
channels 8
}
bindings.0 2
}
pcm.ch3 {
type dshare
ipc_key 1234
slave {
pcm plug_0
rate 48000
channels 8
}
bindings.0 3
}
pcm.plug_0{
type plug
slave {
pcm rate48000Hz
channels 8
}
}
pcm.rate48000Hz {
type rate
slave {
pcm writeFile
format S16_LE
rate 48000
}
}
pcm.writeFile {
type file
slave.pcm null
file "/tmp/fifo"
format "raw"
}
And I shell the cmd
aplay -Dch1 xxx.wav
it response
ALSA lib pcm_direct.c:1817:(_snd_pcm_direct_get_slave_ipc_offset) Invalid type 'null' for slave PCM
aplay: main:828: audio open error: Invalid argument
then I comment out slave.pcm null
and shell aplay -Dch1 xxx.wav again
it response
ALSA lib pcm_direct.c:1817:(_snd_pcm_direct_get_slave_ipc_offset) Invalid type 'file' for slave PCM
aplay: main:828: audio open error: Invalid argument
Is there any idea can solve this problem ?
I am trying to use the multi ALSA plugin to copy my desktop audio to the Loopback device created by snd-aloop. However, when I try to use the .asoundrc below, I get this error:
> aplay -vv test.wav
Playing WAVE 'test.wav' : Signed 32 bit Little Endian, Rate 48000 Hz, Stereo
ALSA lib pcm_params.c:2226:(snd1_pcm_hw_refine_slave) Slave PCM not usable
aplay: set_params:1314: Broken configuration for this PCM: no configurations available
.asoundrc:
pcm.both {
type multi
slaves.a.pcm "dmixer"
slaves.b.pcm "loop"
slaves.a.channels 2
slaves.b.channels 2
bindings.0 { slave a; channel 0; }
bindings.1 { slave a; channel 1; }
bindings.2 { slave b; channel 0; }
bindings.3 { slave b; channel 1; }
}
pcm.dmixer {
type dmix
ipc_key 1231
ipc_perm 0666
slave.pcm "hw:PCH,0"
slave.channels 2
slave.rate 48000
slave.format S32_LE
bindings {
0 0
1 1
}
}
pcm.loop {
type dmix
ipc_key 29637
slave {
pcm "hw:Loopback,0"
rate 48000
format S32_LE
channels 2
period_size 1024
buffer_size 9182
}
}
pcm.hubcap {
type plug
slave {
pcm "hw:Loopback,1,0"
rate 48000
format S32_LE
}
}
pcm.!default {
type asym
playback.pcm {
type plug
slave.pcm "both"
ttable [
[ 1 0 1 0 ]
[ 0 1 0 1 ]
]
}
capture.pcm "plug:dsnoop"
}
defaults.pcm.surround21.card off
defaults.pcm.surround21.device off
defaults.pcm.surround40.card off
defaults.pcm.surround40.device off
defaults.pcm.surround41.card off
defaults.pcm.surround41.device off
defaults.pcm.surround50.card off
defaults.pcm.surround50.device off
defaults.pcm.surround51.card off
defaults.pcm.surround51.device off
defaults.pcm.surround71.card off
defaults.pcm.surround71.device off
Things to note:
When I remove both dmixes, it works fine.
In the multi plugin, when I change both slaves to the same pcm, it works fine for that one pcm.
Ex.
...
type multi
slaves.a.pcm "dmixer"
slaves.b.pcm "dmixer"
...
Try setting slave.period_size 1024 in pcm.dmixer block.
I'm trying to record currently played sound using alsa snd-aloop
Here is my asound.conf
pcm.multi {
type route;
slave.pcm {
type multi;
slaves.a.pcm "output";
slaves.b.pcm "loopin";
slaves.a.channels 2;
slaves.b.channels 2;
bindings.0.slave a;
bindings.0.channel 0;
bindings.1.slave a;
bindings.1.channel 1;
bindings.2.slave b;
bindings.2.channel 0;
bindings.3.slave b;
bindings.3.channel 1;
}
ttable.0.0 1;
ttable.1.1 1;
ttable.0.2 1;
ttable.1.3 1;
}
pcm.!default {
type plug
slave.pcm "multi"
}
pcm.output {
type hw
card 0
}
pcm.loopin {
type plug
slave.pcm "hw:1,0,0"
}
pcm.loopout {
type plug
slave.pcm "hw:1,1,0"
}
Now when I'm running such command :
play sound.mp3
and :
arecord -c 2 -f S16_LE -r 48000 -D loopout test.wav
Sound is played on soundcard 0 and recorded as test.wav
Now my default PCM routes sound to loopin an output.
But when I'm listing PCM devices :
aplay -L
null
Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device
sysdefault:CARD=Loopback
Loopback, Loopback PCM
Default Audio Device
front:CARD=Loopback,DEV=0
Loopback, Loopback PCM
Front speakers
surround21:CARD=Loopback,DEV=0
Loopback, Loopback PCM
2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.0 Surround output to Front and Rear speakers
surround41:CARD=Loopback,DEV=0
Loopback, Loopback PCM
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Loopback,DEV=0
Loopback, Loopback PCM
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Loopback,DEV=0
Loopback, Loopback PCM
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
I do not see added pcm from asound.conf
Is it normal?
My problem is that I have an application configured using this list that does not use my default pcm.
aplay -L can show only those devices that define such a description string.
(This is somewhat undocumented.)
pcm.multi {
...
hint.description "My Little Device"
}