- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在弄清楚如何继续进行我的项目时遇到了麻烦。简而言之,我正在尝试使用来自加速度计的数据来创建FM合成器,以实时更改FM和Pitch参数。
这是我基于的一些代码:
% X axis data will be used for fc parameter
% Y axis data will be used for fm parameter
function y = fmSynth(fc, dur, fm)
fs = 48000;
T = 1/fs; % seconds
t = 0:T:dur; % time vector
% FM parameters
Imin = 0;
Imax = 20;
I = t.*(Imax - Imin)/dur + Imin;
y = sin(2*pi*fc*t + I.*sin(2*pi*fm*t));
plot(t(1:10000), y(1:10000));
sound(y, fs);
% RealTimeAudioProcessor
%
% The RealTimeAudioProcessor object allows the user to process consecutive
% frames of audio in real-time (it lags real-time by the frame size plus
% hardware overhead). The object can easily be extended for any type of
% audio processing by overloading the stepImpl method in a derived class.
%
% Use:
%
% % Create the processor with a number of input channels, number of output
% % channels, sample rate, frame size, and device name.
% rtap = RealTimeAudioProcessor(1, 2, 48000, 256, 'Default');
%
% % Play. This will start *immediately* and block until all audio output is
% % complete.
% rtap.Play();
%
% % Release the audio resource for others (be nice).
% rtap.release();
%
% % The RTAP records some timing values while playing. Show the results.
% rtap.Analyze();
%
% It is recommended that an ASIO audio driver with appropriate hardware be
% used for the audio interface. (ASIO is an open standard from Steinberg
% Media Technologies GmbH).
%
% Tucker McClure @ The MathWorks
% Copyright 2012 The MathWorks, Inc.
classdef RealTimeAudioProcessor < matlab.system.System
properties (Nontunable, Access = protected)
% Settings
frame_size = 256; % Number of samples in the buffer
sample_rate = 48000; % Number of samples per second [samples/s]
end_time = inf; % Number of seconds until playback stops [s]
in_channels = 2; % Number of input channels
out_channels = 2; % Number of output channels
device_name = 'Default';
draw_rate = 0.02; % Rate to update graphics [s]
% Derived quantities
time_step; % Length of frame [s]
time_window; % Array of time values from [0 time_step) [s]
% Device interfaces
ap; % AudioPlayer object to manage output
ar; % AudioRecorder object to manage input
end
properties
% UI handles
figure_handle; % Handle of UI figure
text_handle; % Handle of text in figure
samples_until_draw = 0; % Samples left before updating GUI
% Analysis stuff
max_in_step_time = 0;
max_process_step_time = 0;
max_out_step_time = 0;
end
methods
% Constructor; creates the RTAP and its internal dsp.AudioPlayer.
% After creation, the RTAP is ready to play.
function rtap = RealTimeAudioProcessor(ins, outs, Fs, w, device)
fprintf('Initializing a RealTimeAudioProcessor on %s... ', ...
device);
% Set some internals.
rtap.frame_size = w;
rtap.sample_rate = Fs;
rtap.in_channels = ins;
rtap.out_channels = outs;
rtap.device_name = device;
% Calculate the period.
rtap.time_step = w/Fs;
% Create all the time values for a window.
rtap.time_window = (0:w-1)'/Fs;
% Ok, we set everything up.
fprintf('done.\n');
% Display latency to user.
fprintf('Minimum latency due to buffering: %5.1fms\n', ...
1000 * rtap.time_step);
end
% Enter a quasi-real-time loop in which audio is acquired/generated
% and plugged into the output buffer (if a buffer exists).
function Play(rtap)
% If not set up, setup.
if ~rtap.isLocked
setup(rtap, ...
zeros(rtap.frame_size, 1), ...
zeros(rtap.frame_size, rtap.in_channels));
% Otherwise, if we need a new figure, open one.
elseif ~ishandle(rtap.figure_handle)
rtap.GenerateFigure();
end
% Keep track of time since 'tic'.
t_clock = 0;
% Keep track of how much material we've played since 'tic'.
% At t_clock, this should reach to t_clock + time_step.
t_played = 0;
% Initialize the input.
in = zeros(rtap.frame_size, rtap.in_channels); %#ok<NASGU>
% Start a timer.
tic();
% Loop until the end time has been reached or the figure has
% been closed.
while t_clock < rtap.end_time && ishandle(rtap.figure_handle)
% Play steps until we're |buffer| into the future.
if t_played < t_clock + rtap.time_step
% Create the times for this frame.
time = t_played + rtap.time_window;
% Get the input for one frame.
if rtap.in_channels > 0
step_timer = tic();
in = step(rtap.ar);
rtap.max_in_step_time = ...
max(rtap.max_in_step_time, toc(step_timer));
else
in = zeros(rtap.frame_size, rtap.in_channels);
end
% Process one frame.
step_timer = tic();
out = step(rtap, time, in);
rtap.max_process_step_time = ...
max(rtap.max_process_step_time, toc(step_timer));
% Step the AudioPlayer. Time the step for analysis
% purposes.
if rtap.out_channels > 0
step_timer = tic();
step(rtap.ap, out);
rtap.max_out_step_time = ...
max(rtap.max_out_step_time, toc(step_timer));
end
% Update the time.
t_played = t_played + rtap.time_step;
end
% Release focus so that figure callbacks can occur.
if rtap.samples_until_draw <= 0
drawnow();
rtap.UpdateGraphics();
rtap.samples_until_draw = ...
rtap.sample_rate * rtap.draw_rate;
else
rtap.samples_until_draw = ...
rtap.samples_until_draw - rtap.frame_size;
end
% Update the clock.
t_clock = toc();
end
% Wait for audio to end before exiting. We may have just
% written out a frame, and there may have already been a frame
% in the buffer, so chill for 2 frames.
pause(2*rtap.time_step);
end
% Display timing results from last play.
function Analyze(rtap)
fprintf(['Results for last play:\n', ...
'Maximum input step time: %5.1fms\n', ...
'Maximum process step time: %5.1fms\n', ...
'Maximum output step time: %5.1fms\n'], ...
1000*rtap.max_in_step_time, ...
1000*rtap.max_process_step_time, ...
1000*rtap.max_out_step_time);
end
end
methods (Access = protected)
% Set up the internal System Objects and the figure.
function setupImpl(rtap, ~, ~)
% Create the AudioPlayer.
if rtap.out_channels > 0
rtap.ap = dsp.AudioPlayer(...
'DeviceName', rtap.device_name, ...
'BufferSizeSource', 'Property', ...
'BufferSize', rtap.frame_size, ...
'QueueDuration', 0, ...
'SampleRate', rtap.sample_rate);
% Start with silence. This initializes the AudioPlayer to
% the window size and number of channels and takes longer
% than any subsequent call will take.
step(rtap.ap, zeros(rtap.frame_size, rtap.out_channels));
end
% Create the AudioRecorder (if requested).
if rtap.in_channels > 0
rtap.ar = dsp.AudioRecorder(...
'DeviceName', 'Default', ...
'SampleRate', rtap.sample_rate, ...
'BufferSizeSource', 'Property', ...
'BufferSize', rtap.frame_size, ...
'SamplesPerFrame', rtap.frame_size, ...
'QueueDuration', 0, ...
'OutputDataType', 'double', ...
'NumChannels', rtap.in_channels);
% Initialize the input.
step(rtap.ar);
end
if ishandle(rtap.figure_handle)
close(rtap.figure_handle);
end
rtap.GenerateFigure();
% Draw it.
drawnow();
% Chill out for a second before rushing forward with sound.
pause(rtap.time_step);
end
% Process one frame of audio, given the inputs corresponding to the
% frame and the times.
function out = stepImpl(rtap, time, in) %#ok<INUSD>
out = zeros(rtap.frame_size, rtap.out_channels);
end
% Specify that the step requires 2 inputs.
function n = getNumInputsImpl(~)
n = 2;
end
% Specify that the step requires 1 output.
function n = getNumOutputsImpl(~)
n = 1;
end
% Clean up the AudioPlayer.
function releaseImpl(rtap)
% Release the dsp.AudioPlayer resource.
if rtap.out_channels > 0
release(rtap.ap);
end
% Release the dsp.AudioRecorder too.
if rtap.in_channels > 0
release(rtap.ar);
end
% Close the figure if it's still open.
if ishandle(rtap.figure_handle)
set(rtap.text_handle, 'String', 'Closing.');
close(rtap.figure_handle);
rtap.figure_handle = [];
end
end
% Generate a figure that stays open with updates for the user.
% Closing this figure ends playback.
function GenerateFigure(rtap)
% Get the screen dimensions for centering the figure.
screen_dims = get(0, 'ScreenSize');
figure_width_height = [640 160];
figure_dims = [floor(0.5*( screen_dims(3:4) ...
- figure_width_height)) ...
figure_width_height];
% Generate a figure.
rtap.figure_handle = figure(...
'Name', 'Real-Time Audio Processor Controller',...
'NumberTitle', 'off', ...
'Position', figure_dims);
axes('Position', [0 0 1 1], ...
'Visible', 'off');
rtap.text_handle = text(0.5, 0.5, ...
'Real Time Audio Processor is active.', ...
'HorizontalAlignment', 'center', ...
'VerticalAlignment', 'middle', ...
'Interpreter', 'none');
end
function UpdateGraphics(rtap) %#ok<*MANU>
end
end
end
最佳答案
一个不使用OOP的粗略解决方案是将声音生成代码放在一个循环中,例如在伪代码中:
Fs = ...;
while 1
% generate your signal here ...
signal = ....
% ...
wavplay(signal,Fs,'sync')
end
关于matlab - 实时音频调制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18434967/
Closed. This question is opinion-based。它当前不接受答案。 想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。 2年前关闭。
我想显示我的网站上所有用户都在线(实时;就像任何聊天模块一样)。我正在使用下面提到的脚本来执行此操作。 HTML: Javascript: var doClose = false; documen
有什么方法可以知道 Algolia 何时成功处理了排队作业,或者与上次重新索引相比,Algolia 是否索引了新文档? 我们希望建立一个系统,每当新文档被索引时,浏览网站的用户都会收到实时更新警告,并
构建将在“桌面”而不是浏览器中运行的 Java 应用程序的推荐策略是什么。该应用程序的特点是: 1. Multiple application instances would be running o
这是场景: 我正在编写一个医疗相关程序,可以在没有连接的情况下使用。当采取某些措施时,程序会将时间写入CoreData记录。 这就是问题所在,如果他们的设备将时间设置为比实际时间早的时间。那将是一个大
我有: $(document).ready(function () { $(".div1, .div2, .div3, .div4, .div5").draggable();
我有以下 jquery 代码: $("a[id*='Add_']").live('click', function() { //Get parentID to add to. var
我有一个 jsp 文件,其中包含一个表单。提交表单会调用处理发送的数据的 servlet。我希望当我点击提交按钮时,一个文本区域被跨越并且应该实时显示我的应用程序的日志。我正在使用 Tomcat 7。
我编辑了我的问题,我在 Default.aspx 页面中有一个提交按钮和文本框。我打开两个窗口Default.aspx。我想在这个窗口中向文本框输入文本并按提交,其他窗口将实时更新文本框。 请帮助我!
我用 php 创建了一个小型 CMS,如果其他用户在线或离线,我想显示已登录的用户。 目前,我只创建一个查询请求,但这不会一直更新。我希望用户在发生某些事情时立即看到更改。我正在寻找一个类似于 fac
我有以下问题需要解决。我必须构建一个图形查看器来查看海量数据集。 我们有一些特定格式的文件,其中包含数百万条代表实验结果的记录。每条记录代表大图上的一个样本点。我见过的最大的文件有 4370 万条记录
我最近完成了申请,但遇到了一个大问题。我一次只需要允许 1 个用户访问它。每个用户每次都可以访问一个索引页面和“开始”按钮。当用户点击开始时,应用程序锁定,其他人需要等到用户完成。当用户关闭选项卡/浏
我是 Android 开发新手。我正在寻找任何将音高变换应用到输出声音(实时)的方法。但我找不到任何起点。 我找到了这个 topic但我仍然不知道如何应用它。 有什么建议吗? 最佳答案 一般来说,该算
背景 用户计算机上的桌面应用程序从调制解调器获取电话号码,并在接到电话后将其发送到 PHP 脚本。目前,我可以通过 PHP 在指定端口上接收数据/数据包。然后我有一个连接到 411 数据库并返回指定电
很抱歉提出抽象问题,但我正在寻找一些关于在循环中执行一些等效操作的应用程序类型的示例/建议/文章,并且循环的每次迭代都应该在特定时间部分公开其结果(例如, 10 秒)。 我的应用程序在外部 WCF 服
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: What specifically are wall-clock-time, user-cpu-time,
我最近遇到了一个叫做 LiveChart 的工具,决定试用一下。 不幸的是,我在弄清楚如何实时更新图表值时遇到了一些问题。我很确定有一种干净正确的方法可以做到这一点,但我找不到它。 我希望能够通过 p
我正在实现实时 flutter 库 https://pub.dartlang.org/packages/true_time 遇到错误 W/DiskCacheClient(26153): Cannot
我一直在使用 instagram 的实时推送 api ( http://instagram.com/developer/realtime/ ) 来获取特定位置的更新。我使用“半径”的最大可能值,即 5
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我是一名优秀的程序员,十分优秀!