课 程 设 计 (1) 

原文

audioread

Read audio file

Syntax

  • [y,Fs] = audioread(filename)

  • [y,Fs] = audioread(filename,samples)

  • [y,Fs] = audioread(___,dataType)

Description

[y,Fs] = audioread(filename) reads data from the file named filename, and returns sampled data, y, and a sample rate for that data, Fs.

[y,Fs] = audioread(filename,samples) reads the selected range of audio samples in the file, where samples is a vector of the form [start,finish].

[y,Fs] = audioread(___,dataType) returns sampled data in the data range corresponding to the dataType of 'native' or 'double', and can include any of the input arguments in previous syntaxes.

Examples

Read Complete Audio File

Create a WAVE file from the example file handel.mat, and read the file back into MATLAB®.

Create a WAVE (.wav) file in the current folder.

load handel.matfilename = 'handel.wav';
audiowrite(filename,y,Fs);
clear y Fs

Read the data back into MATLAB using audioread.

[y,Fs] = audioread('handel.wav');

Play the audio.

sound(y,Fs);

Read Portion of Audio File

Create a FLAC file from the example file handel.mat, and then read only the first 2 seconds.

Create a FLAC (.flac) file in the current folder.

load handel.matfilename = 'handel.flac';
audiowrite(filename,y,Fs);

Read only the first 2 seconds.

samples = [1,2*Fs];
clear y Fs
[y,Fs] = audioread(filename,samples);

Play the samples.

sound(y,Fs);

Return Audio in Native Integer Format

Create a FLAC file and read the first 2 seconds according to the previous Example. Then, view the data type of the sampled data y.

whos y

  Name          Size             Bytes  Class     Attributesy         16384x1             131072  double   

The data type of y is double.

Request audio data in the native format of the file, and then view the data type of the sampled data y.

[y,Fs] = audioread(filename,'native');
whos y

  Name          Size            Bytes  Class    Attributesy         16384x1             32768  int16

The data type of y is now int16.

Input Arguments

filename — Name of file to readstring

Name of file to read, specified as a string that includes the file extension. If a path is specified, it can be absolute, relative or partial.

Example: 'myFile.mp3'

Example: '../myFile.mp3'

Example: 'C:\temp\myFile.mp3'

audioread supports the following file formats.

Platform Support File Format
All platforms WAVE (.wav)
OGG (.ogg)
FLAC (.flac)
AU (.au)
AIFF (.aiff.aif)
AIFC (.aifc)
Windows® 7 (or later), Macintosh, and Linux® MP3 (.mp3)
MPEG-4 AAC (.m4a.mp4)

On Windows platforms prior to Windows 7, audioread does not read WAVE files with MP3 encoded data.

On Windows 7 (or later) platforms, audioread might also read any files supported by Windows Media® Foundation.

On Linux platforms, audioread might also read any files supported by GStreamer.

audioread can extract audio from MPEG-4 (.mp4.m4v) video files on Windows 7 or later, Macintosh, and Linux, and from Windows Media Video (.wmv) and AVI (.avi) files on Windows 7 (or later) and Linux platforms.

samples — Audio samples to read[1,inf] (default) | two-element vector of positive scalar integers

Audio samples to read, specified as a two-element vector of the form [start,finish], where start and finish are the first and last samples to read, and are positive scalar integers.

  • start must be less than or equal to finish.

  • start and finish must be less than the number of audio samples in the file,

  • You can use inf to indicate the last sample in the file.

Note:   When reading a portion of some MP3 files on Windows 7 platforms, audioread might read a shifted range of samples. This is due to a limitation in the underlying Windows Media Foundation framework.

When reading a portion of MP3 and M4A files on Linux platforms, audioread might read a shifted range of samples. This is due to a limitation in the underlying GStreamer framework.

Example: [1,100]

Data Types: double

dataType — Data format of audio data, y'double' (default) | 'native'

Data format of audio data,y, specified as one of the following strings:

'double' Double-precision normalized samples.
'native' Samples in the native format found in the file.

For compressed audio formats, such as MP3 and MPEG-4 AAC that do not store data in integer form, 'native' defaults to 'single'.

Output Arguments

y — Audio datamatrix

