# AudioTransportSource::getNextAudioBlock() reading 8 channel file yields a buffer with only 6 channels

**URL:** https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155
**Category:** General JUCE discussion
**Created:** [January 7, 2019, 3:36pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155 "2019-01-07T15:36:03Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 3:36pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/1 "2019-01-07T15:36:03Z")

</div>

I’m hoping to use an AudioTransportSource to read a 8 channel interleaved .wav file

but the buffer it offers up in getNextAudioBlock() only has 6 channels!

How do I get the buffer to have all 8 channels?

reader/transport code

```
	auto* reader = formatManager.createReaderFor(File(start.filename));

	if (reader != nullptr)
	{
		
		std::unique_ptr<AudioFormatReaderSource> newSource(new AudioFormatReaderSource(reader, true));
		newSource->setLooping(start.isLooping);
		transportSource.setSource(newSource.get(), 0, nullptr, reader->sampleRate,8);
		transportSource.start();
		readerSource.reset(newSource.release());

	}

```

btw, if I look at the reader’s raw object in the debugger, I can see the file has 8 channels

this is a gui-less DLL (which works great with 2 chan file)

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 3:46pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/2 "2019-01-07T15:46:39Z")

</div>

How does it manifest? The buffer has just 6 channels or the channels 7 and 8 are silent?

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 3:55pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/3 "2019-01-07T15:55:39Z")

</div>

The buffer (`const AudioSourceChannelInfo& bufferToFill`) only has 6 channels.

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 3:58pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/4 "2019-01-07T15:58:35Z")

</div>

How many channels does the buffer you give to transportSource.getNextAudioBlock have?

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 4:08pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/5 "2019-01-07T16:08:47Z")

</div>

6, I’m giving it `bufferToFill` to

`transportSource.getNextAudioBlock(bufferToFill);`

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 4:10pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/6 "2019-01-07T16:10:15Z")

</div>

Then the behavior seems as expected. The transportsource isn’t going to resize the buffer channel count. It just fills the given buffer with as many channels as that buffer has, even if the file source has more.

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 4:12pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/7 "2019-01-07T16:12:42Z")

</div>

OK, how would I resize that buffer?

Or have I hit a limit?

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 4:14pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/8 "2019-01-07T16:14:08Z")

</div>

You need to have your own AudioBuffer with enough channels and use the TransportSource with that. (Or whatever is giving you the buffer with just 6 channels could maybe be configured to have 8 channels…? But it’s probably best you have your own AudioBuffer anyway.)

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 4:21pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/9 "2019-01-07T16:21:57Z")

</div>

Thanks for you help so far @Xenakios

So, at the moment, I think I’m just a using a default buffer that is created by the ‘transportSource’, would this the be the case? I presume when `TransportSource.Start()` is called, it set’s up the buffer that is passed into `getNextAudioBlock` for the first time?

If so, how would I go about giving it another buffer?

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 4:26pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/10 "2019-01-07T16:26:44Z")

</div>

> [@illagarr](#):
>
> So, at the moment, I think I’m just a using a default buffer that is created by the ‘transportSource’, would this the be the case? I presume when `TransportSource.Start()` is called, it set’s up the buffer that is passed into `getNextAudioBlock` for the first time?
> 
> If so, how would I go about giving it another buffer?

The transportSource has its internal buffer that is set up separately but when you request it to produce audio with getNextAudioBlock, it fills the buffer that is passed in. Where do you get that buffer from? What kind of a JUCE project are you using this stuff in?

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 5:02pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/11 "2019-01-07T17:02:07Z")

</div>

This is Dynamic DLL, based on the AudioAppComponent

I’m not certain where the original buffer is coming from, my assumption was always that that the `transportSource.Start()` function was populating the initial buffer and calling `getNextAudioBlock(const AudioSourceChannelInfo& bufferToFill)`, then using `transportSource.getNextAudioBlock(bufferToFill);` before I’m passing into a `processBlock()`

```
void getNextAudioBlock(const AudioSourceChannelInfo& bufferToFill)
{

	if (readerSource.get() == nullptr)
	{
		bufferToFill.clearActiveBufferRegion();
		return;
	}

	transportSource.getNextAudioBlock(bufferToFill);

	AudioBuffer<float> procBuf(bufferToFill.buffer->getArrayOfWritePointers(),
		bufferToFill.buffer->getNumChannels(), // <- this is 6 too
		bufferToFill.startSample,
		bufferToFill.numSamples);
	MidiBuffer midi;
	processBlock(procBuf, midi);
}
```

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)
#### Post date: [January 7, 2019, 5:05pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/12 "2019-01-07T17:05:35Z")

</div>

When audio is pulled from a chain of AudioSources, the one closest to the output prepares the buffer, that is handed recursively through the chain. Usually this could be an AudioSourcePlayer, that gets the number of channels from the AudioIODevice it is playing to.

