'' SDL2-Example program:
'' Determine available audio drivers
'' translated by TJF 2013
'/*
  'Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>

  'This software is provided 'as-is', without any express or implied
  'warranty.  In no event will the authors be held liable for any damages
  'arising from the use of this software.

  'Permission is granted to anyone to use this software for any purpose,
  'including commercial applications, and to alter it and redistribute it
  'freely.
'*/

#INCLUDE ONCE "SDL2/SDL2.bi"

SUB print_devices CDECL(BYVAL iscapture AS INTEGER)
  VAR typestr = IIF(iscapture, @"capture", @"output")
  VAR n = SDL_GetNumAudioDevices(iscapture)

  SDL_Log(!"%s devices:\n", typestr)

  IF n = -1 THEN
    SDL_Log(!"  Driver can't detect specific %s devices.\n\n", typestr)
  ELSEIF n = 0 THEN
    SDL_Log(!"  No %s devices found.\n\n", typestr)
  ELSE
    FOR i AS INTEGER = 0 TO n - 1
      SDL_Log(!"  %s\n", SDL_GetAudioDeviceName(i, iscapture))
    NEXT
    SDL_Log(!"\n")
  END IF
END SUB


'/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO)

'/* Load the SDL library */
IF SDL_Init(SDL_INIT_AUDIO) < 0 THEN
  SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, !"Couldn't initialize SDL: %s\n", SDL_GetError())
  END 1
END IF

'/* Print available audio drivers */
VAR n = SDL_GetNumAudioDrivers()
IF n = 0 THEN
  SDL_Log(!"No built-in audio drivers\n\n")
ELSE
  SDL_Log(!"Built-in audio drivers:\n")
  FOR i AS INTEGER = 0 TO n - 1
    SDL_Log(!"  %s\n", SDL_GetAudioDriver(i))
  NEXT
  SDL_Log(!"\n")
END IF

SDL_Log(!"Using audio driver: %s\n\n", SDL_GetCurrentAudioDriver())

print_devices(0)
print_devices(1)

SDL_Quit()
