mixLoadRawAudioNoCopy function mixer

Pointer<MixAudio> mixLoadRawAudioNoCopy(
  1. Pointer<MixMixer> mixer,
  2. Pointer<NativeType> data,
  3. int datalen,
  4. Pointer<SdlAudioSpec> spec,
  5. bool freeWhenDone,
)

Load raw PCM data from a memory buffer without making a copy.

This buffer must live for the entire time the returned MIX_Audio lives, as it will access it whenever it needs to mix more data.

This function is meant to maximize efficiency: if the data is already in memory and can remain there, don't copy it. But it can also lead to some interesting tricks, like changing the buffer's contents to alter multiple playing tracks at once. (But, of course, be careful when being too clever.)

MIX_Audio objects can be shared between multiple mixers. The mixer parameter just suggests the most likely mixer to use this audio, in case some optimization might be applied, but this is not required, and a NULL mixer may be specified.

If free_when_done is true, SDL_mixer will call SDL_free(data) when the returned MIX_Audio is eventually destroyed. This can be useful when the data is not static, but rather composed dynamically for this specific MIX_Audio and simply wants to avoid the extra copy.

\param mixer a mixer this audio is intended to be used with. May be NULL. \param data the buffer where the raw PCM data lives. \param datalen the size, in bytes, of the buffer. \param spec what format the raw data is in. \param free_when_done if true, data will be given to SDL_free() when the MIX_Audio is destroyed. \returns an audio object that can be used to make sound on a mixer, or NULL on failure; call SDL_GetError() for more information.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL_mixer 3.0.0.

\sa MIX_DestroyAudio \sa MIX_SetTrackAudio \sa MIX_LoadRawAudio \sa MIX_LoadRawAudio_IO \sa MIX_LoadAudio_IO

extern SDL_DECLSPEC MIX_Audio * SDLCALL MIX_LoadRawAudioNoCopy(MIX_Mixer *mixer, const void *data, size_t datalen, const SDL_AudioSpec *spec, bool free_when_done)

Implementation

Pointer<MixAudio> mixLoadRawAudioNoCopy(
  Pointer<MixMixer> mixer,
  Pointer<NativeType> data,
  int datalen,
  Pointer<SdlAudioSpec> spec,
  bool freeWhenDone,
) {
  final mixLoadRawAudioNoCopyLookupFunction = _libMixer
      .lookupFunction<
        Pointer<MixAudio> Function(
          Pointer<MixMixer> mixer,
          Pointer<NativeType> data,
          Uint32 datalen,
          Pointer<SdlAudioSpec> spec,
          Uint8 freeWhenDone,
        ),
        Pointer<MixAudio> Function(
          Pointer<MixMixer> mixer,
          Pointer<NativeType> data,
          int datalen,
          Pointer<SdlAudioSpec> spec,
          int freeWhenDone,
        )
      >('MIX_LoadRawAudioNoCopy');
  return mixLoadRawAudioNoCopyLookupFunction(
    mixer,
    data,
    datalen,
    spec,
    freeWhenDone ? 1 : 0,
  );
}