Audio data in the file, returned as an m-by-n matrix, where m is the number of audio samples read and n is the number of audio channels in the file.

  • If you do not specify dataType, or dataType is 'double', then y is of type double, and matrix elements are normalized values between −1.0 and 1.0.

  • If dataType is 'native', then y can be one of several MATLAB data types, depending on the file format and the BitsPerSample value of the input file. Call audioinfo to determine theBitsPerSample value of the file.

    File Format BitsPerSample Data Type of y Data Range of y
    WAVE (.wav) 8 uint8 0 ≤ y ≤ 255
    16 int16 -32768 ≤ y ≤ +32767
    24 int32 -2^32 ≤ y ≤ 2^32–1
    32 int32 -2^32 ≤ y ≤ 2^32–1
    32 single -1.0 ≤ y ≤ +1.0
    64 double -1.0 ≤ y ≤ +1.0
    FLAC (.flac) 8 uint8 0 ≤ y ≤ 255
    16 int16 -32768 ≤ y ≤ +32767
    24 int32 -2^32 ≤ y ≤ 2^32–1
    MP3 (.mp3), MPEG-4 AAC (.m4a.mp4), OGG (.ogg), and certain compressed WAVE files N/A single -1.0 ≤ y ≤ +1.0

Note:   Where y is single or double and the BitsPerSample is 32 or 64, values in y might exceed −1.0 or +1.0.

Fs — Sample ratepositive scalar

Sample rate, in hertz, of audio data y, returned as a positive scalar.

Limitations

  • For MP3, MPEG-4 AAC, and AVI audio files on Windows 7 or later and Linux platforms, audioread might read fewer samples than expected. On Windows 7 platforms, this is due to a limitation in the underlying Media Foundation framework. On Linux platforms, this is due to a limitation in the underlying GStreamer framework. If you require sample-accurate reading, work with WAV or FLAC files.

  • On Linux platforms, audioread reads MPEG-4 AAC files that contain single-channel data as stereo data.

翻译

调用结构&描述

  [y, Fs] =audioread(filename)

  从以“filename”为文件名的文件中读取数据,并返回抽样数据y和此数据的抽样率Fs 。

  [y, Fs] =audioread(filename, samples)

  以选定范围从文件中读取音频样本,其中 samples 是具有[start, finish]形式的向量。

  [y, Fs] =audioread( ____, dataType)

  返回数据域中与 dataType 相对应的采样数据,dataType 可选“native(本地类型)”或“double(双精度型)”。

例子

  可以自己从本地音乐里面选择音乐来测试。但是建议适当缩减音频长度,不然计算量会比较大,有可能卡死电脑。剪辑音频可以使用“格式工厂”,它也能用来转换文件格式。

输入  1、对于输入文件,表中给的信息已经很详细了,".wav"格式的音频是一定支持的,通用的".mp3"格式在win7以上及Linux系统上都是可以读取的。

  2、 对于输入参数 samples ,在第一种调用结构中其实是隐藏了 [1, inf] 的默认samples参数,意思是从文件头读到文件尾。在第二种调用格式里面我们可以指定读取的参数范围。要注意 start, finish 两个参数都是正整数,而且他们的大小不能超出抽样个数。这个很容易理解,超出了源文件的抽样范围就不可能有数据。在使用中,可以用 [start, inf] 表示从 start 读到文件尾。

  注意:当在win7平台上读取MP3以及在Linux上读取MP3&M4A格式文件时,可能会出现读取范围转移的现象,这是由于底层Windows Media Foundation框架的局限性造成的。

  3、dataType有两种取值,native 或 double 。默认情况下,native 为单精度类型 single 。

输出

  y 为音频数据,是一个mxn 的矩阵,m是读取文件的抽样个数,n是读取文件的音频信道个数。

    · 在未明确 dataType 和 dataType 取 double 时,y 的类型也是 double。y 的元素为值介于-1.0和1.0之间的规范化值。

    · 如果 dataType 取 native,y 可以为matlab所允许的几种数据类型之一。至于为哪一种类型取决于输入文件的类型,这种对应关系在上面给出的表中。

  注意:当 y 为单精度或双精度数, 且 BitPerSample 为32或64时,y 的值有可能超出 -1.0~1.0。

局限

  · 对于 MP3, MPEG-4 AAC, AVI音频文件,在win7及更高版本和Linux平台上,有可能会出现抽样个数比预期要少的现象。

  · 在Linux上读取MPEG-4 AAC文件时,即使是单声道数据文件,也会当成立体声文件来读。

转载于:https://www.cnblogs.com/Mr-Tiger/p/7896271.html

