第一部分要求写出8个声音基元函数,下面给出了详细的描述

Conventions

The conventions below are used to define the functions in the specification.

For functions that modify a single array of sample data, the data parameter is always passed first. Next any parameters that indicate quantities such as amplitude, duration, or frequency are listed. If a sampler function is required, it is always the last parameter and is optional (the default is to use a sine wave).

Parameter Names

  • data - Corresponds to an array of input data containing samples.
  • amp - Corresponds to amplitude for waves. Amplitude should always be between 0 and 1, inclusive.
  • dur - Duration in seconds.
  • sampler - Function to be used to generate input samples.

In most cases, parameters that indicate a quantity are taken to be percentages, unless specifically noted otherwise or the parameter refers to a duration. For example, the amplitude refers to the percent of the maximum allowable amplitude.

Constants

  • WAVE_MAX - The maximum allowable value of a single sample. Set to 32767.
  • WAVE_MIN - The minimum allowable value of a single sample. Set to -32768.
  • SAMPLE_FREQUENCY - The sampling frequency, in Hertz. Set to 22050.

Useful array and other functions

zeros(n) - return an array of n zeros  empty(n) - create an empty (uninitialized) array  array(l) - construct an array from a list  append(a,b) - append array b to a and return the result  xrange(stop) - similar to range, but faster
max(a) # returns the largest element of a  min(a) # returns the smallest element of a  abs(x) # returns the absolute value of x

Function Specifications

scale_volume(data, factor)

This function takes digital audio in array data and scales it by the value factor. To accomplish this scaling, every element of the array data is multiplied by factor. This multiplication increases or decreases the volume of the wave (corresponding to factors greater than 1 or less than 1, respectively) and may result in values that are out of range. Values out of range need to be clipped:

  • If a scaled sample is greater than WAVE_MAX, set it to WAVE_MAX
  • If a scaled sample is less than WAVE_MIN, set it to WAVE_MIN

Note that that factor may have a floating point value (e.g. 0.5) and thus the resulting new value may not be an integer, as needed. Use the built-in int function, which converts a float to an int by truncating decimal places. For illustration:

x = 3.5  print x,int(x)

prints:

3.5 3

normalize(data)

This function maximizes the possible volume of the sound given in array data. This operation is similar to scale_volume() except that now the value of parameter factor is to be determined in such a way that the volume is maximized and no clipping is needed after scaling. You need to address the special case where all samples are 0.


sin_sample(freq, amp, dur)

This function returns a sine wave with frequency freq, amplitude amp, and duration dur (in seconds).

The amplitude should be specified with a range of 0 to 1 where 1 represents the maximum amplitude. To obtain the actual amplitude in the sample use the WAVE_MAX value to scale it to an appropriate value.


half_speed(data)

This function takes an array of sample data and returns a new array containing the same sound, but at half of the original speed. Naively, this is accomplished by duplicating each sample, effectively halving the sampling frequency at which the sound is played back.

That is, if the original sound is [x1,x2,x3,x4], then the half_speed sound would be [x1,x1,x2,x2,x3,x3,x4,x4].


echo(data, delay, level)

This function takes as parameters a sound array data, a delay in seconds, and an echo level and it returns a new sound array. The generated array will be longer than array data.

Remember that the delay given in seconds is to be translated into SAMPLE_FREQUENCY*delay samples (i.e., array locations). The level is a value between 0 and 1. The level indicates the intensity of the echo in proportion to the original sound; i.e., the original wave is scaled by a factor of (1 - level).

To create an echo effect, consider the original wave and a copy of the wave. Now, shift the second wave forward by the number of seconds specified in variable delay. The two waves are then combined using the following weighting:

result = (1-level)*orig_sample + level*echo_sample

The pieces of the waves that do not overlap are matched by silence (0-valued samples). This technique produces a wave that has the sound of both the wave and the wave shifted by some amount of time, an echo. Generally, the echo is quieter than the original sound (level < .5), but that's not required.

NOTE: Remember that delay may be a floating point number, so it is important to make sure that when calculating the number of samples in the delay that the result is an integer.


combine_mean(list_of_sounds)

This function takes a list consisting of sound files (i.e., a list of arrays) and combines them into a single sound. All sound files must have the same length. The function returns the created sound in a new array (same size).

To calculate the combined sound, take the sum of each wave sample divided by the number of wave samples (i.e., compute the mean).


combine_interleave(list_of_sounds)

This function takes a list of waves that may have different lengths. The resulting wave takes samples from the waves at identical positions and interleaves them. For example:

  [[x1,x2,x3,x4], [y1,y2,y3], [z1,z2,z3,z4,z5]] =>        [x1,y1,z1,x2,y2,z2,x3,y3,z3]