If you need a different number of channels, you need some kind of multiplexer, e.g. [ChannelRemappingAudioSource](https://docs.juce.com/master/classChannelRemappingAudioSource.html), or call getNextAudioBlock yourself with an appropriate pre-allocated buffer.

EDIT: To clarify, the AudioAppComponent aggregates (i.e. has a member of type) AudioSourcePlayer, that pulls audio from the component itself (i.e. calls the `getNextAudioBlock()` method of the component). The buffer is determined by the number of channels requested, when opening the device.

See here:

> <https://github.com/WeAreROLI/JUCE/blob/develop/modules/juce_audio_utils/gui/juce_AudioAppComponent.cpp#L76>

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 5:08pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/13 "2019-01-07T17:08:06Z")

</div>

The buffer that is in the AudioAppComponent::getNextAudioBlock call has nothing to do with the internal buffer of your transportSource. (The internal buffer determines how many channels at maximum it _can_ read from the source file but does not affect how many channels it will actually output, that is determined by the buffer given to transportSource::getNextAudioBlock.) The AudioAppComponent::getNextAudioBlock buffer apparently gets initialized to have 6 channels “somewhere”, then you pass it into the transportSource and that fills it with 6 channels.

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 6:02pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/14 "2019-01-07T18:02:12Z")

</div>

thanks both for your patience with me.

so this making more sense to me.

When I start my class, which inherits from the `AudioAppCompnent`, `setAudioChannels(8, 2);` is being called in the constructor. That calls `deviceManager.initialise()` which is returning an empty string, so is not erroring. I’m assuming that the device is being set with 8 channels?

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 6:07pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/15 "2019-01-07T18:07:23Z")

</div>

> [@illagarr](#):
>
> I’m assuming that the device is being set with 8 channels?

Clearly it isn’t since you get a buffer with just 6 channels in the AudioAppComponent::getNextAudioBlock call. Note that the maximum channel counts that can be initialized for the AudioAppComponent depend on your audio hardware. Whether you get an error when initializing the device with incompatible channel counts or not probably depends on the audio subsystem used. (For me, for example Windows WASAPI is pretty picky about it and the requested channel counts must be supported or JUCE fails to open the device.) You should not really rely on the audio hardware IO channel counts and instead use your own AudioBuffer for the processing. At the end of the processing, you should again adapt to the audio hardware channel counts in some way, for example by remapping the channels, by omitting them or by outputting silence.

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 8:08pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/16 "2019-01-07T20:08:50Z")

</div>

OK. Thanks again. I’m starting to understand more.

I’m a little confused as to where I introduce my own AudioBuffer.

---

<div class="post-metadata">

### Author: ![xenakios](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/xenakios/32/4047_2.png) [@xenakios](https://forum.juce.com/u/xenakios)
#### Post date: [January 7, 2019, 8:14pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/17 "2019-01-07T20:14:48Z")

</div>

You should add that as a member variable of your AudioAppComponent and set its number of channels and size in prepareToPlay. (You must not have a buffer like that as a local variable in your getNextAudioBlock because you would be causing memory allocations to happen which shouldn’t be done during the audio processing.)

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 7, 2019, 8:16pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/18 "2019-01-07T20:16:18Z")

</div>

OK, and then use it in the `transportSource.getNextAudioBlock(myNewBufferEtc);?

---

<div class="post-metadata">

### Author: ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)
#### Post date: [January 7, 2019, 11:38pm UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/19 "2019-01-07T23:38:09Z")

</div>

I was about to suggest the ChannelRemappingAudioSource again, which seems perfect for the case, but looking into the code, I actually think this class should be avoided, it allocates inside the getNextAudioBlock 😱

> <https://github.com/WeAreROLI/JUCE/blob/develop/modules/juce_audio_basics/sources/juce_ChannelRemappingAudioSource.cpp#L107>

So stepping back, what is it, that you need all channels for? Granted, the down mixing is not very intelligent.  
At one point in the chain of AudioSources you want all channels to be present, that is the class, that I would roll my own, providing a buffer with the correct number of channels and implement my own downmix.

Let me know, if you need help with that.

---

<div class="post-metadata">

### Author: ![garrilla](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/garrilla/32/103_2.png) [@garrilla](https://forum.juce.com/u/garrilla)
#### Post date: [January 8, 2019, 9:42am UTC](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155/20 "2019-01-08T09:42:00Z")

</div>

I’m attempting to develop a binauraliser for 7.1 and other multichannel. So the 8 channels do need to be there.

It would be great if you could help me with rolling my own AudioSource.

[Next page](https://forum.juce.com/t/audiotransportsource-getnextaudioblock-reading-8-channel-file-yields-a-buffer-with-only-6-channels/31155.md?page=2)
