Audio File – Giavapps ProAudio

pa_audio_file_load(InputOrOutputBuffer, SampleIndex, SampleCount, ChannelIndex, ChannelCount, SampleRate, Channels, Format, Mixing, FileName) Loads samples from a supported audio file inside the specified Stream Buffer. The Stream Buffer is automatically resized by the Giavapps ProAudio to fit the new number of samples. The number of channels loaded is always limited to the max number of channels that you specified when using pa_stream_open() or pa_stream_open_default(). Sample data will be stored in the Stream Buffer starting from the specified SampleIndex and ChannelIndex. Samples with an Amplitude of 0 (silence) will be added if SampleIndex is greater than the number of samples stored inside the Stream Buffer. When loading an audio file, the Format argument should be set to false: the only exception is for RAW audio files, in that case you must use the proper SampleRate, Channels and Format. Mixing feature provided by Giavapps ProAudio helps you avoiding a lot of extra processing: this feature is meant for mixing (summing) samples Amplitudes of the specified Stream Buffer with those loaded from an audio files.The function returns false if an error occurrs or true otherwise.

InputOrOutputBuffer: indicates the input (false) or output (true) buffer.
SampleIndex: loads new samples starting from the specified sample index if this value is greater than 0.
SampleCount: max number of samples to load from the audio file or false for loading all samples starting from SampleIndex.
ChannelIndex: loads new samples starting from the specified channel index if this value is greater than 0.
ChannelCount: max number of channels to load from the audio file or false for loading all channels starting from ChannelIndex.
SampleRate: sample rate of the audio file (used only for loading raw audio files).
Channels: number of channels of the audio file (used only for loading raw audio files).
Format: format of the audio file, format flags must be separated by the symbol "|" (used only for loading raw audio files).
Mixing: mixing flag.
FileName: file name.

Mixing argument can be one of the following values:

PA_MIXING_REPLACE Replaces the Amplitude of samples stored in the specified Stream Buffer with the Amplitude of samples loaded from an audio file.

PA_MIXING_ADD Adds the Amplitude of samples stored in the specified Stream Buffer to the Amplitude of samples loaded from an audio file.

PA_MIXING_SUBTRACT Subtracts the Amplitude of samples loaded from an audio file to the Amplitude of samples stored in the specified Stream Buffer.

For more info about Format flags and all supported formats see pa_audio_file_save().

 

pa_audio_file_save(InputOrOutputBuffer, SampleIndex, SampleCount, ChannelIndex, ChannelCount, SampleRate, Channels, Format, FileName) Saves the specified Stream Buffer to an audio file. The number of channels saved is always limited to the max number of channels available for the specified file format and the max number of channels that you specified when using pa_stream_open() or pa_stream_open_default(). Sample data will be saved to the audio file starting from the specified SampleIndex and ChannelIndex. Samples with an Amplitude of 0 (silence) will be added if the Stream Buffer has channels with different number of samples or if SampleIndex+SampleCount is greater than the number of samples stored inside the Stream Buffer. The function returns false if an error occurrs or true otherwise.

InputOrOutputBuffer: indicates the input (false) or output (true) buffer.
SampleIndex: saves new samples to the audio file starting from the specified sample index if this value is greater than 0.
SampleCount: max number of samples to save to the audio file or false for saving all samples starting from SampleIndex.
ChannelIndex: saves new samples to the audio file starting from the specified channel index if this value is greater than 0.
ChannelCount: max number of channels to save to the audio file or false for saving all channels starting from ChannelIndex.
SampleRate: sample rate of the audio file.
Channels: number of channels of the audio file.
Format: format of the audio file, format flags must be separated by the symbol "|" (used only for loading raw audio files).
FileName: file name.

Format argument can be a combination of FORMAT | TYPE | ENDIAN flags:

Major Formats:

PA_AUDIO_FILE_FORMAT_WAV Microsoft WAV format (little endian default).

PA_AUDIO_FILE_FORMAT_AIFF Apple/SGI AIFF format (big endian).

PA_AUDIO_FILE_FORMAT_AU Sun/NeXT AU format (big endian).

PA_AUDIO_FILE_FORMAT_RAW RAW PCM data.