The resulting wave's length is equal to the length of the shortest wave multiplied by the number of waves. That is, the waves are only interleaved so long as there are more samples left in all waves.


silence(dur)

Return an array consisting of dur seconds of silence.

转载于:https://www.cnblogs.com/yuxc/archive/2011/03/24/2061844.html

Part1: Specification of Required Functions相关推荐

  1. linux在线文档库

    http://blog.csdn.net/longxibendi/article/details/6048231 1.网址: http://www.mjmwired.net 2.比如查看这个 proc ...

  2. 机器学习:软件漏洞分析

    Software Vulnerability Analysis and Discovery Using Machine-Learning and Data-Mining Techniques: A S ...

  3. 自己收集整理的微软错误代码大全(中文和英文)

    自己收集整理的微软错误代码大全,分别为中文和英文部分,供广大软件开发人员共勉.                  微软错误代码 2.1  中文 0 操作成功完成. 1 功能错误. 2 系统找不到指定的 ...

  4. 使用SQLMonitor监视访问ORACLE的“服务”

    以前使用SQLMonitor抓捕"应用程序"访问ORACLE的SQL语句,用起来比较爽--这次遇到的应用是以WINDOWS服务的方式来运行的,尝试了一下SQLMonitor的监视服 ...

  5. 微软错误代码大全(中文和英文)

    以下内容转载自:点击打开链接 http://blog.csdn.net/magenfeng/article/details/8536557#comments 感谢原创! 微软错误代码 2.1  中文 ...

  6. GetLastError() 返回值一览

    函数原型: DWORD GetLastError() 中文版(不完全) [0]-操作成功完成. [1]-功能错误. [2]-系统找不到指定的文件. [3]-系统找不到指定的路径. [4]-系统无法打开 ...

  7. TVM实现hardware backend

    TVM实现hardware backend 官方的矩阵相加的示例如下: 2个矩阵相加的实现 for (int i = 0; i < n; ++i) { C[i] = A[i] + B[i]; } ...

  8. 利用tuning-primer脚本优化MySQL数据库

    脚本下载网址:  http://www.day32.com/MySQL/tuning-primer.sh #!/bin/sh # vim: ts=8 ######################### ...

  9. Windows C++中__declspec(dllexport)的使用

    __declspec是Microsoft VC中专用的关键字,它配合着一些属性可以对标准C/C++进行扩充.__declspec关键字应该出现在声明的前面. __declspec(dllexport) ...

最新文章

  1. 美国限制研究生入境,港大神操作,只要你愿意,填个表就行,还有机会获得校长奖学金...
  2. python【蓝桥杯vip练习题库】ADV-185五次方数(枚举)
  3. 【BZOJ】3224: Tyvj 1728 普通平衡树
  4. 数据中台应用实战50篇(一)-企业级数据中台的建设方法架构和技术栈
  5. 【问链-EOS公开课】第十二课 EOS整体代码结构
  6. 转jpg java源程序_将pdf文件转成图片并删除java源代码
  7. C#控件访问调用它的父级页面
  8. 灰色关联法 —— matlab
  9. 删除文件夹(包括子文件夹)
  10. C/C++[codeup 2080]整数奇偶排序
  11. linux下C语言获取微秒级时间
  12. 微信公众平台开发【素材管理】上传临时素材
  13. 卓有成效的管理者(珍藏版) (德鲁克管理经典)
  14. HashMap方法tableSizeFor解析
  15. 艾司博讯:拼多多客单价怎么提高
  16. 华为安防产品VCN资料下载
  17. 节点本地范围和链路本地范围_802.11协议精读15:链路模型(基于Free-Space Path Loss)...
  18. IBM 华为等薪资福利规定
  19. 安搭Share:苹果全球首批iPhone12mini/ProMax已开始发货
  20. 实验6-cp –r系统命令的实现--源路径(目录)中的所有文件和子目录,以及子目录中的所有内容,全部拷贝到目标路径(目录)中--操作系统实验

热门文章

  1. 2020年最好用的手机是哪一款_2020年入手5G手机最佳时期到了:5款最佳手机,您认可哪款...
  2. python附加索引_python – 附加两个多索引的pandas数据帧
  3. 关于结构化伪类的案例
  4. java调试时监视_Java监控工具、调优、调试辅助函数
  5. python识别出蓝色_OpenCVPython——无法检测蓝色对象
  6. 安装mysql最后一步第二个打叉_Mysql安装到最后一步时。出现start service红叉   亲朋好友帮忙指导一下!谢谢! 百...
  7. python移动文件中某个内容_如何在Python中移动文件
  8. linux-headers,如何升级linux-headers-generic?
  9. CentOS7 基于http服务搭建本地yum仓库
  10. linux内核killler,Linux内核参数overcommit_memory和OOM killer介绍