# pHAT DAC – Mixing multiple sounds?

**URL:** <https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983>\
**Category:** Support\
**Created:** [September 6, 2016, 12:30pm UTC](https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983 "2016-09-06T12:30:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Heinzelchen](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@Heinzelchen](https://forums.pimoroni.com/u/Heinzelchen)\
**Post date:** [September 6, 2016, 12:30pm UTC](https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983/1 "2016-09-06T12:30:07Z")

</div>

Hello everyone!

I just received my pHAT DAC and am playing around a bit with it. What I’m currently trying to do is playing multiple sounds via a python script **at once**. This works flawlessly with my internal RPi 2 sound system for up to 8 streams. But as soon as I’m using the pHAT DAC there is only one sound coming out at once.

For reference: A small script that I used for the RPi with maximal 8 sounds playing simultaneously. Assume that there is a directory _sounds_ with the soundfiles _1.wav_, _2.wav_, …

```
#!/usr/bin/python3

import time
from subprocess import Popen
from queue import Queue

sounds = Queue(maxsize = 8)

def play(number):
    if sounds.qsize() >= 8: sounds.get().kill()
    process = Popen(['aplay', './sounds/' + str(number) + '.wav'])
    sounds.put(process)

for i in range(1, 10):
    play(i)
    time.sleep(0.5)

```

What I would expect is to get 9 sounds (8 at a time maximal) to play in parallel, each started half a second before the preceding one. What happens in reality is that the first sound seems to block the output. Let’s assume it is 3 seconds long, then only _7.wav_ will be heard, the rest simply doesn’t play.

Is there anything I missed? Isn’t it possible to mix multiple sounds?

Thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![RogueM](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/roguem/32/311_2.png) [@RogueM](https://forums.pimoroni.com/u/RogueM)\
**Post date:** [September 6, 2016, 3:09pm UTC](https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983/2 "2016-09-06T15:09:07Z")

</div>

the pHAT DAC has no hardware mixing capability. I guess that is the problem here, with each of your processes being a different PCM stream. It’s my understanding that you have to set up a dmixer to work around the limitation.

… I can’t say I am particularly knowledgeable on the subject, so I can only refer you to some alsa documentation:

[http://alsa.opensrc.org/Hardware\_mixing,\_software\_mixing](http://alsa.opensrc.org/Hardware_mixing,_software_mixing)

---

<div class="post-metadata">

**Author:** ![Heinzelchen](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@Heinzelchen](https://forums.pimoroni.com/u/Heinzelchen)\
**Post date:** [September 6, 2016, 3:30pm UTC](https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983/3 "2016-09-06T15:30:33Z")

</div>

Thanks a lot for your reply!

That sounds like it must be my problem – thanks for pointing it out. After copying the _.asoundrc_ I get the following error from _aplay_:

```
ALSA lib pcm_direct.c:896:(snd1_pcm_direct_initialize_slave) slave plugin does not support mmap interleaved or mmap noninterleaved access
ALSA lib pcm_dmix.c:1034:(snd_pcm_dmix_open) unable to initialize slave

```

When including the _mmap\_emulation_ parameter as suggested by the linked documentation, I only get:

```
ALSA lib pcm_hw.c:1741:(_snd_pcm_hw_open) Unknown field mmap_emulation
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave

```

As I’m far from an expert in this area, has anyone an idea on how to fix this? Maybe the parameters changed since that documentation-version?

---

<div class="post-metadata">

**Author:** ![gadgetoid](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/gadgetoid/32/13_2.png) [@gadgetoid](https://forums.pimoroni.com/u/gadgetoid)\
**Post date:** [September 6, 2016, 4:26pm UTC](https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983/4 "2016-09-06T16:26:51Z")

</div>

This is probably the least succinct and concise example, but the Piano HAT `simple-piano.py` uses `pygame.mixer` to mix and play multiple .wav files simultaneously. If it works via pHAT DAC you may be able to modify this example for your own purposes:

> <https://github.com/pimoroni/Piano-HAT/blob/master/examples/simple-piano.py>

---

<div class="post-metadata">

**Author:** ![Heinzelchen](https://avatars.discourse-cdn.com/v4/letter/h/dec6dc/32.png) [@Heinzelchen](https://forums.pimoroni.com/u/Heinzelchen)\
**Post date:** [September 6, 2016, 5:01pm UTC](https://forums.pimoroni.com/t/phat-dac-mixing-multiple-sounds/2983/5 "2016-09-06T17:01:33Z")

</div>

Thanks a lot for this hint! It works perfect and is exactly what I wanted!
