Specify channel output for mono audio file


#1

Hi,

I cannot seem to figure out how to specify the output channel I want an audio file to playback on. I've looked at using MixerAudioSource but it doesn't look like I can specify a channel number.

Can someone point me in the right direction?

 

Thanks!

 

EDIT:

This thread is getting quite long so I've removed some of my last edits.

It seems I'm still having trouble with this. With the following code I can map channels 1 and 2 but nothing higher. I'd like to have 24 separate channel outputs.

 

//create the players

    for (int i = 0; i < 24; ++i){

        MediaPlayer *player = new MediaPlayer();


        // Connect the source player to the audio device.

        deviceManager.addAudioCallback(player);


        players.push_back(player);

    }


    String error = deviceManager.initialise(0, 24, nullptr, true);

    if (error.isNotEmpty())

    {

        std::cout << error << std::endl;

    }


    //load files

    for (int i = 0; i < players.size(); ++i){

        String num = String(i + 1);

        String file = "C:/Library/" + num + "_test.wav";

        players[i]->setFile(file, i);

    }


    //lock to ensure sync

    ScopedLock lock(deviceManager.getAudioCallbackLock());


    //playback files

    for (int i = 0; i < players.size(); ++i){

        players[i]->playFromStart();

    }

 

MediaPlayer looks like this:

MediaPlayer::MediaPlayer()

{


    //CoInitialize(0);


    // Configure the format manager to read common audio file types.

    formatManager.registerBasicFormats();


    // Connect the transport source to the remapping source

    remappingSource = new ChannelRemappingAudioSource(&transportSource, true);


    // Connect the remapping source to the source player.

    sourcePlayer.setSource(remappingSource);



    // Listen for changes

    transportSource.addChangeListener(this);

    

}


void MediaPlayer::setFile(String filename, int channel)

{

    File audioFile = File(filename);

    // Create a reader from the selected file.

    readerSource = new AudioFormatReaderSource(formatManager.createReaderFor(audioFile), true);

    transportSource.setSource(readerSource);

    remappingSource->clearAllMappings();

    remappingSource->setOutputChannelMapping(0, channel);

}

#2

Sorry to bump this but really need help with this one!


#3

It looks like this could be a different issue where JUCE can only see 2 channels from the soundcard. I've hooked up a quick demo in max/MSP and can get that to output to each of the 24 channels.

max/MSP gives me the following audio driver options:

  • None
  • as_asio MOTU AVN USB ASIO (this is the one that gives me 24 channels)
  • ad_directsound
  • ad_mme
  • NonRealTime
  • ad_portaudio MME
  • ad_portaudio Windows DirectSound
  • ad_portaudio ASIO
  • ad_portaudio Windows WASAPI
  • ad_rewire
  • Live

When I run the audio settings demo I get the following options:

Audio Device Type:

  • Windows Audio
  • DirectSound

Output:

  • Speakers (MOTU AVB USB Audio)
  • Digital Audio

#4

Try building juce with ASIO enabled, and you'll get access to the ASIO device.


#5

Thanks for the reply. That has got me a step closer!

Using the following code I see a list of devices:


OwnedArray<AudioIODeviceType> types;
myAudioDeviceManager.createAudioDeviceTypes (types);

OwnedArray<AudioIODevice> devices;


for (int i = 0; i < types.size(); ++i)
{
    String typeName (types[i]->getTypeName());
    types[i]->scanForDevices();
    StringArray deviceNames (types[i]->getDeviceNames());
    for (int j = 0; j < deviceNames.size(); ++j)
    {
        AudioIODevice* device = types[i]->createDevice (deviceNames [j]);
        devices.add(device);
    }
}

for(int i=0; i< devices.size(); ++i)
{
    String type = devices[i]->getTypeName();
    String name = devices[i]->getName();
    std::cout << "type: " << type << ". device: " << name << std::endl;
}
​

From that I see:

  • type: Windows Audio. device: Speakers (MOTU AVB USB Audio)
  • type: DirectSound. device: Speakers (MOTU AVB USB Audio)
  • type: ASIO. device: MOTU AVB USB ASIO

However, when I try to initialise the MOTU AVB USB ASIO device I get the following error:

No such device: MOTU AVB USB ASIO

I am trying to initialise like so:

String error = audioDeviceManager.initialise(0, 24, 0, false, "MOTU AVB USB ASIO");

if(error.isNotEmpty()){

    std::cout << error << std::endl;

}

 


#6

Figured it out!

Just needed to add:

audioDeviceManager.setCurrentAudioDeviceType("ASIO", true);

After initialising the audioDeviceManager.