我这里有这个代码,我从如何创建一个可听正弦波的教程有:Java错误生成声音正弦波

import java.nio.ByteBuffer;

import javax.sound.sampled.*;

public class FixedFreqSine {

//This is just an example - you would want to handle LineUnavailable properly...

public static void main(String[] args) throws InterruptedException, LineUnavailableException

{

final int SAMPLING_RATE = 44100; // Audio sampling rate

final int SAMPLE_SIZE = 2; // Audio sample size in bytes

SourceDataLine line;

double fFreq = 440; // Frequency of sine wave in hz

//Position through the sine wave as a percentage (i.e. 0 to 1 is 0 to 2*PI)

double fCyclePosition = 0;

//Open up audio output, using 44100hz sampling rate, 16 bit samples, mono, and big

// endian byte ordering

AudioFormat format = new AudioFormat(SAMPLING_RATE, 16, 1, true, true);

DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);

if (!AudioSystem.isLineSupported(info)){

System.out.println("Line matching " + info + " is not supported.");

throw new LineUnavailableException();

}

line = (SourceDataLine)AudioSystem.getLine(info);

line.open(format);

line.start();

// Make our buffer size match audio system's buffer

ByteBuffer cBuf = ByteBuffer.allocate(line.getBufferSize());

int ctSamplesTotal = SAMPLING_RATE*5; // Output for roughly 5 seconds

//On each pass main loop fills the available free space in the audio buffer

//Main loop creates audio samples for sine wave, runs until we tell the thread to exit

//Each sample is spaced 1/SAMPLING_RATE apart in time

while (ctSamplesTotal>0) {

double fCycleInc = fFreq/SAMPLING_RATE; // Fraction of cycle between samples

cBuf.clear(); // Discard samples from previous pass

// Figure out how many samples we can add

int ctSamplesThisPass = line.available()/SAMPLE_SIZE;

for (int i=0; i < ctSamplesThisPass; i++) {

cBuf.putShort((short)(Short.MAX_VALUE * Math.sin(2*Math.PI * fCyclePosition)));

fCyclePosition += fCycleInc;

if (fCyclePosition > 1)

fCyclePosition -= 1;

}

//Write sine samples to the line buffer. If the audio buffer is full, this will

// block until there is room (we never write more samples than buffer will hold)

line.write(cBuf.array(), 0, cBuf.position());

ctSamplesTotal -= ctSamplesThisPass; // Update total number of samples written

//Wait until the buffer is at least half empty before we add more

while (line.getBufferSize()/2 < line.available())

Thread.sleep(1);

}

//Done playing the whole waveform, now wait until the queued samples finish

//playing, then clean up and exit

line.drain();

line.close();

}

}

它运行正常在Windows 10,和完美的产生声音。然而,在我的Macbook Pro中,我收到以下错误:

2015-11-17 11:20:16.549 java[5899:9037084] Error loading /Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin/Contents/MacOS/SeratoVirtualAudioPlugIn: dlopen(/Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin/Contents/MacOS/SeratoVirtualAudioPlugIn, 262): no suitable image found. Did find:

/Library/Audio/Plug-Ins/HAL/SeratoVirtualAudioPlugIn.plugin/Contents/MacOS/SeratoVirtualAudioPlugIn: mach-o, but wrong architecture

2015-11-17 11:20:16.549 java[5899:9037084] Cannot find function pointer New_SHP_PlugIn for factory 834FC054-C1CC-11D6-BD01-00039315CD46 in CFBundle/CFPlugIn 0x7fd672c25910 (bundle, not loaded)

2015-11-17 11:20:16.580 java[5899:9037084] 11:20:16.580 WARNING: >compload> 472: Kickstart.component -- file://localhost/Library/Audio/Plug-Ins/Components/: trouble parsing Info.plist's AudioComponents, key (null); entry: {type = mutable dict, count = 7,

entries =>

2 : {contents = "manufacturer"} = {contents = "CaNR"}

7 : {contents = "factoryFunction"} = {contents = "KickstartAUFactory"}

8 : {contents = "subtype"} = {contents = "CNKS"}

9 : {contents = "description"} = {contents = "Kickstart"}

10 : {contents = "type"} = {contents = "kAudioUnitType_Effect"}

11 : {contents = "name"} = {contents = "Nicky Romero: Kickstart"}

12 : {contents = "version"} = {value = +65545, type = kCFNumberSInt64Type}

}

2015-11-17 11:20:16.586 java[5899:9037084] 11:20:16.586 WARNING: >compload> 472: Primer.component -- file://localhost/Library/Audio/Plug-Ins/Components/: trouble parsing Info.plist's AudioComponents, key (null); entry: {type = mutable dict, count = 7,

entries =>

2 : {contents = "manufacturer"} = {contents = "AudG"}

7 : {contents = "factoryFunction"} = {contents = "PrimerAUFactory"}

8 : {contents = "subtype"} = {contents = "agp"}

