arsd.simpleaudio

The purpose of this module is to provide audio functions for things like playback, capture, and volume on both Windows (via the mmsystem calls) and Linux (through ALSA).

It is only aimed at the basics, and will be filled in as I want a particular feature. I don't generally need super configurability and see it as a minus, since I don't generally care either, so I'm going to be going for defaults that just work. If you need more though, you can hack the source or maybe just use it for the operating system bindings.

For example, I'm starting this because I want to write a volume control program for my linux box, so that's what is going first. That will consist of a listening callback for volume changes and being able to get/set the volume.

TODO: * pre-resampler that loads a clip and prepares it for repeated fast use * controls so you can tell a particular thing to keep looping until you tell it to stop, or stop after the next loop, etc (think a phaser sound as long as you hold the button down) * playFile function that detects automatically. basically: if(args[1].endsWith("ogg")) a.playOgg(args[1]); else if(args[1].endsWith("wav")) a.playWav(args[1]); else if(mp3) a.playMp3(args[1]);

More...

Members

Aliases

snd_lib_error_handler_t
alias snd_lib_error_handler_t = void function(const(char)* file, int line, const(char)* function_, int err, const(char)* fmt, ...)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_elem_callback_t
alias snd_mixer_elem_callback_t = int function(snd_mixer_elem_t*, uint)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sframes_t
alias snd_pcm_sframes_t = c_long
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_uframes_t
alias snd_pcm_uframes_t = c_ulong
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
ssize_t
alias ssize_t = int
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
ssize_t
alias ssize_t = long
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Classes

AlsaException
class AlsaException
Undocumented in source.
AudioException
class AudioException

Thrown on audio failures. Subclass this to provide OS-specific exceptions

AudioPcmOutThread
deprecated class AudioPcmOutThread

Old thread implementation. I decided to deprecate it in favor of AudioOutputThread because RAII semantics make it easier to get right at the usage point. See that to go forward.

AudioPcmOutThreadImplementation
class AudioPcmOutThreadImplementation

Makes an audio thread for you that you can make various sounds on and it will mix them with good enough latency for simple games.

ResamplingContext
class ResamplingContext
Undocumented in source.
WinMMException
class WinMMException
Undocumented in source.

Enums

MidiEvent
enum MidiEvent
Undocumented in source.
MidiNote
enum MidiNote
Undocumented in source.
snd_pcm_access_t
enum snd_pcm_access_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_format
enum snd_pcm_format
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_stream_t
enum snd_pcm_stream_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Functions

computeFunc
double computeFunc(float x, FuncDef* func)
Undocumented in source. Be warned that the author may not have intended to support it.
cubicCoef
void cubicCoef(float frac, float* interp)
Undocumented in source. Be warned that the author may not have intended to support it.
gcd
uint gcd(uint a, uint b)
Undocumented in source. Be warned that the author may not have intended to support it.
main
void main()
Undocumented in source. Be warned that the author may not have intended to support it.
midiChannelAftertouch
ubyte[] midiChannelAftertouch(ubyte[] where, ubyte channel, byte amount)

Channel aftertouch.

midiNoteAftertouch
ubyte[] midiNoteAftertouch(ubyte[] where, ubyte channel, byte note, byte pressure)

Aftertouch.

midiNoteController
ubyte[] midiNoteController(ubyte[] where, ubyte channel, byte controllerNumber, byte controllerValue)

Controller.

midiNoteOff
ubyte[] midiNoteOff(ubyte[] where, ubyte channel, byte note, byte velocity)

Note off.

midiNoteOn
ubyte[] midiNoteOn(ubyte[] where, ubyte channel, byte note, byte velocity)

Puts a note on at the beginning of the passed slice, advancing it by the amount of the message size. Returns the message slice.

midiNotePitchBend
ubyte[] midiNotePitchBend(ubyte[] where, ubyte channel, short change)

Pitch bend. FIXME doesn't work right

midiProgramChange
ubyte[] midiProgramChange(ubyte[] where, ubyte channel, byte program)

Program change.