PA_AUDIO_FILE_FORMAT_PAF Ensoniq PARIS file format.

PA_AUDIO_FILE_FORMAT_SVX Amiga IFF / SVX8 / SV16 format.

PA_AUDIO_FILE_FORMAT_NIST Sphere NIST format.

PA_AUDIO_FILE_FORMAT_VOC VOC files.

PA_AUDIO_FILE_FORMAT_IRCAM Berkeley/IRCAM/CARL.

PA_AUDIO_FILE_FORMAT_W64 Sonic Foundry’s 64 bit RIFF/WAV.

PA_AUDIO_FILE_FORMAT_MAT4 Matlab ™ V4.2 / GNU Octave 2.0.

PA_AUDIO_FILE_FORMAT_MAT5 Matlab ™ V5.0 / GNU Octave 2.1.

PA_AUDIO_FILE_FORMAT_PVF Portable Voice Format.

PA_AUDIO_FILE_FORMAT_XI Fasttracker 2 Extended Instrument.

PA_AUDIO_FILE_FORMAT_HTK HMM Tool Kit format.

PA_AUDIO_FILE_FORMAT_SDS Midi Sample Dump Standard.

PA_AUDIO_FILE_FORMAT_AVR Audio Visual Research.

PA_AUDIO_FILE_FORMAT_WAVEX MS WAVE with WAVEFORMATEX.

PA_AUDIO_FILE_FORMAT_SD2 Sound Designer 2.

PA_AUDIO_FILE_FORMAT_FLAC FLAC lossless file format.

PA_AUDIO_FILE_FORMAT_CAF Core Audio File format.

PA_AUDIO_FILE_FORMAT_WVE Psion WVE format.

PA_AUDIO_FILE_FORMAT_OGG Xiph OGG container.

PA_AUDIO_FILE_FORMAT_MPC2K Akai MPC 2000 sampler.

PA_AUDIO_FILE_FORMAT_RF64 RF64 WAV file.

SubTypes:

PA_AUDIO_FILE_TYPE_PCM_S8 Signed 8 bit data.

PA_AUDIO_FILE_TYPE_PCM_16 Signed 16 bit data.

PA_AUDIO_FILE_TYPE_PCM_24 Signed 24 bit data.

PA_AUDIO_FILE_TYPE_PCM_32 Signed 32 bit data.

PA_AUDIO_FILE_TYPE_PCM_U8 Unsigned 8 bit data (WAV and RAW only).

PA_AUDIO_FILE_TYPE_FLOAT 32 bit float data.

PA_AUDIO_FILE_TYPE_DOUBLE 64 bit float data.

PA_AUDIO_FILE_TYPE_ULAW U-Law encoded.

PA_AUDIO_FILE_TYPE_ALAW A-Law encoded.

PA_AUDIO_FILE_TYPE_IMA_ADPCM IMA ADPCM.

PA_AUDIO_FILE_TYPE_MS_ADPCM Microsoft ADPCM.

PA_AUDIO_FILE_TYPE_GSM610 GSM 6.10 encoding.

PA_AUDIO_FILE_TYPE_VOX_ADPCM OKI / Dialogix ADPCM.

PA_AUDIO_FILE_TYPE_G721_32 32kbs G721 ADPCM encoding.

PA_AUDIO_FILE_TYPE_G723_24 24kbs G723 ADPCM encoding.

PA_AUDIO_FILE_TYPE_G723_40 40kbs G723 ADPCM encoding.

PA_AUDIO_FILE_TYPE_DWVW_12 12 bit Delta Width Variable Word encoding.

PA_AUDIO_FILE_TYPE_DWVW_16 16 bit Delta Width Variable Word encoding.

PA_AUDIO_FILE_TYPE_DWVW_24 24 bit Delta Width Variable Word encoding.

PA_AUDIO_FILE_TYPE_DWVW_N N bit Delta Width Variable Word encoding.

PA_AUDIO_FILE_TYPE_DPCM_8 8 bit differential PCM (XI only).

PA_AUDIO_FILE_TYPE_DPCM_16 16 bit differential PCM (XI only).

PA_AUDIO_FILE_TYPE_VORBIS Xiph Vorbis encoding.

Endian-ness Options:

