manually creating my own audio file
Show older comments
I followed the instructions in MATLAB website audiowrite, to create an audio wav file. https://www.mathworks.com/help/matlab/ref/audiowrite.html#btjqac7-4
I imported handel.mat etc., and played it back perfectly with, sound(y,Fs);
I then did the same thing for a short music wav file I have, a recording of an E tone simulation of a guitar string, and it played back perfectly as well.
So now I thought I could manually create an array that would create the same sound. I create a short program to create a 44100x2 array so that I would have one second of sound. I displayed the first few rows of the y array I created from the E tone.wav file, "([y,Fs] = audioread('E tone.wav');", used the first value in the array as my data value. This was 9.1553e-05. I alternated between - and + values for each row, as seen in the original wav file
So now I have a 44100x2 array of 9.1553e-05 and -9.1553e-05.
When I use "sound" to play it, I get no sound.
I've review many pages online trying to find out what's going on, but I can't figure out what I'm missing, not seeing.
A chose a different value within the working audio matrix and still nothing.
Does any see what I'm missing?
All help appreciated.
5 Comments
Star Strider
on 26 Jan 2018
‘Does any see what I'm missing?’
That would be much easier if we could see the code you use to create it.
Sure. FYI, I am just learning MATLAB so my code was rough and inefficient, but affective for what I'm trying to do.
Here's what I did as commands (excuse my syntax, not sure proper format for posting commands & code):
>> clear
>> [y,Fs]=audioread('e note.wav');
>> sound(y,Fs)
>> y(1:5,1:2)
ans =
1.0e-03 *
-0.0305 0.0305
0.0916 -0.0305
-0.1221 0.0305
0.1221 -0.0610
-0.1526 0.0305
>> x=ones(44100,2);
>> z=thehardway3(x);
k =
44100 2
>> z(1:5,1:2)
ans =
1.0e-03 *
0.1221 0.1221
-0.1221 -0.1221
0.1221 0.1221
-0.1221 -0.1221
0.1221 0.1221
>>
And Here's the code:
function [x] = thehardway(y)
k=size(y)
for j=1:2
for i=(1:k(1,1))
if mod(i,2)==0
y(i,j) = y(i,j)*(-1)*(.0001221);
end
if mod(i,2)~=0
y(i,j) = y(i,j)*(.0001221);
end
end
x=y;
end
I didn't expect an e tone, just noise, but I get nothing, silence. I thought perhaps its in varying the data values, but shouldn't this single values give me at least a noise?
@Williah: I've formatted your code. You can do this by your own, see http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup#answer_18099
You have posted the code of "thehardway", but call "thehardway3".
Williah
on 27 Jan 2018
Answers (1)
The code can be simplified:
function x = thehardway(y)
x = repmat(0.0001221, size(y));
x(2:2:end, :) = -x(2:2:end, :);
end
You could here this, if you increase the volume by the factor 1000:
sound(x * 1000);
2 Comments
Williah's comment moved here (please post comments in the section for comments, not as an answer. Stephen has moved two other comments of you already):
Thanks for the code rewrite, much more efficient (and informative :) ).
Interesting result. When I used sound, multiplying by 1000, I hear 2 pops, like electric sparks. I'm going to play with the data values to see what I learn.
One more question. What does the data, 0.1221*e-03, represent? What is the unit of measurement of this data?
Jan
on 28 Jan 2018
@Williah: I have no idea, what 0.0001221 represents. I've taken it from your code example. There is no unit for these data. For data of type double, sounds use a range of [-1.0, +1.0]. For a physical meaning, you have to consider the amplifier and speakers.
Categories
Find more on Audio and Video Data in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!