# nodesnim/thirdparty/sdl2/audio

Dark Mode

Search:
Group by:

# Imports

../sdl2

# Types

    AudioFormat = uint16

    AudioCallback = proc (userdata: pointer; stream: ptr uint8; len: cint) {...}{.cdecl.}

    AudioSpec = object
      freq*: cint
      format*: AudioFormat
      channels*: uint8
      silence*: uint8
      samples*: uint16
      padding*: uint16
      size*: uint32
      callback*: AudioCallback
      userdata*: pointer

    AudioCVT {...}{.packed.} = object
      needed*: cint
      src_format*: AudioFormat
      dst_format*: AudioFormat
      rate_incr*: cdouble
      buf*: ptr uint8
      len*: cint
      len_cvt*: cint
      len_mult*: cint
      len_ratio*: cdouble
      filters*: array[10, AudioFilter]
      filter_index*: cint

    AudioFilter = proc (cvt: ptr AudioCVT; format: AudioFormat) {...}{.cdecl.}

    AudioStreamPtr = ptr AudioStream

  (Available since SDL 2.0.7) A pointer to an SDL_AudioStream. Audio streams were added to SDL2 in version 2.0.7, to provide an easier-to-use alternative to SDL_AudioCVT.

  See Also:

  - newAudioStream proc
  - newAudioStream proc
  - put proc
  - get proc
  - available proc
  - flush proc
  - clear proc
  - destroy proc

    AudioDeviceID = uint32

    AudioStatus {...}{.size: 4.} = enum
      SDL_AUDIO_STOPPED = 0, SDL_AUDIO_PLAYING, SDL_AUDIO_PAUSED

# Consts

    SDL_AUDIO_MASK_BITSIZE = 255'u

    SDL_AUDIO_MASK_DATATYPE = 256'u

    SDL_AUDIO_MASK_ENDIAN = 4096'u

    SDL_AUDIO_MASK_SIGNED = 32768'u

    AUDIO_U8 = 0x00000008

    AUDIO_S8 = 0x00008008

    AUDIO_U16LSB = 0x00000010

    AUDIO_S16LSB = 0x00008010

    AUDIO_U16MSB = 0x00001010

    AUDIO_S16MSB = 0x00009010

    AUDIO_U16 = 0x00000010

    AUDIO_S16 = 0x00008010

    AUDIO_S32LSB = 0x00008020

    AUDIO_S32MSB = 0x00009020

    AUDIO_S32 = 0x00008020

    AUDIO_F32LSB = 0x00008120

    AUDIO_F32MSB = 0x00009120

    AUDIO_F32 = 0x00008120

    SDL_AUDIO_ALLOW_FREQUENCY_CHANGE = 0x00000001

    SDL_AUDIO_ALLOW_FORMAT_CHANGE = 0x00000002

    SDL_AUDIO_ALLOW_CHANNELS_CHANGE = 0x00000004

    SDL_AUDIO_ALLOW_ANY_CHANGE = 7

    SDL_MIX_MAXVOLUME = 128