matlab之“audioread”函数帮助文档翻译相关推荐

  1. MATLAB中audioread函数用法

    目录 语法 说明 示例 读取完整的音频文件 读取部分音频文件 返回原生整数格式的音频 audioread函数的功能是读取音频文件. 语法 [y,Fs] = audioread(filename) [y ...

  2. matlab中audioread函数的用法

    audioread函数用法(matlab) 一,语法 1 2 3 [y,Fs] = audioread(filename) [y,Fs] = audioread(filename,samples) [ ...

  3. 【已解决】MATLAB未定义函数或变量 ‘wavread‘,以及audioread,audiowrite,wavwrite

    报错 MATLAB未定义函数或变量 'wavread'. 原因 wavread在当前Matlab版本中废弃,需要改成audioread,同理wavwrite也需要改为audiowrite. 注意 在更 ...

  4. matlab audioread函数用法,Matlab读取写入合成音频信号audioread audiowrite 函数使用方法...

    audioread和audioread函数的使用方法 audioread 语法 示例 audiowrite 语法 示例 更多参数 'BitsPerSample' - 每样本输出位数 'BitRate' ...

  5. matlab pup,matlab利用bar函数画不同颜色直方图

    matlab利用bar函数画直方图,参考文献[1]是matlab官方提供的help文档.里面提供了bar函数的基本用法,但是没有说明如何在同一张图中,为每个bar设置不同的颜色. 例子代码: myda ...

  6. Matlab中bwmorph函数的使用

    Matlab中bwmorph函数的使用 Matlab中提供了一个基于形态学的处理函数,即以膨胀.腐蚀等操作为基础,其语法格式如下: bw2=bwmorph(bw1,operation,n); 其中bw ...

  7. 9.matlab中repmat函数

    来源: matlab中repmat函数的用法 - CSDN博客 https://blog.csdn.net/anqier1009/article/details/5214978 B = repmat( ...

  8. 如何在Matlab中获取函数参数的数目?

    本图文详细介绍了Matlab中获取函数参数数目的方法.

  9. c++引用matlab类,matlab调用C++函数浅谈(一)

    由于在下才疏学浅,在网上看各高手指南时亦觉云里雾里,遂决定一切说明从最基础说起,一是方便自己(记性奇差),二是方便似我的小白.以下部分是我从各网站论坛等摘抄.重组.改写过的,以求更加详实明朗,由于参考 ...

最新文章

  1. 十六进制字符转化为十进制数字
  2. python字符串命名_从输入字符串到命名复制python 2.7
  3. 算法笔记_218:花朵数(Java)
  4. 【错误记录】Flutter 混合开发报错 ( Android 端与 Flutter 端 EventChannel 初始化顺序错误导致无法通信 | EventChannel 通信流程 )
  5. mysql多个子查询_mysql(5)多表--子查询
  6. 《解剖PetShop》系列之二
  7. 11个技巧让你编写出更好的Python代码,值得收藏!!
  8. IDEA导入个性化主题的方法
  9. 龙邱STM32单片机用J-LINK下载无法被识别的解决方法
  10. Xcode 高级调试技巧
  11. 虚拟机Linux IP地址更改
  12. CSS3_04_弹性盒子_多媒体
  13. 双光耦开关电源电路图_开关电源光耦的工作原理及典型接法
  14. MTPA 永磁同步电机 计算
  15. html查重报告转换,知网查重报告网页版如何转换成PDF和WORD?
  16. 解决问题#Word导出PDF出现空白页
  17. 视频流中的DTS/PTS到底是什么?
  18. 康宇的OJ愚人手账1
  19. Java-枚举类enum及常用方法
  20. 飞思卡尔单片机PLL时钟总线模块

热门文章

  1. 已解决mysql报错ERROR 1049 (42000): Unknown database ‘数据库‘
  2. 缓冲区溢出攻击实验(一)
  3. [转载]推荐:互联网思维必读十本书
  4. ES6对数组进行正序和倒序排列
  5. layui内置模块(layer弹出层)
  6. Hibernate中:cannot simultaneously fetch multiple bags的问题
  7. luoguP5108 仰望半月的夜空 [官方?]题解 后缀数组 / 后缀树 / 后缀自动机 + 线段树 / st表 + 二分...
  8. 《奇点临近》奇点和六大纪元
  9. 多属性决策的权重确定方法及matlab 程序
  10. 绝对值不等式解绝对值二次函数的最值_Simplelife_新浪博客