9 : {contents = "description"} = {contents = "Primer"}

10 : {contents = "type"} = {contents = "aumu"}

11 : {contents = "name"} = {contents = "Audible Genius: Primer"}

12 : {contents = "version"} = {value = +65793, type = kCFNumberSInt64Type}

}

我完全不明白这个错误。我唯一知道的是它正在访问我的音频插件。我也知道错误发生在:

line = (SourceDataLine)AudioSystem.getLine(info);

line.open(format);

有没有人知道这个错误的原因是什么?或者如何解决它?

java 生成正弦波声音_Java错误生成声音正弦波相关推荐

  1. java 生成校验验证码_java 验证码生成与校验

    java绘图相关类 验证码工具类 package dt2008.util; import javax.imageio.ImageIO; import javax.servlet.http.HttpSe ...

  2. java 调用word插件_java一键生成word操作,比poi简单

    [Java] 纯文本查看 复制代码package com.jeeplus.modules.fact.util; import java.io.BufferedInputStream; import j ...

  3. java 8位随机数_JAVA中生成指定位数随机数的方法总结

    JAVA中生成指定位数随机数的方法很多,下面列举几种比较常用的方法. 方法一.通过Math类 1 public static String getRandom1(intlen) {2 int rs = ...

  4. java 头像 微信群_java怎么生成带用户微信头像的图片,并把这张图片发送给用户。...

    展开全部 这个是要一个图片中嵌套另外一张图片 你可以62616964757a686964616fe59b9ee7ad9431333431336163试试下面这段代码import java.awt.Co ...

  5. java 生成token代码_java token生成和校验的实例代码

    现在越来越多的登录方式都用到了token作为用户登录令牌,所以实现了一个token生成和校验案例. 缺点:该实现方式token是存储在内存中,不适合分布式项目,如需改为分布式项目部署,可把token存 ...

  6. java导出csv文件_java导出生成csv文件的方法

    本文实例为大家分享了java导出生成csv文件的具体代码,供大家参考,具体内容如下 首先我们需要对csv文件有基础的认识,csv文件类似excel,可以使用excel打开,但是csv文件的本质是逗号分 ...

  7. java 数字 字母 递增_JAVA流水号生成规则(按默认规则递增,数字不够添加字母递增,位数不够自动加1)...

    写道 在某些应用场景中,因业务需要,一般的流水号(前缀+日期或时间+流水号)规则无法满足业务需要,以下是因业务需要拓展出来的流水号生成规则 业务要求: 1.默认限定位数的数字递增 2.在限定位数数字达 ...

  8. java 流水账号生成器_Java流水生成工具

    package com.serialnumber; import java.text.SimpleDateFormat; import java.util.Date; import org.apach ...

  9. java随机生成一个号码_Java 随机生成任意组电话号码过程解析

    需求说明 要求根据用户输入,生成相应组数的电话号码 实现思路 1.通过百度,获取对应真实世界中电话号码的头三位数 2.采用Math.random()方法,生成电话号码的后八位数 代码内容 随机生成任意 ...

最新文章

  1. win7如何配置access数据源
  2. Redis源码解析:07压缩列表
  3. VTK:相互作用之Assembly
  4. python每天1道面试题(3)--字符串组合
  5. Linux操作系统下SSH默认22端口修改方法
  6. 换工位解决ssh 卡住的背后
  7. socket简介 - 获取简单网页内容
  8. 包导出Android升级ADT22后会报ClassNotFoundException的原因分析
  9. 怎么用python画天气图_Python气象绘图教程(十五)—Cartopy_5
  10. 第17课:郭盛华课程_VB编程之菜单界面的设计
  11. 微信小程序人脸识别功能(wx.faceDetect)、带扫脸动画、人脸图片获取(upng.js)及位置展示
  12. 计算机双系统,细说如何给电脑安装双系统
  13. python绘图设置新罗马字体_更改matplotlib中的字体
  14. 学习verilog的经典好教材与资料
  15. PHP中的SAPI是什么,都有那些模式?
  16. Amy-Tabb机器人世界手眼标定(4、Windows)
  17. 商业模式画布的介绍例子
  18. 关于通用雷达信号的时频分析与图像绘制(Matlab)
  19. Java 线程池 +生产者消费者+MySQL读取300 万条数据
  20. window.print()打印html网页的两种方法

热门文章

  1. 微信小程序image组件频闪问题
  2. php如何实现众筹,PHP众筹系统这三点一定要注意
  3. Nodejs之child_process
  4. KOF97简易过关法
  5. 【嵌入式开发教程9】手把手教你做平板电脑-WIFI 驱动实验教程
  6. html页面文字随机效果,教你用javascript实现随机标签云效果_附代码
  7. 卧槽!Pdf转Word用Python轻松搞定!
  8. 2004-2020年全国31省环境规制强度
  9. 调查发现女人比男人更喜欢使用社交网站(组图)
  10. 2.什么是JAVA内存模型?