# Procs

    proc getNumAudioDrivers(): cint {...}{.importc: "SDL_GetNumAudioDrivers".}

    proc getAudioDriver(index: cint): cstring {...}{.importc: "SDL_GetAudioDriver".}

    proc audioInit(driver_name: cstring): cint {...}{.importc: "SDL_AudioInit".}

    proc audioQuit() {...}{.importc: "SDL_AudioQuit".}

    proc getCurrentAudioDriver(): cstring {...}{.importc: "SDL_GetCurrentAudioDriver".}

    proc openAudio(desired: ptr AudioSpec; obtained: ptr AudioSpec): cint {...}{.
        importc: "SDL_OpenAudio".}

    proc getNumAudioDevices(iscapture: cint): cint {...}{.importc: "SDL_GetNumAudioDevices".}

    proc getAudioDeviceName(index: cint; iscapture: cint): cstring {...}{.
        importc: "SDL_GetAudioDeviceName".}

    proc openAudioDevice(device: cstring; iscapture: cint; desired: ptr AudioSpec;
                        obtained: ptr AudioSpec; allowed_changes: cint): AudioDeviceID {...}{.
        importc: "SDL_OpenAudioDevice".}

    proc getAudioStatus(): AudioStatus {...}{.importc: "SDL_GetAudioStatus".}

    proc getAudioDeviceStatus(dev: AudioDeviceID): AudioStatus {...}{.
        importc: "SDL_GetAudioDeviceStatus".}

    proc getQueuedAudioSize(dev: AudioDeviceID): uint32 {...}{.
        importc: "SDL_GetQueuedAudioSize".}

    proc queueAudio(dev: AudioDeviceID; data: pointer; len: uint32): cint {...}{.
        importc: "SDL_QueueAudio".}

    proc pauseAudio(pause_on: cint) {...}{.importc: "SDL_PauseAudio".}

    proc pauseAudioDevice(dev: AudioDeviceID; pause_on: cint) {...}{.
        importc: "SDL_PauseAudioDevice".}

    proc loadWAV_RW(src: ptr RWops; freesrc: cint; spec: ptr AudioSpec;
                   audio_buf: ptr ptr uint8; audio_len: ptr uint32): ptr AudioSpec {...}{.
        importc: "SDL_LoadWAV_RW".}

    proc freeWAV(audio_buf: ptr uint8) {...}{.importc: "SDL_FreeWAV".}

    proc buildAudioCVT(cvt: ptr AudioCVT; src_format: AudioFormat; src_channels: uint8;
                      src_rate: cint; dst_format: AudioFormat; dst_channels: uint8;
                      dst_rate: cint): cint {...}{.importc: "SDL_BuildAudioCVT".}

    proc convertAudio(cvt: ptr AudioCVT): cint {...}{.importc: "SDL_ConvertAudio".}

    proc mixAudio(dst: ptr uint8; src: ptr uint8; len: uint32; volume: cint) {...}{.
        importc: "SDL_MixAudio".}

    proc mixAudioFormat(dst: ptr uint8; src: ptr uint8; format: AudioFormat; len: uint32;
                       volume: cint) {...}{.importc: "SDL_MixAudioFormat".}

    proc lockAudio() {...}{.importc: "SDL_LockAudio".}

    proc lockAudioDevice(dev: AudioDeviceID) {...}{.importc: "SDL_LockAudioDevice".}

    proc unlockAudio() {...}{.importc: "SDL_UnlockAudio".}

    proc unlockAudioDevice(dev: AudioDeviceID) {...}{.importc: "SDL_UnlockAudioDevice".}

    proc closeAudio() {...}{.importc: "SDL_CloseAudio".}

    proc closeAudioDevice(dev: AudioDeviceID) {...}{.importc: "SDL_CloseAudioDevice".}

    proc newAudioStream(src_format: AudioFormat; src_channels: uint8; src_rate: cint;
                       dst_format: AudioFormat; dst_channels: uint8; dst_rate: cint): AudioStreamPtr {...}{.
        importc: "SDL_NewAudioStream".}

  (Available since SDL 2.0.7) Create a new audio stream. return 0 on success, or -1 on error.

  Parameters:

  - `src_format` The format of the source audio
  - `src_channels` The number of channels of the source audio
  - `src_rate` The sampling rate of the source audio
  - `dst_format` The format of the desired audio output
  - `dst_channels` The number of channels of the desired audio output
  - `dst_rate The` sampling rate of the desired audio output

  See also:

  - AudioStreamPtr type
  - newAudioStream proc

    proc newAudioStream(srcSpec, destSpec: AudioSpec): AudioStreamPtr {...}{.raises: [],
        tags: [].}

  (Available since SDL 2.0.7) Create a new audio stream that converts from `srcSpec` to `destSpec`.

  See also:

  - AudioStreamPtr type
  - newAudioStream proc

    proc put(stream: AudioStreamPtr; buf: pointer; len: cint): cint {...}{.
        importc: "SDL_AudioStreamPut".}

  (Available since SDL 2.0.7) Add data to be converted/resampled to the stream. Returns 0 on success, or -1 on error.

  Parameters:

  - `stream` The stream the audio data is being added to
  - `buf` A pointer to the audio data to add
  - `len` The number of bytes to write to the stream

  See also:

  - AudioStreamPtr type

    proc get(stream: AudioStreamPtr; buf: pointer; len: cint): cint {...}{.
        importc: "SDL_AudioStreamGet".}

  (Available since SDL 2.0.7) Get converted/resampled data from the stream. Returns the number of bytes read from the stream, or -1 on error.

  Parameters:

  - `stream` The stream the audio is being requested from
  - `buf` A buffer to fill with audio data
  - `len` The maximum number of bytes to fill

  See also:

  - AudioStreamPtr type

    proc available(stream: AudioStreamPtr): cint {...}{.importc: "SDL_AudioStreamAvailable".}

  (Available since SDL 2.0.7) Get the number of converted/resampled bytes available (BYTES, not samples!). The stream may be buffering data behind the scenes until it has enough to resample correctly, so this number might be lower than what you expect, or even be zero. Add more data or flush the stream if you need the data now.

  See also:

  - AudioStreamPtr type

    proc flush(stream: AudioStreamPtr): cint {...}{.importc: "SDL_AudioStreamFlush".}

  (Available since SDL 2.0.7) Tell the stream that you're done sending data, and anything being buffered should be converted/resampled and made available immediately. Returns 0 on success, -1 on error.

  It is legal to add more data to a stream after flushing, but there will be audio gaps in the output. Generally this is intended to signal the end of input, so the complete output becomes available.

  See also:

  - AudioStreamPtr type

    proc clear(stream: AudioStreamPtr) {...}{.importc: "SDL_AudioStreamClear".}

  (Available since SDL 2.0.7) Clear any pending data in the stream without converting it.

  See also:

  - AudioStreamPtr type

    proc destroy(stream: AudioStreamPtr) {...}{.importc: "SDL_FreeAudioStream".}

  (Available since SDL 2.0.7) Free an audio stream.

  See also:

  - AudioStreamPtr type

# Templates

    template SDL_AUDIO_BITSIZE(x: uint32): uint32

    template SDL_AUDIO_ISFLOAT(x: uint32): bool

    template SDL_AUDIO_ISBIGENDIAN(x: uint32): bool

    template SDL_AUDIO_ISSIGNED(x: uint32): bool

    template SDL_AUDIO_ISINT(x: uint32): bool

    template SDL_AUDIO_ISLITTLEENDIAN(x: uint32): bool

    template SDL_AUDIO_ISUNSIGNED(x: uint32): bool

    template loadWAV(file: string; spec: ptr AudioSpec; audio_buf: ptr ptr uint8;
                    audio_len: ptr uint32): ptr AudioSpec