Keep getting error using sound command

10 views (last 30 days)
Joseph Guzzo
Joseph Guzzo on 30 Apr 2022
Answered: Walter Roberson on 30 Apr 2022
Error message: Error using sound (line 76) Only one- and two-channel audio supported.
Code:
clear; clc; close all;
fs = 44100;
% [h, n] = bpw(lower_cutoff, upper_cutoff, 501, 'type');
% Num 2
[h1, n1] = bpw(0, .627, 501, 'hamm');
[h2, n2] = bpw(.627, 1.25, 501, 'hann');
[h31, n31] = bpw(1.25, 1.88, 501, 'blac');
[h32, n32] = bpw(1.25, 1.88, 501, 'rect');
[h4, n4] = bpw(1.88, 2.51, 501, 'bart');
[h5, n5] = bpw(2.51, pi, 501, 'hann');
Av1 = 1;
Av2 = 1;
Av3 = 1;
Av4 = 1;
Av5 = 1;
im1 = h1 * Av1;
im2 = h2 * Av2;
im31 = h31 * Av3;
im32 = h32 * Av3;
im4 = h4 * Av4;
im5 = h5 * Av5;
TIR = im1 + im2 + im31 + im4 + im5;
% Num 3
audio = audioread("Undone_Clip.wav");
finalSound = conv2(audio, TIR);
sound(finalSound, fs);
  4 Comments
Star Strider
Star Strider on 30 Apr 2022
What’s ‘bpw’?
It’s not in the online documentation (R2022a).
.
Joseph Guzzo
Joseph Guzzo on 30 Apr 2022
Edited: Walter Roberson on 30 Apr 2022
It's a separate windowing function:
function [h,n] = bpw(wl, wu, len, win);
if mod(len,2) == 0
len = len + 1;
end
M = len-1;
n = [-M/2:M/2];
n2 = n+M/2;
h = (wu/pi)*sinc((wu*n)/pi) - (wl/pi)*sinc((wl*n)/pi);
if win == 'bart'
wn = 0.54 - 0.46*cos((2*pi*n2)/M);
elseif win == 'blac'
wn = 0.42 - 0.5*cos(2*pi*n2/M) + 0.08*cos(4*pi*n2/M);
elseif win == 'hamm'
wn = 0.54 - 0.46*cos((2*pi*n2)/M);
elseif win == 'hann'
wn = 0.5 - 0.5*cos((2*pi*n2)/M);
elseif win == 'rect'
wn = 0*n2+1;
else
disp('Not a valid window type! ==> Rect Window Used.');
wn = 0*n2+1;
end
h = h.*wn;
n = n2;

Sign in to comment.

Answers (2)

Image Analyst
Image Analyst on 30 Apr 2022
You sound doesn't have any signal in it. Here's an example:
[y, fs] = audioread('guitartune.wav');
size(y)
ans = 1×2
661500 1
You say your y "finalsound" "is a 1x2 that has values [537146, 502]"
That means you have 537,146 samples but 502 channels. the soundsc can only take 1 or 2 channels. Can you just play 2 of the channels?
stereoSound = finalSound(:, 1:2); % Extract first two channels and ignore remaining 499 channels.
soundsc(stereoSound);

Walter Roberson
Walter Roberson on 30 Apr 2022
audioread() returns something that has one row per sample, and as many columns as there are channels.
n = [-M/2:M/2];
That is a row vector, so your bpw() function returns a row vector.
finalSound = conv2(audio, TIR);
You are conv2() your N x channels with a row vector and you are not using any parameters to clip the size of the output of conv2() . When you do not use options such as 'same' or 'valid', conv2 is going to return a large output. conv2() is symmetric mathematically, so do not just think about convolving the audio with the TIR: you are also convolving the TIR with the audio, so you should expect something about the same width as the TIR as the output width.
You should probably be using conv() of the audio and a column vector TIR and should probably be using the 'same' option

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!