AudioTools
Maple 2020 updates AudioTools with features that help you work with high precision audio, PCM WAV files, and more.
restart:
withAudioTools:
Read Part of an Audio File
Fast Convolution of Audio and Convolution of Multi-Channel Audio
Floating-Point WAV Files
High Sample Rates
Efficient White Noise Generator
Asymmetric Mapping from Internal Signal Values to External File
You can now read part of an audio file with the new samples option for Read.
audFile ≔ FileTools:-JoinPathkerneloptsdatadir, audio, ViolinThreePosVibrato.wav:
violinNote_sub ≔ ReadaudFile, samples = 103..60⋅103
violinNote_sub≔Sample Rate44100File FormatPCM File Bit Depth16Channels2Samples/Channel59001Duration1.33789⁢s
You can create many audio effects with convolution. For example, you can add reverb, or simulate how audio would sound in a specific room with its convolution with an impulse response.
For Maple 2020, AudioTools:-Convolution is significantly faster (for the default case) for those CPUs where the Intel IPP libraries can run optimized code.
Consider this violin note (to interact with the audio playback buttons below, open this page as a worksheet)
violinNote_full ≔ ReadaudFile..,1:
PreviewviolinNote_full,output = embed
Read the kernel for the convolution—a "ding" sound.
kernel ≔ ReadFileTools:-JoinPathkerneloptsdatadir, audio, ding.wav:
Previewkernel, output = embed
Convolution of the violin note with the ding sound (on an i7-8650U processor, Maple 2019 takes 2.6 s, while Maple 2020 takes 0.02 s)
tt ≔ timereal:violinNote_conv ≔ Convolution violinNote_full, kernel:timereal−tt;
0.079
PreviewviolinNote_conv,output=embed
Moreover, AudioTools:-Convolution now supports multi-channel audio. For audio with M channels, the kernel can be specified as an M-column Matrix or Array. Each channel of the kernel is applied to the corresponding channel of the audio.
You can now create 32-bit and 64-bit WAV files.
aud_float ≔ Createrate = 11025, duration = 5,float=true,bits=32;
aud_float≔Sample Rate11025File FormatIEEE_FLOAT File Bit Depth32Channels1Samples/Channel55125Duration5.00000⁢s
#Writeaud_float.wav,aud_float
You can now write audio files with sample rates of up to 232 - 1 Hz = 4.29 GHz.
aud_high_sample_rate ≔ Create rate = 221
aud_high_sample_rate≔Sample Rate2097152File FormatPCM File Bit Depth16Channels1Samples/Channel2097152Duration1.00000⁢s
#Writeaud_high_sample_rate.wav,aud_high_sample_rate
You can now quickly generate audio filled with white noise.
aud_noise ≔ Createnoise = true, duration = 1;
aud_noise≔Sample Rate44100File FormatPCM File Bit Depth16Channels1Samples/Channel44100Duration1.00000⁢s
Previewaud_noise,output=embed
PCM audio is asymmetric—the highest possible value is not equal in magnitude to the lowest possible value. For example, 16-bit audio ranges in value from -32768 to +32767. This means that positive half-cycles of a waveform are compressed compared to negative ones.
AudioTools:-Write and AudioTools:-Read now offer new options to change the mapping of minimum and maximum values in the internal representation of an audio file to external values when written to a PCM WAV file. This now reflects the reality of working with PCM audio.
data ≔ LinearAlgebra:-RandomVector1000, generator = 0..1:for i from 1 to 1000 do if datai = 0 then datai≔−1 end if end do:aud_sym ≔ Createdata;
aud_sym≔Sample Rate44100File FormatPCM File Bit Depth16Channels1Samples/Channel1000Duration0.02268⁢s
minaud_sym;maxaud_sym
1.
aud_path≔FileTools:-JoinPathFileTools:-TemporaryDirectory,foo.wav
aud_path≔C:\Users\skhan\AppData\Local\Temp\foo.wav
Warning, one or more samples could not be represented in the range -32768..32767 and were clipped
aud_asym≔Readaud_path, mapping = min: minaud_asym;maxaud_asym
0.999969482421875
Download Help Document