PA_AUDIO_FILE_ENDIAN_DEFAULT Default file endian-ness.

PA_AUDIO_FILE_ENDIAN_LITTLE Force little endian-ness.

PA_AUDIO_FILE_ENDIAN_BIG Force big endian-ness.

PA_AUDIO_FILE_ENDIAN_CPU Force CPU endian-ness.

 

pa_audio_file_info(FileName, InfoFlag) Retrieves information about the specified audio file.

FileName: file name.
InfoFlag: info flag.

InfoFlag argument can be one of the following values:

PA_AUDIO_FILE_INFO_CHANNELS Returns the number of channels.

PA_AUDIO_FILE_INFO_FORMAT Returns format flags.

PA_AUDIO_FILE_INFO_FRAMES Returns the number of frames (samples per channel).

PA_AUDIO_FILE_INFO_SAMPLE_RATE Returns the sample rate (samples per second).

PA_AUDIO_FILE_INFO_SECTIONS Returns the number of sections.

PA_AUDIO_FILE_INFO_SEEKABLE Returns if the audio file is seekable.

PA_AUDIO_FILE_INFO_ITEMS Returns the product of frames and channels (total number of samples).

 

pa_audio_file_string_get(FileName, StringFlag) Returns string types that can be read from files. Not all file types support this and even the file types which support one, may not support all string types.

FileName: file name.
StringFlag: info flag.

StringFlag argument can be one of the following values:

PA_AUDIO_FILE_STRING_TITLE Returns the title string.

PA_AUDIO_FILE_STRING_COPYRIGHT Returns the copyright string.

PA_AUDIO_FILE_STRING_SOFTWARE Returns the software string.

PA_AUDIO_FILE_STRING_ARTIST Returns the artist string.

PA_AUDIO_FILE_STRING_COMMENT Returns the comment string.

PA_AUDIO_FILE_STRING_DATE Returns the date string.

PA_AUDIO_FILE_STRING_ALBUM Returns the album string.

PA_AUDIO_FILE_STRING_LICENSE Returns the license string.

PA_AUDIO_FILE_STRING_TRACK_NUMBER Returns the track number string.

PA_AUDIO_FILE_STRING_GENRE Returns the genre string.

 

Code Examples

 

Loading Samples from an Audio File

 

var formats = "Waveform Audio File Format (.wav)|*.wav"

+"|Audio Interchange File Format (.aiff)|*.aiff"
+"|Ogg Container File Format (.ogg)|*.ogg";//etc.

filename = get_open_filename(formats,"");
if(filename == ""){exit;}

var result = pa_audio_file_load(1,0,0,0,0,0,0,0,PA_MIXING_REPLACE,filename);

if(result)
{
show_message(filename_name(filename)+" loaded successfully!");
}
else
{
show_message("An error occurred while loading "+filename_name(filename)+" file.");
}

 

Saving the Output Stream Buffer to a Waveform Audio File Format

 

filename = get_save_filename("Waveform Audio File Format (.wav)|*.wav","");
if(filename == ""){exit;}
if(file_exists(filename)){file_delete(filename);}

var result = pa_audio_file_save(1,0,0,0,0,44100,2,PA_AUDIO_FILE_FORMAT_WAV|PA_AUDIO_FILE_TYPE_PCM_32,filename);

if(result)
{
show_message(filename_name(filename)+" saved successfully!");
}
else
{
show_message("An error occurred while saving "+filename_name(filename)+" file.");
}

 

Retrieving Information about Audio Files

 

show_message("NAME: "+filename_name(filename)

+"#CHANNELS: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_CHANNELS))
+"#FORMAT: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_FORMAT))
+"#FRAMES: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_FRAMES))
+"#SAMPLE RATE: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_SAMPLE_RATE))
+"#SECTIONS: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_SECTIONS))
+"#SEEKABLE: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_SEEKABLE))
+"#ITEMS: "+string(pa_audio_file_info(filename,PA_AUDIO_FILE_INFO_ITEMS))
);

 

I am Luigi Piscopo, also known as DJ GiDeejay / Producer / Remixer in the music world. I am a Producer with a lot of experience in photo editing, video editing, audio editing, graphic design, web design, programming and promotion.

Leave a Reply

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

*