Some of the commonly supported audio compression formats include:
- WAV (Waveform Audio File Format): MATLAB can read and write WAV files, which are typically uncompressed audio files. While WAV files are not compressed, they can be used as a reference for comparing compression algorithms.
- AAC (Advanced Audio Coding): MATLAB can encode and decode AAC audio files, which is a widely used lossy compression format known for its high-quality compression. You can use the audiowrite and audioread functions with the 'm4a' file format option for AAC.
- OGG (Ogg Vorbis): MATLAB supports Ogg Vorbis audio compression, a popular open-source lossy compression format. You can use the audiowrite and audioread functions with the 'ogg' file format option for Ogg Vorbis.
- FLAC (Free Lossless Audio Codec): FLAC is a lossless audio compression format supported by MATLAB. You can use the audiowrite and audioread functions with the 'flac' file format option for FLAC.
- MP3 (MPEG-1 Audio Layer III): MATLAB does not have built-in support for encoding MP3 files directly due to licensing restrictions. However, you can use third-party libraries or tools, as mentioned earlier, to work with MP3 compression.
- ALAC (Apple Lossless Audio Codec): MATLAB supports ALAC audio files, a lossless compression format developed by Apple. You can use the audiowrite and audioread functions with the 'alac' file format option for ALAC.
- AIFF (Audio Interchange File Format): MATLAB can read and write AIFF files, which are uncompressed audio files commonly used on Macintosh systems.
- AC3 (Audio Codec 3): MATLAB supports AC3 encoding and decoding for audio compression, which is often used in video files.
MATLAB code that demonstrates how to use the audioread and audiowrite functions to compress an audio file using AAC format and then decompress it:
[y, fs] = audioread('input.wav');
outputAACFile = 'output.aac';
audiowrite(outputAACFile, y, fs, 'BitRate', bitrate, 'Format', 'm4a');
compressedAudio = audioread(outputAACFile);
sound(compressedAudio, fs);
- Replace 'input.wav' with the path to your input audio file.
- Set the outputAACFile variable to the desired name of the compressed AAC audio file.
- Adjust the bitrate variable to control the compression quality. Higher bitrates typically result in better audio quality but larger file sizes.
- The code uses audiowrite to compress the input audio to AAC format with the specified bitrate.
- It then reads the compressed AAC audio file using audioread.
- Optionally, it plays both the original and compressed audio files for comparison.
This code will allow you to compress an audio file to AAC format and save it. You can adjust the bitrate to control the compression quality to suit your needs.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems | Firmware Developement | Simulations
- Electrical and Electronics Engineering
Feel free to contact me.