openAlsaPcm
snd_pcm_t* openAlsaPcm(snd_pcm_stream_t direction, int SampleRate, int channels, string cardName)
Undocumented in source. Be warned that the author may not have intended to support it.
resamplerBasicDirect
int resamplerBasicDirect(SpeexResampler st, uint chanIdx, const(float)* indata, uint* indataLen, float* outdata, uint* outdataLen)
Undocumented in source. Be warned that the author may not have intended to support it.
resamplerBasicInterpolate
int resamplerBasicInterpolate(SpeexResampler st, uint chanIdx, const(float)* indata, uint* indataLen, float* outdata, uint* outdataLen)
Undocumented in source. Be warned that the author may not have intended to support it.
restoreSigIntHandler
void restoreSigIntHandler()
Undocumented in source. Be warned that the author may not have intended to support it.
setSigIntHandler
void setSigIntHandler()
Undocumented in source. Be warned that the author may not have intended to support it.
silence_alsa_messages
void silence_alsa_messages()
Undocumented in source. Be warned that the author may not have intended to support it.
sinc
float sinc(float cutoff, float x, int N, FuncDef* windowFunc)
Undocumented in source. Be warned that the author may not have intended to support it.
snd_lib_error_set_handler
int snd_lib_error_set_handler(snd_lib_error_handler_t handler)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_attach
int snd_mixer_attach(snd_mixer_t* , char* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_close
int snd_mixer_close(snd_mixer_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_elem_set_callback
void snd_mixer_elem_set_callback(snd_mixer_elem_t* , snd_mixer_elem_callback_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_find_selem
snd_mixer_elem_t* snd_mixer_find_selem(snd_mixer_t* , snd_mixer_selem_id_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_handle_events
int snd_mixer_handle_events(snd_mixer_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_load
int snd_mixer_load(snd_mixer_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_open
int snd_mixer_open(snd_mixer_t** , int mode)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_poll_descriptors
int snd_mixer_poll_descriptors(snd_mixer_t* , pollfd* , uint space)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_get_playback_switch
int snd_mixer_selem_get_playback_switch(snd_mixer_elem_t* , int , int* value)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_get_playback_volume
int snd_mixer_selem_get_playback_volume(snd_mixer_elem_t* , int , c_long* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_get_playback_volume_range
int snd_mixer_selem_get_playback_volume_range(snd_mixer_elem_t* , c_long* , c_long* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_id_free
void snd_mixer_selem_id_free(snd_mixer_selem_id_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_id_malloc
int snd_mixer_selem_id_malloc(snd_mixer_selem_id_t** )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_id_set_index
void snd_mixer_selem_id_set_index(snd_mixer_selem_id_t* , uint )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_id_set_name
void snd_mixer_selem_id_set_name(snd_mixer_selem_id_t* , char* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_register
int snd_mixer_selem_register(snd_mixer_t* , void* , void* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_set_playback_switch_all
int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t* , int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_set_playback_volume_all
int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t* , c_long )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_avail
snd_pcm_sframes_t snd_pcm_avail(snd_pcm_t* pcm)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_avail_update
snd_pcm_sframes_t snd_pcm_avail_update(snd_pcm_t* pcm)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_close
int snd_pcm_close(snd_pcm_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params
int snd_pcm_hw_params(snd_pcm_t* , snd_pcm_hw_params_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_any
int snd_pcm_hw_params_any(snd_pcm_t* , snd_pcm_hw_params_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_free
void snd_pcm_hw_params_free(snd_pcm_hw_params_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_malloc
int snd_pcm_hw_params_malloc(snd_pcm_hw_params_t** )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_access
int snd_pcm_hw_params_set_access(snd_pcm_t* , snd_pcm_hw_params_t* , snd_pcm_access_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_buffer_size
int snd_pcm_hw_params_set_buffer_size(snd_pcm_t* , snd_pcm_hw_params_t* , snd_pcm_uframes_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_buffer_size_near
int snd_pcm_hw_params_set_buffer_size_near(snd_pcm_t* , snd_pcm_hw_params_t* , snd_pcm_uframes_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_channels
int snd_pcm_hw_params_set_channels(snd_pcm_t* , snd_pcm_hw_params_t* , uint )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_format
int snd_pcm_hw_params_set_format(snd_pcm_t* , snd_pcm_hw_params_t* , snd_pcm_format )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_periods
int snd_pcm_hw_params_set_periods(snd_pcm_t* , snd_pcm_hw_params_t* , uint , int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_periods_near
int snd_pcm_hw_params_set_periods_near(snd_pcm_t* , snd_pcm_hw_params_t* , uint* , int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_set_rate_near
int snd_pcm_hw_params_set_rate_near(snd_pcm_t* , snd_pcm_hw_params_t* , uint* , int* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_open
int snd_pcm_open(snd_pcm_t** , char* , snd_pcm_stream_t , int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_pause
int snd_pcm_pause(snd_pcm_t* , int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_prepare
int snd_pcm_prepare(snd_pcm_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_readi
snd_pcm_sframes_t snd_pcm_readi(snd_pcm_t* , void* , snd_pcm_uframes_t size)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_recover
int snd_pcm_recover(snd_pcm_t* pcm, int err, int silent)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params
int snd_pcm_sw_params(snd_pcm_t* pcm, snd_pcm_sw_params_t* params)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_current
int snd_pcm_sw_params_current(snd_pcm_t* pcm, snd_pcm_sw_params_t* params)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_free
void snd_pcm_sw_params_free(snd_pcm_sw_params_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_malloc
int snd_pcm_sw_params_malloc(snd_pcm_sw_params_t** )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_set_avail_min
int snd_pcm_sw_params_set_avail_min(snd_pcm_t* , snd_pcm_sw_params_t* , snd_pcm_uframes_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_set_start_threshold
int snd_pcm_sw_params_set_start_threshold(snd_pcm_t* , snd_pcm_sw_params_t* , snd_pcm_uframes_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_set_stop_threshold
int snd_pcm_sw_params_set_stop_threshold(snd_pcm_t* , snd_pcm_sw_params_t* , snd_pcm_uframes_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_wait
int snd_pcm_wait(snd_pcm_t* pcm, int timeout)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_writei
snd_pcm_sframes_t snd_pcm_writei(snd_pcm_t* , void* , snd_pcm_uframes_t size)
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_rawmidi_close
int snd_rawmidi_close(snd_rawmidi_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_rawmidi_drain
int snd_rawmidi_drain(snd_rawmidi_t* )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_rawmidi_open
int snd_rawmidi_open(snd_rawmidi_t** , snd_rawmidi_t** , char* , int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_rawmidi_read
ssize_t snd_rawmidi_read(snd_rawmidi_t* , void* , size_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_rawmidi_write
ssize_t snd_rawmidi_write(snd_rawmidi_t* , void* , size_t )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_strerror
const(char)* snd_strerror(int )
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Interfaces

SampleController
interface SampleController

Provides an interface to control a sound.

Manifest constants

BUFFER_SIZE_FRAMES
enum BUFFER_SIZE_FRAMES;
Undocumented in source.
BUFFER_SIZE_SHORT
enum BUFFER_SIZE_SHORT;
Undocumented in source.
DEFAULT_VOLUME
enum DEFAULT_VOLUME;

A reasonable default volume for an individual sample. It doesn't need to be large; in fact it needs to not be large so mixing doesn't clip too much.

SampleRateFull
enum SampleRateFull;

Static variables

Kaiser10
FuncDef Kaiser10;
Undocumented in source.
Kaiser12
FuncDef Kaiser12;
Undocumented in source.
Kaiser6
FuncDef Kaiser6;
Undocumented in source.
Kaiser8
FuncDef Kaiser8;
Undocumented in source.
interrupted
bool interrupted;
Undocumented in source.
kaiser10Table
double[36] kaiser10Table;
Undocumented in source.
kaiser12Table
double[68] kaiser12Table;
Undocumented in source.
kaiser6Table
double[36] kaiser6Table;
Undocumented in source.
kaiser8Table
double[36] kaiser8Table;
Undocumented in source.
qualityMap
QualityMapping[11] qualityMap;
Undocumented in source.

Structs

AudioInput
struct AudioInput

Gives PCM input access (such as a microphone).

AudioMixer
struct AudioMixer

Interfaces with the default sound card. You should only have a single instance of this and it should be stack allocated, so its destructor cleans up after it.

AudioOutput
struct AudioOutput

Gives PCM output access (such as the speakers).

AudioOutputThread
struct AudioOutputThread

Wraps AudioPcmOutThreadImplementation with RAII semantics for better error handling and disposal than the old way.

CubicUpsampler
struct CubicUpsampler
Undocumented in source.
FuncDef
struct FuncDef
Undocumented in source.
MMClock
struct MMClock

A clock you can use for multimedia applications. It compares time elapsed against a position variable you pass in to figure out how long to wait to get to that point. Very similar to Phobos' StopWatch but with built-in wait capabilities.

MidiInput
struct MidiInput

For reading midi events from hardware, for example, an electronic piano keyboard attached to the computer.

MidiOutput
struct MidiOutput

Gives MIDI output access.

QualityMapping
struct QualityMapping
Undocumented in source.
SpeexResampler
struct SpeexResampler
Undocumented in source.
snd_mixer_elem_t
struct snd_mixer_elem_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_selem_id_t
struct snd_mixer_selem_id_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_mixer_t
struct snd_mixer_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_hw_params_t
struct snd_pcm_hw_params_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_sw_params_t
struct snd_pcm_sw_params_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_pcm_t
struct snd_pcm_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.
snd_rawmidi_t
struct snd_rawmidi_t
Undocumented in source but is binding to C. You might be able to learn more by searching the web for its name.

Detailed Description

* play audio high level with options to wait until completion or return immediately * midi mid-level stuff but see arsd.midi!

* some kind of encoder???????

I will probably NOT do OSS anymore, since my computer doesn't even work with it now. Ditto for Macintosh, as I don't have one and don't really care about them.

Meta

License

GPL3 unless you compile with -version=without_resampler and do *not* use the mp3 functions, in which case it is BSL-1.0.