AudioTools - New Features in Maple 2020 - Maplesoft

What's New in Maple 2020

AudioTools

Maple 2020 updates AudioTools with features that help you work with high precision audio, PCM WAV files, and more.


restart; -1 

with(AudioTools); -1 

Read Part of an Audio File 

You can now read part of an audio file with the new samples option for Read. 

audFile := FileTools:-JoinPath([kernelopts(datadir),  

violinNote_sub := Read(audFile, samples = `^`(10, 3) .. `+`(`*`(60, `*`(`^`(10, 3)))));  

Typesetting:-mprintslash([violinNote_sub := MATRIX([[
 

 

Fast Convolution of Audio and Convolution of Multi-Channel Audio 

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: 

violinNote_full := Read(audFile)[() .. (), 1]; -1 

Preview(violinNote_full, output = embed); Embedded component 

Read the kernel for the convolution-a "ding" sound. 

kernel := Read(FileTools:-JoinPath([kernelopts(datadir),  

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 := time[real](); -1; violinNote_conv := Convolution(violinNote_full, kernel); -1; `+`(time[real](), `-`(tt)); 1 

0.79e-1
 

Preview(violinNote_conv, output = embed); Embedded component 

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. 

Floating-Point WAV Files 

You can now create 32-bit and 64-bit WAV files. 

aud_float := Create(rate = 11025, duration = 5, float = true, bits = 32); 1 

Typesetting:-mprintslash([aud_float := MATRIX([[
 

 

High Sample Rates 

You can now write audio files with sample rates of up to 232 - 1 Hz = 4.29 GHz. 

aud_high_sample_rate := Create(rate = `^`(2, 21));  

Typesetting:-mprintslash([aud_high_sample_rate := MATRIX([[
 

 

Efficient White Noise Generator 

You can now quickly generate audio filled with white noise. 

aud_noise := Create(noise = true, duration = 1); 1 

Typesetting:-mprintslash([aud_noise := MATRIX([[
 

Preview(aud_noise, output = embed); Embedded component 

 

Asymmetric Mapping from Internal Signal Values to External File 

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:-RandomVector(1000, generator = 0 .. 1); -1; for i to 1000 do if data[i] = 0 then data[i] := -1 end if end do; -1; aud_sym := Create(data); 1
data := LinearAlgebra:-RandomVector(1000, generator = 0 .. 1); -1; for i to 1000 do if data[i] = 0 then data[i] := -1 end if end do; -1; aud_sym := Create(data); 1
data := LinearAlgebra:-RandomVector(1000, generator = 0 .. 1); -1; for i to 1000 do if data[i] = 0 then data[i] := -1 end if end do; -1; aud_sym := Create(data); 1
 

Typesetting:-mprintslash([aud_sym := MATRIX([[
 

min(aud_sym); 1; max(aud_sym) 

 

Typesetting:-mprintslash([-1.], [HFloat(-1.0)])
Typesetting:-mprintslash([1.], [HFloat(1.0)])
 

aud_path := FileTools:-JoinPath([FileTools:-TemporaryDirectory(),  

Typesetting:-mprintslash([aud_path :=
 

Write(aud_path, aud_sym, mapping = min); -1 

Warning, one or more samples could not be represented in the range -32768..32767 and were clipped
 

aud_asym := Read(aud_path, mapping = min); -1; min(aud_asym); 1; max(aud_asym) 

 

Typesetting:-mprintslash([-1.], [HFloat(-1.0)])
Typesetting:-mprintslash([.999969482421875], [HFloat(0.999969482421875)])