Jump to content

BlitzMax/Modules/Audio/Audio samples

From Wikibooks, open books for an open world

The BlitzMax audiosample module contains commands to create and load audio samples for use with the BlitzMax BRL.Audio module.

Types

[edit | edit source]

TAudioSample

[edit | edit source]

Audio sample type

Fields
  • samples
  • length
  • hertz
  • format
Methods
  • Copy
  • Convert
Functions
  • Create
  • CreateStatic

TAudioSample: Fields

[edit | edit source]
samples

Field samples:Byte Ptr

Description: Byte pointer to sample data

length

Field length

Description: Length, in samples, of the sample data

hertz

Field hertz

Description: Sample rate

format

Field format

Description: Sample format

TAudioSample: Methods

[edit | edit source]
Copy

Method Copy:TAudioSample()

Description: Copy audio sample

Returns: A new audio sample object

Convert

Method Convert:TAudioSample( to_format )

Description: Convert audio sample

Returns: A new audio sample object in the specified format

TAudioSample: Functions

[edit | edit source]
Create

Function Create:TAudioSample( length,hertz,format )

Description: Create an audio sample

Returns: A new audio sample object

CreateStatic

Function CreateStatic:TAudioSample( samples:Byte Ptr,length,hertz,format )

Description: Create a static audio sample

Returns: A new audio sample object that references an existing block of memory

TAudioSampleLoader

[edit | edit source]

Audio sample loader type

To create your own audio sample loaders, you should extend this type and provide a LoadAudioSample method. To add your audio sample loader to the system, simply create an instance of it using New.

Methods
  • LoadAudioSample

TAudioSampleLoader: Methods

[edit | edit source]
LoadAudioSample

Method LoadAudioSample:TAudioSample( stream:TStream )

Description: Load an audio sample

Returns: A new audio sample object, or Null if sample could not be loaded

Information: Extending types must implement this method.

Functions

[edit | edit source]

CreateAudioSample

[edit | edit source]

Function CreateAudioSample:TAudioSample( length,hertz,format )

Description: Create an audio sample

Returns: An audio sample object

Information: length is the number of samples to allocate for the sample. hertz is the frequency in samples per second (hz) the audio sample will be played. format should be one of:

Format Description
&SF_MONO8 Mono unsigned 8 bit
&SF_MONO16LE Mono signed 16 bit little endian
&SF_MONO16BE Mono signed 16 bit big endian
&SF_STEREO8 Stereo unsigned 8 bit
&SF_STEREO16LE Stereo signed 16 bit little endian
&SF_STEREO16BE Stereo signed 16 bit big endian

Example:

' createaudiosample.bmx

Local sample:TAudioSample=CreateAudioSample( 32,11025,SF_MONO8 )

For Local k=0 Until 32
        sample.samples[k]=Sin(k*360/32)*127.5+127.5
Next

Local sound:TSound=LoadSound( sample,True )

PlaySound(sound)

Input

CreateStaticAudioSample

[edit | edit source]

Function CreateStaticAudioSample:TAudioSample( samples:Byte Ptr,length,hertz,format )

Description: Create an audio sample with existing data

Returns: An audio sample object that references an existing block of memory

Information: The memory referenced by a static audio sample is not released when the audio sample is deleted.

See CreateAudioSample for possile format values.

LoadAudioSample

[edit | edit source]

Function LoadAudioSample:TAudioSample( url:Object )

Description: Load an audio sample

Returns: An audio sample object