About error"The function 'analoginput' is no longer supported. Use the session-based interface."
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
function [signal,Fs,Nbits,time,nfft]=Record(refreshRate)
%%This function records audio from the microphone and writes the audio into
%%a wav file in Record Mode.
% Developed by Gabriel Brais Martinez Silvosa
% September, 2013
%%Acquisition settings
sampleRate = 48000; % Hz
N=24; %N-bit/ sample
ai = analoginput('winsound');
addchannel(ai,1);
sampleRate = setverify(ai, 'SampleRate', sampleRate);
ai.TimerPeriod = refreshRate;
spt = ceil(sampleRate * refreshRate);
ai.SamplesPerTrigger = spt;
nfft=spt;
set(ai,'SamplesPerTrigger',nfft);
%%
% Start Acquisition %%
start(ai);
[data time] = getdata(ai);
%
%Record Acquisition
audiowrite(data,sampleRate,N,'16amship.wav');
%
[signal,Fs,Nbits]=audioread('16amship.wav');
delete(ai);
clear ai
hi all~
When I run matlab I get the error "The function 'analoginput' is no longer supported. Use the session-based interface"(line 13)
Does anyone know how to correct this code?
thanks a lot !
0 Kommentare
Antworten (1)
Satwik
am 18 Mär. 2025
The error you are encountering is because the 'analoginput' function is part of the legacy interface for data acquisition in MATLAB. To address the issue you may refactor the code to use the 'DataAcquisition' object. Below is an updated version of the code using the 'DataAcquisition' interface:
function [signal, Fs, Nbits, time, nfft] = Record(refreshRate)
% Acquisition settings
sampleRate = 48000; % Hz
Nbits = 24; % N-bit/sample
nfft = ceil(sampleRate * refreshRate);
% Create a DataAcquisition object
dq = daq("directsound");
% Add an audio input channel
addinput(dq, "Audio1", 1, "Audio");
% Set the sample rate
dq.Rate = sampleRate;
% Set the duration of the recording
dq.DurationInSeconds = refreshRate;
% Start Acquisition
data = read(dq, seconds(refreshRate));
% Extract time and audio data
time = (0:length(data)-1) / dq.Rate;
audioData = data.Audio1;
% Record Acquisition
filename = '16amship.wav';
audiowrite(filename, audioData, sampleRate, 'BitsPerSample', Nbits);
% Read the recorded audio
[signal, Fs] = audioread(filename);
% The number of bits per sample is assumed to be the same as specified
% in the recording settings
Nbits = Nbits;
end
For more information on the 'DataAcquisition' interface, please refer to the following documentation:
I hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Audio I/O and Waveform Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!