I decided to release a little tool that I created to test the C++ part of my Default Audio Device Switcher that I built using DefSOUND for SoundSwitch.

The tester only uses the lib to list all the audio device found (that are active) and then when a device change state, it will display the change.

Update tooling for VS 2017

Same testing tool, with the possibility to switch audio device.

Used only for testing purpose.

Usage

  • s : toggle the default audio device
  • q : quit the application

You can find enclosed the code used to create the tester:

// AudioEndTester.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "AudioEndPointLibrary.h"
#include <iostream>
#include <string>

void do_work(AudioEndPoint::AudioDeviceList playbackDevices, AudioEndPoint::AudioDeviceList recordingDevices)
{
    
    for (AudioEndPoint::AudioDeviceList::iterator i = playbackDevices.begin(); i != playbackDevices.end(); ++i)
    {
        auto audioDevice = std::move(*i);
        std::wcout << audioDevice->FriendlyName << L" : " << audioDevice->ID <<L" isDefault: "<<(audioDevice->IsDefault(eConsole)?L"True":L"False")<<std::endl;
        if(std::wstring(audioDevice->FriendlyName).find(std::wstring(L"Logitech")) != std::wstring::npos)
        {
            //audioDevice->SetDefault(eMultimedia);
        }
    }
    std::wcout << std::endl << std::endl;
   
    for (AudioEndPoint::AudioDeviceList::iterator i = recordingDevices.begin(); i != recordingDevices.end(); ++i)
    {
        auto audioDevice = std::move(*i);
        std::wcout << audioDevice->FriendlyName << L" : " << audioDevice->ID << std::endl;
        if (std::wstring(audioDevice->FriendlyName).find(std::wstring(L"Logitech")) != std::wstring::npos)
        {
            //audioDevice->SetDefault(eMultimedia);
        }
    }
}

void SetLists(AudioEndPoint::AudioDeviceList& playbackDevices, AudioEndPoint::AudioDeviceList& recordingDevices)
{
    playbackDevices = AudioEndPoint::CAudioEndPointLibrary::GetInstance().GetPlaybackDevices(DefSound::Active);
    recordingDevices = AudioEndPoint::CAudioEndPointLibrary::GetInstance().GetRecordingDevices(DefSound::Active);
}

int main()
{
    AudioEndPoint::AudioDeviceList playbackDevices;
    AudioEndPoint::AudioDeviceList recordingDevices;
    SetLists(playbackDevices, recordingDevices);
    AudioEndPoint::CAudioEndPointLibrary::GetInstance().Signals->DeviceStateChanged.Register([](AudioEndPoint::AudioDevicePtr device, DefSound::EDeviceState newState){
        std::wcout << std::endl << device->FriendlyName <<L" : State (" << device->DeviceState << L")" << std::endl;
    });
   
    auto signInfo = &AudioEndPoint::CAudioEndPointLibrary::GetInstance().Signals->DeviceDefaultChanged.Register([](AudioEndPoint::AudioDevicePtr device, ERole role) {
        std::wcout << std::endl << device->FriendlyName << L" : ROLE (" << role << L", "<<device->IsDefault(role) << L")" << std::endl;        
    });

    AudioEndPoint::CAudioEndPointLibrary::GetInstance().Signals->DeviceRemoved.Register([](AudioEndPoint::AudioDevicePtr device) {
        std::wcout << std::endl << device->ID << L" : REMOVED" << std::endl;
    });
    std::wcout << L"Enter the letter Q + Enter to stop the application" << std::endl << "When a device change state or is disconnected you'll be notified" << std::endl << std::endl;
    auto test = 'a';
    while (test != 'q') {
        do_work(playbackDevices, recordingDevices);
        std::cin >> test;
        if(test == 'r')
        {
            signInfo->m_signal->Unregister(*signInfo);
        }
    }
}