# Issues in juce\_linux\_ALSA format conversion

**URL:** <https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894>\
**Category:** General JUCE discussion\
**Created:** [August 25, 2017, 9:37am UTC](https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894 "2017-08-25T09:37:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcarpent](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@tcarpent](https://forum.juce.com/u/tcarpent)\
**Post date:** [August 25, 2017, 9:37am UTC](https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894/1 "2017-08-25T09:37:59Z")

</div>

Hi,

In the code below, the first loop is OK whilst the second one crashes on little endian platforms (at line 209 in juce\_AudioDataConverters.h). Is there a good reason for that ?

This phenomena occurs in juce\_linux\_ALSA, causing crashes (line 327 in juce\_linux\_ALSA.cpp) when the device is non-interleaved (the AudioData::Converter is always created with AudioData::Interleaved as destination format, which I believe is the origin of the issue).  
My workaround is too pass the ‘isInterleaved’ flag up to the createConverter functions (around lines 396). Could you please have a look at that ?

And while we’re here: the maximum number of channels is restricted to 32 (line 78 in juce\_linux\_ALSA.cpp), which is annoying. RME cards have 192 channels and they are well supported in ALSA (that’s the one I’m using at the moment). So, could you please remove the limitation in line 78 (or maybe make something like 256 instead of 32).

Thanks in advance

```
   const unsigned int numChannels = 2;
   const unsigned int numSamples = 512;

   AudioSampleBuffer buffer( numChannels, numSamples );

   float* const* const data = buffer.getArrayOfWritePointers();

   for (unsigned int i = 0; i < numChannels; ++i)
   {
       jassert( data[i] != nullptr );
       AudioDataConverters::convertFloatToInt32LE( data[i], data[i], numSamples );
   }

   typedef AudioData::Pointer <AudioData::Float32, AudioData::LittleEndian, AudioData::NonInterleaved, AudioData::Const> SourceType;
   typedef AudioData::Pointer <AudioData::Int32, AudioData::LittleEndian, AudioData::Interleaved, AudioData::NonConst> DestType;

   AudioData::ConverterInstance < SourceType, DestType > converter ( 1, numChannels );

   for (unsigned int i = 0; i < numChannels; ++i)
   {
       jassert( data[i] != nullptr );
       converter.convertSamples( data[i], data[i], numSamples );
   }
```

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [August 29, 2017, 9:16am UTC](https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894/2 "2017-08-29T09:16:21Z")

</div>

OK. I’ve increased the maximum channel number to 256. Your fix for the crash looks good to me but I’d like to test it a bit more carefully. Is there anyway I can reproduce the crash in Ubuntu with some kind of virtual ALSA device?

---

<div class="post-metadata">

**Author:** ![tcarpent](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@tcarpent](https://forum.juce.com/u/tcarpent)\
**Post date:** [August 29, 2017, 11:59am UTC](https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894/3 "2017-08-29T11:59:14Z")

</div>

Hi Fabian,

Thanks for the quick reply.  
To reproduce the crash, you would need a device with RW\_NONINTERLEAVED access flag. I dont know if there is any way to create a virtual ALSA device like that.  
If you send me your code, I could test it with two hardware interfaces that I have at hand. At the moment, I dont see other options to test/reproduce.

---

<div class="post-metadata">

**Author:** ![fr810](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/fr810/32/841_2.png) [@fr810](https://forum.juce.com/u/fr810)\
**Post date:** [August 30, 2017, 11:00am UTC](https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894/4 "2017-08-30T11:00:41Z")

</div>

OK can you check if it is fixed on develop now (commit [91e0385](https://github.com/WeAreROLI/JUCE/commit/91e0385d262ae347293de3f78f6f0fa0546b125e))?

---

<div class="post-metadata">

**Author:** ![tcarpent](https://avatars.discourse-cdn.com/v4/letter/t/49beb7/32.png) [@tcarpent](https://forum.juce.com/u/tcarpent)\
**Post date:** [August 30, 2017, 1:36pm UTC](https://forum.juce.com/t/issues-in-juce-linux-alsa-format-conversion/23894/5 "2017-08-30T13:36:26Z")

</div>

Thanks Fabian. Your commit works as expected. As far as I can tell, the issue is solved.
