- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试实现一个系统,在该系统中我可以同时播放一组频率,目前可以单独播放每个频率。下面我有一个代码,它播放给定的频率,一次播放一个。
import java.applet.*;
import java.io.*;
import java.net.*;
import javax.sound.sampled.*;
public final class StdAudio {
public static final int SAMPLE_RATE = 44100;
private static final int BYTES_PER_SAMPLE = 2; // 16-bit audio
private static final int BITS_PER_SAMPLE = 16; // 16-bit audio
private static final double MAX_16_BIT = Short.MAX_VALUE; // 32,767
private static final int SAMPLE_BUFFER_SIZE = 4096;
private static SourceDataLine line; // to play the sound
private static byte[] buffer; // our internal buffer
private static int bufferSize = 0;
// not-instantiable
private StdAudio() { }
// static initializer
static { init(); }
// open up an audio stream
private static void init() {
try {
// 44,100 samples per second, 16-bit audio, mono, signed PCM, little Endian
AudioFormat format = new AudioFormat((float) SAMPLE_RATE, BITS_PER_SAMPLE, 1, true, false);
DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
line = (SourceDataLine) AudioSystem.getLine(info);
line.open(format, SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE);
buffer = new byte[SAMPLE_BUFFER_SIZE * BYTES_PER_SAMPLE/3];
} catch (Exception e) {
System.out.println(e.getMessage());
System.exit(1);
}
// no sound gets made before this call
line.start();
}
/**
* Close standard audio.
*/
public static void close() {
line.drain();
line.stop();
}
/**
* Write one sample (between -1.0 and +1.0) to standard audio. If the sample
* is outside the range, it will be clipped.
*/
public static void play(double in) {
// clip if outside [-1, +1]
if (in < -1.0) in = -1.0;
if (in > +1.0) in = +1.0;
// convert to bytes
short s = (short) (MAX_16_BIT * in);
buffer[bufferSize++] = (byte) s;
buffer[bufferSize++] = (byte) (s >> 8); // little Endian
// send to sound card if buffer is full
if (bufferSize >= buffer.length) {
line.write(buffer, 0, buffer.length);
bufferSize = 0;
}
}
/**
* Write an array of samples (between -1.0 and +1.0) to standard audio. If a sample
* is outside the range, it will be clipped.
*/
public static void play(double[] input) {
for (int i = 0; i < input.length; i++) {
play(input[i]);
}
}
private static double[] tone(double hz, double duration) {
int N = (int) (StdAudio.SAMPLE_RATE * duration);
double[] a = new double[N+1];
for (int i = 0; i <= N; i++)
a[i] = amplitude * Math.sin(2 * Math.PI * i * hz / StdAudio.SAMPLE_RATE);
return a;
}
/**
* Test client - play an A major scale to standard audio.
*/
public static void main(String[] args) {
double hz = 440.4// 440.4 Hz for 1 sec
double duration = 1.0;
double[] a = tone(hz,duration);
StdAudio.play(a);
}
最佳答案
只需将每个时间点的样本值相加,然后除以适当的比例因子即可使您的值保持在范围内。例如,同时播放 A 440 和 C 523.25:
double[] a = tone(440,1.0);
double[] b = tone(523.25,1.0);
for( int i=0; i<a.length; ++ i )
a[i] = ( a[i] + b[i] ) / 2;
StdAudio.play(a);
关于java - 如何使用 javax.sound.sampled 包同时播放一组频率(和弦),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11881595/
In condition, COLUMN = [:id, :tag_list, :price, :url, :Perweight, :Totalweight, :memo, :created_at,
我正在构建一个逻辑回归分类器。 我从一组 500.000 条记录开始,我只想使用其中的一个样本。 你有什么建议: 1) 缩放总体然后采样2)缩放样本3) 仅缩放样本的 X_TRAIN 分割? 为什么?
我正在尝试进行 8 级分类。这是代码: import keras import numpy as np from keras.preprocessing.image import ImageDataG
我想在 Keras 中创建一个可以“逐个样本”学习的模型;这种机器叫online learning ,一个逐个接收和拟合数据的模型。我的问题是:我怎样才能在 Keras 中做到这一点?是否可以通过在拟
请帮帮我。我无法正确使用我的数据表。我想做的是 从表中选择并使用where函数。但我做不到。 这是我的 Controller 代码 public function reporttable ()
我将所有正样本的大小调整为相同的大小,因此负样本的大小也应与正样本的大小相同。 最佳答案 通常,通过对象检测,您可以在图像上滑动固定大小的搜索窗口,从而产生特征响应。然后,分类器将响应与经过训练的模型
为自己创建一个简单的通行证生成器,我注意到如果我希望我的人口只有数字(0-9),总共有 10 个选项,如果我希望我的长度超过 10,它不会使用更多的数字然后一次并返回“样本大于总体”错误。 是否可以维
当我读到一篇论文“批量归一化:通过减少内部协变量偏移来加速深度网络训练”时,我想到了一些问题。 论文中写道: Since m examples from training data can estim
我的代码 import random MyList = [[1,2,3,4,5,6,7,8],[a,s,d,f,g,h,h],[q,w,e,r,t,y]] MyListRandom = [] rand
我正在尝试从图中随机选择 n 个样本。为此,我使用 random.sample 函数创建了一个名为 X 的列表,如下所示: X= random.sample(range(graph.ecount())
我想知道在哪种情况下我可以将“主样本”或“子样本”或同时用于“响应断言”中的“文本响应”。 我用谷歌搜索,但尚未收到满意的答案。 帮助表示赞赏。 最佳答案 根据JMeter帮助, This is fo
我对使用 Hadoop 等大数据工具还很陌生。我想在 Yarn/或 Yarn Simulator 上执行公开可用的集群跟踪 ( https://github.com/google/cluster-da
我正在尝试从 Samsung Galaxy Nexus(Android 4.0)中尽可能快地读出传感器值。为此,我使用不同的传感器和采样率做了一些实验,并发现了一个非常奇怪的行为。当我仅使用 Acc-
首先,我要说的是,我对机器学习、kmeans 和 r 相当陌生,这个项目是一种了解更多相关知识的方法,也是向我们的 CIO 展示这些数据的方法,以便我可以在开发新的帮助台系统。 我有一个 60K 行的
我试图从我的查询集中抽取一些记录来提高性能,例如: from random import sample from my_app import MyModel my_models = MyModel.o
我正在阅读此主题:Typecasting variable with another typedef type_b *sample_b = (type_b *) ((void *) &sample);
首先,这可能是 Snakemake and pandas syntax 的副本.但是,我仍然很困惑,所以我想再解释一下。 在 Snakemake 中,我加载了一个包含多列的示例表。其中一列称为“Rea
你好,我是 python 新手,刚刚开始编写基本的 python 脚本。我决定编写一个密码生成器程序。我遇到了 random.sample() 和 itertools.combinations() 函
假设一个文件有很多原型(prototype)和函数对象声明代码: function Sample() { ... } Sample.prototype.method1 = () => { ..
我正在使用 AVAudioRecorder。我以 44100 采样率以 caf 格式 录制音频。就记录成功了。录制后,我想转换已录制的 caf 采样率为 11025 和 22050 的音频文件。是否可
我是一名优秀的程序员,十分优秀!