课 程 设 计 (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.mat

filename = '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.mat

filename = '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     Attributes

  y         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    Attributes

  y         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文件时,即使是单声道数据文件,也会当成立体声文件来读。

matlab之“audioread”函数帮助文档翻译的更多相关文章

  1. matlab中patch函数的用法

    http://blog.sina.com.cn/s/blog_707b64550100z1nz.html matlab中patch函数的用法——emily (2011-11-18 17:20:33) ...

  2. Matlab基本函数-conj函数

    Matlab基本函数-conj函数 1.conj函数:用于计算复数的共轭值 2.用法说明:y=conj(x)函数计算复数x的共轭值.输出结果y的维数跟输入x的维数一致,返回值为:real(y)-i*i ...

  3. 【原创】Matlab.NET混合编程技巧之找出Matlab内置函数

                  本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新    Matlab和C#混合编程文章目录 :[目录]Matlab和C#混合编程文章目录 Matlab与.N ...

  4. 【原创】Matlab.NET混合编程技巧之直接调用Matlab内置函数

                  本博客所有文章分类的总目录:[总目录]本博客博文总目录-实时更新    Matlab和C#混合编程文章目录 :[目录]Matlab和C#混合编程文章目录 在我的上一篇文章[ ...

  5. matlab画图形函数 semilogx

    matlab画图形函数 semilogx loglog 主要是学习semilogx函数,其中常用的是semilogy函数,即后标为x的是在x轴取对数,为y的是y轴坐标取对数.loglog是x y轴都取 ...

  6. 【matlab】设定函数默认参数

    C++/java/python系列的语言,函数可以有默认值,通常类似如下的形式: funtion_name (param1, param2=default_value, ...) 到了matlab下发 ...

  7. matlab中subplot函数的功能

    转载自http://wenku.baidu.com/link?url=UkbSbQd3cxpT7sFrDw7_BO8zJDCUvPKrmsrbITk-7n7fP8g0Vhvq3QTC0DrwwrXfa ...

  8. Matlab:max函数

    Matlab中max函数在矩阵中求函数大小的实例如下: C = max(A)返回一个数组各不同维中的最大元素.如果A是一个向量,max(A)返回A中的最大元素.如果A是一个矩阵,max(A)将A的每一 ...

  9. 【原创】Matlab中plot函数全功能解析

    [原创]Matlab中plot函数全功能解析 该帖由Matlab技术论(http://www.matlabsky.com)坛原创,更多精彩内容参见http://www.matlabsky.com 功能 ...

随机推荐

  1. github部分有意思的库记录

    1.MMDrawerController (抽屉框架) https://github.com/mutualmobile/MMDrawerController 2.ijkplayer视频直播框架 htt ...

  2. java多线程编程题之连续打印abc的几种解法

    一道编程题如下: 实例化三个线程,一个线程打印a,一个打印b,一个打印c,三个线程同时执行,要求打印出6个连着的abc 题目分析: 通过题意我们可以得出,本题需要我们使用三个线程,三个线程分别会打印6 ...

  3. 我的第一个python web开发框架(9)——目录与配置说明

    和老大聊完后,小白回家接收到相关工具函数包后,就按要求开始干活,首先要做的是熟悉配置参数和了解工具函数有哪些实用的工具. 由于这个项目比较简单,所以不用创建那么多分类,只需要api.common.co ...

  4. ROS命令

    rospack find [package_name]功能:获取软件包的路径 例:运行 rospack find roscpp ,会返回 /opt/ros/indigo/share/roscppros ...

  5. 【NOIP2016提高组】 Day2 T1 组合数问题

    题目传送门:https://www.luogu.org/problemnew/show/P2822                 ↓题目大意↓ 数据的极限范围:n,m≤2000,k≤21,数据组数≤ ...

  6. AVL 树

    一棵AVL树是每个节点的左子树和右子树的高度最多差1的二叉查找树 SearchTree Insert(ElementType X, SearchTree T) { if (T == NULL) { T ...

  7. Android 圆角的效果实现

    Android 自定义ImageView实现圆角图片昨天给学生布置作业,写微信首页,也就是聊天的界面,listView里的item中联系人的头像是圆角的,图形界面如下: 那么我就仔细研究了圆角的具体实 ...

  8. 面试中常用排序算法实现(Java)

    当我们进行数据处理的时候,往往需要对数据进行查找操作,一个有序的数据集往往能够在高效的查找算法下快速得到结果.所以排序的效率就会显的十分重要,本篇我们将着重的介绍几个常见的排序算法,涉及如下内容: 排 ...

  9. C++ 对象成员函数(非静态方法)

    1.神奇的inline语法与语义 inline语义C99和C++98都有.之前在单源文件编写的时候一直没有发现问题,但是一考虑到多文件的链接,就发现矛盾了. 一些inline的原则: 1. inlin ...

  10. HTTP Error 500.19 - Internal Server Error

    1.使用svn对项目进行管理 2.之前都是平安无事,忽然有一天报错:HTTP Error 500.19 - Internal Server Error,如图: 3.经过各种挣扎和求证,最后发现是项目. ...